private Content createPage(final String id, final String name, final String contentTypeName) {
    PropertyTree rootDataSet = new PropertyTree();
    rootDataSet.addString("property1", "value1");

    Region region =
        Region.create()
            .name("myRegion")
            .add(
                PartComponent.create()
                    .name("myPartComponent")
                    .descriptor(DescriptorKey.from("myapplication:myparttemplate"))
                    .build())
            .build();

    PageRegions pageRegions = PageRegions.create().add(region).build();
    Page page =
        Page.create().template(PageTemplateKey.from("my-page")).regions(pageRegions).build();

    return Content.create()
        .id(ContentId.from(id))
        .path(ContentPath.from(name))
        .owner(PrincipalKey.from("user:myStore:me"))
        .displayName("My Content")
        .modifier(PrincipalKey.from("user:system:admin"))
        .type(ContentTypeName.from(contentTypeName))
        .page(page)
        .build();
  }
Exemple #2
0
  @Test
  public void getContentShortcut() throws Exception {
    final PropertyTree rootDataSet = new PropertyTree();
    rootDataSet.addReference("target", Reference.from("ref"));

    final Content content =
        Content.create()
            .id(ContentId.from("id"))
            .path(ContentPath.from("site/somepath/shortcut"))
            .owner(PrincipalKey.from("user:myStore:me"))
            .displayName("My Content")
            .modifier(PrincipalKey.from("user:system:admin"))
            .type(ContentTypeName.shortcut())
            .data(rootDataSet)
            .build();

    Mockito.when(this.contentService.getByPath(content.getPath().asAbsolute())).thenReturn(content);
    Mockito.when(this.portalUrlService.pageUrl(Mockito.any(PageUrlParams.class)))
        .thenReturn("/master/site/otherpath");

    this.request.setContentPath(ContentPath.from("/site/somepath/shortcut"));

    final PortalResponse res = this.handler.handle(this.request);
    assertNotNull(res);
    assertEquals(HttpStatus.TEMPORARY_REDIRECT, res.getStatus());
    assertEquals("/master/site/otherpath", res.getHeaders().get("Location"));
  }
Exemple #3
0
  private Content createPage(
      final String id, final String path, final String contentTypeName, final boolean withPage) {
    PropertyTree rootDataSet = new PropertyTree();
    rootDataSet.addString("property1", "value1");

    final Content.Builder content =
        Content.create()
            .id(ContentId.from(id))
            .path(ContentPath.from(path))
            .owner(PrincipalKey.from("user:myStore:me"))
            .displayName("My Content")
            .modifier(PrincipalKey.from("user:system:admin"))
            .type(ContentTypeName.from(contentTypeName));

    if (withPage) {
      PageRegions pageRegions =
          PageRegions.create()
              .add(
                  Region.create()
                      .name("main-region")
                      .add(PartComponent.create().name(ComponentName.from("mypart")).build())
                      .build())
              .build();

      Page page =
          Page.create()
              .template(PageTemplateKey.from("my-page"))
              .regions(pageRegions)
              .config(rootDataSet)
              .build();
      content.page(page);
    }
    return content.build();
  }
 private void findPrincipals(
     final Map<PrincipalKey, Principal> principals, final AccessControlList acl) {
   for (AccessControlEntry entry : acl) {
     final PrincipalKey key = entry.getPrincipal();
     if (!principals.containsKey(key)) {
       final Optional<? extends Principal> principalValue = securityService.getPrincipal(key);
       if (!principalValue.isPresent()) {
         LOG.warn("Principal could not be resolved: " + key.toString());
       } else {
         principals.put(key, principalValue.get());
       }
     }
   }
 }
  private Site createSite(final String id, final String name, final String contentTypeName) {
    PropertyTree rootDataSet = new PropertyTree();
    rootDataSet.addString("property1", "value1");

    Page page = Page.create().template(PageTemplateKey.from("my-page")).config(rootDataSet).build();

    return Site.create()
        .id(ContentId.from(id))
        .path(ContentPath.from(name))
        .owner(PrincipalKey.from("user:myStore:me"))
        .displayName("My Content")
        .modifier(PrincipalKey.from("user:system:admin"))
        .type(ContentTypeName.from(contentTypeName))
        .page(page)
        .build();
  }
