use of org.apache.catalina.User in project tomcat by apache.
the class UserDatabaseRealm method hasRole.
// --------------------------------------------------------- Public Methods
/**
* Return <code>true</code> if the specified Principal has the specified
* security role, within the context of this Realm; otherwise return
* <code>false</code>. This implementation returns <code>true</code>
* if the <code>User</code> has the role, or if any <code>Group</code>
* that the <code>User</code> is a member of has the role.
*
* @param principal Principal for whom the role is to be checked
* @param role Security role to be checked
*/
@Override
public boolean hasRole(Wrapper wrapper, Principal principal, String role) {
// Check for a role alias defined in a <security-role-ref> element
if (wrapper != null) {
String realRole = wrapper.findSecurityReference(role);
if (realRole != null)
role = realRole;
}
if (principal instanceof GenericPrincipal) {
GenericPrincipal gp = (GenericPrincipal) principal;
if (gp.getUserPrincipal() instanceof User) {
principal = gp.getUserPrincipal();
}
}
if (!(principal instanceof User)) {
//Play nice with SSO and mixed Realms
return super.hasRole(null, principal, role);
}
if ("*".equals(role)) {
return true;
} else if (role == null) {
return false;
}
User user = (User) principal;
Role dbrole = database.findRole(role);
if (dbrole == null) {
return false;
}
if (user.isInRole(dbrole)) {
return true;
}
Iterator<Group> groups = user.getGroups();
while (groups.hasNext()) {
Group group = groups.next();
if (group.isInRole(dbrole)) {
return true;
}
}
return false;
}
use of org.apache.catalina.User in project tomcat by apache.
the class MemoryUserDatabaseMBean method findUser.
/**
* Return the MBean Name for the specified user name (if any);
* otherwise return <code>null</code>.
*
* @param username User name to look up
* @return the user object name
*/
public String findUser(String username) {
UserDatabase database = (UserDatabase) this.resource;
User user = database.findUser(username);
if (user == null) {
return null;
}
try {
ObjectName oname = MBeanUtils.createObjectName(managedUser.getDomain(), user);
return oname.toString();
} catch (MalformedObjectNameException e) {
IllegalArgumentException iae = new IllegalArgumentException("Cannot create object name for user [" + username + "]");
iae.initCause(e);
throw iae;
}
}
use of org.apache.catalina.User in project tomcat by apache.
the class MemoryGroup method getUsers.
/**
* Return the set of {@link org.apache.catalina.User}s that are members of this group.
*/
@Override
public Iterator<User> getUsers() {
ArrayList<User> results = new ArrayList<>();
Iterator<User> users = database.getUsers();
while (users.hasNext()) {
User user = users.next();
if (user.isInGroup(this)) {
results.add(user);
}
}
return (results.iterator());
}
use of org.apache.catalina.User in project tomcat70 by apache.
the class MemoryUserDatabaseMBean method findUser.
/**
* Return the MBean Name for the specified user name (if any);
* otherwise return <code>null</code>.
*
* @param username User name to look up
*/
public String findUser(String username) {
UserDatabase database = (UserDatabase) this.resource;
User user = database.findUser(username);
if (user == null) {
return (null);
}
try {
ObjectName oname = MBeanUtils.createObjectName(managedUser.getDomain(), user);
return (oname.toString());
} catch (MalformedObjectNameException e) {
IllegalArgumentException iae = new IllegalArgumentException("Cannot create object name for user [" + username + "]");
iae.initCause(e);
throw iae;
}
}
use of org.apache.catalina.User in project tomcat70 by apache.
the class UserMBean method getGroups.
// ------------------------------------------------------------- Attributes
/**
* Return the MBean Names of all groups this user is a member of.
*/
public String[] getGroups() {
User user = (User) this.resource;
ArrayList<String> results = new ArrayList<String>();
Iterator<Group> groups = user.getGroups();
while (groups.hasNext()) {
Group group = null;
try {
group = groups.next();
ObjectName oname = MBeanUtils.createObjectName(managed.getDomain(), group);
results.add(oname.toString());
} catch (MalformedObjectNameException e) {
IllegalArgumentException iae = new IllegalArgumentException("Cannot create object name for group " + group);
iae.initCause(e);
throw iae;
}
}
return results.toArray(new String[results.size()]);
}
Aggregations