Search in sources :

Example 16 with UserDetails

use of com.agiletec.aps.system.services.user.UserDetails in project entando-core by entando.

the class UserService method getUsers.

@Override
public PagedMetadata<UserDto> getUsers(RestListRequest requestList) {
    try {
        // transforms the filters by overriding the key specified in the request with the correct one known by the dto
        List<FieldSearchFilter> filters = new ArrayList<FieldSearchFilter>(requestList.buildFieldSearchFilters());
        filters.stream().filter(i -> ((i.getKey() != null) && (UserDto.getEntityFieldName(i.getKey()) != null))).forEach(i -> i.setKey(UserDto.getEntityFieldName(i.getKey())));
        List<UserDetails> users = null;
        if (filters.size() > 0) {
            String text = (String) filters.get(0).getValue();
            users = this.getUserManager().searchUsers(text);
        } else {
            users = this.getUserManager().getUsers();
        }
        List<UserDto> dtoList = dtoBuilder.convert(users);
        SearcherDaoPaginatedResult<UserDetails> result = new SearcherDaoPaginatedResult<>(users.size(), users);
        PagedMetadata<UserDto> pagedMetadata = new PagedMetadata<>(requestList, result);
        pagedMetadata.setBody(dtoList);
        return pagedMetadata;
    } catch (Throwable t) {
        logger.error("error in search groups", t);
        throw new RestServerError("error in search groups", t);
    }
}
Also used : UserDetails(com.agiletec.aps.system.services.user.UserDetails) IAuthenticationProviderManager(com.agiletec.aps.system.services.user.IAuthenticationProviderManager) UserAuthoritiesRequest(org.entando.entando.web.user.model.UserAuthoritiesRequest) Logger(org.slf4j.Logger) ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException) UserDto(org.entando.entando.aps.system.services.user.model.UserDto) LoggerFactory(org.slf4j.LoggerFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) RestRourceNotFoundException(org.entando.entando.aps.system.exception.RestRourceNotFoundException) UserAuthorityDto(org.entando.entando.aps.system.services.user.model.UserAuthorityDto) UserRequest(org.entando.entando.web.user.model.UserRequest) UserPasswordRequest(org.entando.entando.web.user.model.UserPasswordRequest) ArrayList(java.util.ArrayList) FieldSearchFilter(com.agiletec.aps.system.common.FieldSearchFilter) List(java.util.List) User(com.agiletec.aps.system.services.user.User) RestListRequest(org.entando.entando.web.common.model.RestListRequest) RestServerError(org.entando.entando.aps.system.exception.RestServerError) SearcherDaoPaginatedResult(com.agiletec.aps.system.common.model.dao.SearcherDaoPaginatedResult) IUserManager(com.agiletec.aps.system.services.user.IUserManager) PagedMetadata(org.entando.entando.web.common.model.PagedMetadata) IAuthorizationManager(com.agiletec.aps.system.services.authorization.IAuthorizationManager) IDtoBuilder(org.entando.entando.aps.system.services.IDtoBuilder) PagedMetadata(org.entando.entando.web.common.model.PagedMetadata) UserDto(org.entando.entando.aps.system.services.user.model.UserDto) ArrayList(java.util.ArrayList) SearcherDaoPaginatedResult(com.agiletec.aps.system.common.model.dao.SearcherDaoPaginatedResult) UserDetails(com.agiletec.aps.system.services.user.UserDetails) RestServerError(org.entando.entando.aps.system.exception.RestServerError) FieldSearchFilter(com.agiletec.aps.system.common.FieldSearchFilter)

Example 17 with UserDetails

use of com.agiletec.aps.system.services.user.UserDetails in project entando-core by entando.

the class UserProfileManager method addProfile.

@AfterReturning(pointcut = "execution(* com.agiletec.aps.system.services.user.IUserManager.addUser(..)) && args(user,..)")
public void addProfile(Object user) {
    if (user != null) {
        UserDetails userDetails = (UserDetails) user;
        Object profile = userDetails.getProfile();
        if (null != profile) {
            try {
                this.addProfile(userDetails.getUsername(), (IUserProfile) profile);
            } catch (Throwable t) {
                logger.error("Error adding profile on user {}", userDetails.getUsername(), t);
            }
        }
    }
}
Also used : UserDetails(com.agiletec.aps.system.services.user.UserDetails) AfterReturning(org.aspectj.lang.annotation.AfterReturning)

Example 18 with UserDetails

use of com.agiletec.aps.system.services.user.UserDetails in project entando-core by entando.

the class ApiDataObjectInterface method addDataObject.

public StringApiResponse addDataObject(JAXBDataObject jaxbDataObject, Properties properties) throws Throwable {
    StringApiResponse response = new StringApiResponse();
    try {
        String typeCode = jaxbDataObject.getTypeCode();
        DataObject prototype = (DataObject) this.getDataObjectManager().getEntityPrototype(typeCode);
        if (null == prototype) {
            throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "DataObject type with code '" + typeCode + "' does not exist", Response.Status.CONFLICT);
        }
        DataObject dataObject = (DataObject) jaxbDataObject.buildEntity(prototype, this.getCategoryManager());
        if (null != dataObject.getId()) {
            throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "You cannot specify DataObject Id", Response.Status.CONFLICT);
        }
        UserDetails user = (UserDetails) properties.get(SystemConstants.API_USER_PARAMETER);
        dataObject.setFirstEditor((null != user) ? user.getUsername() : SystemConstants.GUEST_USER_NAME);
        response = this.validateAndSaveDataObject(dataObject, properties);
    } catch (ApiException ae) {
        response.addErrors(ae.getErrors());
        response.setResult(IResponseBuilder.FAILURE, null);
    } catch (Throwable t) {
        _logger.error("Error adding DataObject", t);
        throw new ApsSystemException("Error adding DataObject", t);
    }
    return response;
}
Also used : JAXBDataObject(org.entando.entando.aps.system.services.dataobject.api.model.JAXBDataObject) DataObject(org.entando.entando.aps.system.services.dataobject.model.DataObject) UserDetails(com.agiletec.aps.system.services.user.UserDetails) ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException) StringApiResponse(org.entando.entando.aps.system.services.api.model.StringApiResponse) ApiException(org.entando.entando.aps.system.services.api.model.ApiException)

