Search in sources :

Example 6 with ServiceLayerException

use of org.craftercms.studio.api.v1.exception.ServiceLayerException in project studio by craftercms.

the class UserServiceImpl method createUser.

@Override
@HasPermission(type = DefaultPermission.class, action = "create_users")
public User createUser(User user) throws UserAlreadyExistsException, ServiceLayerException, AuthenticationException {
    try {
        entitlementValidator.validateEntitlement(EntitlementType.USER, 1);
    } catch (EntitlementException e) {
        throw new ServiceLayerException("Unable to complete request due to entitlement limits. Please contact " + "your system administrator.", e);
    }
    User toRet = userServiceInternal.createUser(user);
    SiteFeed siteFeed = siteService.getSite(studioConfiguration.getProperty(CONFIGURATION_GLOBAL_SYSTEM_SITE));
    AuditLog auditLog = auditServiceInternal.createAuditLogEntry();
    auditLog.setOperation(OPERATION_CREATE);
    auditLog.setSiteId(siteFeed.getId());
    auditLog.setActorId(getCurrentUser().getUsername());
    auditLog.setPrimaryTargetId(user.getUsername());
    auditLog.setPrimaryTargetType(TARGET_TYPE_USER);
    auditLog.setPrimaryTargetValue(user.getUsername());
    auditServiceInternal.insertAuditLog(auditLog);
    return toRet;
}
Also used : EntitlementException(org.craftercms.commons.entitlements.exception.EntitlementException) User(org.craftercms.studio.api.v2.dal.User) AuthenticatedUser(org.craftercms.studio.model.AuthenticatedUser) SiteFeed(org.craftercms.studio.api.v1.dal.SiteFeed) ServiceLayerException(org.craftercms.studio.api.v1.exception.ServiceLayerException) AuditLog(org.craftercms.studio.api.v2.dal.AuditLog) HasPermission(org.craftercms.commons.security.permissions.annotations.HasPermission)

Example 7 with ServiceLayerException

use of org.craftercms.studio.api.v1.exception.ServiceLayerException in project studio by craftercms.

the class UserServiceImpl method forgotPassword.

@Override
public boolean forgotPassword(String username) throws ServiceLayerException, UserNotFoundException, UserExternallyManagedException {
    logger.debug("Getting user profile for " + username);
    User user = userServiceInternal.getUserByIdOrUsername(-1, username);
    boolean success = false;
    if (user == null) {
        logger.info("User profile not found for " + username);
        throw new UserNotFoundException();
    } else {
        if (user.isExternallyManaged()) {
            throw new UserExternallyManagedException();
        } else {
            if (user.getEmail() != null) {
                String email = user.getEmail();
                logger.debug("Creating security token for forgot password");
                ZonedDateTime now = ZonedDateTime.now();
                ZonedDateTime ttl = now.plusMinutes(Long.parseLong(studioConfiguration.getProperty(SECURITY_FORGOT_PASSWORD_TOKEN_TIMEOUT)));
                long timestamp = ttl.toInstant().toEpochMilli();
                String studioId = instanceService.getInstanceId();
                String token = username + "|" + studioId + "|" + timestamp;
                String hashedToken = encryptToken(token);
                logger.debug("Sending forgot password email to " + email);
                sendForgotPasswordEmail(email, hashedToken);
                success = true;
            } else {
                logger.info("User " + username + " does not have assigned email with account");
                throw new ServiceLayerException("User " + username + " does not have assigned email with account");
            }
        }
    }
    return success;
}
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) AuthenticatedUser(org.craftercms.studio.model.AuthenticatedUser) ZonedDateTime(java.time.ZonedDateTime) ServiceLayerException(org.craftercms.studio.api.v1.exception.ServiceLayerException)

Example 8 with ServiceLayerException

use of org.craftercms.studio.api.v1.exception.ServiceLayerException in project studio by craftercms.

the class GroupServiceInternalImpl method deleteGroup.

@RetryingOperation
@Override
public void deleteGroup(List<Long> groupIds) throws GroupNotFoundException, ServiceLayerException {
    for (Long groupId : groupIds) {
        if (!groupExists(groupId, StringUtils.EMPTY)) {
            throw new GroupNotFoundException("No group found for id '" + groupId + "'");
        }
    }
    Map<String, Object> params = new HashMap<>();
    params.put(GROUP_IDS, groupIds);
    try {
        groupDao.deleteGroups(params);
    } catch (Exception e) {
        throw new ServiceLayerException("Unknown database error", e);
    }
}
Also used : HashMap(java.util.HashMap) ServiceLayerException(org.craftercms.studio.api.v1.exception.ServiceLayerException) GroupNotFoundException(org.craftercms.studio.api.v1.exception.security.GroupNotFoundException) GroupAlreadyExistsException(org.craftercms.studio.api.v1.exception.security.GroupAlreadyExistsException) UserNotFoundException(org.craftercms.studio.api.v1.exception.security.UserNotFoundException) GroupNotFoundException(org.craftercms.studio.api.v1.exception.security.GroupNotFoundException) ConfigurationException(org.craftercms.studio.api.v2.exception.configuration.ConfigurationException) ServiceLayerException(org.craftercms.studio.api.v1.exception.ServiceLayerException) RetryingOperation(org.craftercms.studio.api.v2.annotation.RetryingOperation)