Exemple #6
0
  protected Node createNode(final NodePath parentPath, final String name) {
    final PropertyTree data = new PropertyTree();
    data.setString("displayName", "This is brand new node");
    final PropertySet someData = data.addSet("someData");
    someData.setString("cars", "skoda");
    someData.addString("cars", "tesla model x");
    someData.setString("likes", "plywood");
    someData.setLong("numberOfUselessGadgets", 123L);

    final PatternIndexConfigDocument indexConfig =
        PatternIndexConfigDocument.create()
            .defaultConfig(IndexConfig.MINIMAL)
            .add("displayName", IndexConfig.FULLTEXT)
            .build();

    return Node.create()
        .id(NodeId.from("nodeId"))
        .parentPath(parentPath)
        .name(name)
        .data(data)
        .indexConfigDocument(indexConfig)
        .permissions(
            AccessControlList.create()
                .add(
                    AccessControlEntry.create()
                        .principal(PrincipalKey.ofRole("admin"))
                        .allowAll()
                        .build())
                .build())
        .nodeState(NodeState.DEFAULT)
        .nodeVersionId(NodeVersionId.from("versionKey"))
        .timestamp(Instant.parse("2010-10-10T10:10:10.10Z"))
        .build();
  }
  public static Filter create(final PrincipalKeys principalsKeys) {
    if (isSuperUser()) {
      return null;
    }

    if (principalsKeys.isEmpty()) {
      return createNoPrincipalsFilter();
    }

    final ValueFilter.Builder valueFilterBuilder =
        ValueFilter.create().fieldName(NodeIndexPath.PERMISSIONS_READ.toString());

    for (final PrincipalKey principalKey : principalsKeys) {
      valueFilterBuilder.addValue(ValueFactory.newString(principalKey.toString()));
    }

    return valueFilterBuilder.build();
  }
  private Media createMedia(
      final String id, final String contentPath, final Attachment... attachments) {
    final PropertyTree data = new PropertyTree();
    data.addString("media", attachments[0].getName());

    return Media.create()
        .id(ContentId.from(id))
        .path(contentPath)
        .createdTime(Instant.now())
        .type(ContentTypeName.imageMedia())
        .owner(PrincipalKey.from("user:myStore:me"))
        .displayName("My Content")
        .modifiedTime(Instant.now())
        .modifier(PrincipalKey.from("user:system:admin"))
        .data(data)
        .attachments(Attachments.from(attachments))
        .build();
  }
  @Test
  public void testEquals() {
    final ContentId contentId = ContentId.from("a");

    final ContentPath parentPath = ContentPath.ROOT;

    MoveContentParams params = new MoveContentParams(contentId, parentPath);
    params.creator(PrincipalKey.ofAnonymous());

    assertEquals(contentId, params.getContentId());
    assertEquals(parentPath, params.getParentContentPath());
    assertEquals(PrincipalKey.ofAnonymous(), params.getCreator());

    MoveContentParams params2 =
        new MoveContentParams(params.getContentId(), params.getParentContentPath());

    assertEquals(params, params2);
    assertEquals(params.hashCode(), params2.hashCode());
  }
 private static Filter createNoPrincipalsFilter() {
   return ValueFilter.create()
       .fieldName(NodeIndexPath.PERMISSIONS_READ.toString())
       .addValue(ValueFactory.newString(PrincipalKey.ofAnonymous().toString()))
       .build();
 }
public class UserMembersResolverTest {

  private static final UserStoreKey USER_STORE = UserStoreKey.from("myUserStore");

