Search in sources :

Example 41 with Role

use of org.osgi.service.useradmin.Role in project aries by apache.

the class UserAdmin method addRoleProperty.

/**
 * @see UserAdminMBean#addProperty(String, byte[], String)
 * @see UserAdminMBean#addProperty(String, String, String)
 */
private void addRoleProperty(String key, Object value, String rolename) throws IOException {
    if (rolename == null) {
        throw new IOException("Role name cannot be null");
    }
    if (key == null) {
        throw new IOException("Property key cannot be null");
    }
    Role role = userAdmin.getRole(rolename);
    if (role == null) {
        throw new IOException("Operation fails role with provided rolename = [" + rolename + "] doesn't exist");
    }
    Dictionary<String, Object> properties = role.getProperties();
    if (properties != null) {
        properties.put(key, value);
    }
}
Also used : Role(org.osgi.service.useradmin.Role) IOException(java.io.IOException)

Example 42 with Role

use of org.osgi.service.useradmin.Role in project aries by apache.

the class UserAdmin method getCredentials.

/**
 * @see org.osgi.jmx.service.useradmin.UserAdminMBean#getCredentials(java.lang.String)
 */
public TabularData getCredentials(String username) throws IOException {
    if (username == null) {
        throw new IOException("User name cannot be null");
    }
    Role role = userAdmin.getRole(username);
    if (role == null) {
        return null;
    }
    validateRoleType(role, Role.USER);
    Dictionary<String, Object> credentials = ((User) role).getCredentials();
    if (credentials == null) {
        return null;
    }
    TabularData data = new TabularDataSupport(JmxConstants.PROPERTIES_TYPE);
    for (Enumeration<String> keys = credentials.keys(); keys.hasMoreElements(); ) {
        String key = keys.nextElement();
        data.put(PropertyData.newInstance(key, credentials.get(key)).toCompositeData());
    }
    return data;
}
Also used : Role(org.osgi.service.useradmin.Role) User(org.osgi.service.useradmin.User) TabularDataSupport(javax.management.openmbean.TabularDataSupport) IOException(java.io.IOException) TabularData(javax.management.openmbean.TabularData)

Example 43 with Role

use of org.osgi.service.useradmin.Role in project felix by apache.

the class RoleRepositoryMemoryStore method getRoles.

public Role[] getRoles(String filterValue) throws InvalidSyntaxException {
    Collection roles = m_entries.values();
    Filter filter = null;
    if (filterValue != null) {
        filter = FrameworkUtil.createFilter(filterValue);
    }
    List matchingRoles = new ArrayList();
    Iterator rolesIter = roles.iterator();
    while (rolesIter.hasNext()) {
        Role role = (Role) rolesIter.next();
        if ((filter == null) || filter.match(role.getProperties())) {
            matchingRoles.add(role);
        }
    }
    Role[] result = new Role[matchingRoles.size()];
    return (Role[]) matchingRoles.toArray(result);
}
Also used : Role(org.osgi.service.useradmin.Role) Filter(org.osgi.framework.Filter) ArrayList(java.util.ArrayList) Iterator(java.util.Iterator) Collection(java.util.Collection) List(java.util.List) ArrayList(java.util.ArrayList)

Example 44 with Role

use of org.osgi.service.useradmin.Role in project felix by apache.

the class RoleRepositoryMemoryStore method removeRole.

public Role removeRole(String roleName) {
    if (roleName == null) {
        throw new IllegalArgumentException("Name cannot be null!");
    }
    Role role = getRoleByName(roleName);
    boolean result = m_entries.remove(roleName, role);
    return result ? role : null;
}
Also used : Role(org.osgi.service.useradmin.Role)

Example 45 with Role

use of org.osgi.service.useradmin.Role in project felix by apache.

the class RoleRepositorySerializer method readRole.

/**
 * Reads a role from the given input stream.
 *
 * @param dis the input stream to read the data from, cannot be <code>null</code>.
 * @return the read role, never <code>null</code>.
 * @throws IOException in case of I/O problems.
 */
private Role readRole(DataInputStream dis) throws IOException {
    Role role = RoleFactory.createRole(Role.ROLE, dis.readUTF());
    readDictionary(role.getProperties(), dis);
    return role;
}
Also used : Role(org.osgi.service.useradmin.Role)

Aggregations

Role (org.osgi.service.useradmin.Role)98 Group (org.osgi.service.useradmin.Group)29 IOException (java.io.IOException)17 CountDownLatch (java.util.concurrent.CountDownLatch)13 List (java.util.List)9 User (org.osgi.service.useradmin.User)9 ArrayList (java.util.ArrayList)7 Test (org.junit.Test)6 Collection (java.util.Collection)5 UserAdmin (org.osgi.service.useradmin.UserAdmin)5 DBCollection (com.mongodb.DBCollection)4 Iterator (java.util.Iterator)4 BackendException (org.apache.felix.useradmin.BackendException)4 ObservableRole (org.apache.felix.useradmin.impl.role.ObservableRole)4 Authorization (org.osgi.service.useradmin.Authorization)4 WriteResult (com.mongodb.WriteResult)3 Filter (org.osgi.framework.Filter)3 BasicDBObject (com.mongodb.BasicDBObject)2 DBObject (com.mongodb.DBObject)2 Dictionary (java.util.Dictionary)2