Search in sources :

Example 81 with Context

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;
    });
}
Also used : Context(com.enonic.xp.context.Context)

Example 82 with Context

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;
}
Also used : Context(com.enonic.xp.context.Context) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) PrincipalKey(com.enonic.xp.security.PrincipalKey) AuthenticationInfo(com.enonic.xp.security.auth.AuthenticationInfo)

Example 83 with Context

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());
            }
        }
    });
}
Also used : Context(com.enonic.xp.context.Context) ContentService(com.enonic.xp.content.ContentService) User(com.enonic.xp.security.User) ContentConstants(com.enonic.xp.content.ContentConstants) ProjectService(com.enonic.xp.project.ProjectService) WorkflowInfo(com.enonic.xp.content.WorkflowInfo) ContentInheritType(com.enonic.xp.content.ContentInheritType) Set(java.util.Set) Content(com.enonic.xp.content.Content) AuthenticationInfo(com.enonic.xp.security.auth.AuthenticationInfo) Project(com.enonic.xp.project.Project) Collectors(java.util.stream.Collectors) UpdateContentParams(com.enonic.xp.content.UpdateContentParams) ContentId(com.enonic.xp.content.ContentId) Stream(java.util.stream.Stream) ResetContentInheritParams(com.enonic.xp.content.ResetContentInheritParams) PrincipalKey(com.enonic.xp.security.PrincipalKey) ContextAccessor(com.enonic.xp.context.ContextAccessor) ProjectName(com.enonic.xp.project.ProjectName) RoleKeys(com.enonic.xp.security.RoleKeys) Preconditions(com.google.common.base.Preconditions) Context(com.enonic.xp.context.Context) ContextBuilder(com.enonic.xp.context.ContextBuilder) EnumSet(java.util.EnumSet) ProjectName(com.enonic.xp.project.ProjectName) UpdateContentParams(com.enonic.xp.content.UpdateContentParams) Content(com.enonic.xp.content.Content) ContentInheritType(com.enonic.xp.content.ContentInheritType)

Example 84 with Context

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);
}
Also used : Context(com.enonic.xp.context.Context)

Example 85 with Context

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;
}
Also used : Site(com.enonic.xp.site.Site) Context(com.enonic.xp.context.Context) ProjectName(com.enonic.xp.project.ProjectName) SiteConfigs(com.enonic.xp.site.SiteConfigs) AuthenticationInfo(com.enonic.xp.security.auth.AuthenticationInfo)

Aggregations

Context (com.enonic.xp.context.Context)101 Test (org.junit.jupiter.api.Test)35 AuthenticationInfo (com.enonic.xp.security.auth.AuthenticationInfo)21 Node (com.enonic.xp.node.Node)16 InternalContext (com.enonic.xp.repo.impl.InternalContext)16 User (com.enonic.xp.security.User)13 Content (com.enonic.xp.content.Content)11 PropertyTree (com.enonic.xp.data.PropertyTree)11 PrincipalKey (com.enonic.xp.security.PrincipalKey)10 Branch (com.enonic.xp.branch.Branch)9 AbstractNodeTest (com.enonic.xp.repo.impl.node.AbstractNodeTest)9 ContextAccessor (com.enonic.xp.context.ContextAccessor)8 NodePath (com.enonic.xp.node.NodePath)8 ContextBuilder (com.enonic.xp.context.ContextBuilder)7 ContentId (com.enonic.xp.content.ContentId)6 CreateNodeParams (com.enonic.xp.node.CreateNodeParams)6 Repository (com.enonic.xp.repository.Repository)6 LogAuditLogParams (com.enonic.xp.audit.LogAuditLogParams)5 ProcessUpdateParams (com.enonic.xp.content.processor.ProcessUpdateParams)5 NodeComparison (com.enonic.xp.node.NodeComparison)5