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