use of org.wso2.carbon.identity.role.mgt.core.UserBasicInfo in project carbon-identity-framework by wso2.
the class RoleDAOTest method testDeleteUser.
@Test
public void testDeleteUser() throws Exception {
try (Connection connection1 = DAOUtils.getConnection(DB_NAME);
Connection connection2 = DAOUtils.getConnection(DB_NAME);
Connection connection3 = DAOUtils.getConnection(DB_NAME);
Connection connection4 = DAOUtils.getConnection(DB_NAME);
Connection connection5 = DAOUtils.getConnection(DB_NAME);
Connection connection6 = DAOUtils.getConnection(DB_NAME);
Connection connection7 = DAOUtils.getConnection(DB_NAME)) {
roleDAO = spy(RoleMgtDAOFactory.getInstance().getRoleDAO());
mockCacheClearing();
when(IdentityDatabaseUtil.getUserDBConnection(anyBoolean())).thenReturn(connection1);
when(IdentityDatabaseUtil.getDBConnection(anyBoolean())).thenReturn(connection2);
RoleBasicInfo role = addRole("role1");
doReturn(true).when(roleDAO, "isExistingRoleName", anyString(), anyString());
doCallRealMethod().when(roleDAO, "updateUserListOfRole", anyString(), anyCollection(), anyCollection(), anyString());
when(IdentityDatabaseUtil.getUserDBConnection(anyBoolean())).thenReturn(connection3);
when(IdentityDatabaseUtil.getDBConnection(anyBoolean())).thenReturn(connection4);
mockStatic(IdentityUtil.class);
when(IdentityUtil.getPrimaryDomainName()).thenReturn("PRIMARY");
doReturn(userNamesList).when(roleDAO, "getUserNamesByIDs", eq(userIDsList), anyString());
roleDAO.updateUserListOfRole(role.getId(), userIDsList, null, SAMPLE_TENANT_DOMAIN);
when(IdentityDatabaseUtil.getUserDBConnection(anyBoolean())).thenReturn(connection5);
doReturn("user1").when(roleDAO, "getUserNameByID", anyString(), anyString());
roleDAO.deleteUser("userID1", SAMPLE_TENANT_DOMAIN);
userNamesList.remove("user1");
mockRealmConfiguration();
mockStatic(UserCoreUtil.class);
when(UserCoreUtil.isEveryoneRole(anyString(), any(RealmConfiguration.class))).thenReturn(false);
when(IdentityDatabaseUtil.getUserDBConnection(anyBoolean())).thenReturn(connection6);
when(IdentityDatabaseUtil.getDBConnection(anyBoolean())).thenReturn(connection7);
doCallRealMethod().when(UserCoreUtil.class, "addDomainToName", anyString(), anyString());
doReturn("userID1").when(roleDAO, "getUserIDByName", eq(userNamesList.get(0)), anyString());
List<UserBasicInfo> users = roleDAO.getUserListOfRole(role.getId(), SAMPLE_TENANT_DOMAIN);
assertEquals(getUserNamesList(users), userNamesList);
}
}
use of org.wso2.carbon.identity.role.mgt.core.UserBasicInfo 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.UserBasicInfo in project identity-inbound-provisioning-scim2 by wso2-extensions.
the class SCIMRoleManagerTest method getDummyIdentityRole.
private org.wso2.carbon.identity.role.mgt.core.Role getDummyIdentityRole(String roleId, String roleName, String domain, String tenantDomain) {
org.wso2.carbon.identity.role.mgt.core.Role role = new org.wso2.carbon.identity.role.mgt.core.Role();
role.setId(roleId);
role.setPermissions(Arrays.asList("permission", "usermgt"));
role.setName(roleName);
role.setDomain(domain);
role.setTenantDomain(tenantDomain);
role.setUsers(Arrays.asList(new UserBasicInfo("7646b885-4207-4ca0-bc65-5df82272b6d1", "username1"), new UserBasicInfo("7646b885-4207-4ca0-bc65-5df82272b6d2", "username2")));
GroupBasicInfo groupBasicInfo1 = new GroupBasicInfo();
groupBasicInfo1.setName("groupName1");
groupBasicInfo1.setId("26d3a726-9c00-4f4c-8a4e-f5e310138081");
GroupBasicInfo groupBasicInfo2 = new GroupBasicInfo();
groupBasicInfo2.setName("groupName2");
groupBasicInfo2.setId("26d3a726-9c00-4f4c-8a4e-f5e310138082");
role.setGroups(Arrays.asList(groupBasicInfo1, groupBasicInfo2));
return role;
}
use of org.wso2.carbon.identity.role.mgt.core.UserBasicInfo in project identity-inbound-provisioning-scim2 by wso2-extensions.
the class SCIMRoleManager method getRole.
@Override
public Role getRole(String roleID, Map<String, Boolean> requiredAttributes) throws BadRequestException, CharonException, NotFoundException {
try {
org.wso2.carbon.identity.role.mgt.core.Role role = roleManagementService.getRole(roleID, tenantDomain);
Role scimRole = new Role();
scimRole.setId(role.getId());
scimRole.setDisplayName(role.getName());
String locationURI = SCIMCommonUtils.getSCIMRoleURL(role.getId());
scimRole.setLocation(locationURI);
scimRole.setPermissions(role.getPermissions());
scimRole.setSchemas();
if (systemRoles.contains(role.getName())) {
scimRole.setSystemRole(true);
}
if (CollectionUtils.isNotEmpty(role.getUsers())) {
for (UserBasicInfo userInfo : role.getUsers()) {
String userLocationURI = SCIMCommonUtils.getSCIMUserURL(userInfo.getId());
User user = new User();
user.setUserName(userInfo.getName());
user.setId(userInfo.getId());
user.setLocation(userLocationURI);
scimRole.setUser(user);
}
}
if (CollectionUtils.isNotEmpty(role.getGroups())) {
for (GroupBasicInfo groupInfo : role.getGroups()) {
String groupLocationURI = SCIMCommonUtils.getSCIMGroupURL(groupInfo.getId());
Group group = new Group();
group.setDisplayName(groupInfo.getName());
group.setId(groupInfo.getId());
group.setLocation(groupLocationURI);
scimRole.setGroup(group);
}
}
return scimRole;
} catch (IdentityRoleManagementException e) {
if (StringUtils.equals(ROLE_NOT_FOUND.getCode(), e.getErrorCode())) {
throw new NotFoundException(e.getMessage());
}
throw new CharonException(String.format("Error occurred while getting the role: %s", roleID), e);
}
}
use of org.wso2.carbon.identity.role.mgt.core.UserBasicInfo in project carbon-identity-framework by wso2.
the class RoleDAOTest method testGetUserListOfRole.
@Test
public void testGetUserListOfRole() throws Exception {
try (Connection connection1 = DAOUtils.getConnection(DB_NAME);
Connection connection2 = DAOUtils.getConnection(DB_NAME);
Connection connection3 = DAOUtils.getConnection(DB_NAME);
Connection connection4 = DAOUtils.getConnection(DB_NAME);
Connection connection5 = DAOUtils.getConnection(DB_NAME);
Connection connection6 = DAOUtils.getConnection(DB_NAME)) {
roleDAO = spy(RoleMgtDAOFactory.getInstance().getRoleDAO());
when(IdentityDatabaseUtil.getUserDBConnection(anyBoolean())).thenReturn(connection1);
when(IdentityDatabaseUtil.getDBConnection(anyBoolean())).thenReturn(connection2);
RoleBasicInfo role = addRole("role1");
doReturn(true).when(roleDAO, "isExistingRoleName", anyString(), anyString());
doCallRealMethod().when(roleDAO, "updateUserListOfRole", anyString(), anyCollection(), anyCollection(), anyString());
when(IdentityDatabaseUtil.getUserDBConnection(anyBoolean())).thenReturn(connection3);
when(IdentityDatabaseUtil.getDBConnection(anyBoolean())).thenReturn(connection4);
mockStatic(IdentityUtil.class);
when(IdentityUtil.getPrimaryDomainName()).thenReturn("PRIMARY");
doReturn(userNamesList).when(roleDAO, "getUserNamesByIDs", eq(userIDsList), anyString());
roleDAO.updateUserListOfRole(role.getId(), userIDsList, null, SAMPLE_TENANT_DOMAIN);
mockRealmConfiguration();
mockStatic(UserCoreUtil.class);
when(UserCoreUtil.isEveryoneRole(anyString(), any(RealmConfiguration.class))).thenReturn(false);
when(IdentityDatabaseUtil.getUserDBConnection(anyBoolean())).thenReturn(connection5);
when(IdentityDatabaseUtil.getDBConnection(anyBoolean())).thenReturn(connection6);
doCallRealMethod().when(UserCoreUtil.class, "addDomainToName", anyString(), anyString());
doReturn("userID1").when(roleDAO, "getUserIDByName", eq(userNamesList.get(0)), anyString());
doReturn("userID2").when(roleDAO, "getUserIDByName", eq(userNamesList.get(1)), anyString());
List<UserBasicInfo> users = roleDAO.getUserListOfRole(role.getId(), SAMPLE_TENANT_DOMAIN);
assertEquals(getUserNamesList(users), userNamesList);
}
}
Aggregations