* Return the roles associated with the given user name.
* @param username Username for which roles should be retrieved
*/
- protected ArrayList getRoles(String username) {
+ protected ArrayList<String> getRoles(String username) {
Connection dbConnection = null;
this.userPrincipal = userPrincipal;
if (roles != null) {
this.roles = new String[roles.size()];
- this.roles = (String[]) roles.toArray(this.roles);
+ this.roles = roles.toArray(this.roles);
if (this.roles.length > 0)
Arrays.sort(this.roles);
}
import javax.security.auth.spi.LoginModule;
import org.apache.catalina.Context;
-import org.apache.catalina.Realm;
import org.apache.catalina.authenticator.Constants;
import org.apache.catalina.connector.Request;
import org.apache.catalina.deploy.SecurityConstraint;
* @version $Revision$ $Date$
*/
-public class JAASMemoryLoginModule extends MemoryRealm implements LoginModule, Realm {
+public class JAASMemoryLoginModule extends MemoryRealm implements LoginModule {
// We need to extend MemoryRealm to avoid class cast
private static Log log = LogFactory.getLog(JAASMemoryLoginModule.class);
for (int i=0; i<classNames.length; i++) {
if (classNames[i].length()==0) continue;
try {
- Class principalClass = Class.forName(classNames[i], false,
+ Class<?> principalClass = Class.forName(classNames[i], false,
loader);
if (Principal.class.isAssignableFrom(principalClass)) {
classNamesList.add(classNames[i]);
try {
preparedCredentials.close();
} catch (Throwable f) {
- ;
+ // Ignore
}
this.preparedCredentials = null;
try {
preparedRoles.close();
} catch (Throwable f) {
- ;
+ // Ignore
}
this.preparedRoles = null;
// Instantiate our database driver if necessary
if (driver == null) {
try {
- Class clazz = Class.forName(driverName);
+ Class<?> clazz = Class.forName(driverName);
driver = (Driver) clazz.newInstance();
} catch (Throwable e) {
throw new SQLException(e.getMessage());
*/
protected void release(Connection dbConnection) {
- ; // NO-OP since we are not pooling anything
+ // NO-OP since we are not pooling anything
}
attrIds = new String[0];
constraints.setReturningAttributes(attrIds);
- NamingEnumeration results =
+ NamingEnumeration<SearchResult> results =
context.search(userBase, filter, constraints);
}
// Get result for the first entry found
- SearchResult result = (SearchResult)results.next();
+ SearchResult result = results.next();
// Check no further entries were found
try {
" with filter expression '" + filter + "'");
}
// Searching groups that assign the given group
- NamingEnumeration results = context.search(roleBase, filter, controls);
+ NamingEnumeration<SearchResult> results =
+ context.search(roleBase, filter, controls);
if (results != null) {
// Iterate over the resulting groups
try {
while (results.hasMore()) {
- SearchResult result = (SearchResult) results.next();
+ SearchResult result = results.next();
Attributes attrs = result.getAttributes();
if (attrs == null)
continue;
list.add(commonRole);
if (containerLog.isTraceEnabled()) {
- if (list != null) {
- containerLog.trace(" Found " + list.size() + " user internal roles");
- for (int i=0; i<list.size(); i++)
- containerLog.trace( " Found user internal role " + list.get(i));
- } else {
- containerLog.trace(" Found no user internal roles");
- }
+ containerLog.trace(" Found " + list.size() + " user internal roles");
+ for (int i=0; i<list.size(); i++)
+ containerLog.trace( " Found user internal role " + list.get(i));
}
// Are we configured to do role searches?
controls.setReturningAttributes(new String[] {roleName});
// Perform the configured search and process the results
- NamingEnumeration results =
+ NamingEnumeration<SearchResult> results =
context.search(roleBase, filter, controls);
if (results == null)
return (list); // Should never happen, but just in case ...
HashMap<String, String> groupMap = new HashMap<String, String>();
try {
while (results.hasMore()) {
- SearchResult result = (SearchResult) results.next();
+ SearchResult result = results.next();
Attributes attrs = result.getAttributes();
if (attrs == null)
continue;
Attribute attr = attrs.get(attrId);
if (attr == null)
return (values);
- NamingEnumeration e = attr.getAll();
+ NamingEnumeration<?> e = attr.getAll();
try {
while(e.hasMore()) {
String value = (String)e.next();
*
* @return java.util.Hashtable the configuration for the directory context.
*/
- protected Hashtable getDirectoryContextEnvironment() {
+ protected Hashtable<String,String> getDirectoryContextEnvironment() {
Hashtable<String,String> env = new Hashtable<String,String>();
*/
protected void release(DirContext context) {
- ; // NO-OP since we are not pooling anything
+ // NO-OP since we are not pooling anything
}
startingPoint = endParenLoc+1;
startParenLoc = userPatternString.indexOf('(', startingPoint);
}
- return (String[])pathList.toArray(new String[] {});
+ return pathList.toArray(new String[] {});
}
return null;
*/
public Principal authenticate(String username, String credentials) {
- GenericPrincipal principal =
- (GenericPrincipal) principals.get(username);
+ GenericPrincipal principal = principals.get(username);
boolean validated = false;
if (principal != null) {
*/
protected String getPassword(String username) {
- GenericPrincipal principal =
- (GenericPrincipal) principals.get(username);
+ GenericPrincipal principal = principals.get(username);
if (principal != null) {
return (principal.getPassword());
} else {
*/
protected Principal getPrincipal(String username) {
- return (Principal) principals.get(username);
+ return principals.get(username);
}
*
* @return The principals, keyed by user name (a String)
*/
- protected Map getPrincipals() {
+ protected Map<String,GenericPrincipal> getPrincipals() {
return principals;
}
* Construct a new instance of this <code>Rule</code>.
*/
public MemoryUserRule() {
+ // No initialisation required
}
* throwables will be caught and logged.
*/
public void backgroundProcess() {
+ // NOOP in base class
}
}
public void postRegister(Boolean registrationDone) {
+ // NOOP in base class
}
public void preDeregister() throws Exception {
+ // NOOP in base class
}
public void postDeregister() {
+ // NOOP in base class
}
protected boolean initialized=false;
if(user.isInRole(dbrole)) {
return true;
}
- Iterator groups = user.getGroups();
+ Iterator<Group> groups = user.getGroups();
while(groups.hasNext()) {
- Group group = (Group)groups.next();
+ Group group = groups.next();
if(group.isInRole(dbrole)) {
return true;
}
}
List<String> roles = new ArrayList<String>();
- Iterator uroles = user.getRoles();
+ Iterator<Role> uroles = user.getRoles();
while(uroles.hasNext()) {
- Role role = (Role)uroles.next();
+ Role role = uroles.next();
roles.add(role.getName());
}
- Iterator groups = user.getGroups();
+ Iterator<Group> groups = user.getGroups();
while(groups.hasNext()) {
- Group group = (Group)groups.next();
+ Group group = groups.next();
uroles = group.getRoles();
while(uroles.hasNext()) {
- Role role = (Role)uroles.next();
+ Role role = uroles.next();
roles.add(role.getName());
}
}