Search in sources :

Example 66 with Role

use of org.wso2.carbon.identity.role.mgt.core.Role in project charon by wso2.

the class Role method setGroup.

/**
 * Set a group to the role, where user will have three default attributes such as name, value and $ref.
 *
 * @param group Group object.
 * @throws BadRequestException BadRequestException.
 * @throws CharonException     CharonException.
 */
public void setGroup(Group group) throws BadRequestException, CharonException {
    if (this.isAttributeExist(SCIMConstants.RoleSchemaConstants.GROUPS)) {
        MultiValuedAttribute groups = (MultiValuedAttribute) this.attributeList.get(SCIMConstants.RoleSchemaConstants.GROUPS);
        ComplexAttribute complexAttribute = processGroup(group);
        groups.setAttributeValue(complexAttribute);
    } else {
        MultiValuedAttribute groups = new MultiValuedAttribute(SCIMConstants.RoleSchemaConstants.GROUPS);
        DefaultAttributeFactory.createAttribute(SCIMSchemaDefinitions.SCIMRoleSchemaDefinition.GROUPS, groups);
        ComplexAttribute complexAttribute = processGroup(group);
        groups.setAttributeValue(complexAttribute);
        this.setAttribute(groups);
    }
}
Also used : ComplexAttribute(org.wso2.charon3.core.attributes.ComplexAttribute) MultiValuedAttribute(org.wso2.charon3.core.attributes.MultiValuedAttribute)

Example 67 with Role

use of org.wso2.carbon.identity.role.mgt.core.Role in project charon by wso2.

the class User method replaceRoles.

/**
 * deletes the role attributes and exchanges it with the given values
 */
public void replaceRoles(List<MultiValuedComplexType> multiValuedComplexTypeList) {
    SCIMAttributeSchema complexDefinition = SCIMSchemaDefinitions.SCIMUserSchemaDefinition.ROLES;
    SCIMAttributeSchema valueDefinition = SCIMSchemaDefinitions.SCIMUserSchemaDefinition.ROLES_VALUE;
    SCIMAttributeSchema displayDefinition = SCIMSchemaDefinitions.SCIMUserSchemaDefinition.ROLES_DISPLAY;
    SCIMAttributeSchema typeDefinition = SCIMSchemaDefinitions.SCIMUserSchemaDefinition.ROLES_TYPE;
    addMultivaluedComplexAtribute(multiValuedComplexTypeList, complexDefinition, valueDefinition, displayDefinition, typeDefinition, null, null);
}
Also used : SCIMAttributeSchema(org.wso2.charon3.core.schema.SCIMAttributeSchema)

Example 68 with Role

use of org.wso2.carbon.identity.role.mgt.core.Role in project charon by wso2.

the class Role method setSystemRole.

/**
 * Set the systemRole attribute of the meta attribute.
 *
 * @param isSystemRole Whether this is a read only system role.
 * @throws CharonException     CharonException.
 * @throws BadRequestException BadRequestException.
 */
public void setSystemRole(boolean isSystemRole) throws CharonException, BadRequestException {
    // Create the systemRole attribute as defined in schema.
    SimpleAttribute systemRoleAttribute = (SimpleAttribute) DefaultAttributeFactory.createAttribute(SCIMSchemaDefinitions.SYSTEM_ROLE, new SimpleAttribute(SCIMConstants.CommonSchemaConstants.SYSTEM_ROLE, isSystemRole));
    // Check whether the meta complex attribute already exist.
    if (getMetaAttribute() != null) {
        ComplexAttribute metaAttribute = getMetaAttribute();
        // Check whether the systemRole attribute already exist.
        if (metaAttribute.isSubAttributeExist(systemRoleAttribute.getName())) {
            String error = "Tried to modify a read only attribute.";
            throw new CharonException(error);
        } else {
            metaAttribute.setSubAttribute(systemRoleAttribute);
        }
    } else {
        // Create the meta attribute and set the sub attribute.
        createMetaAttribute();
        getMetaAttribute().setSubAttribute(systemRoleAttribute);
    }
}
Also used : SimpleAttribute(org.wso2.charon3.core.attributes.SimpleAttribute) ComplexAttribute(org.wso2.charon3.core.attributes.ComplexAttribute) CharonException(org.wso2.charon3.core.exceptions.CharonException)

