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;
}
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;
}
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);
}
}
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;
}
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);
}
}
Aggregations