use of com.enonic.xp.context.Context in project xp by enonic.
the class ContextFilter method doHandle.
@Override
protected void doHandle(final HttpServletRequest req, final HttpServletResponse res, final FilterChain chain) throws Exception {
final Context context = ContextBuilder.create().build();
context.getLocalScope().setAttribute(ContentConstants.BRANCH_DRAFT);
context.getLocalScope().setAttribute(ContentConstants.CONTENT_REPO_ID);
context.getLocalScope().setAttribute("__currentTimeMillis", System.currentTimeMillis());
context.getLocalScope().setSession(new SessionWrapper(req));
context.callWith(() -> {
chain.doFilter(req, res);
return null;
});
}
use of com.enonic.xp.context.Context in project xp by enonic.
the class StatusResource method createContextJson.
private ObjectNode createContextJson() {
final Context context = ContextAccessor.current();
final AuthenticationInfo authInfo = context.getAuthInfo();
final ObjectNode node = JsonNodeFactory.instance.objectNode();
node.put("authenticated", (authInfo != null) && authInfo.isAuthenticated());
final ArrayNode principals = node.putArray("principals");
if (authInfo != null) {
for (final PrincipalKey principal : authInfo.getPrincipals()) {
principals.add(principal.toString());
}
}
return node;
}
use of com.enonic.xp.context.Context in project xp by enonic.
the class ResetContentInheritanceCommand method execute.
void execute() {
final ProjectName sourceProjectName = fetchSourceProjectName(params.getProjectName());
validateSourceContentExist(sourceProjectName);
final Context targetContext = ContextBuilder.from(ContextAccessor.current()).repositoryId(params.getProjectName().getRepoId()).branch(ContentConstants.BRANCH_DRAFT).authInfo(createAdminAuthInfo()).build();
targetContext.runWith(() -> {
if (contentService.contentExists(params.getContentId())) {
final Content targetContent = contentService.getById(params.getContentId());
final Set<ContentInheritType> typesToReset = params.getInherit().stream().filter(contentInheritType -> !targetContent.getInherit().contains(contentInheritType)).collect(Collectors.toSet());
if (!typesToReset.isEmpty()) {
final UpdateContentParams updateParams = new UpdateContentParams().contentId(targetContent.getId()).modifier(targetContent.getModifier()).stopInherit(false).editor(edit -> {
edit.inherit = processInherit(edit.inherit, typesToReset);
edit.workflowInfo = WorkflowInfo.inProgress();
});
contentService.update(updateParams);
syncContent(targetContent.getId(), sourceProjectName, params.getProjectName());
}
}
});
}
use of com.enonic.xp.context.Context in project xp by enonic.
the class UnpublishContentCommand method execute.
public UnpublishContentsResult execute() {
final Context context = ContextAccessor.current();
final Context unpublishContext = ContextBuilder.from(context).branch(params.getUnpublishBranch()).build();
return unpublishContext.callWith(this::unpublish);
}
use of com.enonic.xp.context.Context in project xp by enonic.
the class ProjectAccessSiteProcessor method processUpdate.
@Override
public ProcessUpdateResult processUpdate(final ProcessUpdateParams params) {
final Site editedSite = (Site) params.getEditedContent();
final SiteConfigs editedSiteConfigs = editedSite.getSiteConfigs();
final Site originalSite = (Site) params.getOriginalContent();
final SiteConfigs originalSiteConfigs = originalSite.getSiteConfigs();
final Context context = ContextAccessor.current();
final AuthenticationInfo authenticationInfo = context.getAuthInfo();
final ProjectName projectName = ProjectName.from(context.getRepositoryId());
if (!Objects.equals(originalSiteConfigs, editedSiteConfigs)) {
if (!ProjectAccessHelper.hasAdminAccess(authenticationInfo)) {
if (ProjectConstants.DEFAULT_PROJECT_NAME.equals(projectName)) {
throw new ProjectAccessRequiredException(authenticationInfo.getUser().getKey());
} else if (!this.projectPermissionsContextManager.hasAnyProjectRole(authenticationInfo, projectName, Set.of(ProjectRole.OWNER))) {
throw new ProjectAccessRequiredException(authenticationInfo.getUser().getKey(), ProjectRole.OWNER);
}
}
}
return null;
}
Aggregations