Loading projects/cadcAccessControl-Admin/build.xml +0 −1 Original line number Diff line number Diff line Loading @@ -87,7 +87,6 @@ <property name="cadcAccessControl" value="${lib}/cadcAccessControl.jar" /> <property name="cadcAccessControl-Server" value="${lib}/cadcAccessControl-Server.jar" /> <property name="cadcUtil" value="${lib}/cadcUtil.jar" /> <property name="javaUtil" value="${lib}/javaUtil.jar" /> <property name="log4j" value="${ext.lib}/log4j.jar" /> <property name="commons-logging" value="${ext.lib}/commons-logging.jar" /> <property name="jconn3" value="${ext.lib}/jconn3.jar" /> Loading projects/cadcAccessControl-Admin/src/ca/nrc/cadc/ac/admin/List.java→projects/cadcAccessControl-Admin/src/ca/nrc/cadc/ac/admin/AbstractListUsers.java +9 −15 Original line number Diff line number Diff line Loading @@ -7,36 +7,30 @@ import java.util.Collection; import org.apache.log4j.Logger; import ca.nrc.cadc.ac.User; import ca.nrc.cadc.ac.server.UserPersistence; import ca.nrc.cadc.net.TransientException; /** * This class provides a list of all active users in the LDAP server. * This class provides a list of all active or pending users in the LDAP server. * The users' nsaccountlocked attribute is not set. * @author yeunga * */ public class List extends AbstractCommand public abstract class AbstractListUsers extends AbstractCommand { private static final Logger log = Logger.getLogger(List.class); private static final Logger log = Logger.getLogger(AbstractListUsers.class); /** * Constructor */ public List() { } protected abstract Collection<User<Principal>> getUsers() throws AccessControlException, TransientException; @Override public Object run() { try { final UserPersistence<Principal> userPersistence = getUserPersistence(); Collection<User<Principal>> users = userPersistence.getUsers(); Collection<User<Principal>> users = this.getUsers(); for (User<Principal> user : users) { systemOut.println(user.getUserID().getName()); this.systemOut.println(user.getUserID().getName()); } } catch (AccessControlException e) Loading projects/cadcAccessControl-Admin/src/ca/nrc/cadc/ac/admin/Approve.java→projects/cadcAccessControl-Admin/src/ca/nrc/cadc/ac/admin/ApproveUser.java +3 −3 Original line number Diff line number Diff line Loading @@ -8,9 +8,9 @@ import org.apache.log4j.Logger; * @author yeunga * */ public class Approve extends AbstractCommand public class ApproveUser extends AbstractCommand { private static final Logger log = Logger.getLogger(Approve.class); private static final Logger log = Logger.getLogger(ApproveUser.class); private String userID; Loading @@ -18,7 +18,7 @@ public class Approve extends AbstractCommand * Constructor * @param userID Id of the pending user to be approved */ public Approve(final String userID) public ApproveUser(final String userID) { this.userID = userID; } Loading projects/cadcAccessControl-Admin/src/ca/nrc/cadc/ac/admin/CmdLineParser.java +92 −45 Original line number Diff line number Diff line Loading @@ -73,11 +73,14 @@ import java.security.cert.CertificateException; import javax.security.auth.Subject; import org.apache.log4j.Level; import org.apache.log4j.Logger; import ca.nrc.cadc.auth.CertCmdArgUtil; import ca.nrc.cadc.auth.SSLUtil; import ca.nrc.cadc.util.ArgumentMap; import ca.nrc.cadc.util.Log4jInit; import ca.nrc.cadc.util.StringUtil; Loading @@ -93,13 +96,18 @@ public class CmdLineParser private String appName = ""; private AbstractCommand command; private Subject subject; private ArgumentMap am; private Level logLevel = Level.DEBUG; /** * Default constructor. */ public CmdLineParser(final String name) public CmdLineParser(final String name, final String[] args) { this.appName = name; ArgumentMap am = new ArgumentMap( args ); this.am = am; } /** Loading Loading @@ -129,91 +137,130 @@ public class CmdLineParser return this.subject; } /** * Get the log level. * @throws UsageException */ public Level getLogLevel() { return this.logLevel; } /** * Get the log level. * @throws UsageException */ public void setLogLevel() throws UsageException { int count = 0; // only one log level is allowed if (am.isSet("v") || am.isSet("verbose")) { this.logLevel = Level.INFO; count++; } if (am.isSet("d") || am.isSet("debug")) { this.logLevel = Level.DEBUG; count++; } if (count >=2) { String msg = "--verbose and --debug are mutually exclusive options\n"; throw new UsageException(msg); } } protected boolean hasValue(final String userID) throws UsageException { if (!StringUtil.hasText(userID) ||userID.equalsIgnoreCase("true")) { String msg = "Missing userID"; throw new UsageException(msg); } else { return true; } } protected boolean isValid(final ArgumentMap am) throws UsageException { int levelCount = 0; int cmdCount = 0; int count = 0; // only one command is allowed per command line if (am.isSet("list")) { this.command = new List(); cmdCount++; this.command = new ListActiveUsers(); count++; } if (am.isSet("list-pending")) { this.command = new ListPending(); cmdCount++; this.command = new ListPendingUsers(); count++; } String userID = am.getValue("view"); if ((userID != null ) && (!userID.equalsIgnoreCase("true"))) if (userID != null ) { if (this.hasValue(userID)) { this.command = new View(userID); cmdCount++; this.command = new ViewUser(userID); } count++; } userID = am.getValue("reject"); if ((userID != null ) && (!userID.equalsIgnoreCase("true"))) if (userID != null ) { this.command = new Reject(userID); cmdCount++; if (this.hasValue(userID)) { this.command = new RejectUser(userID); } userID = am.getValue("approve"); if ((userID != null ) && (!userID.equalsIgnoreCase("true"))) { this.command = new Approve(userID); cmdCount++; count++; } // only one log level is allowed if (am.isSet("v") || am.isSet("verbose")) userID = am.getValue("approve"); if (userID != null ) { if (this.hasValue(userID)) { levelCount++; this.command = new ApproveUser(userID); } if (am.isSet("d") || am.isSet("debug")) { levelCount++; count++; } if ((cmdCount == 1) && (levelCount <2)) if (count == 1) { return true; } else { String msg = ""; if (cmdCount > 1) { msg = "Only one command can be specified.\n"; } if (levelCount == 2) { msg = "--verbose and --debug are mutually exclusive options\n"; } String msg = "Only one command can be specified.\n"; throw new UsageException(msg); } } /** * Parse the command line arguments. * @param args command line arguments * @throws UsageException Error in command line * @throws CertificateException */ public void parse(final String[] args) throws UsageException, CertificateException public void parse() throws UsageException, CertificateException { ArgumentMap am = new ArgumentMap( args ); this.proceed = false; if (!am.isSet("h") && !am.isSet("help") && isValid(am)) if (!this.am.isSet("h") && !this.am.isSet("help") && isValid(this.am)) { Subject subject = CertCmdArgUtil.initSubject(am, true); Subject subject = CertCmdArgUtil.initSubject(this.am, true); try { SSLUtil.validateSubject(subject, null); Loading @@ -222,7 +269,7 @@ public class CmdLineParser } catch (CertificateException e) { if (am.isSet("list") || am.isSet("list-pending")) if (this.am.isSet("list") || this.am.isSet("list-pending")) { // we can use anonymous subject this.proceed = true; Loading projects/cadcAccessControl-Admin/src/ca/nrc/cadc/ac/admin/ListActiveUsers.java 0 → 100644 +37 −0 Original line number Diff line number Diff line package ca.nrc.cadc.ac.admin; import java.security.AccessControlException; import java.security.Principal; import java.util.Collection; import org.apache.log4j.Logger; import ca.nrc.cadc.ac.User; import ca.nrc.cadc.ac.server.UserPersistence; import ca.nrc.cadc.net.TransientException; /** * This class provides a list of all active users in the LDAP server. * The users' nsaccountlocked attribute is not set. Active users are users * in the main tree. * @author yeunga * */ public class ListActiveUsers extends AbstractListUsers { private static final Logger log = Logger.getLogger(ListActiveUsers.class); /** * Constructor */ public ListActiveUsers() { } protected Collection<User<Principal>> getUsers() throws AccessControlException, TransientException { final UserPersistence<Principal> userPersistence = getUserPersistence(); return userPersistence.getUsers(); } } Loading
projects/cadcAccessControl-Admin/build.xml +0 −1 Original line number Diff line number Diff line Loading @@ -87,7 +87,6 @@ <property name="cadcAccessControl" value="${lib}/cadcAccessControl.jar" /> <property name="cadcAccessControl-Server" value="${lib}/cadcAccessControl-Server.jar" /> <property name="cadcUtil" value="${lib}/cadcUtil.jar" /> <property name="javaUtil" value="${lib}/javaUtil.jar" /> <property name="log4j" value="${ext.lib}/log4j.jar" /> <property name="commons-logging" value="${ext.lib}/commons-logging.jar" /> <property name="jconn3" value="${ext.lib}/jconn3.jar" /> Loading
projects/cadcAccessControl-Admin/src/ca/nrc/cadc/ac/admin/List.java→projects/cadcAccessControl-Admin/src/ca/nrc/cadc/ac/admin/AbstractListUsers.java +9 −15 Original line number Diff line number Diff line Loading @@ -7,36 +7,30 @@ import java.util.Collection; import org.apache.log4j.Logger; import ca.nrc.cadc.ac.User; import ca.nrc.cadc.ac.server.UserPersistence; import ca.nrc.cadc.net.TransientException; /** * This class provides a list of all active users in the LDAP server. * This class provides a list of all active or pending users in the LDAP server. * The users' nsaccountlocked attribute is not set. * @author yeunga * */ public class List extends AbstractCommand public abstract class AbstractListUsers extends AbstractCommand { private static final Logger log = Logger.getLogger(List.class); private static final Logger log = Logger.getLogger(AbstractListUsers.class); /** * Constructor */ public List() { } protected abstract Collection<User<Principal>> getUsers() throws AccessControlException, TransientException; @Override public Object run() { try { final UserPersistence<Principal> userPersistence = getUserPersistence(); Collection<User<Principal>> users = userPersistence.getUsers(); Collection<User<Principal>> users = this.getUsers(); for (User<Principal> user : users) { systemOut.println(user.getUserID().getName()); this.systemOut.println(user.getUserID().getName()); } } catch (AccessControlException e) Loading
projects/cadcAccessControl-Admin/src/ca/nrc/cadc/ac/admin/Approve.java→projects/cadcAccessControl-Admin/src/ca/nrc/cadc/ac/admin/ApproveUser.java +3 −3 Original line number Diff line number Diff line Loading @@ -8,9 +8,9 @@ import org.apache.log4j.Logger; * @author yeunga * */ public class Approve extends AbstractCommand public class ApproveUser extends AbstractCommand { private static final Logger log = Logger.getLogger(Approve.class); private static final Logger log = Logger.getLogger(ApproveUser.class); private String userID; Loading @@ -18,7 +18,7 @@ public class Approve extends AbstractCommand * Constructor * @param userID Id of the pending user to be approved */ public Approve(final String userID) public ApproveUser(final String userID) { this.userID = userID; } Loading
projects/cadcAccessControl-Admin/src/ca/nrc/cadc/ac/admin/CmdLineParser.java +92 −45 Original line number Diff line number Diff line Loading @@ -73,11 +73,14 @@ import java.security.cert.CertificateException; import javax.security.auth.Subject; import org.apache.log4j.Level; import org.apache.log4j.Logger; import ca.nrc.cadc.auth.CertCmdArgUtil; import ca.nrc.cadc.auth.SSLUtil; import ca.nrc.cadc.util.ArgumentMap; import ca.nrc.cadc.util.Log4jInit; import ca.nrc.cadc.util.StringUtil; Loading @@ -93,13 +96,18 @@ public class CmdLineParser private String appName = ""; private AbstractCommand command; private Subject subject; private ArgumentMap am; private Level logLevel = Level.DEBUG; /** * Default constructor. */ public CmdLineParser(final String name) public CmdLineParser(final String name, final String[] args) { this.appName = name; ArgumentMap am = new ArgumentMap( args ); this.am = am; } /** Loading Loading @@ -129,91 +137,130 @@ public class CmdLineParser return this.subject; } /** * Get the log level. * @throws UsageException */ public Level getLogLevel() { return this.logLevel; } /** * Get the log level. * @throws UsageException */ public void setLogLevel() throws UsageException { int count = 0; // only one log level is allowed if (am.isSet("v") || am.isSet("verbose")) { this.logLevel = Level.INFO; count++; } if (am.isSet("d") || am.isSet("debug")) { this.logLevel = Level.DEBUG; count++; } if (count >=2) { String msg = "--verbose and --debug are mutually exclusive options\n"; throw new UsageException(msg); } } protected boolean hasValue(final String userID) throws UsageException { if (!StringUtil.hasText(userID) ||userID.equalsIgnoreCase("true")) { String msg = "Missing userID"; throw new UsageException(msg); } else { return true; } } protected boolean isValid(final ArgumentMap am) throws UsageException { int levelCount = 0; int cmdCount = 0; int count = 0; // only one command is allowed per command line if (am.isSet("list")) { this.command = new List(); cmdCount++; this.command = new ListActiveUsers(); count++; } if (am.isSet("list-pending")) { this.command = new ListPending(); cmdCount++; this.command = new ListPendingUsers(); count++; } String userID = am.getValue("view"); if ((userID != null ) && (!userID.equalsIgnoreCase("true"))) if (userID != null ) { if (this.hasValue(userID)) { this.command = new View(userID); cmdCount++; this.command = new ViewUser(userID); } count++; } userID = am.getValue("reject"); if ((userID != null ) && (!userID.equalsIgnoreCase("true"))) if (userID != null ) { this.command = new Reject(userID); cmdCount++; if (this.hasValue(userID)) { this.command = new RejectUser(userID); } userID = am.getValue("approve"); if ((userID != null ) && (!userID.equalsIgnoreCase("true"))) { this.command = new Approve(userID); cmdCount++; count++; } // only one log level is allowed if (am.isSet("v") || am.isSet("verbose")) userID = am.getValue("approve"); if (userID != null ) { if (this.hasValue(userID)) { levelCount++; this.command = new ApproveUser(userID); } if (am.isSet("d") || am.isSet("debug")) { levelCount++; count++; } if ((cmdCount == 1) && (levelCount <2)) if (count == 1) { return true; } else { String msg = ""; if (cmdCount > 1) { msg = "Only one command can be specified.\n"; } if (levelCount == 2) { msg = "--verbose and --debug are mutually exclusive options\n"; } String msg = "Only one command can be specified.\n"; throw new UsageException(msg); } } /** * Parse the command line arguments. * @param args command line arguments * @throws UsageException Error in command line * @throws CertificateException */ public void parse(final String[] args) throws UsageException, CertificateException public void parse() throws UsageException, CertificateException { ArgumentMap am = new ArgumentMap( args ); this.proceed = false; if (!am.isSet("h") && !am.isSet("help") && isValid(am)) if (!this.am.isSet("h") && !this.am.isSet("help") && isValid(this.am)) { Subject subject = CertCmdArgUtil.initSubject(am, true); Subject subject = CertCmdArgUtil.initSubject(this.am, true); try { SSLUtil.validateSubject(subject, null); Loading @@ -222,7 +269,7 @@ public class CmdLineParser } catch (CertificateException e) { if (am.isSet("list") || am.isSet("list-pending")) if (this.am.isSet("list") || this.am.isSet("list-pending")) { // we can use anonymous subject this.proceed = true; Loading
projects/cadcAccessControl-Admin/src/ca/nrc/cadc/ac/admin/ListActiveUsers.java 0 → 100644 +37 −0 Original line number Diff line number Diff line package ca.nrc.cadc.ac.admin; import java.security.AccessControlException; import java.security.Principal; import java.util.Collection; import org.apache.log4j.Logger; import ca.nrc.cadc.ac.User; import ca.nrc.cadc.ac.server.UserPersistence; import ca.nrc.cadc.net.TransientException; /** * This class provides a list of all active users in the LDAP server. * The users' nsaccountlocked attribute is not set. Active users are users * in the main tree. * @author yeunga * */ public class ListActiveUsers extends AbstractListUsers { private static final Logger log = Logger.getLogger(ListActiveUsers.class); /** * Constructor */ public ListActiveUsers() { } protected Collection<User<Principal>> getUsers() throws AccessControlException, TransientException { final UserPersistence<Principal> userPersistence = getUserPersistence(); return userPersistence.getUsers(); } }