org.apache.catalina.Role Java Examples

The following examples show how to use org.apache.catalina.Role. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: UserMBean.java    From tomcatsrc with Apache License 2.0 6 votes vote down vote up
/**
 * Return the MBean Names of all roles assigned to this user.
 */
public String[] getRoles() {

    User user = (User) this.resource;
    ArrayList<String> results = new ArrayList<String>();
    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) {
            IllegalArgumentException iae = new IllegalArgumentException
                ("Cannot create object name for role " + role);
            iae.initCause(e);
            throw iae;
        }
    }
    return results.toArray(new String[results.size()]);

}
 
Example #2
Source File: UserMBean.java    From Tomcat8-Source-Read with MIT License 6 votes vote down vote up
/**
 * @return the MBean Names of all roles assigned to this user.
 */
public String[] getRoles() {

    User user = (User) this.resource;
    ArrayList<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) {
            IllegalArgumentException iae = new IllegalArgumentException
                ("Cannot create object name for role " + role);
            iae.initCause(e);
            throw iae;
        }
    }
    return results.toArray(new String[results.size()]);
}
 
Example #3
Source File: MBeanUtils.java    From tomcatsrc with Apache License 2.0 6 votes vote down vote up
/**
 * Deregister the MBean for this
 * <code>Role</code> object.
 *
 * @param role The Role to be managed
 *
 * @exception Exception if an MBean cannot be deregistered
 */
static void destroyMBean(Role role)
    throws Exception {

    String mname = createManagedName(role);
    ManagedBean managed = registry.findManagedBean(mname);
    if (managed == null) {
        return;
    }
    String domain = managed.getDomain();
    if (domain == null)
        domain = mserver.getDefaultDomain();
    ObjectName oname = createObjectName(domain, role);
    if( mserver.isRegistered(oname) )
        mserver.unregisterMBean(oname);

}
 
Example #4
Source File: MBeanUtils.java    From Tomcat8-Source-Read with MIT License 6 votes vote down vote up
/**
 * Create, register, and return an MBean for this
 * <code>Role</code> object.
 *
 * @param role The Role to be managed
 * @return a new MBean
 * @exception Exception if an MBean cannot be created or registered
 */
static DynamicMBean createMBean(Role role)
    throws Exception {

    String mname = createManagedName(role);
    ManagedBean managed = registry.findManagedBean(mname);
    if (managed == null) {
        Exception e = new Exception("ManagedBean is not found with "+mname);
        throw new MBeanException(e);
    }
    String domain = managed.getDomain();
    if (domain == null)
        domain = mserver.getDefaultDomain();
    DynamicMBean mbean = managed.createMBean(role);
    ObjectName oname = createObjectName(domain, role);
    if( mserver.isRegistered( oname ))  {
        mserver.unregisterMBean(oname);
    }
    mserver.registerMBean(mbean, oname);
    return mbean;

}
 
Example #5
Source File: MemoryUserDatabaseMBean.java    From Tomcat8-Source-Read with MIT License 6 votes vote down vote up
/**
 * 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;
    }

}
 
Example #6
Source File: MemoryUserDatabaseMBean.java    From Tomcat8-Source-Read with MIT License 6 votes vote down vote up
/**
 * Remove an existing role and destroy the corresponding MBean.
 *
 * @param rolename Role name to remove
 */
public void removeRole(String rolename) {
    UserDatabase database = (UserDatabase) this.resource;
    Role role = database.findRole(rolename);
    if (role == null) {
        return;
    }
    try {
        MBeanUtils.destroyMBean(role);
        database.removeRole(role);
    } catch (Exception e) {
        IllegalArgumentException iae = new IllegalArgumentException(
                "Exception destroying role [" + rolename + "] MBean");
        iae.initCause(e);
        throw iae;
    }
}
 
Example #7
Source File: MemoryUserDatabaseMBean.java    From tomcatsrc with Apache License 2.0 6 votes vote down vote up
/**
 * Remove an existing role and destroy the corresponding MBean.
 *
 * @param rolename Role name to remove
 */
public void removeRole(String rolename) {

    UserDatabase database = (UserDatabase) this.resource;
    Role role = database.findRole(rolename);
    if (role == null) {
        return;
    }
    try {
        MBeanUtils.destroyMBean(role);
        database.removeRole(role);
    } catch (Exception e) {
        IllegalArgumentException iae = new IllegalArgumentException
            ("Exception destroying role [" + rolename + "] MBean");
        iae.initCause(e);
        throw iae;
    }

}
 
