Search in sources :

Example 26 with RoleBasicInfo

use of org.wso2.carbon.identity.role.mgt.core.RoleBasicInfo in project carbon-identity-framework by wso2.

the class RoleManagementServiceImpl method updateUserListOfRole.

@Override
public RoleBasicInfo updateUserListOfRole(String roleID, List<String> newUserIDList, List<String> deletedUserIDList, String tenantDomain) throws IdentityRoleManagementException {
    RoleManagementEventPublisherProxy roleManagementEventPublisherProxy = RoleManagementEventPublisherProxy.getInstance();
    roleManagementEventPublisherProxy.publishPreUpdateUserListOfRole(roleID, newUserIDList, deletedUserIDList, tenantDomain);
    RoleBasicInfo roleBasicInfo = roleDAO.updateUserListOfRole(roleID, newUserIDList, deletedUserIDList, tenantDomain);
    roleManagementEventPublisherProxy.publishPostUpdateUserListOfRole(roleID, newUserIDList, deletedUserIDList, tenantDomain);
    if (log.isDebugEnabled()) {
        log.debug(String.format("%s updated list of users of role of id : %s successfully.", getUser(tenantDomain), roleID));
    }
    audit.info(String.format(auditMessage, getUser(tenantDomain), "Update users list of role by id", roleID, getAuditData(tenantDomain), success));
    return roleBasicInfo;
}
Also used : RoleManagementEventPublisherProxy(org.wso2.carbon.identity.role.mgt.core.RoleManagementEventPublisherProxy) RoleBasicInfo(org.wso2.carbon.identity.role.mgt.core.RoleBasicInfo)

Example 27 with RoleBasicInfo

use of org.wso2.carbon.identity.role.mgt.core.RoleBasicInfo in project carbon-identity-framework by wso2.

the class RoleManagementServiceImpl method setPermissionsForRole.

@Override
public RoleBasicInfo setPermissionsForRole(String roleID, List<String> permissions, String tenantDomain) throws IdentityRoleManagementException {
    RoleManagementEventPublisherProxy roleManagementEventPublisherProxy = RoleManagementEventPublisherProxy.getInstance();
    roleManagementEventPublisherProxy.publishPreSetPermissionsForRole(roleID, permissions, tenantDomain);
    RoleBasicInfo roleBasicInfo = roleDAO.setPermissionsForRole(roleID, permissions, tenantDomain);
    roleManagementEventPublisherProxy.publishPostSetPermissionsForRole(roleID, permissions, tenantDomain);
    if (log.isDebugEnabled()) {
        log.debug(String.format("%s set list of permissions of role of id : %s successfully.", getUser(tenantDomain), roleID));
    }
    audit.info(String.format(auditMessage, getUser(tenantDomain), "Set permission for role by id", roleID, getAuditData(tenantDomain), success));
    return roleBasicInfo;
}
Also used : RoleManagementEventPublisherProxy(org.wso2.carbon.identity.role.mgt.core.RoleManagementEventPublisherProxy) RoleBasicInfo(org.wso2.carbon.identity.role.mgt.core.RoleBasicInfo)

Example 28 with RoleBasicInfo

use of org.wso2.carbon.identity.role.mgt.core.RoleBasicInfo in project carbon-identity-framework by wso2.

the class RoleDAOImpl method getRoles.

@Override
public List<RoleBasicInfo> getRoles(Integer limit, Integer offset, String sortBy, String sortOrder, String tenantDomain) throws IdentityRoleManagementException {
    int tenantId = IdentityTenantUtil.getTenantId(tenantDomain);
    limit = validateLimit(limit);
    offset = validateOffset(offset);
    validateAttributesForSorting(sortBy, sortOrder);
    List<RoleBasicInfo> roles;
    try (Connection connection = IdentityDatabaseUtil.getUserDBConnection(false)) {
        String databaseProductName = connection.getMetaData().getDatabaseProductName();
        try (NamedPreparedStatement statement = new NamedPreparedStatement(connection, getDBTypeSpecificRolesRetrievalQuery(databaseProductName), RoleTableColumns.UM_ID)) {
            statement.setInt(RoleTableColumns.UM_TENANT_ID, tenantId);
            roles = processListRolesQuery(limit, offset, statement, tenantDomain);
        }
    } catch (SQLException e) {
        throw new IdentityRoleManagementServerException(UNEXPECTED_SERVER_ERROR.getCode(), "Error while listing roles in tenantDomain: " + tenantDomain, e);
    }
    return Collections.unmodifiableList(roles);
}
Also used : NamedPreparedStatement(org.wso2.carbon.database.utils.jdbc.NamedPreparedStatement) SQLException(java.sql.SQLException) IdentityRoleManagementServerException(org.wso2.carbon.identity.role.mgt.core.IdentityRoleManagementServerException) Connection(java.sql.Connection) RoleBasicInfo(org.wso2.carbon.identity.role.mgt.core.RoleBasicInfo)

Example 29 with RoleBasicInfo

use of org.wso2.carbon.identity.role.mgt.core.RoleBasicInfo in project carbon-identity-framework by wso2.

