format code

This commit is contained in:
Peter Hormanns 2019-07-16 20:32:31 +02:00
parent 904f4c330f
commit 22dd341de7
31 changed files with 1649 additions and 1652 deletions

View File

@ -13,7 +13,7 @@ public class Group implements Serializable, LDAPBean {
private List<String> members;
public Group() {
members = new ArrayList<String>();
members = new ArrayList<>();
}
public String getName() {

View File

@ -22,9 +22,9 @@ public class GroupsDAO {
this.session = session;
}
public SortedMap<String, Group> loadGroups(final SortedMap<String, User> users) throws LDAPSessionException
{
final SortedMap<String, Group> list = new TreeMap<String, Group>();
public SortedMap<String, Group> loadGroups(final SortedMap<String, User> users) throws LDAPSessionException {
final SortedMap<String, Group> list;
list = new TreeMap<>();
final List<SearchResult> searchResult = session.search("ou=groups"); //$NON-NLS-1$
for (final SearchResult result : searchResult) {
final Attributes attribs = result.getAttributes();
@ -33,11 +33,9 @@ public class GroupsDAO {
grp.setDn(result.getNameInNamespace());
final List<String> listOfMembers = session.getListOfValues(attribs, "uniqueMember"); //$NON-NLS-1$
final String dn = grp.getDn();
for (String userDN : listOfMembers) {
final User user = users.get(userDN);
final List<String> groups = user.getGroups();
listOfMembers.stream().map((userDN) -> users.get(userDN)).map((user) -> user.getGroups()).forEachOrdered((groups) -> {
groups.add(dn);
}
});
grp.setMembers(listOfMembers);
list.put(dn, grp);
}
@ -57,9 +55,9 @@ public class GroupsDAO {
final List<String> uniqueMembers = grp.getMembers();
final BasicAttribute uniqMembers = new BasicAttribute("uniqueMember"); //$NON-NLS-1$
if (uniqueMembers != null && uniqueMembers.size() > 0) {
for (String dn : uniqueMembers) {
uniqueMembers.forEach((dn) -> {
uniqMembers.add(dn);
}
});
}
attributes.put(uniqMembers);
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.setName(session.getStringValue(attribs, "cn")); //$NON-NLS-1$
final List<String> listOfMembers = session.getListOfValues(attribs, "uniqueMember"); //$NON-NLS-1$
for (String userDN : listOfMembers) {
final User user = users.get(userDN);
final List<String> groups = user.getGroups();
listOfMembers.stream().map((userDN) -> users.get(userDN)).map((user) -> user.getGroups()).forEachOrdered((groups) -> {
groups.add(dn);
}
});
grp.setMembers(listOfMembers);
return grp;
}
@ -85,13 +81,13 @@ public class GroupsDAO {
assert grp != null;
final String name = grp.getName();
assert name != null;
if (grp.getMembers().size() == 0) {
if (grp.getMembers().isEmpty()) {
throw new NoGroupMembersException(name);
}
final BasicAttribute membersOfAttrib = new BasicAttribute("uniqueMember"); //$NON-NLS-1$
for (final String memberDN : grp.getMembers()) {
grp.getMembers().forEach((memberDN) -> {
membersOfAttrib.add(memberDN);
}
});
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$
}

View File

@ -69,7 +69,8 @@ private InitialDirContext ctx;
}
try {
final int size = attribute.size();
List<String> listOfValues = new ArrayList<String>();
List<String> listOfValues;
listOfValues = new ArrayList<>();
for (int idx = 0; idx < size; 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 {
final List<SearchResult> searchResult = new ArrayList<SearchResult>();
final List<SearchResult> searchResult;
searchResult = new ArrayList<>();
try {
Attributes matchingAttributes = new BasicAttributes();
matchingAttributes.put(attribName, attribValue);
@ -106,7 +108,8 @@ private InitialDirContext ctx;
}
public List<SearchResult> search(final String name) throws LDAPSessionException {
final List<SearchResult> searchResult = new ArrayList<SearchResult>();
final List<SearchResult> searchResult;
searchResult = new ArrayList<>();
try {
final NamingEnumeration<SearchResult> searchEnum = ctx.search(name, null);
while (searchEnum.hasMore()) {

View File

@ -1,6 +1,5 @@
package de.jalin.ldapadmin.ldap;
public class PasswordValidator {
private static final int MIN_PASSWORD_LEN = 6;
@ -24,13 +23,15 @@ public class PasswordValidator {
} else {
if (type == Character.LOWERCASE_LETTER) {
hasLowerCaseChar = 1;
} else
} else {
if (type == Character.UPPERCASE_LETTER) {
hasUpperCaseChar = 1;
} else
} else {
hasSpecialChar = 1;
}
}
}
}
if (hasDigits + hasLowerCaseChar + hasUpperCaseChar + hasSpecialChar < 3) {
throw new SimplePasswordException("a password requires 3 out of 4 "
+ "different character types: lowercase, uppercase, digits and special characters");

View File

@ -22,8 +22,7 @@ public class UsersDAO {
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 List<SearchResult> enumeration = session.search("ou=users"); //$NON-NLS-1$
for (SearchResult result : enumeration) {

View File

@ -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$
LOG.severe(e.getMessage());
throw new ServletException(e);

View File

@ -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("iddisabled", "create".equals(operation) ? "" : "disabled"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
final GroupsDAO groupsDAO = new GroupsDAO(ldapSession);
final UsersDAO usersDAO = new UsersDAO(ldapSession);
try {
@ -79,7 +78,8 @@ public class GroupServlet extends AbstractLDAPServlet {
members = new ArrayList<>();
final HttpSession httpSession = req.getSession();
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();
while (userDNIterator.hasNext()) {
final String userDN = userDNIterator.next();

View File

@ -21,8 +21,7 @@ public class GroupsServlet extends AbstractLDAPServlet {
@Override
protected void doGet(final HttpServletRequest req, final HttpServletResponse resp)
throws ServletException, IOException
{
throws ServletException, IOException {
final HttpSession httpSession = req.getSession();
cleanSession(httpSession);
final UsersDAO usersDAO = new UsersDAO(ldapSession);

View File

@ -29,7 +29,6 @@ import de.jalin.ldapadmin.ldap.UsersDAO;
@WebServlet(name = "ResetPassword", urlPatterns = {"/passwordreset"})
public class ResetPasswordServlet extends AbstractLDAPServlet {
private static final long serialVersionUID = 1L;
private String smtpHost;

View File

@ -99,7 +99,8 @@ public class UserServlet extends AbstractLDAPServlet {
usr.setMobile(mobile);
final List<String> memberships;
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();
while (groupDNIterator.hasNext()) {
final String groupDN = groupDNIterator.next();