Search in sources :

Example 6 with User

use of org.apache.catalina.User in project tomcat70 by apache.

the class UserMBean method addRole.

/**
 * Add a new {@link Role} to those this user belongs to.
 *
 * @param rolename Role name of the new role
 */
public void addRole(String rolename) {
    User user = (User) this.resource;
    if (user == null) {
        return;
    }
    Role role = user.getUserDatabase().findRole(rolename);
    if (role == null) {
        throw new IllegalArgumentException("Invalid role name '" + rolename + "'");
    }
    user.addRole(role);
}
Also used : Role(org.apache.catalina.Role) User(org.apache.catalina.User)

Example 7 with User

use of org.apache.catalina.User in project tomcat70 by apache.

the class UserMBean method removeRole.

/**
 * Remove a {@link Role} from those this user belongs to.
 *
 * @param rolename Role name of the old role
 */
public void removeRole(String rolename) {
    User user = (User) this.resource;
    if (user == null) {
        return;
    }
    Role role = user.getUserDatabase().findRole(rolename);
    if (role == null) {
        throw new IllegalArgumentException("Invalid role name '" + rolename + "'");
    }
    user.removeRole(role);
}
Also used : Role(org.apache.catalina.Role) User(org.apache.catalina.User)

Example 8 with User

use of org.apache.catalina.User in project tomcat70 by apache.

the class UserMBean method getRoles.

/**
 * Return the MBean Names of all roles assigned to this user.
 */
public String[] getRoles() {
    User user = (User) this.resource;
    ArrayList<String> results = new ArrayList<String>();
    Iterator<Role> roles = user.getRoles();
    while (roles.hasNext()) {
        Role role = null;
        try {
            role = roles.next();
            ObjectName oname = MBeanUtils.createObjectName(managed.getDomain(), role);
            results.add(oname.toString());
        } catch (MalformedObjectNameException e) {
            IllegalArgumentException iae = new IllegalArgumentException("Cannot create object name for role " + role);
            iae.initCause(e);
            throw iae;
        }
    }
    return results.toArray(new String[results.size()]);
}
Also used : Role(org.apache.catalina.Role) MalformedObjectNameException(javax.management.MalformedObjectNameException) User(org.apache.catalina.User) ArrayList(java.util.ArrayList) ObjectName(javax.management.ObjectName)

Example 9 with User

use of org.apache.catalina.User in project tomcat70 by apache.

the class UserMBean method addGroup.

// ------------------------------------------------------------- Operations
/**
 * Add a new {@link Group} to those this user belongs to.
 *
 * @param groupname Group name of the new group
 */
public void addGroup(String groupname) {
    User user = (User) this.resource;
    if (user == null) {
        return;
    }
    Group group = user.getUserDatabase().findGroup(groupname);
    if (group == null) {
        throw new IllegalArgumentException("Invalid group name '" + groupname + "'");
    }
    user.addGroup(group);
}
Also used : Group(org.apache.catalina.Group) User(org.apache.catalina.User)

Example 10 with User

use of org.apache.catalina.User in project tomcat70 by apache.

the class UserMBean method removeGroup.

/**
 * Remove a {@link Group} from those this user belongs to.
 *
 * @param groupname Group name of the old group
 */
public void removeGroup(String groupname) {
    User user = (User) this.resource;
    if (user == null) {
        return;
    }
    Group group = user.getUserDatabase().findGroup(groupname);
    if (group == null) {
        throw new IllegalArgumentException("Invalid group name '" + groupname + "'");
    }
    user.removeGroup(group);
}
Also used : Group(org.apache.catalina.Group) User(org.apache.catalina.User)

Aggregations

User (org.apache.catalina.User)63 UserDatabase (org.apache.catalina.UserDatabase)24 Group (org.apache.catalina.Group)21 Role (org.apache.catalina.Role)18 ArrayList (java.util.ArrayList)17 MalformedObjectNameException (javax.management.MalformedObjectNameException)12 ObjectName (javax.management.ObjectName)9 Test (org.junit.Test)5 Connection (java.sql.Connection)4 MBeanException (javax.management.MBeanException)4 RuntimeOperationsException (javax.management.RuntimeOperationsException)4 PreparedStatement (java.sql.PreparedStatement)3 SQLException (java.sql.SQLException)3 ResultSet (java.sql.ResultSet)2 Statement (java.sql.Statement)2 NamingException (javax.naming.NamingException)2 OperationNotSupportedException (javax.naming.OperationNotSupportedException)2 LoggingBaseTest (org.apache.catalina.startup.LoggingBaseTest)2 BufferedWriter (java.io.BufferedWriter)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1