Example #8
Source File: MemoryGroup.java    From Tomcat8-Source-Read with MIT License 6 votes vote down vote up
/**
 * <p>Return a String representation of this group in XML format.</p>
 */
@Override
public String toString() {
    StringBuilder sb = new StringBuilder("<group groupname=\"");
    sb.append(groupname);
    sb.append("\"");
    if (description != null) {
        sb.append(" description=\"");
        sb.append(description);
        sb.append("\"");
    }
    synchronized (roles) {
        if (roles.size() > 0) {
            sb.append(" roles=\"");
            StringUtils.join(roles, ',', new Function<Role>(){
                @Override public String apply(Role t) { return t.getRolename(); }}, sb);
            sb.append("\"");
        }
    }
    sb.append("/>");
    return sb.toString();
}
 
Example #9
Source File: MemoryUserDatabase.java    From Tomcat8-Source-Read with MIT License 6 votes vote down vote up
/**
 * Create and return a new {@link Role} defined in this user database.
 *
 * @param rolename The role name of the new group (must be unique)
 * @param description The description of this group
 */
@Override
public Role createRole(String rolename, String description) {
    if (rolename == null || rolename.length() == 0) {
        String msg = sm.getString("memoryUserDatabase.nullRole");
        log.warn(msg);
        throw new IllegalArgumentException(msg);
    }

    MemoryRole role = new MemoryRole(this, rolename, description);
    readLock.lock();
    try {
        roles.put(role.getRolename(), role);
    } finally {
        readLock.unlock();
    }
    return role;
}
 
Example #10
Source File: MemoryUserDatabase.java    From Tomcat8-Source-Read with MIT License 6 votes vote down vote up
/**
 * Remove the specified {@link Role} from this user database.
 *
 * @param role The role to be removed
 */
@Override
public void removeRole(Role role) {
    readLock.lock();
    try {
        Iterator<Group> groups = getGroups();
        while (groups.hasNext()) {
            Group group = groups.next();
            group.removeRole(role);
        }
        Iterator<User> users = getUsers();
        while (users.hasNext()) {
            User user = users.next();
            user.removeRole(role);
        }
        roles.remove(role.getRolename());
    } finally {
        readLock.unlock();
    }
}
 
Example #11
Source File: GroupMBean.java    From Tomcat7.0.67 with Apache License 2.0 6 votes vote down vote up
/**
 * Return the MBean Names of all authorized roles for this group.
 */
public String[] getRoles() {

    Group group = (Group) this.resource;
    ArrayList<String> results = new ArrayList<String>();
    Iterator<Role> roles = group.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) {
            IllegalArgumentException iae = new IllegalArgumentException
                ("Cannot create object name for role " + role);
            iae.initCause(e);
            throw iae;
        }
    }
    return results.toArray(new String[results.size()]);

}
 
Example #12
Source File: UserMBean.java    From Tomcat7.0.67 with Apache License 2.0 6 votes vote down vote up
/**
 * Return the MBean Names of all roles assigned to this user.
 */
public String[] getRoles() {

    User user = (User) this.resource;
    ArrayList<String> results = new ArrayList<String>();
    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) {
            IllegalArgumentException iae = new IllegalArgumentException
                ("Cannot create object name for role " + role);
            iae.initCause(e);
            throw iae;
        }
    }
    return results.toArray(new String[results.size()]);

}
 
Example #13
Source File: MemoryUserDatabaseMBean.java    From Tomcat7.0.67 with Apache License 2.0 6 votes vote down vote up
/**
 * Create a new Role and return the corresponding MBean Name.
 *
 * @param rolename Group name of the new group
 * @param description Description of the new group
 */
public String createRole(String rolename, String description) {

    UserDatabase database = (UserDatabase) this.resource;
    Role role = database.createRole(rolename, description);
    try {
        MBeanUtils.createMBean(role);
    } catch (Exception e) {
        IllegalArgumentException iae = new IllegalArgumentException
            ("Exception creating role [" + rolename + "] MBean");
        iae.initCause(e);
        throw iae;
    }
    return (findRole(rolename));

}
 
