use of com.agiletec.aps.system.services.user.UserDetails in project entando-core by entando.
the class ProtectedResourceProvider method provideProtectedResource.
@Override
public boolean provideProtectedResource(HttpServletRequest request, HttpServletResponse response) throws ApsSystemException {
try {
String[] uriSegments = request.getRequestURI().split("/");
int segments = uriSegments.length;
// CONTROLLO ASSOCIAZIONE RISORSA A CONTENUTO
int indexGuardian = 0;
String checkContentAssociation = uriSegments[segments - 2];
if (checkContentAssociation.equals(AbstractResourceAttribute.REFERENCED_RESOURCE_INDICATOR)) {
// LA Sintassi /<RES_ID>/<SIZE>/<LANG_CODE>/<REFERENCED_RESOURCE_INDICATOR>/<CONTENT_ID>
indexGuardian = 2;
}
String resId = uriSegments[segments - 3 - indexGuardian];
UserDetails currentUser = (UserDetails) request.getSession().getAttribute(SystemConstants.SESSIONPARAM_CURRENT_USER);
if (currentUser == null) {
currentUser = this.getUserManager().getGuestUser();
}
boolean isAuthForProtectedRes = false;
if (indexGuardian != 0) {
if (this.isAuthOnProtectedRes(currentUser, resId, uriSegments[segments - 1])) {
isAuthForProtectedRes = true;
} else {
this.executeLoginRedirect(request, response);
return true;
}
}
ResourceInterface resource = this.getResourceManager().loadResource(resId);
if (resource == null) {
return false;
}
IAuthorizationManager authManager = this.getAuthorizationManager();
if (isAuthForProtectedRes || authManager.isAuthOnGroup(currentUser, resource.getMainGroup()) || authManager.isAuthOnGroup(currentUser, Group.ADMINS_GROUP_NAME)) {
ResourceInstance instance = null;
if (resource.isMultiInstance()) {
String sizeStr = uriSegments[segments - 2 - indexGuardian];
if (!this.isValidNumericString(sizeStr)) {
return false;
}
int size = Integer.parseInt(sizeStr);
String langCode = uriSegments[segments - 1 - indexGuardian];
instance = ((AbstractMultiInstanceResource) resource).getInstance(size, langCode);
} else {
instance = ((AbstractMonoInstanceResource) resource).getInstance();
}
this.createResponse(response, resource, instance);
return true;
}
} catch (Throwable t) {
_logger.error("Error extracting protected resource", t);
throw new ApsSystemException("Error extracting protected resource", t);
}
return false;
}
use of com.agiletec.aps.system.services.user.UserDetails in project entando-core by entando.
the class ApiContentInterface method addContent.
public StringApiResponse addContent(JAXBContent jaxbContent, Properties properties) throws Throwable {
StringApiResponse response = new StringApiResponse();
try {
String typeCode = jaxbContent.getTypeCode();
Content prototype = (Content) this.getContentManager().getEntityPrototype(typeCode);
if (null == prototype) {
throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "Content type with code '" + typeCode + "' does not exist", Response.Status.CONFLICT);
}
Content content = (Content) jaxbContent.buildEntity(prototype, this.getCategoryManager());
if (null != content.getId()) {
throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "You cannot specify Content Id", Response.Status.CONFLICT);
}
UserDetails user = (UserDetails) properties.get(SystemConstants.API_USER_PARAMETER);
content.setFirstEditor((null != user) ? user.getUsername() : SystemConstants.GUEST_USER_NAME);
response = this.validateAndSaveContent(content, properties);
} catch (ApiException ae) {
response.addErrors(ae.getErrors());
response.setResult(IResponseBuilder.FAILURE, null);
} catch (Throwable t) {
_logger.error("Error adding content", t);
throw new ApsSystemException("Error adding content", t);
}
return response;
}
use of com.agiletec.aps.system.services.user.UserDetails in project entando-core by entando.
the class ApiContentInterface method extractContents.
protected List<String> extractContents(Properties properties) throws Throwable {
List<String> contentsId = null;
try {
ApiContentListBean bean = this.buildSearchBean(properties);
UserDetails user = (UserDetails) properties.get(SystemConstants.API_USER_PARAMETER);
contentsId = this.getContentListHelper().getContentsId(bean, user);
} catch (ApiException ae) {
throw ae;
} catch (Throwable t) {
_logger.error("error in extractContents", t);
throw new ApsSystemException("Error into API method", t);
}
return contentsId;
}
use of com.agiletec.aps.system.services.user.UserDetails in project entando-core by entando.
the class ApiResourceInterface method addResource.
public StringApiResponse addResource(JAXBResource jaxbResource, Properties properties) throws ApiException, Throwable {
StringApiResponse response = new StringApiResponse();
BaseResourceDataBean bean = null;
try {
UserDetails user = (UserDetails) properties.get(SystemConstants.API_USER_PARAMETER);
this.check(jaxbResource, user, response, true);
if (null != response.getErrors() && !response.getErrors().isEmpty()) {
return response;
}
bean = jaxbResource.createBataBean(this.getCategoryManager());
String id = bean.getResourceId();
if (null != id && id.trim().length() > 0) {
Pattern pattern = Pattern.compile("^[a-zA-Z]+$");
Matcher matcher = pattern.matcher(id);
if (!matcher.matches()) {
throw new ApiException(IApiErrorCodes.API_PARAMETER_VALIDATION_ERROR, "The resourceId can contain only alphabetic characters", Response.Status.CONFLICT);
}
}
this.getResourceManager().addResource(bean);
response.setResult(IResponseBuilder.SUCCESS);
} catch (ApiException ae) {
throw ae;
} catch (Throwable t) {
_logger.error("error in addResource", t);
throw new ApsSystemException("Error into API method", t);
} finally {
if (null != bean && null != bean.getFile()) {
bean.getFile().delete();
}
}
return response;
}
use of com.agiletec.aps.system.services.user.UserDetails in project entando-core by entando.
the class ApiResourceInterface method updateResource.
public StringApiResponse updateResource(JAXBResource jaxbResource, Properties properties) throws Throwable {
StringApiResponse response = new StringApiResponse();
BaseResourceDataBean bean = null;
try {
UserDetails user = (UserDetails) properties.get(SystemConstants.API_USER_PARAMETER);
this.check(jaxbResource, user, response, false);
if (null != response.getErrors() && !response.getErrors().isEmpty()) {
return response;
}
bean = jaxbResource.createBataBean(this.getCategoryManager());
this.getResourceManager().updateResource(bean);
response.setResult(IResponseBuilder.SUCCESS);
} catch (Throwable t) {
_logger.error("error in updateResource", t);
throw new ApsSystemException("Error into API method", t);
} finally {
if (null != bean && null != bean.getFile()) {
bean.getFile().delete();
}
}
return response;
}
Aggregations