Search in sources :

Example 91 with Role

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

the class UserManager method getProperties.

public Hashtable getProperties(String rolename) {
    try {
        Role role = ac.getUserAdmin().getRole(rolename);
        Dictionary dic = role.getProperties();
        Hashtable props = new Hashtable();
        Enumeration keys = dic.keys();
        while (keys.hasMoreElements()) {
            Object key = keys.nextElement();
            props.put(key, dic.get(key));
        }
        return props;
    } catch (NullPointerException npe) {
        ac.debug("UserAdmin not available. ");
        return null;
    }
}
Also used : Role(org.osgi.service.useradmin.Role) Dictionary(java.util.Dictionary) Enumeration(java.util.Enumeration) Hashtable(java.util.Hashtable)

Example 92 with Role

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

the class UserAdmin method addCredential.

private void addCredential(String key, Object value, String username) throws IOException {
    if (username == null) {
        throw new IOException("User name cannot be null");
    }
    if (key == null) {
        throw new IOException("Credential key cannot be null");
    }
    Role role = userAdmin.getRole(username);
    if (role == null) {
        throw new IOException("Operation fails user with provided username = [" + username + "] doesn't exist");
    }
    validateRoleType(role, Role.USER);
    Dictionary<String, Object> credentials = ((User) role).getCredentials();
    if (credentials != null) {
        credentials.put(key, value);
    }
}
Also used : Role(org.osgi.service.useradmin.Role) User(org.osgi.service.useradmin.User) IOException(java.io.IOException)

Example 93 with Role

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

the class UserAdmin method removeProperty.

/**
 * @see org.osgi.jmx.service.useradmin.UserAdminMBean#removeProperty(java.lang.String, java.lang.String)
 */
public void removeProperty(String key, String rolename) throws IOException {
    if (rolename == null) {
        throw new IOException("Role name cannot be null");
    }
    Role role = userAdmin.getRole(rolename);
    if (role == null) {
        throw new IOException("Operation fails role with provided rolename = [" + rolename + "] doesn't exist");
    }
    role.getProperties().remove(key);
}
Also used : Role(org.osgi.service.useradmin.Role) IOException(java.io.IOException)

Example 94 with Role

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

the class UserAdmin method getRequiredMembers.

/**
 * @see org.osgi.jmx.service.useradmin.UserAdminMBean#getRequiredMembers(java.lang.String)
 */
public String[] getRequiredMembers(String groupname) throws IOException {
    if (groupname == null) {
        throw new IOException("Group name cannot be null");
    }
    Role role = userAdmin.getRole(groupname);
    if (role != null) {
        validateRoleType(role, Role.GROUP);
        Role[] roles = ((Group) role).getRequiredMembers();
        if (roles != null) {
            String[] reqMembers = new String[roles.length];
            for (int i = 0; i < roles.length; i++) {
                reqMembers[i] = roles[i].getName();
            }
            return reqMembers;
        }
    }
    return null;
}
Also used : Role(org.osgi.service.useradmin.Role) Group(org.osgi.service.useradmin.Group) IOException(java.io.IOException)

Example 95 with Role

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

the class UserAdmin method getProperties.

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

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