Search in sources :

Example 1 with USER_ID

use of org.craftercms.studio.api.v2.dal.QueryParameterNames.USER_ID in project studio by craftercms.

the class UserServiceInternalImpl method setUserPassword.

@RetryingOperation
@Override
public boolean setUserPassword(String username, String newPassword) throws UserNotFoundException, UserExternallyManagedException, ServiceLayerException {
    if (!userExists(-1, username)) {
        throw new UserNotFoundException();
    } else {
        if (verifyPasswordRequirements(newPassword)) {
            Map<String, Object> params = new HashMap<String, Object>();
            params.put(USER_ID, -1);
            params.put(USERNAME, username);
            try {
                User user = userDao.getUserByIdOrUsername(params);
                if (user.isExternallyManaged()) {
                    throw new UserExternallyManagedException();
                } else {
                    String hashedPassword = CryptoUtils.hashPassword(newPassword);
                    params = new HashMap<String, Object>();
                    params.put(USERNAME, username);
                    params.put(PASSWORD, hashedPassword);
                    userDao.setUserPassword(params);
                    return true;
                }
            } catch (Exception e) {
                throw new ServiceLayerException("Unknown database error", e);
            }
        } else {
            throw new PasswordRequirementsFailedException("User password does not fulfill requirements");
        }
    }
}
Also used : UserNotFoundException(org.craftercms.studio.api.v1.exception.security.UserNotFoundException) UserExternallyManagedException(org.craftercms.studio.api.v1.exception.security.UserExternallyManagedException) User(org.craftercms.studio.api.v2.dal.User) HashMap(java.util.HashMap) ServiceLayerException(org.craftercms.studio.api.v1.exception.ServiceLayerException) PasswordDoesNotMatchException(org.craftercms.studio.api.v1.exception.security.PasswordDoesNotMatchException) UserAlreadyExistsException(org.craftercms.studio.api.v1.exception.security.UserAlreadyExistsException) UserNotFoundException(org.craftercms.studio.api.v1.exception.security.UserNotFoundException) UserExternallyManagedException(org.craftercms.studio.api.v1.exception.security.UserExternallyManagedException) PasswordRequirementsFailedException(org.craftercms.studio.api.v2.exception.PasswordRequirementsFailedException) ServiceLayerException(org.craftercms.studio.api.v1.exception.ServiceLayerException) PasswordRequirementsFailedException(org.craftercms.studio.api.v2.exception.PasswordRequirementsFailedException) RetryingOperation(org.craftercms.studio.api.v2.annotation.RetryingOperation)

Example 2 with USER_ID

use of org.craftercms.studio.api.v2.dal.QueryParameterNames.USER_ID in project studio by craftercms.

the class UserServiceInternalImpl method updateUser.

@RetryingOperation
@Override
public void updateUser(User user) throws UserNotFoundException, ServiceLayerException {
    long userId = user.getId();
    String username = user.getUsername() != null ? user.getUsername() : StringUtils.EMPTY;
    User oldUser = getUserByIdOrUsername(userId, username);
    Map<String, Object> params = new HashMap<>();
    params.put(USER_ID, oldUser.getId());
    params.put(FIRST_NAME, user.getFirstName());
    params.put(LAST_NAME, user.getLastName());
    params.put(EMAIL, user.getEmail());
    params.put(TIMEZONE, StringUtils.EMPTY);
    params.put(LOCALE, StringUtils.EMPTY);
    try {
        userDao.updateUser(params);
    } catch (Exception e) {
        throw new ServiceLayerException("Unknown database error", e);
    }
}
Also used : User(org.craftercms.studio.api.v2.dal.User) HashMap(java.util.HashMap) ServiceLayerException(org.craftercms.studio.api.v1.exception.ServiceLayerException) PasswordDoesNotMatchException(org.craftercms.studio.api.v1.exception.security.PasswordDoesNotMatchException) UserAlreadyExistsException(org.craftercms.studio.api.v1.exception.security.UserAlreadyExistsException) UserNotFoundException(org.craftercms.studio.api.v1.exception.security.UserNotFoundException) UserExternallyManagedException(org.craftercms.studio.api.v1.exception.security.UserExternallyManagedException) PasswordRequirementsFailedException(org.craftercms.studio.api.v2.exception.PasswordRequirementsFailedException) ServiceLayerException(org.craftercms.studio.api.v1.exception.ServiceLayerException) RetryingOperation(org.craftercms.studio.api.v2.annotation.RetryingOperation)

Example 3 with USER_ID

use of org.craftercms.studio.api.v2.dal.QueryParameterNames.USER_ID in project studio by craftercms.

the class UserServiceInternalImpl method getUserGroups.

