Search in sources :

Example 21 with IdentityRoleManagementException

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

the class RoleManagementServiceImpl method getRoles.

@Override
public List<RoleBasicInfo> getRoles(String filter, Integer limit, Integer offset, String sortBy, String sortOrder, String tenantDomain) throws IdentityRoleManagementException {
    RoleManagementEventPublisherProxy roleManagementEventPublisherProxy = RoleManagementEventPublisherProxy.getInstance();
    roleManagementEventPublisherProxy.publishPreGetRoles(filter, limit, offset, sortBy, sortOrder, tenantDomain);
    List<RoleBasicInfo> roleBasicInfoList = roleDAO.getRoles(filter, limit, offset, sortBy, sortOrder, tenantDomain);
    roleManagementEventPublisherProxy.publishPostGetRoles(filter, limit, offset, sortBy, sortOrder, tenantDomain);
    if (log.isDebugEnabled()) {
        log.debug(String.format("%s get filtered roles successfully.", getUser(tenantDomain)));
    }
    return roleBasicInfoList;
}
Also used : RoleManagementEventPublisherProxy(org.wso2.carbon.identity.role.mgt.core.RoleManagementEventPublisherProxy) RoleBasicInfo(org.wso2.carbon.identity.role.mgt.core.RoleBasicInfo)

Example 22 with IdentityRoleManagementException

use of org.wso2.carbon.identity.role.mgt.core.IdentityRoleManagementException in project identity-inbound-auth-oauth by wso2-extensions.

the class IdentityOauthEventHandler method handleEvent.

@Override
public void handleEvent(Event event) throws IdentityEventException {
    if (IdentityEventConstants.Event.POST_SET_USER_CLAIMS.equals(event.getEventName()) || IdentityEventConstants.Event.POST_SET_USER_CLAIM.equals(event.getEventName())) {
        String username = (String) event.getEventProperties().get(IdentityEventConstants.EventProperty.USER_NAME);
        UserStoreManager userStoreManager = (UserStoreManager) event.getEventProperties().get(IdentityEventConstants.EventProperty.USER_STORE_MANAGER);
        try {
            revokeTokensOfLockedUser(username, userStoreManager);
            revokeTokensOfDisabledUser(username, userStoreManager);
            OAuthUtil.removeUserClaimsFromCache(username, userStoreManager);
        } catch (UserStoreException e) {
            String errorMsg = "Error occurred while revoking  access token for User : " + username;
            log.error(errorMsg, e);
            throw new IdentityEventException(errorMsg);
        }
    } else if (IdentityEventConstants.Event.POST_UPDATE_USER_LIST_OF_ROLE_EVENT.equals(event.getEventName())) {
        Object userIdList = event.getEventProperties().get(IdentityEventConstants.EventProperty.DELETE_USER_ID_LIST);
        List<String> deletedUserIDList;
        if (userIdList instanceof List<?>) {
            deletedUserIDList = (List<String>) userIdList;
            terminateSession(deletedUserIDList);
        }
    } else if (IdentityEventConstants.Event.PRE_DELETE_ROLE_EVENT.equals(event.getEventName()) || IdentityEventConstants.Event.POST_SET_PERMISSIONS_FOR_ROLE_EVENT.equals(event.getEventName())) {
        String roleId = (String) event.getEventProperties().get(IdentityEventConstants.EventProperty.ROLE_ID);
        String tenantDomain = (String) event.getEventProperties().get(IdentityEventConstants.EventProperty.TENANT_DOMAIN);
        try {
            List<UserBasicInfo> userList = roleDAO.getRole(roleId, tenantDomain).getUsers();
            List<String> userIdList = new ArrayList<>();
            if (userList != null) {
                for (UserBasicInfo userBasicInfo : userList) {
                    userIdList.add(userBasicInfo.getId());
                }
                terminateSession(userIdList);
            }
        } catch (IdentityRoleManagementException e) {
            String errorMsg = "Invaild role id :" + roleId + "in tenant domain " + tenantDomain;
            throw new IdentityEventException(errorMsg);
        }
    }
}
Also used : UserBasicInfo(org.wso2.carbon.identity.role.mgt.core.UserBasicInfo) IdentityEventException(org.wso2.carbon.identity.event.IdentityEventException) UserStoreException(org.wso2.carbon.user.core.UserStoreException) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) UserStoreManager(org.wso2.carbon.user.core.UserStoreManager) IdentityRoleManagementException(org.wso2.carbon.identity.role.mgt.core.IdentityRoleManagementException)

Example 23 with IdentityRoleManagementException

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

the class SCIMRoleManagerTest method testGetRolePositive.

@Test(dataProvider = "dataProviderForGetRolePositive")
public void testGetRolePositive(String roleId, String roleName, String domain, String tenantDomain, String attributeKey, Boolean attributeValue, boolean isEmptyLists) throws IdentityRoleManagementException, BadRequestException, NotFoundException, CharonException {
    org.wso2.carbon.identity.role.mgt.core.Role role = getDummyIdentityRole(roleId, roleName, domain, tenantDomain, isEmptyLists);
    Map<String, Boolean> attributeMap = null;
    if (attributeKey != null) {
        // If attributeKey is not null, Add dummy data to attributeMap.
        attributeMap = new HashMap<>();
        attributeMap.put(attributeKey, attributeValue);
    }
    when(mockRoleManagementService.getRole(roleId, tenantDomain)).thenReturn(role);
    SCIMRoleManager scimRoleManager = new SCIMRoleManager(mockRoleManagementService, tenantDomain);
    Role scimRole = scimRoleManager.getRole(roleId, attributeMap);
    assertScimRoleFull(scimRole, roleId);
}
Also used : Role(org.wso2.charon3.core.objects.Role) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.testng.annotations.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 24 with IdentityRoleManagementException

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

