use of org.wso2.carbon.apimgt.rest.api.store.dto.UserDTO in project carbon-apimgt by wso2.
the class SelfSignupApiServiceImpl method selfSignupPost.
@Override
public Response selfSignupPost(UserDTO body, Request request) throws NotFoundException {
try {
APIStore apiStore = RestApiUtil.getConsumer();
apiStore.selfSignUp(MiscMappingUtil.fromUserDTOToUser(body));
} catch (APIManagementException e) {
String errorMessage = "Error occurred while user signup: " + body.getUsername();
Map<String, String> paramList = new HashMap<>();
paramList.put(APIMgtConstants.ExceptionsConstants.USERNAME, body.getUsername());
ErrorDTO errorDTO = RestApiUtil.getErrorDTO(e.getErrorHandler(), paramList);
errorDTO.setDescription(e.getMessage());
log.error(errorMessage, e);
return Response.status(e.getErrorHandler().getHttpStatusCode()).entity(errorDTO).build();
}
body.setPassword(null);
return Response.ok(body).build();
}
use of org.wso2.carbon.apimgt.rest.api.store.dto.UserDTO in project carbon-apimgt by wso2.
the class MiscMappingUtil method fromUserDTOToUser.
public static User fromUserDTOToUser(UserDTO userDTO) {
User user = new User();
user.setUsername(userDTO.getUsername());
user.setPassword(userDTO.getPassword().toCharArray());
user.setFirstName(userDTO.getFirstName());
user.setLastName(userDTO.getLastName());
user.setEmail(userDTO.getEmail());
return user;
}
use of org.wso2.carbon.apimgt.rest.api.store.dto.UserDTO in project carbon-apimgt by wso2.
the class SelfSignupApiServiceImplTestCase method testSelfSignupPost.
@Test
public void testSelfSignupPost() throws APIManagementException, NotFoundException {
TestUtil.printTestMethodName();
SelfSignupApiServiceImpl selfSignupApiService = new SelfSignupApiServiceImpl();
APIStore apiStore = Mockito.mock(APIStoreImpl.class);
PowerMockito.mockStatic(RestApiUtil.class);
PowerMockito.when(RestApiUtil.getConsumer()).thenReturn(apiStore);
Request request = TestUtil.getRequest();
PowerMockito.when(RestApiUtil.getLoggedInUsername(request)).thenReturn(USER);
User user = new User();
user.setEmail("john@john.doe");
user.setPassword(UUID.randomUUID().toString().toCharArray());
user.setFirstName("John");
user.setLastName("Doe");
user.setUsername("johnd");
UserDTO userDTO = new UserDTO();
userDTO.setEmail("john@john.doe");
userDTO.setPassword(UUID.randomUUID().toString());
userDTO.setFirstName("John");
userDTO.setLastName("Doe");
userDTO.setUsername("johnd");
Mockito.doNothing().when(apiStore).selfSignUp(user);
Response response = selfSignupApiService.selfSignupPost(userDTO, request);
Assert.assertEquals(200, response.getStatus());
}
use of org.wso2.carbon.apimgt.rest.api.store.dto.UserDTO in project carbon-identity-framework by wso2.
the class Utils method getVerifiedChallenges.
/**
* gets no of verified user challenges
*
* @param userDTO bean class that contains user and tenant Information
* @return no of verified challenges
* @throws IdentityException if fails
*/
public static int getVerifiedChallenges(UserDTO userDTO) throws IdentityException {
int noOfChallenges = 0;
try {
UserRegistry registry = IdentityMgtServiceComponent.getRegistryService().getConfigSystemRegistry(MultitenantConstants.SUPER_TENANT_ID);
String identityKeyMgtPath = IdentityMgtConstants.IDENTITY_MANAGEMENT_CHALLENGES + RegistryConstants.PATH_SEPARATOR + userDTO.getUserId() + RegistryConstants.PATH_SEPARATOR + userDTO.getUserId();
Resource resource;
if (registry.resourceExists(identityKeyMgtPath)) {
resource = registry.get(identityKeyMgtPath);
String property = resource.getProperty(IdentityMgtConstants.VERIFIED_CHALLENGES);
if (property != null) {
return Integer.parseInt(property);
}
}
} catch (RegistryException e) {
log.error("Error while processing userKey", e);
}
return noOfChallenges;
}
use of org.wso2.carbon.apimgt.rest.api.store.dto.UserDTO in project carbon-identity-framework by wso2.
the class UserInformationRecoveryService method getUserChallengeQuestion.
/**
* To get the challenge question for the user.
*
* @param userName
* @param confirmation
* @param questionId - Question id returned from the getUserChanllegneQuestionIds
* method.
* @return Populated question bean with the question details and the key.
* @throws IdentityMgtServiceException
*/
public UserChallengesDTO getUserChallengeQuestion(String userName, String confirmation, String questionId) throws IdentityMgtServiceException {
UserDTO userDTO = null;
UserChallengesDTO userChallengesDTO = new UserChallengesDTO();
if (log.isDebugEnabled()) {
log.debug("User challenge question request received with username :" + userName);
}
try {
userDTO = Utils.processUserId(userName);
} catch (IdentityException e) {
return handleChallengesError(VerificationBean.ERROR_CODE_INVALID_USER + " Error validating user : " + userName, null);
}
try {
if (IdentityMgtConfig.getInstance().isSaasEnabled()) {
PrivilegedCarbonContext.startTenantFlow();
PrivilegedCarbonContext carbonContext = PrivilegedCarbonContext.getThreadLocalCarbonContext();
carbonContext.setTenantId(userDTO.getTenantId());
carbonContext.setTenantDomain(userDTO.getTenantDomain());
}
RecoveryProcessor processor = IdentityMgtServiceComponent.getRecoveryProcessor();
VerificationBean bean;
try {
bean = processor.verifyConfirmationCode(20, userDTO.getUserId(), confirmation);
if (bean.isVerified()) {
bean = processor.updateConfirmationCode(40, userDTO.getUserId(), userDTO.getTenantId());
} else if (processor.verifyConfirmationCode(30, userDTO.getUserId(), confirmation).isVerified()) {
bean = processor.updateConfirmationCode(40, userDTO.getUserId(), userDTO.getTenantId());
} else {
bean.setVerified(false);
}
} catch (IdentityException e) {
userChallengesDTO = UserIdentityManagementUtil.getCustomErrorMessagesForChallengQuestions(e, userName);
if (userChallengesDTO == null) {
userChallengesDTO = handleChallengesError(VerificationBean.ERROR_CODE_INVALID_CODE + " Invalid confirmation code for user : " + userName, e);
}
return userChallengesDTO;
}
if (bean.isVerified()) {
userChallengesDTO = processor.getQuestionProcessor().getUserChallengeQuestion(userDTO.getUserId(), userDTO.getTenantId(), questionId);
userChallengesDTO.setKey(bean.getKey());
userChallengesDTO.setVerfied(true);
if (log.isDebugEnabled()) {
log.debug("User challenge question retrieved successfully");
}
} else {
if (log.isDebugEnabled()) {
log.debug("Verification failed for user. Error : " + bean.getError());
}
userChallengesDTO.setError(VerificationBean.ERROR_CODE_INVALID_USER + " " + bean.getError());
}
} finally {
if (IdentityMgtConfig.getInstance().isSaasEnabled()) {
PrivilegedCarbonContext.endTenantFlow();
}
}
return userChallengesDTO;
}
Aggregations