the class RoleDAOImpl method setPermissions.

private RoleBasicInfo setPermissions(String roleID, List<String> permissions, String tenantDomain, String roleName) throws IdentityRoleManagementServerException {
    roleName = appendInternalDomain(roleName);
    /*
        Permission list can be empty in case we want to remove the permissions.
        Therefore validating for NULL will be sufficient.
         */
    if (permissions == null) {
        if (log.isDebugEnabled()) {
            log.debug("Permissions list is null. Therefore not proceeding further.");
        }
        return new RoleBasicInfo(roleID, roleName);
    }
    try {
        getUserAdminProxy().setRoleUIPermission(roleName, permissions.toArray(new String[0]));
        clearUserRolesCacheByTenant(IdentityTenantUtil.getTenantId(tenantDomain));
        return new RoleBasicInfo(roleID, roleName);
    } catch (UserAdminException e) {
        throw new IdentityRoleManagementServerException(UNEXPECTED_SERVER_ERROR.getCode(), "An error occurred when setting permissions for the role: " + roleName, e);
    }
}
Also used : IdentityRoleManagementServerException(org.wso2.carbon.identity.role.mgt.core.IdentityRoleManagementServerException) UserAdminException(org.wso2.carbon.user.mgt.common.UserAdminException) RoleBasicInfo(org.wso2.carbon.identity.role.mgt.core.RoleBasicInfo)

Example 30 with RoleBasicInfo

use of org.wso2.carbon.identity.role.mgt.core.RoleBasicInfo in project identity-inbound-provisioning-scim2 by wso2-extensions.

the class SCIMRoleManagerTest method testUpdateRoleUpdateRoleName.

@Test(dataProvider = "dataProviderForUpdateRoleUpdateRoleName")
public void testUpdateRoleUpdateRoleName(String roleId, String oldRoleName, String newRoleName, String tenantDomain, String type) throws IdentityRoleManagementException, BadRequestException, CharonException, ConflictException, NotFoundException {
    RoleBasicInfo roleBasicInfo = new RoleBasicInfo(roleId, newRoleName);
    Role[] oldAndNewRoles = getOldAndNewRoleDummies(roleId, oldRoleName, newRoleName, type);
    when(mockRoleManagementService.updateRoleName(anyString(), anyString(), anyString())).thenReturn(roleBasicInfo);
    when(mockRoleManagementService.updateUserListOfRole(eq(roleId), anyListOf(String.class), anyListOf(String.class), anyString())).thenReturn(roleBasicInfo);
    when(mockRoleManagementService.updateGroupListOfRole(eq(roleId), anyListOf(String.class), anyListOf(String.class), anyString())).thenReturn(roleBasicInfo);
    when(mockRoleManagementService.setPermissionsForRole(eq(roleId), anyListOf(String.class), anyString())).thenReturn(roleBasicInfo);
    SCIMRoleManager scimRoleManager = new SCIMRoleManager(mockRoleManagementService, tenantDomain);
    scimRoleManager.updateRole(oldAndNewRoles[0], oldAndNewRoles[1]);
    assertTrue(true, "updateRole execute successfully");
}
Also used : Role(org.wso2.charon3.core.objects.Role) Matchers.anyString(org.mockito.Matchers.anyString) RoleBasicInfo(org.wso2.carbon.identity.role.mgt.core.RoleBasicInfo) Test(org.testng.annotations.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Aggregations

RoleBasicInfo (org.wso2.carbon.identity.role.mgt.core.RoleBasicInfo)34 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)17 Test (org.testng.annotations.Test)17 Connection (java.sql.Connection)15 ArrayList (java.util.ArrayList)8 IdentityRoleManagementClientException (org.wso2.carbon.identity.role.mgt.core.IdentityRoleManagementClientException)8 Matchers.anyString (org.mockito.Matchers.anyString)7 RealmConfiguration (org.wso2.carbon.user.api.RealmConfiguration)7 Role (org.wso2.charon3.core.objects.Role)7 IdentityRoleManagementServerException (org.wso2.carbon.identity.role.mgt.core.IdentityRoleManagementServerException)6 RoleManagementEventPublisherProxy (org.wso2.carbon.identity.role.mgt.core.RoleManagementEventPublisherProxy)6 SQLException (java.sql.SQLException)5 IdentityRoleManagementException (org.wso2.carbon.identity.role.mgt.core.IdentityRoleManagementException)5 NamedPreparedStatement (org.wso2.carbon.database.utils.jdbc.NamedPreparedStatement)3 CharonException (org.wso2.charon3.core.exceptions.CharonException)3 GroupBasicInfo (org.wso2.carbon.identity.role.mgt.core.GroupBasicInfo)2 UserBasicInfo (org.wso2.carbon.identity.role.mgt.core.UserBasicInfo)2 AuthorizationManager (org.wso2.carbon.user.api.AuthorizationManager)2 JDBCAuthorizationManager (org.wso2.carbon.user.core.authorization.JDBCAuthorizationManager)2 BadRequestException (org.wso2.charon3.core.exceptions.BadRequestException)2