Search in sources :

Example 21 with User

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

the class MemoryUserCreationFactory method removeGroup.

/**
 * Remove the specified {@link Group} from this user database.
 *
 * @param group The group to be removed
 */
@Override
public void removeGroup(Group group) {
    readLock.lock();
    try {
        Iterator<User> users = getUsers();
        while (users.hasNext()) {
            User user = users.next();
            user.removeGroup(group);
        }
        groups.remove(group.getGroupname());
    } finally {
        readLock.unlock();
    }
}
Also used : User(org.apache.catalina.User)

Example 22 with User

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

the class GenericGroup method getUsers.

/**
 * Return the set of {@link org.apache.catalina.User}s that are members of this group.
 */
@Override
public Iterator<User> getUsers() {
    List<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();
}
Also used : User(org.apache.catalina.User) ArrayList(java.util.ArrayList) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList)

Example 23 with User

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

the class DataSourceUserDatabaseMBean method addUserGroup.

/**
 * Add group to user.
 * @param username The user name
 * @param groupname The group name
 */
public void addUserGroup(String username, String groupname) {
    UserDatabase database = (UserDatabase) this.resource;
    User user = database.findUser(username);
    Group group = database.findGroup(groupname);
    if (user != null && group != null) {
        user.addGroup(group);
    }
}
Also used : Group(org.apache.catalina.Group) User(org.apache.catalina.User) UserDatabase(org.apache.catalina.UserDatabase)

Example 24 with User

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

the class GlobalResourcesLifecycleListener method createMBeans.

/**
 * Create the MBeans for the specified UserDatabase and its contents.
 *
 * @param name Complete resource name of this UserDatabase
 * @param database The UserDatabase to be processed
 *
 * @exception Exception if an exception occurs while creating MBeans
 */
protected void createMBeans(String name, UserDatabase database) throws Exception {
    // Create the MBean for the UserDatabase itself
    if (log.isDebugEnabled()) {
        log.debug("Creating UserDatabase MBeans for resource " + name);
        log.debug("Database=" + database);
    }
    try {
        MBeanUtils.createMBean(database);
    } catch (Exception e) {
        throw new IllegalArgumentException(sm.getString("globalResources.createError.userDatabase", name), e);
    }
    if (database.isSparse()) {
        // Avoid loading all the database as mbeans
        return;
    }
    // Create the MBeans for each defined Role
    Iterator<Role> roles = database.getRoles();
    while (roles.hasNext()) {
        Role role = roles.next();
        if (log.isDebugEnabled()) {
            log.debug("  Creating Role MBean for role " + role);
        }
        try {
            MBeanUtils.createMBean(role);
        } catch (Exception e) {
            throw new IllegalArgumentException(sm.getString("globalResources.createError.userDatabase.role", role), e);
        }
    }
    // Create the MBeans for each defined Group
    Iterator<Group> groups = database.getGroups();
    while (groups.hasNext()) {
        Group group = groups.next();
        if (log.isDebugEnabled()) {
            log.debug("  Creating Group MBean for group " + group);
        }
        try {
            MBeanUtils.createMBean(group);
        } catch (Exception e) {
            throw new IllegalArgumentException(sm.getString("globalResources.createError.userDatabase.group", group), e);
        }
    }
    // Create the MBeans for each defined User
    Iterator<User> users = database.getUsers();
    while (users.hasNext()) {
        User user = users.next();
        if (log.isDebugEnabled()) {
            log.debug("  Creating User MBean for user " + user);
        }
        try {
            MBeanUtils.createMBean(user);
        } catch (Exception e) {
            throw new IllegalArgumentException(sm.getString("globalResources.createError.userDatabase.user", user), e);
        }
    }
}
Also used : Role(org.apache.catalina.Role) Group(org.apache.catalina.Group) User(org.apache.catalina.User) NamingException(javax.naming.NamingException) OperationNotSupportedException(javax.naming.OperationNotSupportedException)

Example 25 with User

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

the class GroupMBean method getUsers.

/**
 * @return the MBean Names of all users that are members of this group.
 */
public String[] getUsers() {
    Group group = (Group) this.resource;
    List<String> results = new ArrayList<>();
    Iterator<User> users = group.getUsers();
    while (users.hasNext()) {
        User user = null;
        try {
            user = users.next();
            ObjectName oname = MBeanUtils.createObjectName(managed.getDomain(), user);
            results.add(oname.toString());
        } catch (MalformedObjectNameException e) {
            throw new IllegalArgumentException(sm.getString("userMBean.createError.user", user), e);
        }
    }
    return results.toArray(new String[0]);
}
Also used : Group(org.apache.catalina.Group) MalformedObjectNameException(javax.management.MalformedObjectNameException) User(org.apache.catalina.User) ArrayList(java.util.ArrayList) ObjectName(javax.management.ObjectName)

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