use of org.craftercms.studio.model.AuthenticatedUser in project studio by craftercms.
the class UsersController method getCurrentUser.
/**
* Get current authenticated user API
*
* @return Response containing current authenticated user
*/
@GetMapping(ME)
public ResponseBody getCurrentUser() throws AuthenticationException, ServiceLayerException {
AuthenticatedUser user = userService.getCurrentUser();
ResultOne<AuthenticatedUser> result = new ResultOne<>();
result.setResponse(OK);
result.setEntity(RESULT_KEY_CURRENT_USER, user);
ResponseBody responseBody = new ResponseBody();
responseBody.setResult(result);
return responseBody;
}
use of org.craftercms.studio.model.AuthenticatedUser in project studio by craftercms.
the class ContentServiceImpl method deleteContent.
@Override
@HasPermission(type = CompositePermission.class, action = ACTION_DELETE_CONTENT)
public boolean deleteContent(@ProtectedResourceId(SITE_ID_RESOURCE_ID) String siteId, @ProtectedResourceId(PATH_LIST_RESOURCE_ID) List<String> paths, String submissionComment) throws ServiceLayerException, AuthenticationException, DeploymentException {
List<String> contentToDelete = new ArrayList<String>();
contentToDelete.addAll(getChildItems(siteId, paths));
contentToDelete.addAll(paths);
objectStateService.setSystemProcessingBulk(siteId, contentToDelete, true);
AuthenticatedUser currentUser = userService.getCurrentUser();
deploymentService.delete(siteId, contentToDelete, currentUser.getUsername(), ZonedDateTime.now(ZoneOffset.UTC), submissionComment);
objectStateService.setSystemProcessingBulk(siteId, contentToDelete, false);
insertDeleteContentApprovedActivity(siteId, currentUser.getUsername(), contentToDelete);
return true;
}
use of org.craftercms.studio.model.AuthenticatedUser in project studio by craftercms.
the class ContentServiceImpl method deleteContent.
@Override
@HasPermission(type = DefaultPermission.class, action = ACTION_DELETE_CONTENT)
public boolean deleteContent(@ProtectedResourceId(SITE_ID_RESOURCE_ID) String siteId, @ProtectedResourceId(PATH_RESOURCE_ID) String path, String submissionComment) throws ServiceLayerException, AuthenticationException, DeploymentException {
List<String> contentToDelete = new ArrayList<String>();
contentToDelete.addAll(getChildItems(siteId, path));
contentToDelete.add(path);
objectStateService.setSystemProcessingBulk(siteId, contentToDelete, true);
AuthenticatedUser currentUser = userService.getCurrentUser();
deploymentService.delete(siteId, contentToDelete, currentUser.getUsername(), ZonedDateTime.now(ZoneOffset.UTC), submissionComment);
objectStateService.setSystemProcessingBulk(siteId, contentToDelete, false);
insertDeleteContentApprovedActivity(siteId, currentUser.getUsername(), contentToDelete);
return true;
}
use of org.craftercms.studio.model.AuthenticatedUser in project studio by craftercms.
the class UserServiceImpl method getCurrentUser.
@Override
public AuthenticatedUser getCurrentUser() throws AuthenticationException, ServiceLayerException {
Authentication authentication = securityService.getAuthentication();
if (authentication != null) {
String username = authentication.getUsername();
User user;
try {
user = userServiceInternal.getUserByIdOrUsername(0, username);
} catch (UserNotFoundException e) {
throw new ServiceLayerException("Current authenticated user '" + username + "' wasn't found in repository", e);
}
if (user != null) {
AuthenticatedUser authUser = new AuthenticatedUser(user);
authUser.setAuthenticationType(authentication.getAuthenticationType());
return authUser;
} else {
throw new ServiceLayerException("Current authenticated user '" + username + "' wasn't found in repository");
}
} else {
throw new AuthenticationException("User should be authenticated");
}
}
Aggregations