Example #14
Source File: MemoryUserDatabaseMBean.java    From Tomcat7.0.67 with Apache License 2.0 6 votes vote down vote up
/**
 * Return the MBean Name for the specified role name (if any);
 * otherwise return <code>null</code>.
 *
 * @param rolename Role name to look up
 */
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;
    }

}
 
Example #15
Source File: MemoryUserDatabaseMBean.java    From Tomcat7.0.67 with Apache License 2.0 6 votes vote down vote up
/**
 * Remove an existing role and destroy the corresponding MBean.
 *
 * @param rolename Role name to remove
 */
public void removeRole(String rolename) {

    UserDatabase database = (UserDatabase) this.resource;
    Role role = database.findRole(rolename);
    if (role == null) {
        return;
    }
    try {
        MBeanUtils.destroyMBean(role);
        database.removeRole(role);
    } catch (Exception e) {
        IllegalArgumentException iae = new IllegalArgumentException
            ("Exception destroying role [" + rolename + "] MBean");
        iae.initCause(e);
        throw iae;
    }

}
 
Example #16
Source File: MBeanUtils.java    From Tomcat7.0.67 with Apache License 2.0 6 votes vote down vote up
/**
 * Create, register, and return an MBean for this
 * <code>Role</code> object.
 *
 * @param role The Role to be managed
 *
 * @exception Exception if an MBean cannot be created or registered
 */
static DynamicMBean createMBean(Role role)
    throws Exception {

    String mname = createManagedName(role);
    ManagedBean managed = registry.findManagedBean(mname);
    if (managed == null) {
        Exception e = new Exception("ManagedBean is not found with "+mname);
        throw new MBeanException(e);
    }
    String domain = managed.getDomain();
    if (domain == null)
        domain = mserver.getDefaultDomain();
    DynamicMBean mbean = managed.createMBean(role);
    ObjectName oname = createObjectName(domain, role);
    if( mserver.isRegistered( oname ))  {
        mserver.unregisterMBean(oname);
    }
    mserver.registerMBean(mbean, oname);
    return (mbean);

}
 
Example #17
Source File: MBeanUtils.java    From Tomcat7.0.67 with Apache License 2.0 6 votes vote down vote up
/**
 * Deregister the MBean for this
 * <code>Role</code> object.
 *
 * @param role The Role to be managed
 *
 * @exception Exception if an MBean cannot be deregistered
 */
static void destroyMBean(Role role)
    throws Exception {

    String mname = createManagedName(role);
    ManagedBean managed = registry.findManagedBean(mname);
    if (managed == null) {
        return;
    }
    String domain = managed.getDomain();
    if (domain == null)
        domain = mserver.getDefaultDomain();
    ObjectName oname = createObjectName(domain, role);
    if( mserver.isRegistered(oname) )
        mserver.unregisterMBean(oname);

}
 
Example #18
Source File: MBeanUtils.java    From tomcatsrc with Apache License 2.0 6 votes vote down vote up
/**
 * Create, register, and return an MBean for this
 * <code>Role</code> object.
 *
 * @param role The Role to be managed
 *
 * @exception Exception if an MBean cannot be created or registered
 */
static DynamicMBean createMBean(Role role)
    throws Exception {

    String mname = createManagedName(role);
    ManagedBean managed = registry.findManagedBean(mname);
    if (managed == null) {
        Exception e = new Exception("ManagedBean is not found with "+mname);
        throw new MBeanException(e);
    }
    String domain = managed.getDomain();
    if (domain == null)
        domain = mserver.getDefaultDomain();
    DynamicMBean mbean = managed.createMBean(role);
    ObjectName oname = createObjectName(domain, role);
    if( mserver.isRegistered( oname ))  {
        mserver.unregisterMBean(oname);
    }
    mserver.registerMBean(mbean, oname);
    return (mbean);

}
 
Example #19
Source File: MemoryUserDatabase.java    From Tomcat7.0.67 with Apache License 2.0 6 votes vote down vote up
/**
 * Remove the specified {@link Role} from this user database.
 *
 * @param role The role to be removed
 */
@Override
public void removeRole(Role role) {

    synchronized (roles) {
        Iterator<Group> groups = getGroups();
        while (groups.hasNext()) {
            Group group = groups.next();
            group.removeRole(role);
        }
        Iterator<User> users = getUsers();
        while (users.hasNext()) {
            User user = users.next();
            user.removeRole(role);
        }
        roles.remove(role.getRolename());
    }

}
 