Example 19 with UserDetails

use of com.agiletec.aps.system.services.user.UserDetails in project entando-core by entando.

the class ApiDataObjectInterface method getDataObject.

public JAXBDataObject getDataObject(Properties properties) throws ApiException, Throwable {
    JAXBDataObject jaxbDataObject = null;
    String id = properties.getProperty("id");
    try {
        String langCode = properties.getProperty(SystemConstants.API_LANG_CODE_PARAMETER);
        DataObject mainDataObject = this.getPublicDataObject(id);
        jaxbDataObject = this.getJAXBDataObjectInstance(mainDataObject, langCode);
        UserDetails user = (UserDetails) properties.get(SystemConstants.API_USER_PARAMETER);
        if (null == user) {
            user = this.getUserManager().getGuestUser();
        }
        if (!this.getDataObjectAuthorizationHelper().isAuth(user, mainDataObject)) {
            throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "Required DataObject '" + id + "' does not allowed", Response.Status.FORBIDDEN);
        }
    } catch (ApiException ae) {
        throw ae;
    } catch (Throwable t) {
        _logger.error("error in getDataObject", t);
        throw new ApsSystemException("Error into API method", t);
    }
    return jaxbDataObject;
}
Also used : JAXBDataObject(org.entando.entando.aps.system.services.dataobject.api.model.JAXBDataObject) DataObject(org.entando.entando.aps.system.services.dataobject.model.DataObject) UserDetails(com.agiletec.aps.system.services.user.UserDetails) JAXBDataObject(org.entando.entando.aps.system.services.dataobject.api.model.JAXBDataObject) ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException) ApiException(org.entando.entando.aps.system.services.api.model.ApiException)

Example 20 with UserDetails

use of com.agiletec.aps.system.services.user.UserDetails in project entando-core by entando.

the class BaseDataObjectDispenser method getRenderizationInfo.

protected DataObjectRenderizationInfo getRenderizationInfo(PublicDataTypeAuthorizationInfo authInfo, String dataObjectId, long modelId, String langCode, RequestContext reqCtx, boolean cacheable) {
    DataObjectRenderizationInfo renderInfo = null;
    try {
        UserDetails currentUser = (null != reqCtx) ? (UserDetails) reqCtx.getRequest().getSession().getAttribute(SystemConstants.SESSIONPARAM_CURRENT_USER) : null;
        List<Group> userGroups = (null != currentUser) ? this.getAuthorizationManager().getUserGroups(currentUser) : new ArrayList<Group>();
        if (authInfo.isUserAllowed(userGroups)) {
            renderInfo = this.getBaseRenderizationInfo(authInfo, dataObjectId, modelId, langCode, currentUser, reqCtx, cacheable);
            if (null == renderInfo) {
                return null;
            }
        } else {
            String renderedDataObject = "Current user '" + currentUser.getUsername() + "' can't view this DataObject";
            DataObject dataObjectToRender = this.getDataObjectManager().loadDataObject(dataObjectId, true, cacheable);
            renderInfo = new DataObjectRenderizationInfo(dataObjectToRender, renderedDataObject, modelId, langCode, null);
            renderInfo.setRenderedDataobject(renderedDataObject);
            return renderInfo;
        }
    } catch (Throwable t) {
        _logger.error("Error while rendering dataObject {}", dataObjectId, t);
        return null;
    }
    return renderInfo;
}
Also used : Group(com.agiletec.aps.system.services.group.Group) UserDetails(com.agiletec.aps.system.services.user.UserDetails) DataObject(org.entando.entando.aps.system.services.dataobject.model.DataObject)

Aggregations

UserDetails (com.agiletec.aps.system.services.user.UserDetails)271 Test (org.junit.Test)150 ResultActions (org.springframework.test.web.servlet.ResultActions)142 AbstractControllerIntegrationTest (org.entando.entando.web.AbstractControllerIntegrationTest)77 AbstractControllerTest (org.entando.entando.web.AbstractControllerTest)71 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)25 ApsSystemException (com.agiletec.aps.system.exception.ApsSystemException)22 Group (com.agiletec.aps.system.services.group.Group)15 ArrayList (java.util.ArrayList)15 IAuthorizationManager (com.agiletec.aps.system.services.authorization.IAuthorizationManager)14 ApiException (org.entando.entando.aps.system.services.api.model.ApiException)13 Content (com.agiletec.plugins.jacms.aps.system.services.content.model.Content)12 HttpSession (javax.servlet.http.HttpSession)12 RestListRequest (org.entando.entando.web.common.model.RestListRequest)12 HashMap (java.util.HashMap)9 StringApiResponse (org.entando.entando.aps.system.services.api.model.StringApiResponse)9 DataObject (org.entando.entando.aps.system.services.dataobject.model.DataObject)9 IPage (com.agiletec.aps.system.services.page.IPage)8 JspException (javax.servlet.jsp.JspException)8 Page (com.agiletec.aps.system.services.page.Page)7