Search in sources :

Example 56 with Role

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

the class RoleRepository method getRoles.

/**
 * Returns a collection with all roles matching a given key-value pair.
 *
 * @param key the key to search for;
 * @param value the value to search for.
 * @return a list with all matching roles, can be empty, but never <code>null</code>.
 */
public List getRoles(String key, String value) {
    if (key == null) {
        throw new IllegalArgumentException("Key cannot be null!");
    }
    if (value == null) {
        throw new IllegalArgumentException("Value cannot be null!");
    }
    List matchingRoles = new ArrayList();
    try {
        String criteria = "(".concat(key).concat("=").concat(value).concat(")");
        Role[] roles = m_store.getRoles(criteria);
        for (int i = 0; i < roles.length; i++) {
            Role role = roles[i];
            if (!isPredefinedRole(role.getName())) {
                matchingRoles.add(wireChangeListener(role));
            }
        }
    } catch (Exception e) {
        throw new BackendException("Failed to get roles!", e);
    }
    return matchingRoles;
}
Also used : ObservableRole(org.apache.felix.useradmin.impl.role.ObservableRole) Role(org.osgi.service.useradmin.Role) ArrayList(java.util.ArrayList) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) List(java.util.List) ArrayList(java.util.ArrayList) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) BackendException(org.apache.felix.useradmin.BackendException) BackendException(org.apache.felix.useradmin.BackendException)

Example 57 with Role

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

the class RoleRepository method removeRole.

/**
 * Removes a given role from this manager.
 *
 * @param role the role to remove, cannot be <code>null</code>.
 * @return <code>true</code> if the role was removed (i.e., it was managed by this manager), or <code>false</code> if it was not found.
 */
public boolean removeRole(String name) {
    if (name == null) {
        throw new IllegalArgumentException("Name cannot be null!");
    }
    checkPermissions();
    // Cannot remove predefined roles...
    if (isPredefinedRole(name)) {
        return false;
    }
    try {
        Role result = m_store.removeRole(name);
        if (result != null) {
            // FELIX-3755: Remove the role as (required)member from all groups...
            removeRoleFromAllGroups(result);
            unwireChangeListener(result);
            m_roleChangeReflector.roleRemoved(result);
            return true;
        }
        return false;
    } catch (Exception e) {
        throw new BackendException("Failed to remove role " + name + "!", e);
    }
}
Also used : ObservableRole(org.apache.felix.useradmin.impl.role.ObservableRole) Role(org.osgi.service.useradmin.Role) BackendException(org.apache.felix.useradmin.BackendException) BackendException(org.apache.felix.useradmin.BackendException)

Example 58 with Role

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

the class RoleRepository method addRole.

/**
 * Adds a given role to this manager.
 *
 * @param role the role to add, cannot be <code>null</code>. If it is already contained by this manager, this method will not do anything.
 * @return the given role if added, <code>null</code> otherwise.
 */
public Role addRole(String name, int type) {
    if ((name == null) || "".equals(name.trim())) {
        throw new IllegalArgumentException("Name cannot be null or empty!");
    }
    if (type != Role.GROUP && type != Role.USER) {
        throw new IllegalArgumentException("Invalid role type!");
    }
    checkPermissions();
    try {
        Role result = m_store.addRole(name, type);
        if (result != null) {
            result = wireChangeListener(result);
            m_roleChangeReflector.roleAdded(result);
        }
        return result;
    } catch (Exception e) {
        throw new BackendException("Adding role " + name + " failed!", e);
    }
}
Also used : ObservableRole(org.apache.felix.useradmin.impl.role.ObservableRole) Role(org.osgi.service.useradmin.Role) BackendException(org.apache.felix.useradmin.BackendException) BackendException(org.apache.felix.useradmin.BackendException)

Example 59 with Role

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

the class UserAdminImpl method getUser.

/**
 * {@inheritDoc}
 */
public User getUser(String key, String value) {
    User result = null;
    List roles = m_roleRepository.getRoles(key, value);
    if (roles.size() == 1) {
        Role foundRole = (Role) roles.get(0);
        if (foundRole.getType() == Role.USER) {
            result = (User) foundRole;
        }
    }
    return result;
}
Also used : Role(org.osgi.service.useradmin.Role) User(org.osgi.service.useradmin.User) List(java.util.List)

Example 60 with Role

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

the class GroupImpl method getMembers.

/**
 * {@inheritDoc}
 */
public Role[] getMembers() {
    Role[] roles;
    synchronized (m_lock) {
        Collection values = m_members.values();
        roles = (Role[]) values.toArray(new Role[values.size()]);
    }
    return (roles.length == 0) ? null : roles;
}
Also used : Role(org.osgi.service.useradmin.Role) Collection(java.util.Collection)

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