format code
This commit is contained in:
parent
904f4c330f
commit
22dd341de7
@ -13,7 +13,7 @@ public class Group implements Serializable, LDAPBean {
|
|||||||
private List<String> members;
|
private List<String> members;
|
||||||
|
|
||||||
public Group() {
|
public Group() {
|
||||||
members = new ArrayList<String>();
|
members = new ArrayList<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getName() {
|
public String getName() {
|
||||||
|
@ -22,9 +22,9 @@ public class GroupsDAO {
|
|||||||
this.session = session;
|
this.session = session;
|
||||||
}
|
}
|
||||||
|
|
||||||
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 = new TreeMap<String, Group>();
|
list = new TreeMap<>();
|
||||||
final List<SearchResult> searchResult = session.search("ou=groups"); //$NON-NLS-1$
|
final List<SearchResult> searchResult = session.search("ou=groups"); //$NON-NLS-1$
|
||||||
for (final SearchResult result : searchResult) {
|
for (final SearchResult result : searchResult) {
|
||||||
final Attributes attribs = result.getAttributes();
|
final Attributes attribs = result.getAttributes();
|
||||||
@ -33,11 +33,9 @@ public class GroupsDAO {
|
|||||||
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"); //$NON-NLS-1$
|
||||||
final String dn = grp.getDn();
|
final String dn = grp.getDn();
|
||||||
for (String userDN : listOfMembers) {
|
listOfMembers.stream().map((userDN) -> users.get(userDN)).map((user) -> user.getGroups()).forEachOrdered((groups) -> {
|
||||||
final User user = users.get(userDN);
|
|
||||||
final List<String> groups = user.getGroups();
|
|
||||||
groups.add(dn);
|
groups.add(dn);
|
||||||
}
|
});
|
||||||
grp.setMembers(listOfMembers);
|
grp.setMembers(listOfMembers);
|
||||||
list.put(dn, grp);
|
list.put(dn, grp);
|
||||||
}
|
}
|
||||||
@ -57,9 +55,9 @@ public class GroupsDAO {
|
|||||||
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"); //$NON-NLS-1$
|
||||||
if (uniqueMembers != null && uniqueMembers.size() > 0) {
|
if (uniqueMembers != null && uniqueMembers.size() > 0) {
|
||||||
for (String dn : uniqueMembers) {
|
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); //$NON-NLS-1$ //$NON-NLS-2$
|
||||||
@ -72,11 +70,9 @@ public class GroupsDAO {
|
|||||||
grp.setDn(dn);
|
grp.setDn(dn);
|
||||||
grp.setName(session.getStringValue(attribs, "cn")); //$NON-NLS-1$
|
grp.setName(session.getStringValue(attribs, "cn")); //$NON-NLS-1$
|
||||||
final List<String> listOfMembers = session.getListOfValues(attribs, "uniqueMember"); //$NON-NLS-1$
|
final List<String> listOfMembers = session.getListOfValues(attribs, "uniqueMember"); //$NON-NLS-1$
|
||||||
for (String userDN : listOfMembers) {
|
listOfMembers.stream().map((userDN) -> users.get(userDN)).map((user) -> user.getGroups()).forEachOrdered((groups) -> {
|
||||||
final User user = users.get(userDN);
|
|
||||||
final List<String> groups = user.getGroups();
|
|
||||||
groups.add(dn);
|
groups.add(dn);
|
||||||
}
|
});
|
||||||
grp.setMembers(listOfMembers);
|
grp.setMembers(listOfMembers);
|
||||||
return grp;
|
return grp;
|
||||||
}
|
}
|
||||||
@ -85,13 +81,13 @@ public class GroupsDAO {
|
|||||||
assert grp != null;
|
assert grp != null;
|
||||||
final String name = grp.getName();
|
final String name = grp.getName();
|
||||||
assert name != null;
|
assert name != null;
|
||||||
if (grp.getMembers().size() == 0) {
|
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"); //$NON-NLS-1$
|
||||||
for (final String memberDN : grp.getMembers()) {
|
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}); //$NON-NLS-1$ //$NON-NLS-2$
|
||||||
}
|
}
|
||||||
|
@ -69,7 +69,8 @@ private InitialDirContext ctx;
|
|||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
final int size = attribute.size();
|
final int size = attribute.size();
|
||||||
List<String> listOfValues = new ArrayList<String>();
|
List<String> listOfValues;
|
||||||
|
listOfValues = new ArrayList<>();
|
||||||
for (int idx = 0; idx < size; idx++) {
|
for (int idx = 0; idx < size; idx++) {
|
||||||
listOfValues.add((String) attribute.get(idx));
|
listOfValues.add((String) attribute.get(idx));
|
||||||
}
|
}
|
||||||
@ -91,7 +92,8 @@ private InitialDirContext ctx;
|
|||||||
}
|
}
|
||||||
|
|
||||||
public List<SearchResult> search(final String name, final String attribName, final String attribValue) throws LDAPSessionException {
|
public List<SearchResult> search(final String name, final String attribName, final String attribValue) throws LDAPSessionException {
|
||||||
final List<SearchResult> searchResult = new ArrayList<SearchResult>();
|
final List<SearchResult> searchResult;
|
||||||
|
searchResult = new ArrayList<>();
|
||||||
try {
|
try {
|
||||||
Attributes matchingAttributes = new BasicAttributes();
|
Attributes matchingAttributes = new BasicAttributes();
|
||||||
matchingAttributes.put(attribName, attribValue);
|
matchingAttributes.put(attribName, attribValue);
|
||||||
@ -106,7 +108,8 @@ private InitialDirContext ctx;
|
|||||||
}
|
}
|
||||||
|
|
||||||
public List<SearchResult> search(final String name) throws LDAPSessionException {
|
public List<SearchResult> search(final String name) throws LDAPSessionException {
|
||||||
final List<SearchResult> searchResult = new ArrayList<SearchResult>();
|
final List<SearchResult> searchResult;
|
||||||
|
searchResult = new ArrayList<>();
|
||||||
try {
|
try {
|
||||||
final NamingEnumeration<SearchResult> searchEnum = ctx.search(name, null);
|
final NamingEnumeration<SearchResult> searchEnum = ctx.search(name, null);
|
||||||
while (searchEnum.hasMore()) {
|
while (searchEnum.hasMore()) {
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
package de.jalin.ldapadmin.ldap;
|
package de.jalin.ldapadmin.ldap;
|
||||||
|
|
||||||
|
|
||||||
public class PasswordValidator {
|
public class PasswordValidator {
|
||||||
|
|
||||||
private static final int MIN_PASSWORD_LEN = 6;
|
private static final int MIN_PASSWORD_LEN = 6;
|
||||||
@ -24,13 +23,15 @@ public class PasswordValidator {
|
|||||||
} else {
|
} else {
|
||||||
if (type == Character.LOWERCASE_LETTER) {
|
if (type == Character.LOWERCASE_LETTER) {
|
||||||
hasLowerCaseChar = 1;
|
hasLowerCaseChar = 1;
|
||||||
} else
|
} else {
|
||||||
if (type == Character.UPPERCASE_LETTER) {
|
if (type == Character.UPPERCASE_LETTER) {
|
||||||
hasUpperCaseChar = 1;
|
hasUpperCaseChar = 1;
|
||||||
} else
|
} else {
|
||||||
hasSpecialChar = 1;
|
hasSpecialChar = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
if (hasDigits + hasLowerCaseChar + hasUpperCaseChar + hasSpecialChar < 3) {
|
if (hasDigits + hasLowerCaseChar + hasUpperCaseChar + hasSpecialChar < 3) {
|
||||||
throw new SimplePasswordException("a password requires 3 out of 4 "
|
throw new SimplePasswordException("a password requires 3 out of 4 "
|
||||||
+ "different character types: lowercase, uppercase, digits and special characters");
|
+ "different character types: lowercase, uppercase, digits and special characters");
|
||||||
|
@ -22,8 +22,7 @@ public class UsersDAO {
|
|||||||
this.session = session;
|
this.session = session;
|
||||||
}
|
}
|
||||||
|
|
||||||
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"); //$NON-NLS-1$
|
||||||
for (SearchResult result : enumeration) {
|
for (SearchResult result : enumeration) {
|
||||||
|
@ -66,8 +66,7 @@ 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); //$NON-NLS-1$
|
||||||
LOG.severe(e.getMessage());
|
LOG.severe(e.getMessage());
|
||||||
throw new ServletException(e);
|
throw new ServletException(e);
|
||||||
|
@ -43,7 +43,6 @@ public class GroupServlet extends AbstractLDAPServlet {
|
|||||||
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" : ""); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
|
||||||
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"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
|
||||||
|
|
||||||
|
|
||||||
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 {
|
||||||
@ -79,7 +78,8 @@ public class GroupServlet extends AbstractLDAPServlet {
|
|||||||
members = new ArrayList<>();
|
members = new ArrayList<>();
|
||||||
final HttpSession httpSession = req.getSession();
|
final HttpSession httpSession = req.getSession();
|
||||||
cleanSession(httpSession);
|
cleanSession(httpSession);
|
||||||
@SuppressWarnings("unchecked") final SortedMap<String, User> usersHash = (SortedMap<String, User>) httpSession.getAttribute("users"); //$NON-NLS-1$
|
@SuppressWarnings("unchecked")
|
||||||
|
final SortedMap<String, User> usersHash = (SortedMap<String, User>) httpSession.getAttribute("users"); //$NON-NLS-1$
|
||||||
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();
|
||||||
|
@ -21,8 +21,7 @@ public class GroupsServlet extends AbstractLDAPServlet {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
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();
|
||||||
cleanSession(httpSession);
|
cleanSession(httpSession);
|
||||||
final UsersDAO usersDAO = new UsersDAO(ldapSession);
|
final UsersDAO usersDAO = new UsersDAO(ldapSession);
|
||||||
|
@ -29,7 +29,6 @@ import de.jalin.ldapadmin.ldap.UsersDAO;
|
|||||||
@WebServlet(name = "ResetPassword", urlPatterns = {"/passwordreset"})
|
@WebServlet(name = "ResetPassword", urlPatterns = {"/passwordreset"})
|
||||||
public class ResetPasswordServlet extends AbstractLDAPServlet {
|
public class ResetPasswordServlet extends AbstractLDAPServlet {
|
||||||
|
|
||||||
|
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
private String smtpHost;
|
private String smtpHost;
|
||||||
|
@ -99,7 +99,8 @@ public class UserServlet extends AbstractLDAPServlet {
|
|||||||
usr.setMobile(mobile);
|
usr.setMobile(mobile);
|
||||||
final List<String> memberships;
|
final List<String> memberships;
|
||||||
memberships = new ArrayList<>();
|
memberships = new ArrayList<>();
|
||||||
@SuppressWarnings("unchecked") final SortedMap<String, Group> groupsHash = (SortedMap<String, Group>) httpSession.getAttribute("groups"); //$NON-NLS-1$
|
@SuppressWarnings("unchecked")
|
||||||
|
final SortedMap<String, Group> groupsHash = (SortedMap<String, Group>) httpSession.getAttribute("groups"); //$NON-NLS-1$
|
||||||
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();
|
||||||
|
Loading…
Reference in New Issue
Block a user