the class SCIMRoleManagerTest method testUpdateRoleUpdateRoleNameThrowingErrors.

@Test(dataProvider = "dataProviderForUpdateRoleUpdateRoleNameThrowingErrors", expectedExceptions = { ConflictException.class, NotFoundException.class, BadRequestException.class, CharonException.class })
public void testUpdateRoleUpdateRoleNameThrowingErrors(String roleId, String oldRoleName, String newRoleName, String tenantDomain, String sError) throws IdentityRoleManagementException, BadRequestException, CharonException, ConflictException, NotFoundException {
    Role[] oldAndNewRoles = getOldAndNewRoleDummies(roleId, oldRoleName, newRoleName);
    when(mockRoleManagementService.updateRoleName(anyString(), anyString(), anyString())).thenAnswer(invocationOnMock -> {
        String newRoleNameArg = invocationOnMock.getArgumentAt(1, String.class);
        String roleIdArg = invocationOnMock.getArgumentAt(0, String.class);
        String tenantDomainArg = invocationOnMock.getArgumentAt(2, String.class);
        if (EXISTING_ROLE_NAMES.contains(newRoleNameArg)) {
            throw new IdentityRoleManagementClientException(ROLE_ALREADY_EXISTS.getCode(), "Role name: " + newRoleNameArg + " is already there in the system. Please pick another role name.");
        }
        if (NON_EXISTING_ROLE_IDS.contains(roleIdArg)) {
            throw new IdentityRoleManagementClientException(ROLE_NOT_FOUND.getCode(), "Role id: " + roleIdArg + " does not exist in the system.");
        }
        if (SYSTEM_ROLES.contains(oldRoleName)) {
            throw new IdentityRoleManagementClientException(RoleConstants.Error.OPERATION_FORBIDDEN.getCode(), "Invalid operation. Role: " + oldRoleName + " Cannot be renamed since it's a read only system role.");
        }
        Throwable unExpectedErrors = unExpectedErrorThrower(tenantDomainArg, sError, "Error while updating users to the role: %s in the tenantDomain: %s", roleIdArg);
        if (unExpectedErrors != null)
            throw unExpectedErrors;
        return null;
    });
    SCIMRoleManager scimRoleManager = new SCIMRoleManager(mockRoleManagementService, tenantDomain);
    scimRoleManager.updateRole(oldAndNewRoles[0], oldAndNewRoles[1]);
}
Also used : Role(org.wso2.charon3.core.objects.Role) Matchers.anyString(org.mockito.Matchers.anyString) IdentityRoleManagementClientException(org.wso2.carbon.identity.role.mgt.core.IdentityRoleManagementClientException) Test(org.testng.annotations.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 25 with IdentityRoleManagementException

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

the class SCIMRoleManagerTest method testCreateRolePositive.

@Test(dataProvider = "dataProviderForCreateRolePositive")
public void testCreateRolePositive(String roleId, String roleDisplayName, String tenantDomain) throws IdentityRoleManagementException, BadRequestException, CharonException, ConflictException {
    Role role = getDummyRole(roleId, roleDisplayName);
    when(mockRoleManagementService.addRole(anyString(), anyListOf(String.class), anyListOf(String.class), anyListOf(String.class), anyString())).thenReturn(new RoleBasicInfo(roleId, roleDisplayName));
    SCIMRoleManager scimRoleManager = new SCIMRoleManager(mockRoleManagementService, tenantDomain);
    Role createdRole = scimRoleManager.createRole(role);
    assertEquals(createdRole.getDisplayName(), roleDisplayName);
    assertEquals(createdRole.getId(), roleId);
}
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

IdentityRoleManagementClientException (org.wso2.carbon.identity.role.mgt.core.IdentityRoleManagementClientException)29 IdentityRoleManagementServerException (org.wso2.carbon.identity.role.mgt.core.IdentityRoleManagementServerException)23 RoleBasicInfo (org.wso2.carbon.identity.role.mgt.core.RoleBasicInfo)22 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)20 Test (org.testng.annotations.Test)20 NamedPreparedStatement (org.wso2.carbon.database.utils.jdbc.NamedPreparedStatement)20 Connection (java.sql.Connection)19 SQLException (java.sql.SQLException)19 Matchers.anyString (org.mockito.Matchers.anyString)14 IdentityRoleManagementException (org.wso2.carbon.identity.role.mgt.core.IdentityRoleManagementException)14 Role (org.wso2.charon3.core.objects.Role)13 ResultSet (java.sql.ResultSet)12 RoleManagementEventPublisherProxy (org.wso2.carbon.identity.role.mgt.core.RoleManagementEventPublisherProxy)11 ArrayList (java.util.ArrayList)9 CharonException (org.wso2.charon3.core.exceptions.CharonException)8 ExpressionNode (org.wso2.charon3.core.utils.codeutils.ExpressionNode)8 Node (org.wso2.charon3.core.utils.codeutils.Node)8 OperationNode (org.wso2.charon3.core.utils.codeutils.OperationNode)8 UserStoreException (org.wso2.carbon.user.api.UserStoreException)6 BadRequestException (org.wso2.charon3.core.exceptions.BadRequestException)6