Search in sources :

Example 1 with AuthenticatedUser

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;
}
Also used : ResultOne(org.craftercms.studio.model.rest.ResultOne) AuthenticatedUser(org.craftercms.studio.model.AuthenticatedUser) ResponseBody(org.craftercms.studio.model.rest.ResponseBody) GetMapping(org.springframework.web.bind.annotation.GetMapping)

Example 2 with AuthenticatedUser

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;
}
Also used : ArrayList(java.util.ArrayList) AuthenticatedUser(org.craftercms.studio.model.AuthenticatedUser) HasPermission(org.craftercms.commons.security.permissions.annotations.HasPermission)

Example 3 with AuthenticatedUser

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;
}
Also used : ArrayList(java.util.ArrayList) AuthenticatedUser(org.craftercms.studio.model.AuthenticatedUser) HasPermission(org.craftercms.commons.security.permissions.annotations.HasPermission)

Example 4 with AuthenticatedUser

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");
    }
}
Also used : UserNotFoundException(org.craftercms.studio.api.v1.exception.security.UserNotFoundException) User(org.craftercms.studio.api.v2.dal.User) AuthenticatedUser(org.craftercms.studio.model.AuthenticatedUser) AuthenticationException(org.craftercms.studio.api.v1.exception.security.AuthenticationException) ServiceLayerException(org.craftercms.studio.api.v1.exception.ServiceLayerException) AuthenticatedUser(org.craftercms.studio.model.AuthenticatedUser)

Aggregations

AuthenticatedUser (org.craftercms.studio.model.AuthenticatedUser)4 ArrayList (java.util.ArrayList)2 HasPermission (org.craftercms.commons.security.permissions.annotations.HasPermission)2 ServiceLayerException (org.craftercms.studio.api.v1.exception.ServiceLayerException)1 AuthenticationException (org.craftercms.studio.api.v1.exception.security.AuthenticationException)1 UserNotFoundException (org.craftercms.studio.api.v1.exception.security.UserNotFoundException)1 User (org.craftercms.studio.api.v2.dal.User)1 ResponseBody (org.craftercms.studio.model.rest.ResponseBody)1 ResultOne (org.craftercms.studio.model.rest.ResultOne)1 GetMapping (org.springframework.web.bind.annotation.GetMapping)1