Example #20
Source File: MemoryGroup.java    From Tomcat7.0.67 with Apache License 2.0 5 votes vote down vote up
/**
 * Remove a {@link Role} from those assigned to this group.
 *
 * @param role The old role
 */
@Override
public void removeRole(Role role) {

    synchronized (roles) {
        roles.remove(role);
    }

}
 
Example #21
Source File: MemoryUserDatabase.java    From tomcatsrc with Apache License 2.0 5 votes vote down vote up
/**
 * Return the {@link Role} with the specified role name, if any;
 * otherwise return <code>null</code>.
 *
 * @param rolename Name of the role to return
 */
@Override
public Role findRole(String rolename) {

    synchronized (roles) {
        return roles.get(rolename);
    }

}
 
Example #22
Source File: MemoryGroup.java    From Tomcat7.0.67 with Apache License 2.0 5 votes vote down vote up
/**
 * Add a new {@link Role} to those assigned specifically to this group.
 *
 * @param role The new role
 */
@Override
public void addRole(Role role) {

    synchronized (roles) {
        if (!roles.contains(role)) {
            roles.add(role);
        }
    }

}
 
Example #23
Source File: MemoryUserDatabase.java    From Tomcat7.0.67 with Apache License 2.0 5 votes vote down vote up
@Override
public Object createObject(Attributes attributes) {
    String rolename = attributes.getValue("rolename");
    if (rolename == null) {
        rolename = attributes.getValue("name");
    }
    String description = attributes.getValue("description");
    Role role = database.createRole(rolename, description);
    return (role);
}
 
Example #24
Source File: MemoryGroup.java    From Tomcat7.0.67 with Apache License 2.0 5 votes vote down vote up
/**
 * Return the set of {@link Role}s assigned specifically to this group.
 */
@Override
public Iterator<Role> getRoles() {

    synchronized (roles) {
        return (roles.iterator());
    }

}
 
Example #25
Source File: MemoryUser.java    From tomcatsrc with Apache License 2.0 5 votes vote down vote up
/**
 * Add a new {@link Role} to those assigned specifically to this user.
 *
 * @param role The new role
 */
@Override
public void addRole(Role role) {

    synchronized (roles) {
        if (!roles.contains(role)) {
            roles.add(role);
        }
    }

}
 
Example #26
Source File: UserMBean.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
/**
 * 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("Invalid role name '" + rolename + "'");
    }
    user.addRole(role);
}
 
Example #27
Source File: MemoryUserDatabaseMBean.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
/**
 * @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()]);
}
 
Example #28
Source File: MemoryUserDatabaseMBean.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
/**
 * Create a new Role and return the corresponding MBean Name.
 *
 * @param rolename Group name of the new group
 * @param description Description of the new group
 * @return the new role object name
 */
public String createRole(String rolename, String description) {
    UserDatabase database = (UserDatabase) this.resource;
    Role role = database.createRole(rolename, description);
    try {
        MBeanUtils.createMBean(role);
    } catch (Exception e) {
        IllegalArgumentException iae = new IllegalArgumentException(
                "Exception creating role [" + rolename + "] MBean");
        iae.initCause(e);
        throw iae;
    }
    return findRole(rolename);
}
 
Example #29
Source File: MemoryUserDatabaseMBean.java    From Tomcat7.0.67 with Apache License 2.0 5 votes vote down vote up
/**
 * Return the MBean Names of all roles defined in this database.
 */
public String[] getRoles() {

    UserDatabase database = (UserDatabase) this.resource;
    ArrayList<String> results = new ArrayList<String>();
    Iterator<Role> roles = database.getRoles();
    while (roles.hasNext()) {
        Role role = roles.next();
        results.add(findRole(role.getRolename()));
    }
    return results.toArray(new String[results.size()]);

}
 
Example #30
Source File: MemoryUser.java    From Tomcat7.0.67 with Apache License 2.0 5 votes vote down vote up
/**
 * Return the set of {@link Role}s assigned specifically to this user.
 */
@Override
public Iterator<Role> getRoles() {

    synchronized (roles) {
        return (roles.iterator());
    }

}