  private static final PrincipalKey GROUP_1 = PrincipalKey.ofGroup(USER_STORE, "group_1");

  private static final PrincipalKey GROUP_2 = PrincipalKey.ofGroup(USER_STORE, "group_2");

  private static final PrincipalKey USER_1 = PrincipalKey.ofUser(USER_STORE, "user_1");

  private static final PrincipalKey USER_2 = PrincipalKey.ofUser(USER_STORE, "user_2");

  private static final PrincipalKey USER_3 = PrincipalKey.ofUser(USER_STORE, "user_3");

  private SecurityService securityService;

  @Before
  public final void setUp() throws Exception {
    this.securityService = Mockito.mock(SecurityService.class);
  }

  @Test
  public void testGetUserMembersNone() throws Exception {
    Mockito.when(this.securityService.getRelationships(any(PrincipalKey.class)))
        .thenReturn(PrincipalRelationships.empty());

    final UserMembersResolver resolver = new UserMembersResolver(this.securityService);

    final PrincipalKeys res = resolver.getUserMembers(GROUP_1);
    assertEquals(0, res.getSize());
  }

  @Test
  public void testGetUserMembersDirect() throws Exception {
    final PrincipalRelationships memberships =
        PrincipalRelationships.from(
            PrincipalRelationship.from(GROUP_1).to(USER_1),
            PrincipalRelationship.from(GROUP_1).to(USER_2),
            PrincipalRelationship.from(GROUP_1).to(USER_3));
    Mockito.when(this.securityService.getRelationships(eq(GROUP_1))).thenReturn(memberships);

    final UserMembersResolver resolver = new UserMembersResolver(this.securityService);

    final PrincipalKeys res = resolver.getUserMembers(GROUP_1);
    assertEquals(3, res.getSize());
  }

  @Test
  public void testGetUserMembersIndirect() throws Exception {
    final PrincipalRelationships group1Memberships =
        PrincipalRelationships.from(PrincipalRelationship.from(GROUP_1).to(GROUP_2));
    final PrincipalRelationships group2Memberships =
        PrincipalRelationships.from(
            PrincipalRelationship.from(GROUP_2).to(USER_1),
            PrincipalRelationship.from(GROUP_2).to(USER_2),
            PrincipalRelationship.from(GROUP_2).to(USER_3));
    Mockito.when(this.securityService.getRelationships(eq(GROUP_1))).thenReturn(group1Memberships);
    Mockito.when(this.securityService.getRelationships(eq(GROUP_2))).thenReturn(group2Memberships);

    final UserMembersResolver resolver = new UserMembersResolver(this.securityService);

    final PrincipalKeys res = resolver.getUserMembers(GROUP_1);
    assertEquals(3, res.getSize());
  }

  @Test
  public void testGetUserMembersDuplicates() throws Exception {
    final PrincipalRelationships group1Memberships =
        PrincipalRelationships.from(
            PrincipalRelationship.from(GROUP_1).to(GROUP_2),
            PrincipalRelationship.from(GROUP_1).to(USER_1),
            PrincipalRelationship.from(GROUP_1).to(USER_3));
    final PrincipalRelationships group2Memberships =
        PrincipalRelationships.from(
            PrincipalRelationship.from(GROUP_2).to(USER_1),
            PrincipalRelationship.from(GROUP_2).to(USER_2),
            PrincipalRelationship.from(GROUP_2).to(USER_3));
    Mockito.when(this.securityService.getRelationships(eq(GROUP_1))).thenReturn(group1Memberships);
    Mockito.when(this.securityService.getRelationships(eq(GROUP_2))).thenReturn(group2Memberships);

    final UserMembersResolver resolver = new UserMembersResolver(this.securityService);

    final PrincipalKeys res = resolver.getUserMembers(GROUP_1);
    assertEquals(3, res.getSize());
  }
}