Search in sources :

Example 26 with User

use of org.apache.catalina.User in project tomcat 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;
    List<String> results = new ArrayList<>();
    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) {
            throw new IllegalArgumentException(sm.getString("userMBean.createError.role", role), e);
        }
    }
    return results.toArray(new String[0]);
}
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 27 with User

use of org.apache.catalina.User in project tomcat 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(sm.getString("userMBean.invalidGroup", groupname));
    }
    user.addGroup(group);
}
Also used : Group(org.apache.catalina.Group) User(org.apache.catalina.User)

Example 28 with User

use of org.apache.catalina.User in project tomcat 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(sm.getString("userMBean.invalidGroup", groupname));
    }
    user.removeGroup(group);
}
Also used : Group(org.apache.catalina.Group) User(org.apache.catalina.User)

Example 29 with User

use of org.apache.catalina.User in project tomcat 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(sm.getString("userMBean.invalidRole", rolename));
    }
    user.addRole(role);
}
Also used : Role(org.apache.catalina.Role) User(org.apache.catalina.User)

Example 30 with User

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

the class SparseUserDatabaseMBean method createUser.

/**
 * Create a new User and return the corresponding MBean Name.
 *
 * @param username User name of the new user
 * @param password Password for the new user
 * @param fullName Full name for the new user
 * @return the new user object name
 */
public String createUser(String username, String password, String fullName) {
    UserDatabase database = (UserDatabase) this.resource;
    User user = database.createUser(username, password, fullName);
    try {
        MBeanUtils.createMBean(user);
    } catch (Exception e) {
        throw new IllegalArgumentException(sm.getString("userMBean.createMBeanError.user", username), e);
    }
    return findUser(username);
}
Also used : User(org.apache.catalina.User) UserDatabase(org.apache.catalina.UserDatabase)

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