use of org.wso2.carbon.apimgt.rest.api.store.dto.UserDTO in project identity-governance by wso2-extensions.
the class UsernameUpdateServiceImplTest method testExceptionWhileRetrievingNullRealm.
@Test(expectedExceptions = UsernameUpdateException.class)
public void testExceptionWhileRetrievingNullRealm() throws Exception {
UserDTO userDTO = buildUserDTO("testuser1", "testuser11", UserCoreConstants.PRIMARY_DEFAULT_DOMAIN_NAME, MultitenantConstants.SUPER_TENANT_DOMAIN_NAME);
RealmService realmService = mock(RealmService.class);
TenantManager tenantManager = mock(TenantManager.class);
when(realmService.getTenantManager()).thenReturn(tenantManager);
when(tenantManager.getTenantId(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME)).thenReturn(MultitenantConstants.SUPER_TENANT_ID);
when(realmService.getTenantUserRealm(MultitenantConstants.SUPER_TENANT_ID)).thenReturn(null);
UsernameUpdateServiceImpl usernameUpdateServiceImpl = new UsernameUpdateServiceImpl();
usernameUpdateServiceImpl.setRealmService(realmService);
usernameUpdateServiceImpl.updateUsername(userDTO);
}
use of org.wso2.carbon.apimgt.rest.api.store.dto.UserDTO in project identity-governance by wso2-extensions.
the class UsernameUpdateServiceImplTest method testUpdateUsername.
@Test(dataProvider = "getValidUsers")
public void testUpdateUsername(String existingUsername, String newUsername, String userStoreDomain, String tenantDomain) throws Exception {
UserDTO userDTO = buildUserDTO(existingUsername, newUsername, userStoreDomain, tenantDomain);
RealmService realmService = mock(RealmService.class);
TenantManager tenantManager = mock(TenantManager.class);
UserRealm userRealm = mock(UserRealm.class);
UserStoreManager userStoreManager = mock(UserStoreManager.class);
when(realmService.getTenantManager()).thenReturn(tenantManager);
when(tenantManager.getTenantId(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME)).thenReturn(MultitenantConstants.SUPER_TENANT_ID);
when(realmService.getTenantUserRealm(MultitenantConstants.SUPER_TENANT_ID)).thenReturn(userRealm);
when(userRealm.getUserStoreManager()).thenReturn(userStoreManager);
when(userStoreManager.isExistingUser(UserCoreUtil.addDomainToName(userDTO.getExistingUsername(), userDTO.getUserStoreDomain()))).thenReturn(true);
mockedForgetMeToolExecutor.when(() -> ForgetMeToolExecutor.run(userDTO.getExistingUsername(), userDTO.getNewUsername(), userDTO.getUserStoreDomain(), userDTO.getTenantDomain(), MultitenantConstants.SUPER_TENANT_ID)).thenAnswer((Answer<Void>) invocation -> null);
;
UsernameUpdateServiceImpl usernameUpdateServiceImpl = new UsernameUpdateServiceImpl();
usernameUpdateServiceImpl.setRealmService(realmService);
StatusDTO statusDTO = usernameUpdateServiceImpl.updateUsername(userDTO);
usernameUpdateServiceImpl.unsetRealmService(null);
Assert.assertEquals(STATUS_SUCCESS.getCode(), statusDTO.getCode());
Assert.assertEquals(String.format(STATUS_SUCCESS.getMessage(), userDTO.getExistingUsername(), userDTO.getNewUsername()), statusDTO.getMessage());
}
use of org.wso2.carbon.apimgt.rest.api.store.dto.UserDTO in project identity-governance by wso2-extensions.
the class UsernameUpdateServiceImpl method updateUsername.
@Override
public StatusDTO updateUsername(UserDTO userDTO) throws UsernameUpdateException {
validate(userDTO);
String tenantDomain = userDTO.getTenantDomain();
String domainQualifiedUsername = UserCoreUtil.addDomainToName(userDTO.getExistingUsername(), userDTO.getUserStoreDomain());
UserStoreManager userStoreManager = getUserStoreManager(tenantDomain);
if (isExistingUser(domainQualifiedUsername, tenantDomain, userStoreManager)) {
performUpdate(userDTO, userStoreManager);
} else {
throw new UsernameUpdateClientException(String.format(ERROR_USER_NOT_FOUND.getMessage(), tenantDomain, domainQualifiedUsername), ERROR_USER_NOT_FOUND.getCode(), UsernameUpdateClientException.ErrorType.NOT_FOUND);
}
return UpdateUsernameServiceUtil.buildStatus(STATUS_SUCCESS.getCode(), String.format(STATUS_SUCCESS.getMessage(), userDTO.getExistingUsername(), userDTO.getNewUsername()));
}
use of org.wso2.carbon.apimgt.rest.api.store.dto.UserDTO in project identity-governance by wso2-extensions.
the class UpdateUsernameApiServiceImpl method updateUsernamePut.
/**
* Username update service method.
*
* @param user UsernameUpdateRequestDTO{@link UsernameUpdateRequestDTO} including update request parameters
* @return Response status. Returns 200 upon successful update
*/
@Override
public Response updateUsernamePut(UsernameUpdateRequestDTO user) {
try {
UserDTO userDTO = new UserDTO();
userDTO.setExistingUsername(user.getExistingUsername());
userDTO.setNewUsername(user.getNewUsername());
userDTO.setUserStoreDomain(user.getRealm());
userDTO.setTenantDomain(getTenantDomainFromContext());
UsernameUpdateService usernameUpdateService = Utils.getUsernameUpdateService();
usernameUpdateService.updateUsername(userDTO);
} catch (UsernameUpdateClientException e) {
handleClientError(e);
} catch (UsernameUpdateException e) {
handleServerError(e);
} catch (Throwable e) {
handleUnexpectedServerError(e);
}
return Response.ok().status(Response.Status.OK).build();
}
use of org.wso2.carbon.apimgt.rest.api.store.dto.UserDTO in project identity-governance by wso2-extensions.
the class Utils method getUser.
public static User getUser(UserDTO userDTO) {
User user = new User();
user.setTenantDomain(userDTO.getTenantDomain());
if (userDTO.getRealm() == null) {
userDTO.setRealm(IdentityUtil.getPrimaryDomainName());
}
user.setUserStoreDomain(userDTO.getRealm());
user.setUserName(userDTO.getUsername());
return user;
}
Aggregations