Loading projects/cadcAccessControl-Server/build.xml +6 −5 Original line number Diff line number Diff line Loading @@ -94,13 +94,14 @@ <property name="cadcUtil" value="${lib}/cadcUtil.jar" /> <property name="cadcUWS" value="${lib}/cadcUWS.jar" /> <property name="javacsv" value="${ext.lib}/javacsv.jar" /> <property name="jdom2" value="${ext.lib}/jdom2.jar" /> <property name="log4j" value="${ext.lib}/log4j.jar" /> <property name="servlet" value="${ext.lib}/servlet-api.jar" /> <property name="unboundid" value="${ext.lib}/unboundid-ldapsdk-se.jar" /> <property name="xerces" value="${ext.lib}/xerces.jar" /> <property name="jars" value="${cadcAccessControl}:${cadcLog}:${cadcRegistry}:${cadcUtil}:${cadcUWS}:${jdom2}:${log4j}:${servlet}:${unboundid}:${xerces}" /> <property name="jars" value="${cadcAccessControl}:${cadcLog}:${cadcRegistry}:${cadcUtil}:${cadcUWS}:${javacsv}:${jdom2}:${log4j}:${servlet}:${unboundid}:${xerces}" /> <target name="build" depends="compile"> <jar jarfile="${build}/lib/${project}.jar" Loading Loading @@ -130,7 +131,7 @@ </copy> </target> <!-- <target name="test" depends="compile-test,resources"> <target name="test" depends="compile,compile-test,resources"> <echo message="Running test suite..." /> <junit printsummary="yes" haltonfailure="yes" fork="yes"> <classpath> Loading @@ -138,9 +139,9 @@ <pathelement path="${build}/test/class"/> <pathelement path="${testingJars}"/> </classpath> <test name="ca.nrc.cadc.ac.server.ldap.LdapDAOTest" /> <test name="ca.nrc.cadc.ac.server.ldap.LdapGroupDAOTest" /> <formatter type="plain" usefile="false" /> </junit> </target>--> </target> </project> projects/cadcAccessControl-Server/src/ca/nrc/cadc/ac/server/GroupPersistence.java +10 −0 Original line number Diff line number Diff line Loading @@ -81,6 +81,16 @@ import ca.nrc.cadc.net.TransientException; public abstract interface GroupPersistence<T extends Principal> { /** * Get all group names. * * @return A collection of strings. * @throws TransientException If an temporary, unexpected problem occurred. * @throws AccessControlException If the operation is not permitted. */ public Collection<String> getGroupNames() throws TransientException, AccessControlException; /** * Get the group with the given Group ID. * Loading projects/cadcAccessControl-Server/src/ca/nrc/cadc/ac/server/ldap/LdapGroupDAO.java +53 −1 Original line number Diff line number Diff line Loading @@ -88,6 +88,7 @@ import ca.nrc.cadc.ac.Role; import ca.nrc.cadc.ac.User; import ca.nrc.cadc.ac.UserNotFoundException; import ca.nrc.cadc.net.TransientException; import ca.nrc.cadc.util.StringUtil; import com.unboundid.ldap.sdk.AddRequest; import com.unboundid.ldap.sdk.Attribute; Loading Loading @@ -214,7 +215,7 @@ public class LdapGroupDAO<T extends Principal> extends LdapDAO attributes.add(new Attribute("objectClass", "groupofuniquenames")); attributes.add(new Attribute("cn", groupID)); if (description != null) if (StringUtil.hasText(description)) { attributes.add(new Attribute("description", description)); } Loading Loading @@ -306,6 +307,57 @@ public class LdapGroupDAO<T extends Principal> extends LdapDAO } } /** * Get all group names. * * @return A collection of strings * * @throws TransientException If an temporary, unexpected problem occurred. */ public Collection<String> getGroupNames() throws TransientException, AccessControlException { try { Filter filter = Filter.createEqualityFilter("cn", "*"); String [] attributes = new String[] {"cn", "nsaccountlock"}; SearchRequest searchRequest = new SearchRequest(config.getGroupsDN(), SearchScope.SUB, filter, attributes); SearchResult searchResult = null; try { searchResult = getConnection().search(searchRequest); } catch (LDAPSearchException e) { if (e.getResultCode() == ResultCode.NO_SUCH_OBJECT) { logger.debug("Count not find groups root", e); throw new IllegalStateException("Count not find groups root"); } } LdapDAO.checkLdapResult(searchResult.getResultCode()); List<String> groupNames = new ArrayList<String>(); for (SearchResultEntry next : searchResult.getSearchEntries()) { groupNames.add(next.getAttributeValue("cn")); } return groupNames; } catch (LDAPException e1) { LdapDAO.checkLdapResult(e1.getResultCode()); throw new IllegalStateException("Unexpected exception: " + e1.getMatchedDN(), e1); } } /** * Get the group with the given Group ID. * Loading projects/cadcAccessControl-Server/src/ca/nrc/cadc/ac/server/ldap/LdapGroupPersistence.java +26 −1 Original line number Diff line number Diff line Loading @@ -94,6 +94,31 @@ public class LdapGroupPersistence<T extends Principal> config = LdapConfig.getLdapConfig(); } public Collection<String> getGroupNames() throws TransientException, AccessControlException { LdapGroupDAO<T> groupDAO = null; LdapUserDAO<T> userDAO = null; try { userDAO = new LdapUserDAO<T>(config); groupDAO = new LdapGroupDAO<T>(config, userDAO); Collection<String> ret = groupDAO.getGroupNames(); return ret; } finally { if (groupDAO != null) { groupDAO.close(); } if (userDAO != null) { userDAO.close(); } } } public Group getGroup(String groupName) throws GroupNotFoundException, TransientException, AccessControlException Loading projects/cadcAccessControl-Server/src/ca/nrc/cadc/ac/server/web/GetGroupNamesAction.java +9 −2 Original line number Diff line number Diff line Loading @@ -73,6 +73,8 @@ import ca.nrc.cadc.ac.server.GroupPersistence; import com.csvreader.CsvWriter; import javax.servlet.http.HttpServletResponse; public class GetGroupNamesAction extends GroupsAction { Loading @@ -86,9 +88,9 @@ public class GetGroupNamesAction extends GroupsAction { GroupPersistence groupPersistence = getGroupPersistence(); Collection<String> groups = groupPersistence.getGroupNames(); response.setContentType("text/csv"); getHttpServletResponse().setContentType("text/csv"); CsvWriter writer = new CsvWriter(response.getWriter(), ','); CsvWriter writer = new CsvWriter(getHttpServletResponse().getWriter(), ','); for (String group : groups) { Loading @@ -98,4 +100,9 @@ public class GetGroupNamesAction extends GroupsAction return null; } protected HttpServletResponse getHttpServletResponse() { return this.response; } } Loading
projects/cadcAccessControl-Server/build.xml +6 −5 Original line number Diff line number Diff line Loading @@ -94,13 +94,14 @@ <property name="cadcUtil" value="${lib}/cadcUtil.jar" /> <property name="cadcUWS" value="${lib}/cadcUWS.jar" /> <property name="javacsv" value="${ext.lib}/javacsv.jar" /> <property name="jdom2" value="${ext.lib}/jdom2.jar" /> <property name="log4j" value="${ext.lib}/log4j.jar" /> <property name="servlet" value="${ext.lib}/servlet-api.jar" /> <property name="unboundid" value="${ext.lib}/unboundid-ldapsdk-se.jar" /> <property name="xerces" value="${ext.lib}/xerces.jar" /> <property name="jars" value="${cadcAccessControl}:${cadcLog}:${cadcRegistry}:${cadcUtil}:${cadcUWS}:${jdom2}:${log4j}:${servlet}:${unboundid}:${xerces}" /> <property name="jars" value="${cadcAccessControl}:${cadcLog}:${cadcRegistry}:${cadcUtil}:${cadcUWS}:${javacsv}:${jdom2}:${log4j}:${servlet}:${unboundid}:${xerces}" /> <target name="build" depends="compile"> <jar jarfile="${build}/lib/${project}.jar" Loading Loading @@ -130,7 +131,7 @@ </copy> </target> <!-- <target name="test" depends="compile-test,resources"> <target name="test" depends="compile,compile-test,resources"> <echo message="Running test suite..." /> <junit printsummary="yes" haltonfailure="yes" fork="yes"> <classpath> Loading @@ -138,9 +139,9 @@ <pathelement path="${build}/test/class"/> <pathelement path="${testingJars}"/> </classpath> <test name="ca.nrc.cadc.ac.server.ldap.LdapDAOTest" /> <test name="ca.nrc.cadc.ac.server.ldap.LdapGroupDAOTest" /> <formatter type="plain" usefile="false" /> </junit> </target>--> </target> </project>
projects/cadcAccessControl-Server/src/ca/nrc/cadc/ac/server/GroupPersistence.java +10 −0 Original line number Diff line number Diff line Loading @@ -81,6 +81,16 @@ import ca.nrc.cadc.net.TransientException; public abstract interface GroupPersistence<T extends Principal> { /** * Get all group names. * * @return A collection of strings. * @throws TransientException If an temporary, unexpected problem occurred. * @throws AccessControlException If the operation is not permitted. */ public Collection<String> getGroupNames() throws TransientException, AccessControlException; /** * Get the group with the given Group ID. * Loading
projects/cadcAccessControl-Server/src/ca/nrc/cadc/ac/server/ldap/LdapGroupDAO.java +53 −1 Original line number Diff line number Diff line Loading @@ -88,6 +88,7 @@ import ca.nrc.cadc.ac.Role; import ca.nrc.cadc.ac.User; import ca.nrc.cadc.ac.UserNotFoundException; import ca.nrc.cadc.net.TransientException; import ca.nrc.cadc.util.StringUtil; import com.unboundid.ldap.sdk.AddRequest; import com.unboundid.ldap.sdk.Attribute; Loading Loading @@ -214,7 +215,7 @@ public class LdapGroupDAO<T extends Principal> extends LdapDAO attributes.add(new Attribute("objectClass", "groupofuniquenames")); attributes.add(new Attribute("cn", groupID)); if (description != null) if (StringUtil.hasText(description)) { attributes.add(new Attribute("description", description)); } Loading Loading @@ -306,6 +307,57 @@ public class LdapGroupDAO<T extends Principal> extends LdapDAO } } /** * Get all group names. * * @return A collection of strings * * @throws TransientException If an temporary, unexpected problem occurred. */ public Collection<String> getGroupNames() throws TransientException, AccessControlException { try { Filter filter = Filter.createEqualityFilter("cn", "*"); String [] attributes = new String[] {"cn", "nsaccountlock"}; SearchRequest searchRequest = new SearchRequest(config.getGroupsDN(), SearchScope.SUB, filter, attributes); SearchResult searchResult = null; try { searchResult = getConnection().search(searchRequest); } catch (LDAPSearchException e) { if (e.getResultCode() == ResultCode.NO_SUCH_OBJECT) { logger.debug("Count not find groups root", e); throw new IllegalStateException("Count not find groups root"); } } LdapDAO.checkLdapResult(searchResult.getResultCode()); List<String> groupNames = new ArrayList<String>(); for (SearchResultEntry next : searchResult.getSearchEntries()) { groupNames.add(next.getAttributeValue("cn")); } return groupNames; } catch (LDAPException e1) { LdapDAO.checkLdapResult(e1.getResultCode()); throw new IllegalStateException("Unexpected exception: " + e1.getMatchedDN(), e1); } } /** * Get the group with the given Group ID. * Loading
projects/cadcAccessControl-Server/src/ca/nrc/cadc/ac/server/ldap/LdapGroupPersistence.java +26 −1 Original line number Diff line number Diff line Loading @@ -94,6 +94,31 @@ public class LdapGroupPersistence<T extends Principal> config = LdapConfig.getLdapConfig(); } public Collection<String> getGroupNames() throws TransientException, AccessControlException { LdapGroupDAO<T> groupDAO = null; LdapUserDAO<T> userDAO = null; try { userDAO = new LdapUserDAO<T>(config); groupDAO = new LdapGroupDAO<T>(config, userDAO); Collection<String> ret = groupDAO.getGroupNames(); return ret; } finally { if (groupDAO != null) { groupDAO.close(); } if (userDAO != null) { userDAO.close(); } } } public Group getGroup(String groupName) throws GroupNotFoundException, TransientException, AccessControlException Loading
projects/cadcAccessControl-Server/src/ca/nrc/cadc/ac/server/web/GetGroupNamesAction.java +9 −2 Original line number Diff line number Diff line Loading @@ -73,6 +73,8 @@ import ca.nrc.cadc.ac.server.GroupPersistence; import com.csvreader.CsvWriter; import javax.servlet.http.HttpServletResponse; public class GetGroupNamesAction extends GroupsAction { Loading @@ -86,9 +88,9 @@ public class GetGroupNamesAction extends GroupsAction { GroupPersistence groupPersistence = getGroupPersistence(); Collection<String> groups = groupPersistence.getGroupNames(); response.setContentType("text/csv"); getHttpServletResponse().setContentType("text/csv"); CsvWriter writer = new CsvWriter(response.getWriter(), ','); CsvWriter writer = new CsvWriter(getHttpServletResponse().getWriter(), ','); for (String group : groups) { Loading @@ -98,4 +100,9 @@ public class GetGroupNamesAction extends GroupsAction return null; } protected HttpServletResponse getHttpServletResponse() { return this.response; } }