Search in sources :

Example 6 with UserDatabase

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

the class MemoryUserDatabaseMBean method findRole.

/**
     * Return the MBean Name for the specified role name (if any);
     * otherwise return <code>null</code>.
     *
     * @param rolename Role name to look up
     * @return the role object name
     */
public String findRole(String rolename) {
    UserDatabase database = (UserDatabase) this.resource;
    Role role = database.findRole(rolename);
    if (role == null) {
        return null;
    }
    try {
        ObjectName oname = MBeanUtils.createObjectName(managedRole.getDomain(), role);
        return oname.toString();
    } catch (MalformedObjectNameException e) {
        IllegalArgumentException iae = new IllegalArgumentException("Cannot create object name for role [" + rolename + "]");
        iae.initCause(e);
        throw iae;
    }
}
Also used : Role(org.apache.catalina.Role) MalformedObjectNameException(javax.management.MalformedObjectNameException) UserDatabase(org.apache.catalina.UserDatabase) ObjectName(javax.management.ObjectName)

Example 7 with UserDatabase

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

the class MemoryUserDatabaseMBean method createGroup.

// ------------------------------------------------------------- Operations
/**
     * Create a new Group and return the corresponding MBean Name.
     *
     * @param groupname Group name of the new group
     * @param description Description of the new group
     * @return the new group object name
     */
public String createGroup(String groupname, String description) {
    UserDatabase database = (UserDatabase) this.resource;
    Group group = database.createGroup(groupname, description);
    try {
        MBeanUtils.createMBean(group);
    } catch (Exception e) {
        IllegalArgumentException iae = new IllegalArgumentException("Exception creating group [" + groupname + "] MBean");
        iae.initCause(e);
        throw iae;
    }
    return findGroup(groupname);
}
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 8 with UserDatabase

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

the class MemoryUserDatabaseMBean method getUsers.

/**
     * @return the MBean Names of all users defined in this database.
     */
public String[] getUsers() {
    UserDatabase database = (UserDatabase) this.resource;
    ArrayList<String> results = new ArrayList<>();
    Iterator<User> users = database.getUsers();
    while (users.hasNext()) {
        User user = users.next();
        results.add(findUser(user.getUsername()));
    }
    return results.toArray(new String[results.size()]);
}
Also used : User(org.apache.catalina.User) UserDatabase(org.apache.catalina.UserDatabase) ArrayList(java.util.ArrayList)

Example 9 with UserDatabase

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

the class MemoryUserDatabaseMBean method getGroups.

// ------------------------------------------------------------- Attributes
/**
     * @return the MBean Names of all groups defined in this database.
     */
public String[] getGroups() {
    UserDatabase database = (UserDatabase) this.resource;
    ArrayList<String> results = new ArrayList<>();
    Iterator<Group> groups = database.getGroups();
    while (groups.hasNext()) {
        Group group = groups.next();
        results.add(findGroup(group.getGroupname()));
    }
    return results.toArray(new String[results.size()]);
}
Also used : Group(org.apache.catalina.Group) UserDatabase(org.apache.catalina.UserDatabase) ArrayList(java.util.ArrayList)

Example 10 with UserDatabase

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

the class MemoryUserDatabaseMBean method findGroup.

/**
     * Return the MBean Name for the specified group name (if any);
     * otherwise return <code>null</code>.
     *
     * @param groupname Group name to look up
     * @return the group object name
     */
public String findGroup(String groupname) {
    UserDatabase database = (UserDatabase) this.resource;
    Group group = database.findGroup(groupname);
    if (group == null) {
        return null;
    }
    try {
        ObjectName oname = MBeanUtils.createObjectName(managedGroup.getDomain(), group);
        return oname.toString();
    } catch (MalformedObjectNameException e) {
        IllegalArgumentException iae = new IllegalArgumentException("Cannot create object name for group [" + groupname + "]");
        iae.initCause(e);
        throw iae;
    }
}
Also used : Group(org.apache.catalina.Group) MalformedObjectNameException(javax.management.MalformedObjectNameException) UserDatabase(org.apache.catalina.UserDatabase) ObjectName(javax.management.ObjectName)

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