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;
}
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);
}
}
}
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);
}
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]);
}
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);
}
Aggregations