Search in sources :

Example 36 with User

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

the class DataSourceUserDatabaseMBean method createUser.

/**
 * Create a new User and return the corresponding 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 name
 */
public String createUser(String username, String password, String fullName) {
    UserDatabase database = (UserDatabase) this.resource;
    User user = database.createUser(username, password, fullName);
    return user.getUsername();
}
Also used : User(org.apache.catalina.User) UserDatabase(org.apache.catalina.UserDatabase)

Example 37 with User

use of org.apache.catalina.User 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 38 with User

use of org.apache.catalina.User 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 39 with User

use of org.apache.catalina.User 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 40 with User

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

the class MemoryGroup method getUsers.

/**
 * Return the set of {@link org.apache.catalina.User}s that are members of this group.
 */
@Override
public Iterator<User> getUsers() {
    ArrayList<User> results = new ArrayList<User>();
    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)

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