GenericValue val = GenericValue.getGenericValueFromObject(properties.get(key)); if (val.isMultiValue()) { group.setProperty((String) key, val.getValues()); } else { group.setProperty((String) key, val.get());
@NotNull protected DefaultSyncResultImpl syncGroup(@NotNull ExternalGroup external, @NotNull Group group) throws RepositoryException { // make also sure the local user to be synced belongs to the same IDP. Note: 'external' has been verified before. if (!isSameIDP(group)) { return new DefaultSyncResultImpl(new DefaultSyncedIdentity(external.getId(), external.getExternalId(), false, -1), SyncResult.Status.FOREIGN); } SyncResult.Status status; // first check if group is expired if (!forceGroupSync && !isExpired(group)) { status = SyncResult.Status.NOP; } else { syncExternalIdentity(external, group, config.group()); // finally "touch" the sync property group.setProperty(REP_LAST_SYNCED, nowValue); status = SyncResult.Status.UPDATE; } return new DefaultSyncResultImpl(createSyncedIdentity(group), status); }
@Override protected void setUp() throws Exception { super.setUp(); p = getTestPrincipal(); gr = userMgr.createGroup(p); Value[] vs = new Value[]{ superuser.getValueFactory().createValue("v1"), superuser.getValueFactory().createValue("v2") }; relPath = "relPath/" + propertyName1; relPath2 = "another/" + propertyName1; relPath3 = "relPath/child/" + propertyName1; gr.setProperty(relPath, vs); gr.setProperty(relPath2, vs); gr.setProperty(relPath3, superuser.getValueFactory().createValue("v3")); superuser.save(); }
@Test public void testGetIdentityRefEmptyMvProperty() throws Exception { Group gr = createTestGroup(); // NOTE: making rep:externalId a multivalue property without any value // not committing the changes as this prop is expected to become // protected to prevent unintentional or malicious modification. gr.setProperty(DefaultSyncContext.REP_EXTERNAL_ID, new Value[0]); ExternalIdentityRef ref = DefaultSyncContext.getIdentityRef(gr); assertNull(ref); }
boolean isMultiValued = protectedGroupProps.get(pName); if (isMultiValued) { group.setProperty(pName, new Value[] {v}); } else { group.setProperty(pName, v);
@Test public void testFindWithRelPathMultipleSelectorNames() throws Exception { user.setProperty(propertyName, v); Group g = createGroup("g", null); g.setProperty("rel/path/to/" + propertyName, v); root.commit(); for (AuthorizableType type : new AuthorizableType[] {AuthorizableType.AUTHORIZABLE, AuthorizableType.GROUP}) { Iterator<Authorizable> result = queryMgr.findAuthorizables("rel/path/to/" + propertyName, v.getString(), AuthorizableType.AUTHORIZABLE, false); assertResultContainsAuthorizables(result, g); } }
@Test public void testQuerySortRespectCase() throws Exception { Group g = createGroup("g1", null); g.setProperty(propertyName, valueFactory.createValue("aaa")); Group g2 = createGroup("g2", null); g2.setProperty(propertyName, valueFactory.createValue("BBB")); user.setProperty(propertyName, valueFactory.createValue("c")); root.commit(); Query q = new Query() { @Override public <T> void build(QueryBuilder<T> builder) { builder.setCondition(builder.exists(propertyName)); builder.setSortOrder(propertyName, QueryBuilder.Direction.DESCENDING, false); } }; Iterator<Authorizable> result = queryMgr.findAuthorizables(q); assertEquals(ImmutableList.of(user, g, g2), ImmutableList.copyOf(result)); }
@Test public void testFindWithRelPathTypeMismatch() throws Exception { user.setProperty(propertyName, v); Group g = createGroup("g", null); g.setProperty("rel/path/to/" + propertyName, v); root.commit(); Iterator<Authorizable> result = queryMgr.findAuthorizables("rel/path/to/" + propertyName, v.getString(), AuthorizableType.USER, false); assertResultContainsAuthorizables(result); }
@Test public void testQuerySortIgnoreCase() throws Exception { Group g = createGroup("g1", null); g.setProperty(propertyName, valueFactory.createValue("aaa")); Group g2 = createGroup("g2", null); g2.setProperty(propertyName, valueFactory.createValue("BBB")); user.setProperty(propertyName, valueFactory.createValue("c")); root.commit(); Query q = new Query() { @Override public <T> void build(QueryBuilder<T> builder) { builder.setCondition(builder.exists(propertyName)); builder.setSortOrder(propertyName, QueryBuilder.Direction.DESCENDING, true); } }; Iterator<Authorizable> result = queryMgr.findAuthorizables(q); assertEquals(ImmutableList.of(user, g2, g), ImmutableList.copyOf(result)); }
public void setRoleDescription( Session session, final ITenant theTenant, final String roleName, final String description ) throws NotFoundException, RepositoryException { Group jackrabbitGroup = getJackrabbitGroup( theTenant, roleName, session ); if ( jackrabbitGroup != null && TenantUtils.isAccessibleTenant( theTenant == null ? tenantedRoleNameUtils .getTenant( jackrabbitGroup.getID() ) : theTenant ) ) { if ( description == null ) { jackrabbitGroup.removeProperty( "description" ); //$NON-NLS-1$ } else { jackrabbitGroup .setProperty( "description", session.getValueFactory().createValue( description ) ); //$NON-NLS-1$ } } else { throw new NotFoundException( Messages.getInstance().getString( "AbstractJcrBackedUserRoleDao.ERROR_0002_ROLE_NOT_FOUND" ) ); } }
@Override protected void setUp() throws Exception { super.setUp(); userManager = ((JackrabbitSession) superuser).getUserManager(); testUser = ExerciseUtility.createTestUser(userManager); testUser.disable("no longer active"); testGroup = ExerciseUtility.createTestGroup(userManager); testGroup.addMember(testUser); testGroup.setProperty("Name", superuser.getValueFactory().createValue("Test Group")); superuser.save(); }
@Test public void testCreateSyncedIdentityEmptyLastSyncedProperty() throws Exception { Group gr = createTestGroup(); gr.setProperty(DefaultSyncContext.REP_LAST_SYNCED, new Value[0]); SyncedIdentity si = DefaultSyncContext.createSyncedIdentity(gr); assertNotNull(si); assertEquals(-1, si.lastSynced()); }
@Test public void testQueryBoundWithSortOrder() throws Exception { Group g = createGroup("g1", null); g.setProperty(propertyName, valueFactory.createValue(50)); Group g2 = createGroup("g2", null); g2.setProperty(propertyName, valueFactory.createValue(60)); user.setProperty(propertyName, valueFactory.createValue(101)); root.commit(); Query q = new Query() { @Override public <T> void build(QueryBuilder<T> builder) { builder.setLimit(valueFactory.createValue(100), Long.MAX_VALUE); builder.setSortOrder(propertyName, QueryBuilder.Direction.ASCENDING); builder.setCondition(builder.gt(propertyName, valueFactory.createValue(20))); } }; Iterator<Authorizable> result = queryMgr.findAuthorizables(q); assertResultContainsAuthorizables(result, user); }
@Test public void testIsExpiredEmptyLastSyncedProperty() throws Exception { Group gr = createTestGroup(); gr.setProperty(DefaultSyncContext.REP_LAST_SYNCED, new Value[0]); assertTrue(syncCtx.isExpired(gr, syncConfig.group().getExpirationTime(), "any")); }
@Test public void testQueryBoundWithoutSortOrder() throws Exception { Group g = createGroup("g1", null); g.setProperty(propertyName, valueFactory.createValue(50)); Group g2 = createGroup("g2", null); g2.setProperty(propertyName, valueFactory.createValue(60)); user.setProperty(propertyName, valueFactory.createValue(101)); root.commit(); Query q = new Query() { @Override public <T> void build(QueryBuilder<T> builder) { builder.setLimit(valueFactory.createValue(100), Long.MAX_VALUE); builder.setCondition(builder.gt(propertyName, valueFactory.createValue(20))); } }; Iterator<Authorizable> result = queryMgr.findAuthorizables(q); assertResultContainsAuthorizables(result, user, g, g2); }
@Test public void testQueryBoundWithSortOrderMissingCondition() throws Exception { Group g = createGroup("g1", null); g.setProperty(propertyName, valueFactory.createValue(50)); Group g2 = createGroup("g2", null); g2.setProperty(propertyName, valueFactory.createValue(60)); user.setProperty(propertyName, valueFactory.createValue(101)); root.commit(); Query q = new Query() { @Override public <T> void build(QueryBuilder<T> builder) { builder.setLimit(valueFactory.createValue(100), Long.MAX_VALUE); builder.setSortOrder(propertyName, QueryBuilder.Direction.ASCENDING); } }; Iterator<Authorizable> result = queryMgr.findAuthorizables(q); assertResultContainsAuthorizables(result, user); }
@Test public void testQueryNoScope() throws Exception { Group g = createGroup(null, EveryonePrincipal.getInstance()); g.setProperty(propertyName, v); user.setProperty(propertyName, v); root.commit(); Query q = new Query() { @Override public <T> void build(QueryBuilder<T> builder) { builder.setCondition(builder.eq(propertyName, v)); } }; Iterator<Authorizable> result = queryMgr.findAuthorizables(q); assertResultContainsAuthorizables(result, user, g); }
@Test public void testQueryScopeEveryoneWithIdDiffersPrincipalName() throws Exception { Group g = createGroup("eGroup", EveryonePrincipal.getInstance()); g.setProperty(propertyName, v); user.setProperty(propertyName, v); root.commit(); Query q = new Query() { @Override public <T> void build(QueryBuilder<T> builder) { builder.setCondition(builder.eq(propertyName, v)); builder.setScope("eGroup", false); } }; Iterator<Authorizable> result = queryMgr.findAuthorizables(q); assertResultContainsAuthorizables(result, user); }
@Test public void testQueryScopeEveryoneFiltersEveryone() throws Exception { Group g = createGroup(null, EveryonePrincipal.getInstance()); g.setProperty(propertyName, v); user.setProperty(propertyName, v); root.commit(); Query q = new Query() { @Override public <T> void build(QueryBuilder<T> builder) { builder.setCondition(builder.eq(propertyName, v)); builder.setScope(EveryonePrincipal.NAME, false); } }; Iterator<Authorizable> result = queryMgr.findAuthorizables(q); assertResultContainsAuthorizables(result, user); }
public void testSetSpecialProperties() throws NotExecutableException, RepositoryException { Value v = superuser.getValueFactory().createValue("any_value"); User u = getTestUser(superuser); for (String pName : protectedUserProps) { try { u.setProperty(pName, v); save(superuser); fail("changing the '" + pName + "' property on a User should fail."); } catch (RepositoryException e) { // success } } Group g = getTestGroup(superuser); for (String pName : protectedGroupProps) { try { g.setProperty(pName, v); save(superuser); fail("changing the '" + pName + "' property on a Group should fail."); } catch (RepositoryException e) { // success } } }