@Override
public List<Group> getUserGroups(long userId, String username) throws UserNotFoundException, ServiceLayerException {
    if (!userExists(userId, username)) {
        throw new UserNotFoundException("No user found for username '" + username + "' or id '" + userId + "'");
    }
    Map<String, Object> params = new HashMap<>();
    params.put(USER_ID, userId);
    params.put(USERNAME, username);
    try {
        return userDao.getUserGroups(params);
    } catch (Exception e) {
        throw new ServiceLayerException("Unknown database error", e);
    }
}
Also used : UserNotFoundException(org.craftercms.studio.api.v1.exception.security.UserNotFoundException) HashMap(java.util.HashMap) ServiceLayerException(org.craftercms.studio.api.v1.exception.ServiceLayerException) PasswordDoesNotMatchException(org.craftercms.studio.api.v1.exception.security.PasswordDoesNotMatchException) UserAlreadyExistsException(org.craftercms.studio.api.v1.exception.security.UserAlreadyExistsException) UserNotFoundException(org.craftercms.studio.api.v1.exception.security.UserNotFoundException) UserExternallyManagedException(org.craftercms.studio.api.v1.exception.security.UserExternallyManagedException) PasswordRequirementsFailedException(org.craftercms.studio.api.v2.exception.PasswordRequirementsFailedException) ServiceLayerException(org.craftercms.studio.api.v1.exception.ServiceLayerException)

Example 4 with USER_ID

use of org.craftercms.studio.api.v2.dal.QueryParameterNames.USER_ID in project studio by craftercms.

the class UserServiceInternalImpl method getUserByIdOrUsername.

@Override
public User getUserByIdOrUsername(long userId, String username) throws ServiceLayerException, UserNotFoundException {
    Map<String, Object> params = new HashMap<>();
    params.put(USER_ID, userId);
    params.put(USERNAME, username);
    User user;
    try {
        user = userDao.getUserByIdOrUsername(params);
    } catch (Exception e) {
        throw new ServiceLayerException("Unknown database error", e);
    }
    if (user == null) {
        throw new UserNotFoundException("No user found for username '" + username + "' or id '" + userId + "'");
    }
    return user;
}
Also used : UserNotFoundException(org.craftercms.studio.api.v1.exception.security.UserNotFoundException) User(org.craftercms.studio.api.v2.dal.User) HashMap(java.util.HashMap) ServiceLayerException(org.craftercms.studio.api.v1.exception.ServiceLayerException) PasswordDoesNotMatchException(org.craftercms.studio.api.v1.exception.security.PasswordDoesNotMatchException) UserAlreadyExistsException(org.craftercms.studio.api.v1.exception.security.UserAlreadyExistsException) UserNotFoundException(org.craftercms.studio.api.v1.exception.security.UserNotFoundException) UserExternallyManagedException(org.craftercms.studio.api.v1.exception.security.UserExternallyManagedException) PasswordRequirementsFailedException(org.craftercms.studio.api.v2.exception.PasswordRequirementsFailedException) ServiceLayerException(org.craftercms.studio.api.v1.exception.ServiceLayerException)

Example 5 with USER_ID

use of org.craftercms.studio.api.v2.dal.QueryParameterNames.USER_ID in project studio by craftercms.

the class UserDetailsManagerImpl method loadUserByUsername.

@Override
public UserDetails loadUserByUsername(String username) throws ServiceLayerException {
    Map<String, Object> params = new HashMap<String, Object>();
    params.put(USER_ID, -1);
    params.put(USERNAME, username);
    try {
        User user = userDAO.getUserByIdOrUsername(params);
        return user;
    } catch (Exception e) {
        throw new ServiceLayerException("Unknown database error", e);
    }
}
Also used : User(org.craftercms.studio.api.v2.dal.User) HashMap(java.util.HashMap) ServiceLayerException(org.craftercms.studio.api.v1.exception.ServiceLayerException) ServiceLayerException(org.craftercms.studio.api.v1.exception.ServiceLayerException)

Aggregations

HashMap (java.util.HashMap)10 ServiceLayerException (org.craftercms.studio.api.v1.exception.ServiceLayerException)9 User (org.craftercms.studio.api.v2.dal.User)8 UserAlreadyExistsException (org.craftercms.studio.api.v1.exception.security.UserAlreadyExistsException)7 UserNotFoundException (org.craftercms.studio.api.v1.exception.security.UserNotFoundException)7 PasswordDoesNotMatchException (org.craftercms.studio.api.v1.exception.security.PasswordDoesNotMatchException)6 UserExternallyManagedException (org.craftercms.studio.api.v1.exception.security.UserExternallyManagedException)6 PasswordRequirementsFailedException (org.craftercms.studio.api.v2.exception.PasswordRequirementsFailedException)6 AuthenticationSystemException (org.craftercms.studio.api.v1.exception.security.AuthenticationSystemException)3 RetryingOperation (org.craftercms.studio.api.v2.annotation.RetryingOperation)3 UserDAO (org.craftercms.studio.api.v2.dal.UserDAO)3 ArrayList (java.util.ArrayList)2 SiteFeed (org.craftercms.studio.api.v1.dal.SiteFeed)2 BadCredentialsException (org.craftercms.studio.api.v1.exception.security.BadCredentialsException)2 SiteService (org.craftercms.studio.api.v1.service.site.SiteService)2 AuditLog (org.craftercms.studio.api.v2.dal.AuditLog)2 Group (org.craftercms.studio.api.v2.dal.Group)2 GroupDAO (org.craftercms.studio.api.v2.dal.GroupDAO)2 UserGroup (org.craftercms.studio.api.v2.dal.UserGroup)2 AuditServiceInternal (org.craftercms.studio.api.v2.service.audit.internal.AuditServiceInternal)2