clean comments
This commit is contained in:
parent
8c1f3d7a40
commit
565913903a
@ -22,6 +22,6 @@ public class MembershipCheck {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public String getChecked() {
|
public String getChecked() {
|
||||||
return user != null && group != null && user.getGroups().contains(group.getDn()) ? "checked" : ""; //$NON-NLS-1$ //$NON-NLS-2$
|
return user != null && group != null && user.getGroups().contains(group.getDn()) ? "checked" : "";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -111,7 +111,7 @@ public class User implements Serializable, LDAPBean {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return getFirstname() + " " + getLastname() + " (" + getLogin() + ", " + getEmail() + ")"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
|
return getFirstname() + " " + getLastname() + " (" + getLogin() + ", " + getEmail() + ")";
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -76,7 +76,11 @@ public class DirectoryServiceRunner {
|
|||||||
final CacheService cacheService = service.getCacheService();
|
final CacheService cacheService = service.getCacheService();
|
||||||
final Cache cache = cacheService.getCache("dnCache");
|
final Cache cache = cacheService.getCache("dnCache");
|
||||||
final DefaultDnFactory defaultDnFactory = new DefaultDnFactory(schemaManager, cache);
|
final DefaultDnFactory defaultDnFactory = new DefaultDnFactory(schemaManager, cache);
|
||||||
final Partition partition = partitionFactory.createPartition(schemaManager, defaultDnFactory, partitionId, dnString, 400, new File("ldap-data." + Double.valueOf(Math.random()).hashCode()));
|
final Partition partition =
|
||||||
|
partitionFactory.createPartition(
|
||||||
|
schemaManager, defaultDnFactory, partitionId, dnString, 400,
|
||||||
|
new File("ldap-data." + Double.valueOf(Math.random()).hashCode())
|
||||||
|
);
|
||||||
service.addPartition(partition);
|
service.addPartition(partition);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -25,13 +25,13 @@ public class GroupsDAO {
|
|||||||
public SortedMap<String, Group> loadGroups(final SortedMap<String, User> users) throws LDAPSessionException {
|
public SortedMap<String, Group> loadGroups(final SortedMap<String, User> users) throws LDAPSessionException {
|
||||||
final SortedMap<String, Group> list;
|
final SortedMap<String, Group> list;
|
||||||
list = new TreeMap<>();
|
list = new TreeMap<>();
|
||||||
final List<SearchResult> searchResult = session.search("ou=groups"); //$NON-NLS-1$
|
final List<SearchResult> searchResult = session.search("ou=groups");
|
||||||
for (final SearchResult result : searchResult) {
|
for (final SearchResult result : searchResult) {
|
||||||
final Attributes attribs = result.getAttributes();
|
final Attributes attribs = result.getAttributes();
|
||||||
final Group grp = new Group();
|
final Group grp = new Group();
|
||||||
grp.setName(session.getStringValue(attribs, "cn")); //$NON-NLS-1$
|
grp.setName(session.getStringValue(attribs, "cn"));
|
||||||
grp.setDn(result.getNameInNamespace());
|
grp.setDn(result.getNameInNamespace());
|
||||||
final List<String> listOfMembers = session.getListOfValues(attribs, "uniqueMember"); //$NON-NLS-1$
|
final List<String> listOfMembers = session.getListOfValues(attribs, "uniqueMember");
|
||||||
final String dn = grp.getDn();
|
final String dn = grp.getDn();
|
||||||
listOfMembers.stream().map((userDN) -> users.get(userDN)).map((user) -> user.getGroups()).forEachOrdered((groups) -> {
|
listOfMembers.stream().map((userDN) -> users.get(userDN)).map((user) -> user.getGroups()).forEachOrdered((groups) -> {
|
||||||
groups.add(dn);
|
groups.add(dn);
|
||||||
@ -47,29 +47,29 @@ public class GroupsDAO {
|
|||||||
final String name = grp.getName();
|
final String name = grp.getName();
|
||||||
assert name != null;
|
assert name != null;
|
||||||
final BasicAttributes attributes = new BasicAttributes();
|
final BasicAttributes attributes = new BasicAttributes();
|
||||||
final BasicAttribute objClass = new BasicAttribute("objectClass"); //$NON-NLS-1$
|
final BasicAttribute objClass = new BasicAttribute("objectClass");
|
||||||
objClass.add("top"); //$NON-NLS-1$
|
objClass.add("top");
|
||||||
objClass.add("groupOfUniqueNames"); //$NON-NLS-1$
|
objClass.add("groupOfUniqueNames");
|
||||||
attributes.put(objClass);
|
attributes.put(objClass);
|
||||||
attributes.put("cn", name); //$NON-NLS-1$
|
attributes.put("cn", name);
|
||||||
final List<String> uniqueMembers = grp.getMembers();
|
final List<String> uniqueMembers = grp.getMembers();
|
||||||
final BasicAttribute uniqMembers = new BasicAttribute("uniqueMember"); //$NON-NLS-1$
|
final BasicAttribute uniqMembers = new BasicAttribute("uniqueMember");
|
||||||
if (uniqueMembers != null && uniqueMembers.size() > 0) {
|
if (uniqueMembers != null && uniqueMembers.size() > 0) {
|
||||||
uniqueMembers.forEach((dn) -> {
|
uniqueMembers.forEach((dn) -> {
|
||||||
uniqMembers.add(dn);
|
uniqMembers.add(dn);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
attributes.put(uniqMembers);
|
attributes.put(uniqMembers);
|
||||||
final String dn = session.createSubcontext("cn=${cn},ou=groups".replace("${cn}", name), attributes); //$NON-NLS-1$ //$NON-NLS-2$
|
final String dn = session.createSubcontext("cn=${cn},ou=groups".replace("${cn}", name), attributes);
|
||||||
grp.setDn(dn);
|
grp.setDn(dn);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Group readGroup(final String dn, final SortedMap<String, User> users) throws LDAPSessionException {
|
public Group readGroup(final String dn, final SortedMap<String, User> users) throws LDAPSessionException {
|
||||||
final Attributes attribs = session.getAttributes(dn.substring(0, dn.indexOf("ou=groups") + 9)); //$NON-NLS-1$
|
final Attributes attribs = session.getAttributes(dn.substring(0, dn.indexOf("ou=groups") + 9));
|
||||||
final Group grp = new Group();
|
final Group grp = new Group();
|
||||||
grp.setDn(dn);
|
grp.setDn(dn);
|
||||||
grp.setName(session.getStringValue(attribs, "cn")); //$NON-NLS-1$
|
grp.setName(session.getStringValue(attribs, "cn"));
|
||||||
final List<String> listOfMembers = session.getListOfValues(attribs, "uniqueMember"); //$NON-NLS-1$
|
final List<String> listOfMembers = session.getListOfValues(attribs, "uniqueMember");
|
||||||
listOfMembers.stream().map((userDN) -> users.get(userDN)).map((user) -> user.getGroups()).forEachOrdered((groups) -> {
|
listOfMembers.stream().map((userDN) -> users.get(userDN)).map((user) -> user.getGroups()).forEachOrdered((groups) -> {
|
||||||
groups.add(dn);
|
groups.add(dn);
|
||||||
});
|
});
|
||||||
@ -84,22 +84,22 @@ public class GroupsDAO {
|
|||||||
if (grp.getMembers().isEmpty()) {
|
if (grp.getMembers().isEmpty()) {
|
||||||
throw new NoGroupMembersException(name);
|
throw new NoGroupMembersException(name);
|
||||||
}
|
}
|
||||||
final BasicAttribute membersOfAttrib = new BasicAttribute("uniqueMember"); //$NON-NLS-1$
|
final BasicAttribute membersOfAttrib = new BasicAttribute("uniqueMember");
|
||||||
grp.getMembers().forEach((memberDN) -> {
|
grp.getMembers().forEach((memberDN) -> {
|
||||||
membersOfAttrib.add(memberDN);
|
membersOfAttrib.add(memberDN);
|
||||||
});
|
});
|
||||||
final ModificationItem modificationItem = new ModificationItem(DirContext.REPLACE_ATTRIBUTE, membersOfAttrib);
|
final ModificationItem modificationItem = new ModificationItem(DirContext.REPLACE_ATTRIBUTE, membersOfAttrib);
|
||||||
session.modifyAttributes("cn=${cn},ou=groups".replace("${cn}", name), new ModificationItem[]{modificationItem}); //$NON-NLS-1$ //$NON-NLS-2$
|
session.modifyAttributes("cn=${cn},ou=groups".replace("${cn}", name), new ModificationItem[]{modificationItem});
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updateMemberships(final User usr) throws LDAPSessionException, NoGroupMembersException {
|
public void updateMemberships(final User usr) throws LDAPSessionException, NoGroupMembersException {
|
||||||
final List<SearchResult> searchResult = session.search("ou=groups"); //$NON-NLS-1$
|
final List<SearchResult> searchResult = session.search("ou=groups");
|
||||||
for (final SearchResult result : searchResult) {
|
for (final SearchResult result : searchResult) {
|
||||||
final Attributes attribs = result.getAttributes();
|
final Attributes attribs = result.getAttributes();
|
||||||
final Group grp = new Group();
|
final Group grp = new Group();
|
||||||
grp.setName(session.getStringValue(attribs, "cn")); //$NON-NLS-1$
|
grp.setName(session.getStringValue(attribs, "cn"));
|
||||||
grp.setDn(result.getNameInNamespace());
|
grp.setDn(result.getNameInNamespace());
|
||||||
final List<String> listOfGroupMembers = session.getListOfValues(attribs, "uniqueMember"); //$NON-NLS-1$
|
final List<String> listOfGroupMembers = session.getListOfValues(attribs, "uniqueMember");
|
||||||
grp.setMembers(listOfGroupMembers);
|
grp.setMembers(listOfGroupMembers);
|
||||||
final List<String> listOfUserMemberships = usr.getGroups();
|
final List<String> listOfUserMemberships = usr.getGroups();
|
||||||
if (listOfGroupMembers.contains(usr.getDn()) && !listOfUserMemberships.contains(grp.getDn())) {
|
if (listOfGroupMembers.contains(usr.getDn()) && !listOfUserMemberships.contains(grp.getDn())) {
|
||||||
@ -115,7 +115,7 @@ public class GroupsDAO {
|
|||||||
|
|
||||||
public void delete(final Group grp) throws LDAPSessionException {
|
public void delete(final Group grp) throws LDAPSessionException {
|
||||||
assert grp != null;
|
assert grp != null;
|
||||||
session.unbind("cn=${id},ou=groups", grp.getName()); //$NON-NLS-1$
|
session.unbind("cn=${id},ou=groups", grp.getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -24,10 +24,10 @@ public class LDAPSession {
|
|||||||
|
|
||||||
public LDAPSession(final String providerURL, final String principal, final String password) throws LDAPSessionException {
|
public LDAPSession(final String providerURL, final String principal, final String password) throws LDAPSessionException {
|
||||||
final Properties env = new Properties();
|
final Properties env = new Properties();
|
||||||
env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory"); //$NON-NLS-1$
|
env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
|
||||||
env.put("com.sun.jndi.ldap.connect.pool", "true"); //$NON-NLS-1$ //$NON-NLS-2$
|
env.put("com.sun.jndi.ldap.connect.pool", "true");
|
||||||
env.put(Context.PROVIDER_URL, providerURL);
|
env.put(Context.PROVIDER_URL, providerURL);
|
||||||
env.put(Context.SECURITY_AUTHENTICATION, "simple"); //$NON-NLS-1$
|
env.put(Context.SECURITY_AUTHENTICATION, "simple");
|
||||||
env.put(Context.SECURITY_PRINCIPAL, principal);
|
env.put(Context.SECURITY_PRINCIPAL, principal);
|
||||||
env.put(Context.SECURITY_CREDENTIALS, password);
|
env.put(Context.SECURITY_CREDENTIALS, password);
|
||||||
try {
|
try {
|
||||||
@ -140,7 +140,7 @@ public class LDAPSession {
|
|||||||
|
|
||||||
public void unbind(final String searchPattern, final String id) throws LDAPSessionException {
|
public void unbind(final String searchPattern, final String id) throws LDAPSessionException {
|
||||||
try {
|
try {
|
||||||
ctx.unbind(searchPattern.replace("${id}", id)); //$NON-NLS-1$
|
ctx.unbind(searchPattern.replace("${id}", id));
|
||||||
} catch (NamingException e) {
|
} catch (NamingException e) {
|
||||||
throw new LDAPSessionException(e);
|
throw new LDAPSessionException(e);
|
||||||
}
|
}
|
||||||
@ -156,12 +156,12 @@ public class LDAPSession {
|
|||||||
private void createOrgUnitNodesIfNotExist() throws LDAPSessionException {
|
private void createOrgUnitNodesIfNotExist() throws LDAPSessionException {
|
||||||
try {
|
try {
|
||||||
final BasicAttributes usersAttributes = new BasicAttributes();
|
final BasicAttributes usersAttributes = new BasicAttributes();
|
||||||
final BasicAttribute usersObjClass = new BasicAttribute("objectClass"); //$NON-NLS-1$
|
final BasicAttribute usersObjClass = new BasicAttribute("objectClass");
|
||||||
usersObjClass.add("top"); //$NON-NLS-1$
|
usersObjClass.add("top");
|
||||||
usersObjClass.add("organizationalUnit"); //$NON-NLS-1$
|
usersObjClass.add("organizationalUnit");
|
||||||
usersAttributes.put(usersObjClass);
|
usersAttributes.put(usersObjClass);
|
||||||
usersAttributes.put("ou", "users"); //$NON-NLS-1$ //$NON-NLS-2$
|
usersAttributes.put("ou", "users");
|
||||||
ctx.createSubcontext("ou=users", usersAttributes); //$NON-NLS-1$
|
ctx.createSubcontext("ou=users", usersAttributes);
|
||||||
} catch (NamingException e) {
|
} catch (NamingException e) {
|
||||||
if (!((e instanceof NameAlreadyBoundException) || (e instanceof NoPermissionException))) {
|
if (!((e instanceof NameAlreadyBoundException) || (e instanceof NoPermissionException))) {
|
||||||
throw new LDAPSessionException(e);
|
throw new LDAPSessionException(e);
|
||||||
@ -169,12 +169,12 @@ public class LDAPSession {
|
|||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
final BasicAttributes groupsAttributes = new BasicAttributes();
|
final BasicAttributes groupsAttributes = new BasicAttributes();
|
||||||
final BasicAttribute groupsObjClass = new BasicAttribute("objectClass"); //$NON-NLS-1$
|
final BasicAttribute groupsObjClass = new BasicAttribute("objectClass");
|
||||||
groupsObjClass.add("top"); //$NON-NLS-1$
|
groupsObjClass.add("top");
|
||||||
groupsObjClass.add("organizationalUnit"); //$NON-NLS-1$
|
groupsObjClass.add("organizationalUnit");
|
||||||
groupsAttributes.put(groupsObjClass);
|
groupsAttributes.put(groupsObjClass);
|
||||||
groupsAttributes.put("ou", "groups"); //$NON-NLS-1$ //$NON-NLS-2$
|
groupsAttributes.put("ou", "groups");
|
||||||
ctx.createSubcontext("ou=groups", groupsAttributes); //$NON-NLS-1$
|
ctx.createSubcontext("ou=groups", groupsAttributes);
|
||||||
} catch (NamingException e) {
|
} catch (NamingException e) {
|
||||||
if (!((e instanceof NameAlreadyBoundException) || (e instanceof NoPermissionException))) {
|
if (!((e instanceof NameAlreadyBoundException) || (e instanceof NoPermissionException))) {
|
||||||
throw new LDAPSessionException(e);
|
throw new LDAPSessionException(e);
|
||||||
|
@ -24,18 +24,18 @@ public class UsersDAO {
|
|||||||
|
|
||||||
public SortedMap<String, User> loadUsers() throws LDAPSessionException {
|
public SortedMap<String, User> loadUsers() throws LDAPSessionException {
|
||||||
final SortedMap<String, User> usersHash = new TreeMap<String, User>();
|
final SortedMap<String, User> usersHash = new TreeMap<String, User>();
|
||||||
final List<SearchResult> enumeration = session.search("ou=users"); //$NON-NLS-1$
|
final List<SearchResult> enumeration = session.search("ou=users");
|
||||||
for (SearchResult result : enumeration) {
|
for (SearchResult result : enumeration) {
|
||||||
final Attributes attribs = result.getAttributes();
|
final Attributes attribs = result.getAttributes();
|
||||||
final User usr = new User();
|
final User usr = new User();
|
||||||
usr.setFirstname(session.getStringValue(attribs, "givenName")); //$NON-NLS-1$
|
usr.setFirstname(session.getStringValue(attribs, "givenName"));
|
||||||
usr.setLastname(session.getStringValue(attribs, "sn")); //$NON-NLS-1$
|
usr.setLastname(session.getStringValue(attribs, "sn"));
|
||||||
usr.setEmail(session.getStringValue(attribs, "mail")); //$NON-NLS-1$
|
usr.setEmail(session.getStringValue(attribs, "mail"));
|
||||||
usr.setLogin(session.getStringValue(attribs, "uid")); //$NON-NLS-1$
|
usr.setLogin(session.getStringValue(attribs, "uid"));
|
||||||
usr.setPhone(session.getStringValue(attribs, "telephoneNumber")); //$NON-NLS-1$
|
usr.setPhone(session.getStringValue(attribs, "telephoneNumber"));
|
||||||
usr.setMobile(session.getStringValue(attribs, "mobile")); //$NON-NLS-1$
|
usr.setMobile(session.getStringValue(attribs, "mobile"));
|
||||||
usr.setDisplayname(session.getStringValue(attribs, "displayName")); //$NON-NLS-1$
|
usr.setDisplayname(session.getStringValue(attribs, "displayName"));
|
||||||
usr.setLogin(session.getStringValue(attribs, "uid")); //$NON-NLS-1$
|
usr.setLogin(session.getStringValue(attribs, "uid"));
|
||||||
usr.setDn(result.getNameInNamespace());
|
usr.setDn(result.getNameInNamespace());
|
||||||
usersHash.put(usr.getDn(), usr);
|
usersHash.put(usr.getDn(), usr);
|
||||||
}
|
}
|
||||||
@ -46,65 +46,65 @@ public class UsersDAO {
|
|||||||
assert usr != null;
|
assert usr != null;
|
||||||
final String uid = usr.getLogin();
|
final String uid = usr.getLogin();
|
||||||
if (!hasValue(uid)) {
|
if (!hasValue(uid)) {
|
||||||
throw new RequiredAttributeException("uid"); //$NON-NLS-1$
|
throw new RequiredAttributeException("uid");
|
||||||
}
|
}
|
||||||
assert uid != null;
|
assert uid != null;
|
||||||
final BasicAttributes attributes = new BasicAttributes();
|
final BasicAttributes attributes = new BasicAttributes();
|
||||||
final BasicAttribute objClass = new BasicAttribute("objectClass"); //$NON-NLS-1$
|
final BasicAttribute objClass = new BasicAttribute("objectClass");
|
||||||
objClass.add("top"); //$NON-NLS-1$
|
objClass.add("top");
|
||||||
objClass.add("person"); //$NON-NLS-1$
|
objClass.add("person");
|
||||||
objClass.add("organizationalPerson"); //$NON-NLS-1$
|
objClass.add("organizationalPerson");
|
||||||
objClass.add("inetOrgPerson"); //$NON-NLS-1$
|
objClass.add("inetOrgPerson");
|
||||||
attributes.put(objClass);
|
attributes.put(objClass);
|
||||||
final String firstName = usr.getFirstname();
|
final String firstName = usr.getFirstname();
|
||||||
if (hasValue(firstName)) {
|
if (hasValue(firstName)) {
|
||||||
attributes.put("givenName", firstName); //$NON-NLS-1$
|
attributes.put("givenName", firstName);
|
||||||
}
|
}
|
||||||
final String lastname = usr.getLastname();
|
final String lastname = usr.getLastname();
|
||||||
if (!hasValue(lastname)) {
|
if (!hasValue(lastname)) {
|
||||||
throw new RequiredAttributeException("lastname"); //$NON-NLS-1$
|
throw new RequiredAttributeException("lastname");
|
||||||
}
|
}
|
||||||
attributes.put("sn", lastname); //$NON-NLS-1$
|
attributes.put("sn", lastname);
|
||||||
final String email = usr.getEmail();
|
final String email = usr.getEmail();
|
||||||
if (hasValue(email)) {
|
if (hasValue(email)) {
|
||||||
attributes.put("mail", email); //$NON-NLS-1$
|
attributes.put("mail", email);
|
||||||
}
|
}
|
||||||
attributes.put("uid", uid); //$NON-NLS-1$
|
attributes.put("uid", uid);
|
||||||
attributes.put("cn", uid); //$NON-NLS-1$
|
attributes.put("cn", uid);
|
||||||
final String telephone = usr.getPhone();
|
final String telephone = usr.getPhone();
|
||||||
if (hasValue(telephone)) {
|
if (hasValue(telephone)) {
|
||||||
attributes.put("telephoneNumber", telephone); //$NON-NLS-1$
|
attributes.put("telephoneNumber", telephone);
|
||||||
}
|
}
|
||||||
final String mobile = usr.getMobile();
|
final String mobile = usr.getMobile();
|
||||||
if (hasValue(mobile)) {
|
if (hasValue(mobile)) {
|
||||||
attributes.put("mobile", mobile); //$NON-NLS-1$
|
attributes.put("mobile", mobile);
|
||||||
}
|
}
|
||||||
final String comment = usr.getDisplayname();
|
final String comment = usr.getDisplayname();
|
||||||
if (hasValue(comment)) {
|
if (hasValue(comment)) {
|
||||||
attributes.put("displayName", comment); //$NON-NLS-1$
|
attributes.put("displayName", comment);
|
||||||
} else {
|
} else {
|
||||||
attributes.put("displayName", firstName == null ? lastname : lastname + ", " + firstName); //$NON-NLS-1$ //$NON-NLS-2$
|
attributes.put("displayName", firstName == null ? lastname : lastname + ", " + firstName);
|
||||||
}
|
}
|
||||||
final String password = usr.getPassword();
|
final String password = usr.getPassword();
|
||||||
if (!hasValue(password)) {
|
if (!hasValue(password)) {
|
||||||
throw new RequiredAttributeException("password"); //$NON-NLS-1$
|
throw new RequiredAttributeException("password");
|
||||||
}
|
}
|
||||||
attributes.put("userPassword", password); //$NON-NLS-1$
|
attributes.put("userPassword", password);
|
||||||
final String dn = session.createSubcontext("uid=${uid},ou=users".replace("${uid}", uid), attributes); //$NON-NLS-1$ //$NON-NLS-2$
|
final String dn = session.createSubcontext("uid=${uid},ou=users".replace("${uid}", uid), attributes);
|
||||||
usr.setDn(dn);
|
usr.setDn(dn);
|
||||||
}
|
}
|
||||||
|
|
||||||
public User read(final String dn) throws LDAPSessionException {
|
public User read(final String dn) throws LDAPSessionException {
|
||||||
final Attributes attribs = session.getAttributes(dn.substring(0, dn.indexOf("ou=users") + 8)); //$NON-NLS-1$
|
final Attributes attribs = session.getAttributes(dn.substring(0, dn.indexOf("ou=users") + 8));
|
||||||
final User usr = new User();
|
final User usr = new User();
|
||||||
usr.setFirstname(session.getStringValue(attribs, "givenName")); //$NON-NLS-1$
|
usr.setFirstname(session.getStringValue(attribs, "givenName"));
|
||||||
usr.setLastname(session.getStringValue(attribs, "sn")); //$NON-NLS-1$
|
usr.setLastname(session.getStringValue(attribs, "sn"));
|
||||||
usr.setEmail(session.getStringValue(attribs, "mail")); //$NON-NLS-1$
|
usr.setEmail(session.getStringValue(attribs, "mail"));
|
||||||
usr.setLogin(session.getStringValue(attribs, "uid")); //$NON-NLS-1$
|
usr.setLogin(session.getStringValue(attribs, "uid"));
|
||||||
usr.setPhone(session.getStringValue(attribs, "telephoneNumber")); //$NON-NLS-1$
|
usr.setPhone(session.getStringValue(attribs, "telephoneNumber"));
|
||||||
usr.setMobile(session.getStringValue(attribs, "mobile")); //$NON-NLS-1$
|
usr.setMobile(session.getStringValue(attribs, "mobile"));
|
||||||
usr.setDisplayname(session.getStringValue(attribs, "displayName")); //$NON-NLS-1$
|
usr.setDisplayname(session.getStringValue(attribs, "displayName"));
|
||||||
usr.setLogin(session.getStringValue(attribs, "uid")); //$NON-NLS-1$
|
usr.setLogin(session.getStringValue(attribs, "uid"));
|
||||||
usr.setDn(dn);
|
usr.setDn(dn);
|
||||||
return usr;
|
return usr;
|
||||||
}
|
}
|
||||||
@ -114,21 +114,21 @@ public class UsersDAO {
|
|||||||
final String uid = usr.getLogin();
|
final String uid = usr.getLogin();
|
||||||
assert uid != null;
|
assert uid != null;
|
||||||
final Attributes attribs = session.getAttributes(
|
final Attributes attribs = session.getAttributes(
|
||||||
"uid=${uid},ou=users".replace("${uid}", uid)); //$NON-NLS-1$ //$NON-NLS-2$
|
"uid=${uid},ou=users".replace("${uid}", uid));
|
||||||
final List<ModificationItem> updates = new ArrayList<ModificationItem>();
|
final List<ModificationItem> updates = new ArrayList<ModificationItem>();
|
||||||
addStringAttrUpdate(updates, attribs, "displayName", usr.getDisplayname()); //$NON-NLS-1$
|
addStringAttrUpdate(updates, attribs, "displayName", usr.getDisplayname());
|
||||||
addStringAttrUpdate(updates, attribs, "mail", usr.getEmail()); //$NON-NLS-1$
|
addStringAttrUpdate(updates, attribs, "mail", usr.getEmail());
|
||||||
addStringAttrUpdate(updates, attribs, "givenName", usr.getFirstname()); //$NON-NLS-1$
|
addStringAttrUpdate(updates, attribs, "givenName", usr.getFirstname());
|
||||||
addStringAttrUpdate(updates, attribs, "sn", usr.getLastname()); //$NON-NLS-1$
|
addStringAttrUpdate(updates, attribs, "sn", usr.getLastname());
|
||||||
addStringAttrUpdate(updates, attribs, "mobile", usr.getMobile()); //$NON-NLS-1$
|
addStringAttrUpdate(updates, attribs, "mobile", usr.getMobile());
|
||||||
addStringAttrUpdate(updates, attribs, "telephoneNumber", usr.getPhone()); //$NON-NLS-1$
|
addStringAttrUpdate(updates, attribs, "telephoneNumber", usr.getPhone());
|
||||||
addPasswordUpdate(updates, "userPassword", usr.getPassword()); //$NON-NLS-1$
|
addPasswordUpdate(updates, "userPassword", usr.getPassword());
|
||||||
session.modifyAttributes("uid=${uid},ou=users".replace("${uid}", uid), updates.toArray(new ModificationItem[]{})); //$NON-NLS-1$ //$NON-NLS-2$
|
session.modifyAttributes("uid=${uid},ou=users".replace("${uid}", uid), updates.toArray(new ModificationItem[]{}));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void delete(final User user) throws LDAPSessionException {
|
public void delete(final User user) throws LDAPSessionException {
|
||||||
assert user != null;
|
assert user != null;
|
||||||
session.unbind("uid=${id},ou=users", user.getLogin()); //$NON-NLS-1$
|
session.unbind("uid=${id},ou=users", user.getLogin());
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean hasValue(final String email) {
|
private boolean hasValue(final String email) {
|
||||||
|
@ -45,11 +45,11 @@ public class AbstractLDAPServlet extends HttpServlet {
|
|||||||
@Override
|
@Override
|
||||||
public void init() throws ServletException {
|
public void init() throws ServletException {
|
||||||
super.init();
|
super.init();
|
||||||
final InputStream inputStream = this.getClass().getClassLoader().getResourceAsStream("config.properties"); //$NON-NLS-1$
|
final InputStream inputStream = this.getClass().getClassLoader().getResourceAsStream("config.properties");
|
||||||
config = new Properties();
|
config = new Properties();
|
||||||
try {
|
try {
|
||||||
config.load(inputStream);
|
config.load(inputStream);
|
||||||
ldapSession = new LDAPSession(config.getProperty("provider.url"), config.getProperty("security.principal"), config.getProperty("security.password")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
|
ldapSession = new LDAPSession(config.getProperty("provider.url"), config.getProperty("security.principal"), config.getProperty("security.password"));
|
||||||
} catch (IOException | LDAPSessionException e) {
|
} catch (IOException | LDAPSessionException e) {
|
||||||
LOG.severe(e.getMessage());
|
LOG.severe(e.getMessage());
|
||||||
throw new ServletException(e);
|
throw new ServletException(e);
|
||||||
@ -67,15 +67,15 @@ public class AbstractLDAPServlet extends HttpServlet {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected void throwServletException(final HttpSession session, final Exception e) throws ServletException {
|
protected void throwServletException(final HttpSession session, final Exception e) throws ServletException {
|
||||||
session.setAttribute("servletexception", e); //$NON-NLS-1$
|
session.setAttribute("servletexception", e);
|
||||||
LOG.severe(e.getMessage());
|
LOG.severe(e.getMessage());
|
||||||
throw new ServletException(e);
|
throw new ServletException(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void cleanSession(final HttpSession httpSession) {
|
protected void cleanSession(final HttpSession httpSession) {
|
||||||
httpSession.removeAttribute("errormessage"); //$NON-NLS-1$
|
httpSession.removeAttribute("errormessage");
|
||||||
httpSession.removeAttribute("successmessage"); //$NON-NLS-1$
|
httpSession.removeAttribute("successmessage");
|
||||||
httpSession.removeAttribute("servletexception"); //$NON-NLS-1$
|
httpSession.removeAttribute("servletexception");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -29,34 +29,34 @@ public class GroupServlet extends AbstractLDAPServlet {
|
|||||||
protected void doGet(final HttpServletRequest req, final HttpServletResponse resp)
|
protected void doGet(final HttpServletRequest req, final HttpServletResponse resp)
|
||||||
throws ServletException, IOException {
|
throws ServletException, IOException {
|
||||||
final String pathInfo = req.getPathInfo();
|
final String pathInfo = req.getPathInfo();
|
||||||
String groupDN = ""; //$NON-NLS-1$
|
String groupDN = "";
|
||||||
if (pathInfo != null && pathInfo.length() > 1 && pathInfo.charAt(0) == '/') {
|
if (pathInfo != null && pathInfo.length() > 1 && pathInfo.charAt(0) == '/') {
|
||||||
groupDN = pathInfo.substring(1);
|
groupDN = pathInfo.substring(1);
|
||||||
}
|
}
|
||||||
final HttpSession httpSession = req.getSession();
|
final HttpSession httpSession = req.getSession();
|
||||||
cleanSession(httpSession);
|
cleanSession(httpSession);
|
||||||
String operation = req.getParameter("op"); //$NON-NLS-1$
|
String operation = req.getParameter("op");
|
||||||
if (operation == null || operation.isEmpty()) {
|
if (operation == null || operation.isEmpty()) {
|
||||||
operation = "view"; //$NON-NLS-1$
|
operation = "view";
|
||||||
}
|
}
|
||||||
httpSession.setAttribute("operation", operation); //$NON-NLS-1$
|
httpSession.setAttribute("operation", operation);
|
||||||
httpSession.setAttribute("formdisabled", "view".equals(operation) || "delete".equals(operation) ? "disabled" : ""); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
|
httpSession.setAttribute("formdisabled", "view".equals(operation) || "delete".equals(operation) ? "disabled" : "");
|
||||||
httpSession.setAttribute("iddisabled", "create".equals(operation) ? "" : "disabled"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
|
httpSession.setAttribute("iddisabled", "create".equals(operation) ? "" : "disabled");
|
||||||
|
|
||||||
final GroupsDAO groupsDAO = new GroupsDAO(ldapSession);
|
final GroupsDAO groupsDAO = new GroupsDAO(ldapSession);
|
||||||
final UsersDAO usersDAO = new UsersDAO(ldapSession);
|
final UsersDAO usersDAO = new UsersDAO(ldapSession);
|
||||||
try {
|
try {
|
||||||
final SortedMap<String, User> users = usersDAO.loadUsers();
|
final SortedMap<String, User> users = usersDAO.loadUsers();
|
||||||
httpSession.setAttribute("users", users); //$NON-NLS-1$
|
httpSession.setAttribute("users", users);
|
||||||
if (groupDN != null && groupDN.length() > 9) {
|
if (groupDN != null && groupDN.length() > 9) {
|
||||||
httpSession.setAttribute("group", groupsDAO.readGroup(groupDN, users)); //$NON-NLS-1$
|
httpSession.setAttribute("group", groupsDAO.readGroup(groupDN, users));
|
||||||
} else {
|
} else {
|
||||||
httpSession.setAttribute("group", new Group()); //$NON-NLS-1$
|
httpSession.setAttribute("group", new Group());
|
||||||
}
|
}
|
||||||
} catch (LDAPSessionException e) {
|
} catch (LDAPSessionException e) {
|
||||||
throwServletException(httpSession, e);
|
throwServletException(httpSession, e);
|
||||||
}
|
}
|
||||||
req.getRequestDispatcher("/group.jsp").forward(req, resp); //$NON-NLS-1$
|
req.getRequestDispatcher("/group.jsp").forward(req, resp);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -64,13 +64,13 @@ public class GroupServlet extends AbstractLDAPServlet {
|
|||||||
throws ServletException, IOException {
|
throws ServletException, IOException {
|
||||||
final Messages messages = new Messages(req.getLocale());
|
final Messages messages = new Messages(req.getLocale());
|
||||||
final String pathInfo = req.getPathInfo();
|
final String pathInfo = req.getPathInfo();
|
||||||
String dn = ""; //$NON-NLS-1$
|
String dn = "";
|
||||||
if (pathInfo != null && pathInfo.length() > 1 && pathInfo.charAt(0) == '/') {
|
if (pathInfo != null && pathInfo.length() > 1 && pathInfo.charAt(0) == '/') {
|
||||||
dn = pathInfo.substring(1);
|
dn = pathInfo.substring(1);
|
||||||
}
|
}
|
||||||
String operation = req.getParameter("op"); //$NON-NLS-1$
|
String operation = req.getParameter("op");
|
||||||
if (operation == null || operation.isEmpty()) {
|
if (operation == null || operation.isEmpty()) {
|
||||||
operation = "none"; //$NON-NLS-1$
|
operation = "none";
|
||||||
}
|
}
|
||||||
final GroupsDAO groupsDAO = new GroupsDAO(ldapSession);
|
final GroupsDAO groupsDAO = new GroupsDAO(ldapSession);
|
||||||
final Group grp = new Group();
|
final Group grp = new Group();
|
||||||
@ -79,64 +79,64 @@ public class GroupServlet extends AbstractLDAPServlet {
|
|||||||
final HttpSession httpSession = req.getSession();
|
final HttpSession httpSession = req.getSession();
|
||||||
cleanSession(httpSession);
|
cleanSession(httpSession);
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
final SortedMap<String, User> usersHash = (SortedMap<String, User>) httpSession.getAttribute("users"); //$NON-NLS-1$
|
final SortedMap<String, User> usersHash = (SortedMap<String, User>) httpSession.getAttribute("users");
|
||||||
final Iterator<String> userDNIterator = usersHash.keySet().iterator();
|
final Iterator<String> userDNIterator = usersHash.keySet().iterator();
|
||||||
while (userDNIterator.hasNext()) {
|
while (userDNIterator.hasNext()) {
|
||||||
final String userDN = userDNIterator.next();
|
final String userDN = userDNIterator.next();
|
||||||
final User usr = usersHash.get(userDN);
|
final User usr = usersHash.get(userDN);
|
||||||
final String isChecked = req.getParameter("check_user_" + usr.getLogin()); //$NON-NLS-1$
|
final String isChecked = req.getParameter("check_user_" + usr.getLogin());
|
||||||
if (isChecked != null && !isChecked.isEmpty()) {
|
if (isChecked != null && !isChecked.isEmpty()) {
|
||||||
members.add(usr.getDn());
|
members.add(usr.getDn());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
grp.setMembers(members);
|
grp.setMembers(members);
|
||||||
try {
|
try {
|
||||||
if ("edit".equals(operation) && !dn.isEmpty()) { //$NON-NLS-1$
|
if ("edit".equals(operation) && !dn.isEmpty()) {
|
||||||
final Group oldValue = groupsDAO.readGroup(dn, usersHash);
|
final Group oldValue = groupsDAO.readGroup(dn, usersHash);
|
||||||
grp.setDn(dn);
|
grp.setDn(dn);
|
||||||
grp.setName(oldValue.getName());
|
grp.setName(oldValue.getName());
|
||||||
if (grp.getMembers().isEmpty()) {
|
if (grp.getMembers().isEmpty()) {
|
||||||
httpSession.setAttribute("group", grp); //$NON-NLS-1$
|
httpSession.setAttribute("group", grp);
|
||||||
httpSession.setAttribute("errormessage", messages.getString("GroupServlet.no_empty_group")); //$NON-NLS-1$ //$NON-NLS-2$
|
httpSession.setAttribute("errormessage", messages.getString("GroupServlet.no_empty_group"));
|
||||||
req.getRequestDispatcher("/group.jsp").forward(req, resp); //$NON-NLS-1$
|
req.getRequestDispatcher("/group.jsp").forward(req, resp);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
groupsDAO.update(grp);
|
groupsDAO.update(grp);
|
||||||
} catch (NoGroupMembersException e) {
|
} catch (NoGroupMembersException e) {
|
||||||
httpSession.setAttribute("group", grp); //$NON-NLS-1$
|
httpSession.setAttribute("group", grp);
|
||||||
httpSession.setAttribute("errormessage", messages.getString("GroupServlet.no_empty_group")); //$NON-NLS-1$ //$NON-NLS-2$
|
httpSession.setAttribute("errormessage", messages.getString("GroupServlet.no_empty_group"));
|
||||||
req.getRequestDispatcher("/group.jsp").forward(req, resp); //$NON-NLS-1$
|
req.getRequestDispatcher("/group.jsp").forward(req, resp);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ("delete".equals(operation) && !dn.isEmpty()) { //$NON-NLS-1$
|
if ("delete".equals(operation) && !dn.isEmpty()) {
|
||||||
final Group oldValue = groupsDAO.readGroup(dn, usersHash);
|
final Group oldValue = groupsDAO.readGroup(dn, usersHash);
|
||||||
grp.setDn(dn);
|
grp.setDn(dn);
|
||||||
grp.setName(oldValue.getName());
|
grp.setName(oldValue.getName());
|
||||||
groupsDAO.delete(grp);
|
groupsDAO.delete(grp);
|
||||||
}
|
}
|
||||||
if ("create".equals(operation)) { //$NON-NLS-1$
|
if ("create".equals(operation)) {
|
||||||
final String grpName = req.getParameter("name"); //$NON-NLS-1$
|
final String grpName = req.getParameter("name");
|
||||||
grp.setName(grpName);
|
grp.setName(grpName);
|
||||||
if (grp.getMembers().isEmpty()) {
|
if (grp.getMembers().isEmpty()) {
|
||||||
httpSession.setAttribute("group", grp); //$NON-NLS-1$
|
httpSession.setAttribute("group", grp);
|
||||||
httpSession.setAttribute("errormessage", messages.getString("GroupServlet.no_empty_group")); //$NON-NLS-1$ //$NON-NLS-2$
|
httpSession.setAttribute("errormessage", messages.getString("GroupServlet.no_empty_group"));
|
||||||
req.getRequestDispatcher("/group.jsp").forward(req, resp); //$NON-NLS-1$
|
req.getRequestDispatcher("/group.jsp").forward(req, resp);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
groupsDAO.create(grp);
|
groupsDAO.create(grp);
|
||||||
} catch (AlreadyBoundException e) {
|
} catch (AlreadyBoundException e) {
|
||||||
httpSession.setAttribute("group", grp); //$NON-NLS-1$
|
httpSession.setAttribute("group", grp);
|
||||||
httpSession.setAttribute("errormessage", messages.getString("GroupServlet.group_exists")); //$NON-NLS-1$ //$NON-NLS-2$
|
httpSession.setAttribute("errormessage", messages.getString("GroupServlet.group_exists"));
|
||||||
req.getRequestDispatcher("/group.jsp").forward(req, resp); //$NON-NLS-1$
|
req.getRequestDispatcher("/group.jsp").forward(req, resp);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
resp.sendRedirect(req.getContextPath() + req.getServletPath() + "/" + grp.getDn()); //$NON-NLS-1$
|
resp.sendRedirect(req.getContextPath() + req.getServletPath() + "/" + grp.getDn());
|
||||||
} else {
|
} else {
|
||||||
if ("delete".equals(operation)) { //$NON-NLS-1$
|
if ("delete".equals(operation)) {
|
||||||
resp.sendRedirect(req.getContextPath() + "/groups"); //$NON-NLS-1$
|
resp.sendRedirect(req.getContextPath() + "/groups");
|
||||||
} else {
|
} else {
|
||||||
resp.sendRedirect(req.getContextPath() + req.getServletPath() + pathInfo);
|
resp.sendRedirect(req.getContextPath() + req.getServletPath() + pathInfo);
|
||||||
}
|
}
|
||||||
|
@ -28,12 +28,12 @@ public class GroupsServlet extends AbstractLDAPServlet {
|
|||||||
final GroupsDAO groupsDAO = new GroupsDAO(ldapSession);
|
final GroupsDAO groupsDAO = new GroupsDAO(ldapSession);
|
||||||
try {
|
try {
|
||||||
final SortedMap<String, User> loadedUsers = usersDAO.loadUsers();
|
final SortedMap<String, User> loadedUsers = usersDAO.loadUsers();
|
||||||
httpSession.setAttribute("users", loadedUsers); //$NON-NLS-1$
|
httpSession.setAttribute("users", loadedUsers);
|
||||||
httpSession.setAttribute("groups", groupsDAO.loadGroups(loadedUsers)); //$NON-NLS-1$
|
httpSession.setAttribute("groups", groupsDAO.loadGroups(loadedUsers));
|
||||||
} catch (LDAPSessionException e) {
|
} catch (LDAPSessionException e) {
|
||||||
throwServletException(httpSession, e);
|
throwServletException(httpSession, e);
|
||||||
}
|
}
|
||||||
req.getRequestDispatcher("/groups.jsp").forward(req, resp); //$NON-NLS-1$
|
req.getRequestDispatcher("/groups.jsp").forward(req, resp);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -19,7 +19,7 @@ public class LogoutServlet extends AbstractLDAPServlet {
|
|||||||
final HttpSession httpSession = req.getSession();
|
final HttpSession httpSession = req.getSession();
|
||||||
cleanSession(httpSession);
|
cleanSession(httpSession);
|
||||||
httpSession.invalidate();
|
httpSession.invalidate();
|
||||||
resp.sendRedirect(httpSession.getServletContext().getContextPath() + "/"); //$NON-NLS-1$
|
resp.sendRedirect(httpSession.getServletContext().getContextPath() + "/");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -6,7 +6,7 @@ import java.util.ResourceBundle;
|
|||||||
|
|
||||||
public class Messages {
|
public class Messages {
|
||||||
|
|
||||||
private static final String BUNDLE_NAME = "de.jalin.ldapadmin.web.messages"; //$NON-NLS-1$
|
private static final String BUNDLE_NAME = "de.jalin.ldapadmin.web.messages";
|
||||||
|
|
||||||
private final ResourceBundle resourceBundle;
|
private final ResourceBundle resourceBundle;
|
||||||
|
|
||||||
|
@ -27,32 +27,32 @@ public class ProfileServlet extends AbstractLDAPServlet {
|
|||||||
protected void doGet(final HttpServletRequest req, final HttpServletResponse resp)
|
protected void doGet(final HttpServletRequest req, final HttpServletResponse resp)
|
||||||
throws ServletException, IOException {
|
throws ServletException, IOException {
|
||||||
final HttpSession httpSession = req.getSession();
|
final HttpSession httpSession = req.getSession();
|
||||||
String userDN = ""; //$NON-NLS-1$
|
String userDN = "";
|
||||||
try {
|
try {
|
||||||
final String remoteUID = req.getRemoteUser();
|
final String remoteUID = req.getRemoteUser();
|
||||||
final List<SearchResult> list = ldapSession.search("ou=users", "uid", remoteUID); //$NON-NLS-1$ //$NON-NLS-2$
|
final List<SearchResult> list = ldapSession.search("ou=users", "uid", remoteUID);
|
||||||
if (list != null && list.size() > 0) {
|
if (list != null && list.size() > 0) {
|
||||||
final SearchResult first = list.get(0);
|
final SearchResult first = list.get(0);
|
||||||
userDN = first.getNameInNamespace();
|
userDN = first.getNameInNamespace();
|
||||||
}
|
}
|
||||||
cleanSession(httpSession);
|
cleanSession(httpSession);
|
||||||
String operation = req.getParameter("op"); //$NON-NLS-1$
|
String operation = req.getParameter("op");
|
||||||
if (operation == null || operation.isEmpty()) {
|
if (operation == null || operation.isEmpty()) {
|
||||||
operation = "profile"; //$NON-NLS-1$
|
operation = "profile";
|
||||||
}
|
}
|
||||||
httpSession.setAttribute("operation", operation); //$NON-NLS-1$
|
httpSession.setAttribute("operation", operation);
|
||||||
httpSession.setAttribute("formdisabled", "profile".equals(operation) ? "disabled" : ""); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
|
httpSession.setAttribute("formdisabled", "profile".equals(operation) ? "disabled" : "");
|
||||||
httpSession.setAttribute("iddisabled", "disabled"); //$NON-NLS-1$ //$NON-NLS-2$
|
httpSession.setAttribute("iddisabled", "disabled");
|
||||||
final UsersDAO usersDAO = new UsersDAO(ldapSession);
|
final UsersDAO usersDAO = new UsersDAO(ldapSession);
|
||||||
final GroupsDAO groupsDAO = new GroupsDAO(ldapSession);
|
final GroupsDAO groupsDAO = new GroupsDAO(ldapSession);
|
||||||
SortedMap<String, User> users = usersDAO.loadUsers();
|
SortedMap<String, User> users = usersDAO.loadUsers();
|
||||||
httpSession.setAttribute("users", users); //$NON-NLS-1$
|
httpSession.setAttribute("users", users);
|
||||||
httpSession.setAttribute("groups", groupsDAO.loadGroups(users)); //$NON-NLS-1$
|
httpSession.setAttribute("groups", groupsDAO.loadGroups(users));
|
||||||
httpSession.setAttribute("user", users.get(userDN)); //$NON-NLS-1$
|
httpSession.setAttribute("user", users.get(userDN));
|
||||||
} catch (LDAPSessionException e) {
|
} catch (LDAPSessionException e) {
|
||||||
throwServletException(httpSession, e);
|
throwServletException(httpSession, e);
|
||||||
}
|
}
|
||||||
req.getRequestDispatcher("/user.jsp").forward(req, resp); //$NON-NLS-1$
|
req.getRequestDispatcher("/user.jsp").forward(req, resp);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -62,54 +62,54 @@ public class ProfileServlet extends AbstractLDAPServlet {
|
|||||||
final HttpSession httpSession = req.getSession();
|
final HttpSession httpSession = req.getSession();
|
||||||
cleanSession(httpSession);
|
cleanSession(httpSession);
|
||||||
final String pathInfo = req.getPathInfo();
|
final String pathInfo = req.getPathInfo();
|
||||||
String dn = ""; //$NON-NLS-1$
|
String dn = "";
|
||||||
if (pathInfo != null && pathInfo.length() > 1 && pathInfo.charAt(0) == '/') {
|
if (pathInfo != null && pathInfo.length() > 1 && pathInfo.charAt(0) == '/') {
|
||||||
dn = pathInfo.substring(1);
|
dn = pathInfo.substring(1);
|
||||||
}
|
}
|
||||||
String operation = req.getParameter("op"); //$NON-NLS-1$
|
String operation = req.getParameter("op");
|
||||||
if (operation == null || operation.isEmpty()) {
|
if (operation == null || operation.isEmpty()) {
|
||||||
operation = "none"; //$NON-NLS-1$
|
operation = "none";
|
||||||
}
|
}
|
||||||
final UsersDAO usersDAO = new UsersDAO(ldapSession);
|
final UsersDAO usersDAO = new UsersDAO(ldapSession);
|
||||||
final String password = req.getParameter("password"); //$NON-NLS-1$
|
final String password = req.getParameter("password");
|
||||||
final String password2 = req.getParameter("password2"); //$NON-NLS-1$
|
final String password2 = req.getParameter("password2");
|
||||||
final User usr = (User) httpSession.getAttribute("user"); //$NON-NLS-1$
|
final User usr = (User) httpSession.getAttribute("user");
|
||||||
try {
|
try {
|
||||||
if (password != null && !password.isEmpty()) {
|
if (password != null && !password.isEmpty()) {
|
||||||
if (password2 == null || !password2.equals(password)) {
|
if (password2 == null || !password2.equals(password)) {
|
||||||
throw new ValidationException("password2", messages.getString("ProfileServlet.passwords_donot_match")); //$NON-NLS-1$ //$NON-NLS-2$
|
throw new ValidationException("password2", messages.getString("ProfileServlet.passwords_donot_match"));
|
||||||
} else {
|
} else {
|
||||||
usr.setAndValidatePassword(password);
|
usr.setAndValidatePassword(password);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (SimplePasswordException e) {
|
} catch (SimplePasswordException e) {
|
||||||
httpSession.setAttribute("user", usr); //$NON-NLS-1$
|
httpSession.setAttribute("user", usr);
|
||||||
httpSession.setAttribute("errormessage", messages.getString("ResetPasswordServlet.simple_password")); //$NON-NLS-1$ //$NON-NLS-2$
|
httpSession.setAttribute("errormessage", messages.getString("ResetPasswordServlet.simple_password"));
|
||||||
req.getRequestDispatcher("/user.jsp").forward(req, resp); //$NON-NLS-1$
|
req.getRequestDispatcher("/user.jsp").forward(req, resp);
|
||||||
return;
|
return;
|
||||||
} catch (ValidationException e) {
|
} catch (ValidationException e) {
|
||||||
httpSession.setAttribute("user", usr); //$NON-NLS-1$
|
httpSession.setAttribute("user", usr);
|
||||||
httpSession.setAttribute("errormessage", messages.getString("ProfileServlet.inputfield") + e.getFieldname() + " " + e.getCondition()); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
|
httpSession.setAttribute("errormessage", messages.getString("ProfileServlet.inputfield") + e.getFieldname() + " " + e.getCondition());
|
||||||
req.getRequestDispatcher("/user.jsp").forward(req, resp); //$NON-NLS-1$
|
req.getRequestDispatcher("/user.jsp").forward(req, resp);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
if ("password".equals(operation)) { //$NON-NLS-1$
|
if ("password".equals(operation)) {
|
||||||
final User oldValue = usersDAO.read(dn);
|
final User oldValue = usersDAO.read(dn);
|
||||||
usr.setLogin(oldValue.getLogin());
|
usr.setLogin(oldValue.getLogin());
|
||||||
usr.setDn(dn);
|
usr.setDn(dn);
|
||||||
usersDAO.update(usr);
|
usersDAO.update(usr);
|
||||||
httpSession.setAttribute("successmessage", messages.getString("ProfileServlet.password_changed")); //$NON-NLS-1$ //$NON-NLS-2$
|
httpSession.setAttribute("successmessage", messages.getString("ProfileServlet.password_changed"));
|
||||||
httpSession.setAttribute("operation", "profile"); //$NON-NLS-1$ //$NON-NLS-2$
|
httpSession.setAttribute("operation", "profile");
|
||||||
httpSession.setAttribute("user", usr); //$NON-NLS-1$
|
httpSession.setAttribute("user", usr);
|
||||||
req.getRequestDispatcher("/user.jsp").forward(req, resp);
|
req.getRequestDispatcher("/user.jsp").forward(req, resp);
|
||||||
}
|
}
|
||||||
} catch (LDAPSessionException e) {
|
} catch (LDAPSessionException e) {
|
||||||
final String excMessage = e.getMessage();
|
final String excMessage = e.getMessage();
|
||||||
if (excMessage != null && excMessage.contains("invalid reuse of password")) { //$NON-NLS-1$
|
if (excMessage != null && excMessage.contains("invalid reuse of password")) {
|
||||||
httpSession.setAttribute("user", usr); //$NON-NLS-1$
|
httpSession.setAttribute("user", usr);
|
||||||
httpSession.setAttribute("errormessage", messages.getString("ProfileServlet.invalid_reuse")); //$NON-NLS-1$ //$NON-NLS-2$
|
httpSession.setAttribute("errormessage", messages.getString("ProfileServlet.invalid_reuse"));
|
||||||
req.getRequestDispatcher("/user.jsp").forward(req, resp); //$NON-NLS-1$
|
req.getRequestDispatcher("/user.jsp").forward(req, resp);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
throwServletException(httpSession, e);
|
throwServletException(httpSession, e);
|
||||||
|
@ -38,9 +38,9 @@ public class ResetPasswordServlet extends AbstractLDAPServlet {
|
|||||||
@Override
|
@Override
|
||||||
public void init() throws ServletException {
|
public void init() throws ServletException {
|
||||||
super.init();
|
super.init();
|
||||||
smtpHost = config.getProperty("smtp.host", "localhost"); //$NON-NLS-1$ //$NON-NLS-2$
|
smtpHost = config.getProperty("smtp.host", "localhost");
|
||||||
smtpPort = config.getProperty("smtp.port", "25"); //$NON-NLS-1$ //$NON-NLS-2$
|
smtpPort = config.getProperty("smtp.port", "25");
|
||||||
smtpFrom = config.getProperty("smtp.from", "nobody@localhost"); //$NON-NLS-1$ //$NON-NLS-2$
|
smtpFrom = config.getProperty("smtp.from", "nobody@localhost");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -48,26 +48,26 @@ public class ResetPasswordServlet extends AbstractLDAPServlet {
|
|||||||
throws ServletException, IOException {
|
throws ServletException, IOException {
|
||||||
final HttpSession httpSession = req.getSession();
|
final HttpSession httpSession = req.getSession();
|
||||||
cleanSession(httpSession);
|
cleanSession(httpSession);
|
||||||
final String token = req.getParameter("token"); //$NON-NLS-1$
|
final String token = req.getParameter("token");
|
||||||
if (token != null && !token.isEmpty()) {
|
if (token != null && !token.isEmpty()) {
|
||||||
final File passwdResetFile = new File("/tmp/passwd" + token + ".tmp"); //$NON-NLS-1$ //$NON-NLS-2$
|
final File passwdResetFile = new File("/tmp/passwd" + token + ".tmp");
|
||||||
if (passwdResetFile.exists() && passwdResetFile.canRead()) {
|
if (passwdResetFile.exists() && passwdResetFile.canRead()) {
|
||||||
try (final BufferedReader reader = new BufferedReader(new FileReader(passwdResetFile))) {
|
try (final BufferedReader reader = new BufferedReader(new FileReader(passwdResetFile))) {
|
||||||
final String[] uidAndEMail = reader.readLine().split(":"); //$NON-NLS-1$
|
final String[] uidAndEMail = reader.readLine().split(":");
|
||||||
final UsersDAO usrDAO = new UsersDAO(ldapSession);
|
final UsersDAO usrDAO = new UsersDAO(ldapSession);
|
||||||
final User usr = usrDAO.read("uid=" + uidAndEMail[0] + ",ou=users,"); //$NON-NLS-1$ //$NON-NLS-2$
|
final User usr = usrDAO.read("uid=" + uidAndEMail[0] + ",ou=users,");
|
||||||
httpSession.setAttribute("user", usr); //$NON-NLS-1$
|
httpSession.setAttribute("user", usr);
|
||||||
req.getRequestDispatcher("/new-password.jsp").forward(req, resp); //$NON-NLS-1$
|
req.getRequestDispatcher("/new-password.jsp").forward(req, resp);
|
||||||
return;
|
return;
|
||||||
} catch (LDAPSessionException e) {
|
} catch (LDAPSessionException e) {
|
||||||
LOG.warning("no valid password reset request");
|
LOG.warning("no valid password reset request");
|
||||||
httpSession.setAttribute("errormessage", new Messages(req.getLocale()).getString("ResetPasswordServlet.no_valid_passwordreset_request")); //$NON-NLS-1$ //$NON-NLS-2$
|
httpSession.setAttribute("errormessage", new Messages(req.getLocale()).getString("ResetPasswordServlet.no_valid_passwordreset_request"));
|
||||||
req.getRequestDispatcher("/reset-password.jsp").forward(req, resp); //$NON-NLS-1$
|
req.getRequestDispatcher("/reset-password.jsp").forward(req, resp);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
req.getRequestDispatcher("/reset-password.jsp").forward(req, resp); //$NON-NLS-1$
|
req.getRequestDispatcher("/reset-password.jsp").forward(req, resp);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -77,34 +77,34 @@ public class ResetPasswordServlet extends AbstractLDAPServlet {
|
|||||||
final HttpSession httpSession = req.getSession();
|
final HttpSession httpSession = req.getSession();
|
||||||
cleanSession(httpSession);
|
cleanSession(httpSession);
|
||||||
final UsersDAO usrDAO = new UsersDAO(ldapSession);
|
final UsersDAO usrDAO = new UsersDAO(ldapSession);
|
||||||
final String loginParam = req.getParameter("login"); //$NON-NLS-1$
|
final String loginParam = req.getParameter("login");
|
||||||
final User sessUsr = (User) httpSession.getAttribute("user"); //$NON-NLS-1$
|
final User sessUsr = (User) httpSession.getAttribute("user");
|
||||||
if (loginParam != null && sessUsr != null && loginParam.equals(sessUsr.getLogin())) {
|
if (loginParam != null && sessUsr != null && loginParam.equals(sessUsr.getLogin())) {
|
||||||
final String password1 = req.getParameter("password"); //$NON-NLS-1$
|
final String password1 = req.getParameter("password");
|
||||||
final String password2 = req.getParameter("password2"); //$NON-NLS-1$
|
final String password2 = req.getParameter("password2");
|
||||||
if (password1 != null && !password1.isEmpty()) {
|
if (password1 != null && !password1.isEmpty()) {
|
||||||
if (password2 == null || !password2.equals(password1)) {
|
if (password2 == null || !password2.equals(password1)) {
|
||||||
httpSession.setAttribute("errormessage", messages.getString("ResetPasswordServlet.passwords_donot_match")); //$NON-NLS-1$ //$NON-NLS-2$
|
httpSession.setAttribute("errormessage", messages.getString("ResetPasswordServlet.passwords_donot_match"));
|
||||||
req.getRequestDispatcher("/new-password.jsp").forward(req, resp); //$NON-NLS-1$
|
req.getRequestDispatcher("/new-password.jsp").forward(req, resp);
|
||||||
return;
|
return;
|
||||||
} else {
|
} else {
|
||||||
try {
|
try {
|
||||||
sessUsr.setAndValidatePassword(password1);
|
sessUsr.setAndValidatePassword(password1);
|
||||||
usrDAO.update(sessUsr);
|
usrDAO.update(sessUsr);
|
||||||
httpSession.setAttribute("successmessage", messages.getString("ResetPasswordServlet.password_changed")); //$NON-NLS-1$ //$NON-NLS-2$
|
httpSession.setAttribute("successmessage", messages.getString("ResetPasswordServlet.password_changed"));
|
||||||
req.getRequestDispatcher("/new-password.jsp").forward(req, resp); //$NON-NLS-1$
|
req.getRequestDispatcher("/new-password.jsp").forward(req, resp);
|
||||||
return;
|
return;
|
||||||
} catch (SimplePasswordException e) {
|
} catch (SimplePasswordException e) {
|
||||||
httpSession.setAttribute("user", sessUsr); //$NON-NLS-1$
|
httpSession.setAttribute("user", sessUsr);
|
||||||
httpSession.setAttribute("errormessage", messages.getString("ResetPasswordServlet.simple_password")); //$NON-NLS-1$ //$NON-NLS-2$
|
httpSession.setAttribute("errormessage", messages.getString("ResetPasswordServlet.simple_password"));
|
||||||
req.getRequestDispatcher("/new-password.jsp").forward(req, resp); //$NON-NLS-1$
|
req.getRequestDispatcher("/new-password.jsp").forward(req, resp);
|
||||||
return;
|
return;
|
||||||
} catch (LDAPSessionException e) {
|
} catch (LDAPSessionException e) {
|
||||||
final String excMessage = e.getMessage();
|
final String excMessage = e.getMessage();
|
||||||
if (excMessage != null && excMessage.contains("invalid reuse of password")) { //$NON-NLS-1$
|
if (excMessage != null && excMessage.contains("invalid reuse of password")) {
|
||||||
httpSession.setAttribute("user", sessUsr); //$NON-NLS-1$
|
httpSession.setAttribute("user", sessUsr);
|
||||||
httpSession.setAttribute("errormessage", messages.getString("ResetPasswordServlet.invalid_password_reuse")); //$NON-NLS-1$ //$NON-NLS-2$
|
httpSession.setAttribute("errormessage", messages.getString("ResetPasswordServlet.invalid_password_reuse"));
|
||||||
req.getRequestDispatcher("/new-password.jsp").forward(req, resp); //$NON-NLS-1$
|
req.getRequestDispatcher("/new-password.jsp").forward(req, resp);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
throwServletException(httpSession, e);
|
throwServletException(httpSession, e);
|
||||||
@ -112,55 +112,55 @@ public class ResetPasswordServlet extends AbstractLDAPServlet {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
final String loginOrEMail = req.getParameter("loginoremail"); //$NON-NLS-1$
|
final String loginOrEMail = req.getParameter("loginoremail");
|
||||||
final File tempFile = File.createTempFile("passwd", ".tmp", new File("/tmp")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
|
final File tempFile = File.createTempFile("passwd", ".tmp", new File("/tmp"));
|
||||||
try (final PrintStream printStream = new PrintStream(tempFile)) {
|
try (final PrintStream printStream = new PrintStream(tempFile)) {
|
||||||
String email = ""; //$NON-NLS-1$
|
String email = "";
|
||||||
String login = ""; //$NON-NLS-1$
|
String login = "";
|
||||||
String salutation = ""; //$NON-NLS-1$
|
String salutation = "";
|
||||||
if (loginOrEMail != null) {
|
if (loginOrEMail != null) {
|
||||||
if (loginOrEMail.contains("@")) { //$NON-NLS-1$
|
if (loginOrEMail.contains("@")) {
|
||||||
final SortedMap<String, User> usersMap = usrDAO.loadUsers();
|
final SortedMap<String, User> usersMap = usrDAO.loadUsers();
|
||||||
final Collection<User> allUsers = usersMap.values();
|
final Collection<User> allUsers = usersMap.values();
|
||||||
for (User usr : allUsers) {
|
for (User usr : allUsers) {
|
||||||
if (usr.getEmail() != null && usr.getEmail().equalsIgnoreCase(loginOrEMail)) {
|
if (usr.getEmail() != null && usr.getEmail().equalsIgnoreCase(loginOrEMail)) {
|
||||||
login = usr.getLogin();
|
login = usr.getLogin();
|
||||||
email = usr.getEmail();
|
email = usr.getEmail();
|
||||||
salutation = usr.getFirstname() + " " + usr.getLastname(); //$NON-NLS-1$
|
salutation = usr.getFirstname() + " " + usr.getLastname();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
final User usr = usrDAO.read("uid=" + loginOrEMail + ",ou=users,"); //$NON-NLS-1$ //$NON-NLS-2$
|
final User usr = usrDAO.read("uid=" + loginOrEMail + ",ou=users,");
|
||||||
if (usr != null) {
|
if (usr != null) {
|
||||||
login = usr.getLogin();
|
login = usr.getLogin();
|
||||||
email = usr.getEmail();
|
email = usr.getEmail();
|
||||||
salutation = usr.getFirstname() + " " + usr.getLastname(); //$NON-NLS-1$
|
salutation = usr.getFirstname() + " " + usr.getLastname();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (login.isEmpty() || email.isEmpty()) {
|
if (login.isEmpty() || email.isEmpty()) {
|
||||||
httpSession.setAttribute("errormessage", messages.getString("ResetPasswordServlet.error_sending_password_reset")); //$NON-NLS-1$ //$NON-NLS-2$
|
httpSession.setAttribute("errormessage", messages.getString("ResetPasswordServlet.error_sending_password_reset"));
|
||||||
req.getRequestDispatcher("/reset-password.jsp").forward(req, resp); //$NON-NLS-1$
|
req.getRequestDispatcher("/reset-password.jsp").forward(req, resp);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
printStream.println(login + ":" + email); //$NON-NLS-1$
|
printStream.println(login + ":" + email);
|
||||||
}
|
}
|
||||||
final StringBuffer messageText = new StringBuffer(messages.getString("ResetPasswordServlet.email_greeting")); //$NON-NLS-1$
|
final StringBuffer messageText = new StringBuffer(messages.getString("ResetPasswordServlet.email_greeting"));
|
||||||
messageText.append(salutation);
|
messageText.append(salutation);
|
||||||
messageText.append(messages.getString("ResetPasswordServlet.email_content")); //$NON-NLS-1$
|
messageText.append(messages.getString("ResetPasswordServlet.email_content"));
|
||||||
messageText.append(req.getRequestURL().toString().replaceAll("^http\\:", "https://"));
|
messageText.append(req.getRequestURL().toString().replaceAll("^http\\:", "https://"));
|
||||||
messageText.append("?token="); //$NON-NLS-1$
|
messageText.append("?token=");
|
||||||
final String filename = tempFile.getName();
|
final String filename = tempFile.getName();
|
||||||
messageText.append(filename.substring(6, filename.length() - 4));
|
messageText.append(filename.substring(6, filename.length() - 4));
|
||||||
messageText.append(messages.getString("ResetPasswordServlet.email_signature")); //$NON-NLS-1$
|
messageText.append(messages.getString("ResetPasswordServlet.email_signature"));
|
||||||
smtpSend(smtpHost, smtpPort, messages, smtpFrom, email, messages.getString("ResetPasswordServlet.email_subject"), messageText.toString()); //$NON-NLS-1$ //$NON-NLS-2$
|
smtpSend(smtpHost, smtpPort, messages, smtpFrom, email, messages.getString("ResetPasswordServlet.email_subject"), messageText.toString());
|
||||||
} catch (LDAPSessionException | IOException e) {
|
} catch (LDAPSessionException | IOException e) {
|
||||||
LOG.severe("smtp problem");
|
LOG.severe("smtp problem");
|
||||||
httpSession.setAttribute("errormessage", messages.getString("ResetPasswordServlet.error_sending_password_reset")); //$NON-NLS-1$ //$NON-NLS-2$
|
httpSession.setAttribute("errormessage", messages.getString("ResetPasswordServlet.error_sending_password_reset"));
|
||||||
req.getRequestDispatcher("/reset-password.jsp").forward(req, resp); //$NON-NLS-1$
|
req.getRequestDispatcher("/reset-password.jsp").forward(req, resp);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
httpSession.invalidate();
|
httpSession.invalidate();
|
||||||
resp.sendRedirect(httpSession.getServletContext().getContextPath() + "/"); //$NON-NLS-1$
|
resp.sendRedirect(httpSession.getServletContext().getContextPath() + "/");
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void smtpSend(final String smtpHost, final String smtpPort, final Messages messages, final String fromAddress, final String toAddress, final String subject, final String text) throws IOException {
|
private static void smtpSend(final String smtpHost, final String smtpPort, final Messages messages, final String fromAddress, final String toAddress, final String subject, final String text) throws IOException {
|
||||||
@ -169,14 +169,14 @@ public class ResetPasswordServlet extends AbstractLDAPServlet {
|
|||||||
client.connect(smtpHost, Integer.parseInt(smtpPort));
|
client.connect(smtpHost, Integer.parseInt(smtpPort));
|
||||||
int reply = client.getReplyCode();
|
int reply = client.getReplyCode();
|
||||||
if (!SMTPReply.isPositiveCompletion(reply)) {
|
if (!SMTPReply.isPositiveCompletion(reply)) {
|
||||||
throw new IOException(messages.getString("ResetPasswordServlet.error_sending_email_server")); //$NON-NLS-1$
|
throw new IOException(messages.getString("ResetPasswordServlet.error_sending_email_server"));
|
||||||
}
|
}
|
||||||
client.login(canonicalHostName);
|
client.login(canonicalHostName);
|
||||||
client.setSender(fromAddress.trim());
|
client.setSender(fromAddress.trim());
|
||||||
client.addRecipient(toAddress.trim());
|
client.addRecipient(toAddress.trim());
|
||||||
final Writer sendMessageData = client.sendMessageData();
|
final Writer sendMessageData = client.sendMessageData();
|
||||||
if (sendMessageData == null) {
|
if (sendMessageData == null) {
|
||||||
throw new IOException(messages.getString("ResetPasswordServlet.error_sending_email_relay")); //$NON-NLS-1$
|
throw new IOException(messages.getString("ResetPasswordServlet.error_sending_email_relay"));
|
||||||
}
|
}
|
||||||
try (PrintWriter wr = new PrintWriter(sendMessageData)) {
|
try (PrintWriter wr = new PrintWriter(sendMessageData)) {
|
||||||
final SimpleSMTPHeader header = new SimpleSMTPHeader(fromAddress, toAddress, subject);
|
final SimpleSMTPHeader header = new SimpleSMTPHeader(fromAddress, toAddress, subject);
|
||||||
@ -186,7 +186,7 @@ public class ResetPasswordServlet extends AbstractLDAPServlet {
|
|||||||
wr.write(text);
|
wr.write(text);
|
||||||
}
|
}
|
||||||
if (!client.completePendingCommand()) {
|
if (!client.completePendingCommand()) {
|
||||||
throw new IOException(messages.getString("ResetPasswordServlet.error_sending_email")); //$NON-NLS-1$
|
throw new IOException(messages.getString("ResetPasswordServlet.error_sending_email"));
|
||||||
}
|
}
|
||||||
client.logout();
|
client.logout();
|
||||||
client.disconnect();
|
client.disconnect();
|
||||||
|
@ -32,34 +32,34 @@ public class UserServlet extends AbstractLDAPServlet {
|
|||||||
protected void doGet(final HttpServletRequest req, final HttpServletResponse resp)
|
protected void doGet(final HttpServletRequest req, final HttpServletResponse resp)
|
||||||
throws ServletException, IOException {
|
throws ServletException, IOException {
|
||||||
final String pathInfo = req.getPathInfo();
|
final String pathInfo = req.getPathInfo();
|
||||||
String userDN = ""; //$NON-NLS-1$
|
String userDN = "";
|
||||||
if (pathInfo != null && pathInfo.length() > 1 && pathInfo.charAt(0) == '/') {
|
if (pathInfo != null && pathInfo.length() > 1 && pathInfo.charAt(0) == '/') {
|
||||||
userDN = pathInfo.substring(1);
|
userDN = pathInfo.substring(1);
|
||||||
}
|
}
|
||||||
final HttpSession httpSession = req.getSession();
|
final HttpSession httpSession = req.getSession();
|
||||||
cleanSession(httpSession);
|
cleanSession(httpSession);
|
||||||
String operation = req.getParameter("op"); //$NON-NLS-1$
|
String operation = req.getParameter("op");
|
||||||
if (operation == null || operation.isEmpty()) {
|
if (operation == null || operation.isEmpty()) {
|
||||||
operation = "view"; //$NON-NLS-1$
|
operation = "view";
|
||||||
}
|
}
|
||||||
httpSession.setAttribute("operation", operation); //$NON-NLS-1$
|
httpSession.setAttribute("operation", operation);
|
||||||
httpSession.setAttribute("formdisabled", "view".equals(operation) || "delete".equals(operation) ? "disabled" : ""); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
|
httpSession.setAttribute("formdisabled", "view".equals(operation) || "delete".equals(operation) ? "disabled" : "");
|
||||||
httpSession.setAttribute("iddisabled", "create".equals(operation) ? "" : "disabled"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
|
httpSession.setAttribute("iddisabled", "create".equals(operation) ? "" : "disabled");
|
||||||
final UsersDAO usersDAO = new UsersDAO(ldapSession);
|
final UsersDAO usersDAO = new UsersDAO(ldapSession);
|
||||||
final GroupsDAO groupsDAO = new GroupsDAO(ldapSession);
|
final GroupsDAO groupsDAO = new GroupsDAO(ldapSession);
|
||||||
try {
|
try {
|
||||||
SortedMap<String, User> users = usersDAO.loadUsers();
|
SortedMap<String, User> users = usersDAO.loadUsers();
|
||||||
httpSession.setAttribute("users", users); //$NON-NLS-1$
|
httpSession.setAttribute("users", users);
|
||||||
httpSession.setAttribute("groups", groupsDAO.loadGroups(users)); //$NON-NLS-1$
|
httpSession.setAttribute("groups", groupsDAO.loadGroups(users));
|
||||||
if ("create".equals(operation)) { //$NON-NLS-1$
|
if ("create".equals(operation)) {
|
||||||
httpSession.setAttribute("user", new User()); //$NON-NLS-1$
|
httpSession.setAttribute("user", new User());
|
||||||
} else {
|
} else {
|
||||||
httpSession.setAttribute("user", users.get(userDN)); //$NON-NLS-1$
|
httpSession.setAttribute("user", users.get(userDN));
|
||||||
}
|
}
|
||||||
} catch (LDAPSessionException e) {
|
} catch (LDAPSessionException e) {
|
||||||
throwServletException(httpSession, e);
|
throwServletException(httpSession, e);
|
||||||
}
|
}
|
||||||
req.getRequestDispatcher("/user.jsp").forward(req, resp); //$NON-NLS-1$
|
req.getRequestDispatcher("/user.jsp").forward(req, resp);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -69,23 +69,23 @@ public class UserServlet extends AbstractLDAPServlet {
|
|||||||
final HttpSession httpSession = req.getSession();
|
final HttpSession httpSession = req.getSession();
|
||||||
cleanSession(httpSession);
|
cleanSession(httpSession);
|
||||||
final String pathInfo = req.getPathInfo();
|
final String pathInfo = req.getPathInfo();
|
||||||
String dn = ""; //$NON-NLS-1$
|
String dn = "";
|
||||||
if (pathInfo != null && pathInfo.length() > 1 && pathInfo.charAt(0) == '/') {
|
if (pathInfo != null && pathInfo.length() > 1 && pathInfo.charAt(0) == '/') {
|
||||||
dn = pathInfo.substring(1);
|
dn = pathInfo.substring(1);
|
||||||
}
|
}
|
||||||
String operation = req.getParameter("op"); //$NON-NLS-1$
|
String operation = req.getParameter("op");
|
||||||
if (operation == null || operation.isEmpty()) {
|
if (operation == null || operation.isEmpty()) {
|
||||||
operation = "none"; //$NON-NLS-1$
|
operation = "none";
|
||||||
}
|
}
|
||||||
final UsersDAO usersDAO = new UsersDAO(ldapSession);
|
final UsersDAO usersDAO = new UsersDAO(ldapSession);
|
||||||
final String login = req.getParameter("login"); //$NON-NLS-1$
|
final String login = req.getParameter("login");
|
||||||
final String firstname = req.getParameter("firstname"); //$NON-NLS-1$
|
final String firstname = req.getParameter("firstname");
|
||||||
final String lastname = req.getParameter("lastname"); //$NON-NLS-1$
|
final String lastname = req.getParameter("lastname");
|
||||||
final String email = req.getParameter("email"); //$NON-NLS-1$
|
final String email = req.getParameter("email");
|
||||||
final String phone = req.getParameter("phone"); //$NON-NLS-1$
|
final String phone = req.getParameter("phone");
|
||||||
final String mobile = req.getParameter("mobile"); //$NON-NLS-1$
|
final String mobile = req.getParameter("mobile");
|
||||||
final String password = req.getParameter("password"); //$NON-NLS-1$
|
final String password = req.getParameter("password");
|
||||||
final String password2 = req.getParameter("password2"); //$NON-NLS-1$
|
final String password2 = req.getParameter("password2");
|
||||||
final User usr = new User();
|
final User usr = new User();
|
||||||
if (!dn.isEmpty()) {
|
if (!dn.isEmpty()) {
|
||||||
usr.setDn(dn);
|
usr.setDn(dn);
|
||||||
@ -93,57 +93,57 @@ public class UserServlet extends AbstractLDAPServlet {
|
|||||||
usr.setLogin(login);
|
usr.setLogin(login);
|
||||||
usr.setFirstname(firstname);
|
usr.setFirstname(firstname);
|
||||||
usr.setLastname(lastname);
|
usr.setLastname(lastname);
|
||||||
usr.setDisplayname(lastname + ", " + firstname); //$NON-NLS-1$
|
usr.setDisplayname(lastname + ", " + firstname);
|
||||||
usr.setEmail(email);
|
usr.setEmail(email);
|
||||||
usr.setPhone(phone);
|
usr.setPhone(phone);
|
||||||
usr.setMobile(mobile);
|
usr.setMobile(mobile);
|
||||||
final List<String> memberships;
|
final List<String> memberships;
|
||||||
memberships = new ArrayList<>();
|
memberships = new ArrayList<>();
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
final SortedMap<String, Group> groupsHash = (SortedMap<String, Group>) httpSession.getAttribute("groups"); //$NON-NLS-1$
|
final SortedMap<String, Group> groupsHash = (SortedMap<String, Group>) httpSession.getAttribute("groups");
|
||||||
final Iterator<String> groupDNIterator = groupsHash.keySet().iterator();
|
final Iterator<String> groupDNIterator = groupsHash.keySet().iterator();
|
||||||
while (groupDNIterator.hasNext()) {
|
while (groupDNIterator.hasNext()) {
|
||||||
final String groupDN = groupDNIterator.next();
|
final String groupDN = groupDNIterator.next();
|
||||||
final Group grp = groupsHash.get(groupDN);
|
final Group grp = groupsHash.get(groupDN);
|
||||||
final String isChecked = req.getParameter("check_group_" + grp.getName()); //$NON-NLS-1$
|
final String isChecked = req.getParameter("check_group_" + grp.getName());
|
||||||
if (isChecked != null && !isChecked.isEmpty()) {
|
if (isChecked != null && !isChecked.isEmpty()) {
|
||||||
memberships.add(grp.getDn());
|
memberships.add(grp.getDn());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
usr.setGroups(memberships);
|
usr.setGroups(memberships);
|
||||||
try {
|
try {
|
||||||
validatePhone(messages, "phone", phone); //$NON-NLS-1$
|
validatePhone(messages, "phone", phone);
|
||||||
validatePhone(messages, "mobile", mobile); //$NON-NLS-1$
|
validatePhone(messages, "mobile", mobile);
|
||||||
validateEMail(messages, email);
|
validateEMail(messages, email);
|
||||||
validateLastName(messages, lastname);
|
validateLastName(messages, lastname);
|
||||||
if (password != null && !password.isEmpty()) {
|
if (password != null && !password.isEmpty()) {
|
||||||
if (password2 == null || !password2.equals(password)) {
|
if (password2 == null || !password2.equals(password)) {
|
||||||
throw new ValidationException("password2", messages.getString("UserServlet.passwords_donot_match")); //$NON-NLS-1$ //$NON-NLS-2$
|
throw new ValidationException("password2", messages.getString("UserServlet.passwords_donot_match"));
|
||||||
} else {
|
} else {
|
||||||
usr.setAndValidatePassword(password);
|
usr.setAndValidatePassword(password);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (SimplePasswordException e) {
|
} catch (SimplePasswordException e) {
|
||||||
httpSession.setAttribute("user", usr); //$NON-NLS-1$
|
httpSession.setAttribute("user", usr);
|
||||||
httpSession.setAttribute("errormessage", messages.getString("ResetPasswordServlet.simple_password")); //$NON-NLS-1$ //$NON-NLS-2$
|
httpSession.setAttribute("errormessage", messages.getString("ResetPasswordServlet.simple_password"));
|
||||||
req.getRequestDispatcher("/user.jsp").forward(req, resp); //$NON-NLS-1$
|
req.getRequestDispatcher("/user.jsp").forward(req, resp);
|
||||||
return;
|
return;
|
||||||
} catch (ValidationException e) {
|
} catch (ValidationException e) {
|
||||||
httpSession.setAttribute("user", usr); //$NON-NLS-1$
|
httpSession.setAttribute("user", usr);
|
||||||
httpSession.setAttribute("errormessage", messages.getString("UserServlet.input_field") + " \"" + e.getFieldname() + "\" " + e.getCondition()); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
|
httpSession.setAttribute("errormessage", messages.getString("UserServlet.input_field") + " \"" + e.getFieldname() + "\" " + e.getCondition());
|
||||||
req.getRequestDispatcher("/user.jsp").forward(req, resp); //$NON-NLS-1$
|
req.getRequestDispatcher("/user.jsp").forward(req, resp);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
final GroupsDAO groupsDAO = new GroupsDAO(ldapSession);
|
final GroupsDAO groupsDAO = new GroupsDAO(ldapSession);
|
||||||
try {
|
try {
|
||||||
if ("edit".equals(operation)) { //$NON-NLS-1$
|
if ("edit".equals(operation)) {
|
||||||
final User oldValue = usersDAO.read(dn);
|
final User oldValue = usersDAO.read(dn);
|
||||||
usr.setLogin(oldValue.getLogin());
|
usr.setLogin(oldValue.getLogin());
|
||||||
usr.setDn(dn);
|
usr.setDn(dn);
|
||||||
usersDAO.update(usr);
|
usersDAO.update(usr);
|
||||||
groupsDAO.updateMemberships(usr);
|
groupsDAO.updateMemberships(usr);
|
||||||
}
|
}
|
||||||
if ("delete".equals(operation)) { //$NON-NLS-1$
|
if ("delete".equals(operation)) {
|
||||||
final User oldValue = usersDAO.read(dn);
|
final User oldValue = usersDAO.read(dn);
|
||||||
usr.setLogin(oldValue.getLogin());
|
usr.setLogin(oldValue.getLogin());
|
||||||
usr.setDn(dn);
|
usr.setDn(dn);
|
||||||
@ -151,39 +151,39 @@ public class UserServlet extends AbstractLDAPServlet {
|
|||||||
groupsDAO.updateMemberships(usr);
|
groupsDAO.updateMemberships(usr);
|
||||||
usersDAO.delete(usr);
|
usersDAO.delete(usr);
|
||||||
}
|
}
|
||||||
if ("create".equals(operation)) { //$NON-NLS-1$
|
if ("create".equals(operation)) {
|
||||||
usr.setLogin(login);
|
usr.setLogin(login);
|
||||||
usersDAO.create(usr);
|
usersDAO.create(usr);
|
||||||
groupsDAO.updateMemberships(usr);
|
groupsDAO.updateMemberships(usr);
|
||||||
resp.sendRedirect(req.getContextPath() + req.getServletPath() + "/" + usr.getDn()); //$NON-NLS-1$
|
resp.sendRedirect(req.getContextPath() + req.getServletPath() + "/" + usr.getDn());
|
||||||
} else {
|
} else {
|
||||||
if ("delete".equals(operation)) { //$NON-NLS-1$
|
if ("delete".equals(operation)) {
|
||||||
resp.sendRedirect(req.getContextPath() + "/users"); //$NON-NLS-1$
|
resp.sendRedirect(req.getContextPath() + "/users");
|
||||||
} else {
|
} else {
|
||||||
resp.sendRedirect(req.getContextPath() + req.getServletPath() + pathInfo);
|
resp.sendRedirect(req.getContextPath() + req.getServletPath() + pathInfo);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (LDAPSessionException e) {
|
} catch (LDAPSessionException e) {
|
||||||
final String excMessage = e.getMessage();
|
final String excMessage = e.getMessage();
|
||||||
if (excMessage != null && excMessage.contains("invalid reuse of password")) { //$NON-NLS-1$
|
if (excMessage != null && excMessage.contains("invalid reuse of password")) {
|
||||||
httpSession.setAttribute("user", usr); //$NON-NLS-1$
|
httpSession.setAttribute("user", usr);
|
||||||
httpSession.setAttribute("errormessage", messages.getString("UserServlet.invalid_password_reuse")); //$NON-NLS-1$ //$NON-NLS-2$
|
httpSession.setAttribute("errormessage", messages.getString("UserServlet.invalid_password_reuse"));
|
||||||
req.getRequestDispatcher("/user.jsp").forward(req, resp); //$NON-NLS-1$
|
req.getRequestDispatcher("/user.jsp").forward(req, resp);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
throwServletException(httpSession, e);
|
throwServletException(httpSession, e);
|
||||||
} catch (NoGroupMembersException e) {
|
} catch (NoGroupMembersException e) {
|
||||||
httpSession.setAttribute("user", usr); //$NON-NLS-1$
|
httpSession.setAttribute("user", usr);
|
||||||
httpSession.setAttribute("errormessage", messages.getString("UserServlet.group_last_member")); //$NON-NLS-1$ //$NON-NLS-2$
|
httpSession.setAttribute("errormessage", messages.getString("UserServlet.group_last_member"));
|
||||||
req.getRequestDispatcher("/user.jsp").forward(req, resp); //$NON-NLS-1$
|
req.getRequestDispatcher("/user.jsp").forward(req, resp);
|
||||||
} catch (RequiredAttributeException e) {
|
} catch (RequiredAttributeException e) {
|
||||||
httpSession.setAttribute("user", usr); //$NON-NLS-1$
|
httpSession.setAttribute("user", usr);
|
||||||
httpSession.setAttribute("errormessage", messages.getString("UserServlet.the_input_field") + " " + e.getFieldname() + " " + messages.getString("UserServlet.is_required")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
|
httpSession.setAttribute("errormessage", messages.getString("UserServlet.the_input_field") + " " + e.getFieldname() + " " + messages.getString("UserServlet.is_required"));
|
||||||
req.getRequestDispatcher("/user.jsp").forward(req, resp); //$NON-NLS-1$
|
req.getRequestDispatcher("/user.jsp").forward(req, resp);
|
||||||
} catch (AlreadyBoundException e) {
|
} catch (AlreadyBoundException e) {
|
||||||
httpSession.setAttribute("user", usr); //$NON-NLS-1$
|
httpSession.setAttribute("user", usr);
|
||||||
httpSession.setAttribute("errormessage", messages.getString("UserServlet.user_exists")); //$NON-NLS-1$ //$NON-NLS-2$
|
httpSession.setAttribute("errormessage", messages.getString("UserServlet.user_exists"));
|
||||||
req.getRequestDispatcher("/user.jsp").forward(req, resp); //$NON-NLS-1$
|
req.getRequestDispatcher("/user.jsp").forward(req, resp);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -192,8 +192,8 @@ public class UserServlet extends AbstractLDAPServlet {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
final String valid = phone.trim();
|
final String valid = phone.trim();
|
||||||
if (!valid.matches("[0-9\\-\\ \\(\\)]*")) { //$NON-NLS-1$
|
if (!valid.matches("[0-9\\-\\ \\(\\)]*")) {
|
||||||
throw new ValidationException(field, messages.getString("UserServlet.phone_not_valid")); //$NON-NLS-1$
|
throw new ValidationException(field, messages.getString("UserServlet.phone_not_valid"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -202,14 +202,14 @@ public class UserServlet extends AbstractLDAPServlet {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
final String valid = email.trim();
|
final String valid = email.trim();
|
||||||
if (!valid.matches("[A-Za-z0-9_+\\.\\-]*@[a-z0-9\\.\\-üöäß]*")) { //$NON-NLS-1$
|
if (!valid.matches("[A-Za-z0-9_+\\.\\-]*@[a-z0-9\\.\\-üöäß]*")) {
|
||||||
throw new ValidationException("email", messages.getString("UserServlet.email_not_valid")); //$NON-NLS-1$ //$NON-NLS-2$
|
throw new ValidationException("email", messages.getString("UserServlet.email_not_valid"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void validateLastName(final Messages messages, final String lastname) throws ValidationException {
|
private void validateLastName(final Messages messages, final String lastname) throws ValidationException {
|
||||||
if (lastname == null || lastname.isEmpty()) {
|
if (lastname == null || lastname.isEmpty()) {
|
||||||
throw new ValidationException("lastname", messages.getString("UserServlet.is_required")); //$NON-NLS-1$ //$NON-NLS-2$
|
throw new ValidationException("lastname", messages.getString("UserServlet.is_required"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -30,12 +30,12 @@ public class UsersServlet extends AbstractLDAPServlet {
|
|||||||
try {
|
try {
|
||||||
final SortedMap<String, User> users = usersDAO.loadUsers();
|
final SortedMap<String, User> users = usersDAO.loadUsers();
|
||||||
final SortedMap<String, Group> groups = groupsDAO.loadGroups(users);
|
final SortedMap<String, Group> groups = groupsDAO.loadGroups(users);
|
||||||
httpSession.setAttribute("users", users); //$NON-NLS-1$
|
httpSession.setAttribute("users", users);
|
||||||
httpSession.setAttribute("groups", groups); //$NON-NLS-1$
|
httpSession.setAttribute("groups", groups);
|
||||||
} catch (LDAPSessionException e) {
|
} catch (LDAPSessionException e) {
|
||||||
throwServletException(httpSession, e);
|
throwServletException(httpSession, e);
|
||||||
}
|
}
|
||||||
req.getRequestDispatcher("/users.jsp").forward(req, resp); //$NON-NLS-1$
|
req.getRequestDispatcher("/users.jsp").forward(req, resp);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user