Search in sources :

Example 1 with UserDatabase

use of org.apache.catalina.UserDatabase 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;
    }
}
Also used : MalformedObjectNameException(javax.management.MalformedObjectNameException) User(org.apache.catalina.User) UserDatabase(org.apache.catalina.UserDatabase) ObjectName(javax.management.ObjectName)

Example 2 with UserDatabase

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

the class MemoryUserDatabaseMBean method removeGroup.

/**
     * Remove an existing group and destroy the corresponding MBean.
     *
     * @param groupname Group name to remove
     */
public void removeGroup(String groupname) {
    UserDatabase database = (UserDatabase) this.resource;
    Group group = database.findGroup(groupname);
    if (group == null) {
        return;
    }
    try {
        MBeanUtils.destroyMBean(group);
        database.removeGroup(group);
    } catch (Exception e) {
        IllegalArgumentException iae = new IllegalArgumentException("Exception destroying group [" + groupname + "] MBean");
        iae.initCause(e);
        throw iae;
    }
}
Also used : Group(org.apache.catalina.Group) UserDatabase(org.apache.catalina.UserDatabase) MalformedObjectNameException(javax.management.MalformedObjectNameException) MBeanException(javax.management.MBeanException) RuntimeOperationsException(javax.management.RuntimeOperationsException)

Example 3 with UserDatabase

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

the class MemoryUserDatabaseMBean method removeUser.

/**
     * Remove an existing user and destroy the corresponding MBean.
     *
     * @param username User name to remove
     */
public void removeUser(String username) {
    UserDatabase database = (UserDatabase) this.resource;
    User user = database.findUser(username);
    if (user == null) {
        return;
    }
    try {
        MBeanUtils.destroyMBean(user);
        database.removeUser(user);
    } catch (Exception e) {
        IllegalArgumentException iae = new IllegalArgumentException("Exception destroying user [" + username + "] MBean");
        iae.initCause(e);
        throw iae;
    }
}
Also used : User(org.apache.catalina.User) UserDatabase(org.apache.catalina.UserDatabase) MalformedObjectNameException(javax.management.MalformedObjectNameException) MBeanException(javax.management.MBeanException) RuntimeOperationsException(javax.management.RuntimeOperationsException)

Example 4 with UserDatabase

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

the class MemoryUserDatabaseMBean 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) {
        IllegalArgumentException iae = new IllegalArgumentException("Exception creating user [" + username + "] MBean");
        iae.initCause(e);
        throw iae;
    }
    return findUser(username);
}
Also used : User(org.apache.catalina.User) UserDatabase(org.apache.catalina.UserDatabase) MalformedObjectNameException(javax.management.MalformedObjectNameException) MBeanException(javax.management.MBeanException) RuntimeOperationsException(javax.management.RuntimeOperationsException)

Example 5 with UserDatabase

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

the class MemoryUserDatabaseMBean method getRoles.

/**
     * @return the MBean Names of all roles defined in this database.
     */
public String[] getRoles() {
    UserDatabase database = (UserDatabase) this.resource;
    ArrayList<String> results = new ArrayList<>();
    Iterator<Role> roles = database.getRoles();
    while (roles.hasNext()) {
        Role role = roles.next();
        results.add(findRole(role.getRolename()));
    }
    return results.toArray(new String[results.size()]);
}
Also used : Role(org.apache.catalina.Role) UserDatabase(org.apache.catalina.UserDatabase) ArrayList(java.util.ArrayList)

Aggregations

UserDatabase (org.apache.catalina.UserDatabase)14 MalformedObjectNameException (javax.management.MalformedObjectNameException)9 MBeanException (javax.management.MBeanException)6 RuntimeOperationsException (javax.management.RuntimeOperationsException)6 Group (org.apache.catalina.Group)4 Role (org.apache.catalina.Role)4 User (org.apache.catalina.User)4 ArrayList (java.util.ArrayList)3 ObjectName (javax.management.ObjectName)3 Binding (javax.naming.Binding)1 Context (javax.naming.Context)1 InitialContext (javax.naming.InitialContext)1 NamingException (javax.naming.NamingException)1 OperationNotSupportedException (javax.naming.OperationNotSupportedException)1 NamingResourcesImpl (org.apache.catalina.deploy.NamingResourcesImpl)1 MemoryUserDatabase (org.apache.catalina.users.MemoryUserDatabase)1 ContextResource (org.apache.tomcat.util.descriptor.web.ContextResource)1