Search in sources :

Example 1 with UserNotFoundException

use of com.odysseusinc.arachne.portal.exception.UserNotFoundException in project ArachneCentralAPI by OHDSI.

the class BaseUserController method findUserStatus.

@ApiOperation("Get status of registered user")
@GetMapping(value = "/api/v1/auth/status/{userUuid}")
public JsonResult<CommonArachneUserStatusDTO> findUserStatus(@PathVariable("userUuid") String uuid) throws UserNotFoundException {
    JsonResult<CommonArachneUserStatusDTO> result;
    IUser user = userService.getByUuid(uuid);
    if (user == null) {
        throw new UserNotFoundException("userUuid", "user not found");
    } else {
        result = new JsonResult<>(JsonResult.ErrorCode.NO_ERROR);
        result.setResult(user.getEnabled() ? CommonArachneUserStatusDTO.APPROVED : CommonArachneUserStatusDTO.PENDING);
    }
    return result;
}
Also used : UserNotFoundException(com.odysseusinc.arachne.portal.exception.UserNotFoundException) CommonArachneUserStatusDTO(com.odysseusinc.arachne.commons.api.v1.dto.CommonArachneUserStatusDTO) IUser(com.odysseusinc.arachne.portal.model.IUser) GetMapping(org.springframework.web.bind.annotation.GetMapping) ApiOperation(io.swagger.annotations.ApiOperation)

Example 2 with UserNotFoundException

use of com.odysseusinc.arachne.portal.exception.UserNotFoundException in project ArachneCentralAPI by OHDSI.

the class BaseUserController method activate.

@ApiOperation("Register user via activation code.")
@GetMapping(value = "/api/v1/user-management/activation/{activationCode}")
public void activate(Principal principal, HttpServletRequest request, @PathVariable("activationCode") String activateCode, @RequestParam(value = "callbackUrl", required = false) String callbackUrl, HttpServletResponse response) throws IOException, UserNotFoundException, NotExistException, NoSuchFieldException, IllegalAccessException, SolrServerException, URISyntaxException {
    getAuthToken(request).forEach(authenticator::invalidateToken);
    Boolean activated;
    try {
        userService.confirmUserEmail(activateCode);
        activated = true;
    } catch (UserNotFoundException ex) {
        activated = false;
    }
    String safeCallback = callbackUrl != null ? callbackUrl : "/auth/login";
    URIBuilder redirectURIBuilder = new URIBuilder(safeCallback);
    redirectURIBuilder.addParameter("message", activated ? "email-confirmed" : "email-not-confirmed");
    response.sendRedirect(redirectURIBuilder.build().toString());
}
Also used : UserNotFoundException(com.odysseusinc.arachne.portal.exception.UserNotFoundException) URIBuilder(org.apache.http.client.utils.URIBuilder) GetMapping(org.springframework.web.bind.annotation.GetMapping) ApiOperation(io.swagger.annotations.ApiOperation)

Example 3 with UserNotFoundException

use of com.odysseusinc.arachne.portal.exception.UserNotFoundException in project ArachneCentralAPI by OHDSI.

the class BaseUserServiceImpl method remove.

@Override
@PreAuthorize("hasRole('ROLE_ADMIN')")
@Transactional(rollbackFor = Exception.class)
public void remove(Long id) throws ValidationException, UserNotFoundException, NotExistException, IOException, SolrServerException {
    if (id == null) {
        throw new ValidationException("remove user: id must be not null");
    }
    U user = rawUserRepository.findById(id).orElseThrow(() -> new UserNotFoundException("removeUser", "remove user: user not found"));
    solrService.delete(user);
    rawUserRepository.deleteById(user.getId());
}
Also used : UserNotFoundException(com.odysseusinc.arachne.portal.exception.UserNotFoundException) PasswordValidationException(com.odysseusinc.arachne.portal.exception.PasswordValidationException) ValidationException(com.odysseusinc.arachne.portal.exception.ValidationException) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

UserNotFoundException (com.odysseusinc.arachne.portal.exception.UserNotFoundException)3 ApiOperation (io.swagger.annotations.ApiOperation)2 GetMapping (org.springframework.web.bind.annotation.GetMapping)2 CommonArachneUserStatusDTO (com.odysseusinc.arachne.commons.api.v1.dto.CommonArachneUserStatusDTO)1 PasswordValidationException (com.odysseusinc.arachne.portal.exception.PasswordValidationException)1 ValidationException (com.odysseusinc.arachne.portal.exception.ValidationException)1 IUser (com.odysseusinc.arachne.portal.model.IUser)1 URIBuilder (org.apache.http.client.utils.URIBuilder)1 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)1 Transactional (org.springframework.transaction.annotation.Transactional)1