Example 9 with ServiceLayerException

use of org.craftercms.studio.api.v1.exception.ServiceLayerException in project studio by craftercms.

the class GroupServiceInternalImpl method getSiteGroups.

@Override
public List<String> getSiteGroups(String siteId) throws ServiceLayerException {
    Map<String, List<String>> groupRoleMapping;
    try {
        groupRoleMapping = configurationService.geRoleMappings(siteId);
    } catch (ConfigurationException e) {
        throw new ServiceLayerException("Unable to get role mappings config for site '" + siteId + "'", e);
    }
    List<String> groups = new ArrayList<>();
    groups.addAll(groupRoleMapping.keySet());
    return groups;
}
Also used : ConfigurationException(org.craftercms.studio.api.v2.exception.configuration.ConfigurationException) ArrayList(java.util.ArrayList) ServiceLayerException(org.craftercms.studio.api.v1.exception.ServiceLayerException) ArrayList(java.util.ArrayList) List(java.util.List)

Example 10 with ServiceLayerException

use of org.craftercms.studio.api.v1.exception.ServiceLayerException in project studio by craftercms.

the class GroupServiceInternalImpl method createGroup.

@Override
public Group createGroup(long orgId, String groupName, String groupDescription) throws GroupAlreadyExistsException, ServiceLayerException {
    if (groupExists(-1, groupName)) {
        throw new GroupAlreadyExistsException("Group '" + groupName + "' already exists");
    }
    Map<String, Object> params = new HashMap<>();
    params.put(ORG_ID, orgId);
    params.put(GROUP_NAME, groupName);
    params.put(GROUP_DESCRIPTION, groupDescription);
    try {
        groupDao.createGroup(params);
        Group group = new Group();
        group.setId((Long) params.get(ID));
        group.setGroupName(groupName);
        group.setGroupDescription(groupDescription);
        return group;
    } catch (Exception e) {
        throw new ServiceLayerException("Unknown database error", e);
    }
}
Also used : Group(org.craftercms.studio.api.v2.dal.Group) HashMap(java.util.HashMap) GroupAlreadyExistsException(org.craftercms.studio.api.v1.exception.security.GroupAlreadyExistsException) ServiceLayerException(org.craftercms.studio.api.v1.exception.ServiceLayerException) GroupAlreadyExistsException(org.craftercms.studio.api.v1.exception.security.GroupAlreadyExistsException) UserNotFoundException(org.craftercms.studio.api.v1.exception.security.UserNotFoundException) GroupNotFoundException(org.craftercms.studio.api.v1.exception.security.GroupNotFoundException) ConfigurationException(org.craftercms.studio.api.v2.exception.configuration.ConfigurationException) ServiceLayerException(org.craftercms.studio.api.v1.exception.ServiceLayerException)

Aggregations

ServiceLayerException (org.craftercms.studio.api.v1.exception.ServiceLayerException)124 UserNotFoundException (org.craftercms.studio.api.v1.exception.security.UserNotFoundException)62 HashMap (java.util.HashMap)55 ArrayList (java.util.ArrayList)45 IOException (java.io.IOException)39 User (org.craftercms.studio.api.v2.dal.User)36 Repository (org.eclipse.jgit.lib.Repository)35 Git (org.eclipse.jgit.api.Git)33 GitAPIException (org.eclipse.jgit.api.errors.GitAPIException)33 ContentRepository (org.craftercms.studio.api.v1.repository.ContentRepository)32 RemoteRepository (org.craftercms.studio.api.v2.dal.RemoteRepository)30 SiteFeed (org.craftercms.studio.api.v1.dal.SiteFeed)29 SiteNotFoundException (org.craftercms.studio.api.v1.exception.SiteNotFoundException)29 CryptoException (org.craftercms.commons.crypto.CryptoException)28 ValidateParams (org.craftercms.commons.validation.annotations.param.ValidateParams)27 GitRepositoryHelper (org.craftercms.studio.api.v2.utils.GitRepositoryHelper)24 ContentItemTO (org.craftercms.studio.api.v1.to.ContentItemTO)23 Path (java.nio.file.Path)21 InvalidRemoteUrlException (org.craftercms.studio.api.v1.exception.repository.InvalidRemoteUrlException)21 AuditLog (org.craftercms.studio.api.v2.dal.AuditLog)20