Example 69 with Role

use of org.wso2.carbon.identity.role.mgt.core.Role in project charon by wso2.

the class Role method setUser.

/**
 * Set a user to the role, where user will have three default attributes such as name, value and $ref.
 *
 * @param user User object.
 * @throws BadRequestException BadRequestException.
 * @throws CharonException     CharonException.
 */
public void setUser(User user) throws BadRequestException, CharonException {
    if (this.isAttributeExist(SCIMConstants.RoleSchemaConstants.USERS)) {
        MultiValuedAttribute users = (MultiValuedAttribute) this.attributeList.get(SCIMConstants.RoleSchemaConstants.USERS);
        ComplexAttribute complexAttribute = processUser(user);
        users.setAttributeValue(complexAttribute);
    } else {
        MultiValuedAttribute users = new MultiValuedAttribute(SCIMConstants.RoleSchemaConstants.USERS);
        DefaultAttributeFactory.createAttribute(SCIMSchemaDefinitions.SCIMRoleSchemaDefinition.USERS, users);
        ComplexAttribute complexAttribute = processUser(user);
        users.setAttributeValue(complexAttribute);
        this.setAttribute(users);
    }
}
Also used : ComplexAttribute(org.wso2.charon3.core.attributes.ComplexAttribute) MultiValuedAttribute(org.wso2.charon3.core.attributes.MultiValuedAttribute)

Example 70 with Role

use of org.wso2.carbon.identity.role.mgt.core.Role in project carbon-business-process by wso2.

the class CommonTaskUtil method calculateRole.

/**
 * Calculates the Role.
 *
 * @param evalCtx    : The evaluation context.
 * @param  roleExpression : the role expression
 * @param expressionLanguage : Expression language associated with the argument named "role"
 * @return : The task priority
 */
public static String calculateRole(EvaluationContext evalCtx, String roleExpression, String expressionLanguage) {
    ExpressionLanguageRuntime expLangRuntime = HumanTaskServiceComponent.getHumanTaskServer().getTaskEngine().getExpressionLanguageRuntime(expressionLanguage);
    String role = expLangRuntime.evaluateAsString(roleExpression, evalCtx);
    if (role == null) {
        log.warn(String.format("Role cannot be  null"));
    }
    return role;
}
Also used : ExpressionLanguageRuntime(org.wso2.carbon.humantask.core.engine.runtime.api.ExpressionLanguageRuntime)

Aggregations

Test (org.testng.annotations.Test)85 ArrayList (java.util.ArrayList)74 UserStoreException (org.wso2.carbon.user.api.UserStoreException)56 HashMap (java.util.HashMap)52 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)42 Connection (java.sql.Connection)36 SQLException (java.sql.SQLException)34 Role (org.wso2.charon3.core.objects.Role)33 AbstractUserStoreManager (org.wso2.carbon.user.core.common.AbstractUserStoreManager)31 CharonException (org.wso2.charon3.core.exceptions.CharonException)29 RoleBasicInfo (org.wso2.carbon.identity.role.mgt.core.RoleBasicInfo)26 PreparedStatement (java.sql.PreparedStatement)25 APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)24 RoleMapping (org.wso2.carbon.identity.application.common.model.RoleMapping)24 ISIntegrationTest (org.wso2.identity.integration.common.utils.ISIntegrationTest)23 HashSet (java.util.HashSet)20 UserStoreManager (org.wso2.carbon.user.api.UserStoreManager)20 IdentityProvider (org.wso2.carbon.identity.application.common.model.IdentityProvider)19 IdentityRoleManagementClientException (org.wso2.carbon.identity.role.mgt.core.IdentityRoleManagementClientException)19 Matchers.anyString (org.mockito.Matchers.anyString)18