@Test public void testRemoveNotExistingProperty() throws RepositoryException, NotExecutableException { String hint = "Fullname"; String propName = hint; int i = 0; while (user.hasProperty(propName)) { propName = hint + i; i++; } assertFalse(user.removeProperty(propName)); superuser.save(); }
@Test public void testSetPropertyByRelPath() throws NotExecutableException, RepositoryException { Value[] v = new Value[] {superuser.getValueFactory().createValue("Super User")}; List<String> relPaths = new ArrayList<String>(); relPaths.add("testing/Fullname"); relPaths.add("testing/Email"); relPaths.add("testing/testing/testing/Fullname"); relPaths.add("testing/testing/testing/Email"); for (String relPath : relPaths) { try { user.setProperty(relPath, v); superuser.save(); assertTrue(user.hasProperty(relPath)); String propName = Text.getName(relPath); assertFalse(user.hasProperty(propName)); } finally { // try to remove the property even if previous calls failed. user.removeProperty(relPath); superuser.save(); } } }
@Test public void testRemoveSpecialProperties() throws NotExecutableException, RepositoryException { for (String pName : protectedUserProps.keySet()) { try { if (user.removeProperty(pName)) { superuser.save(); fail("removing the '" + pName + "' property on a User should fail."); } // else: property not present: fine as well. } catch (RepositoryException e) { // success } finally { superuser.refresh(false); } } for (String pName : protectedGroupProps.keySet()) { try { if (group.removeProperty(pName)) { superuser.save(); fail("removing the '" + pName + "' property on a Group should fail."); } // else: property not present. fine as well. } catch (RepositoryException e) { // success } finally { superuser.refresh(false); } } }
@Override public void after() throws Exception { try { user.removeProperty(propertyName); for (Group g : groups) { g.remove(); } if (root.hasPendingChanges()) { root.commit(); } } finally { super.after(); } }
public void setUserDescription( Session session, final ITenant theTenant, final String userName, final String description ) throws NotFoundException, RepositoryException { User jackrabbitUser = getJackrabbitUser( theTenant, userName, session ); if ( ( jackrabbitUser == null ) || !TenantUtils.isAccessibleTenant( theTenant == null ? tenantedUserNameUtils .getTenant( jackrabbitUser.getID() ) : theTenant ) ) { throw new NotFoundException( Messages.getInstance().getString( "AbstractJcrBackedUserRoleDao.ERROR_0003_USER_NOT_FOUND" ) ); } if ( description == null ) { jackrabbitUser.removeProperty( "description" ); //$NON-NLS-1$ } else { jackrabbitUser.setProperty( "description", session.getValueFactory().createValue( description ) ); //$NON-NLS-1$ } }
assertEquals(Arrays.asList(v), Arrays.asList(user.getProperty("./" + propName))); assertTrue(user.removeProperty(propName)); assertFalse(user.hasProperty(propName)); } finally { user.removeProperty(propName); superuser.save();
@Test public void testGetPropertyNames() throws NotExecutableException, RepositoryException { String propName = "Fullname"; Value v = superuser.getValueFactory().createValue("Super User"); try { user.setProperty(propName, v); superuser.save(); } catch (RepositoryException e) { throw new NotExecutableException("Cannot test 'Authorizable.setProperty'."); } try { for (Iterator<String> it = user.getPropertyNames(); it.hasNext();) { String name = it.next(); assertTrue(user.hasProperty(name)); assertNotNull(user.getProperty(name)); } } finally { // try to remove the property again even if previous calls failed. user.removeProperty(propName); superuser.save(); } }
@Test public void testSingleToMultiValued() throws Exception { UserManager uMgr = getUserManager(superuser); try { Value v = superuser.getValueFactory().createValue("anyValue"); user.setProperty("someProp", v); if (!uMgr.isAutoSave()) { superuser.save(); } Value[] vs = new Value[] {v, v}; user.setProperty("someProp", vs); if (!uMgr.isAutoSave()) { superuser.save(); } } finally { if (user.removeProperty("someProp") && !uMgr.isAutoSave()) { superuser.save(); } } }
@Test public void testMultiValuedToSingle() throws Exception { UserManager uMgr = getUserManager(superuser); try { Value v = superuser.getValueFactory().createValue("anyValue"); Value[] vs = new Value[] {v, v}; user.setProperty("someProp", vs); if (!uMgr.isAutoSave()) { superuser.save(); } user.setProperty("someProp", v); if (!uMgr.isAutoSave()) { superuser.save(); } } finally { if (user.removeProperty("someProp") && !uMgr.isAutoSave()) { superuser.save(); } } } }
assertEquals(v, user.getProperty("./" + propName)[0]); assertTrue(user.removeProperty(propName)); assertFalse(user.hasProperty(propName)); } finally { user.removeProperty(propName); superuser.save();
testUser.removeProperty(EMAIL_REL_PATH); testUser.removeProperty(PETS_REL_PATH); superuser.save();
user.removeProperty(relPath); superuser.save();
@Test public void testSyncExternalToExistingLocalUser() throws Exception { ExternalUser external = idp.listUsers().next(); syncCtx.sync(external); User u = userManager.getAuthorizable(external.getId(), User.class); u.removeProperty(ExternalIdentityConstants.REP_EXTERNAL_ID); SyncResult result = syncCtx.sync(external); assertEquals(SyncResult.Status.FOREIGN, result.getStatus()); SyncedIdentity si = result.getIdentity(); assertNotNull(si); assertEquals(external.getExternalId(), si.getExternalIdRef()); }
public void testRemoveSpecialProperties() throws NotExecutableException, RepositoryException { User u = getTestUser(superuser); for (String pName : protectedUserProps) { try { u.removeProperty(pName); save(superuser); fail("removing the '" + pName + "' property on a User should fail."); } catch (RepositoryException e) { // success } } Group g = getTestGroup(superuser); for (String pName : protectedGroupProps) { try { g.removeProperty(pName); save(superuser); fail("removing the '" + pName + "' property on a Group should fail."); } catch (RepositoryException e) { // success } } }
@Test public void testAuthorizable() throws Exception { User u = mgr.createUser("u", "u"); u.setProperty("prop", getValueFactory().createValue("value")); assertFalse(root.hasPendingChanges()); u.setProperty("prop", new Value[] {getValueFactory().createValue(true)}); assertFalse(root.hasPendingChanges()); u.removeProperty("prop"); assertFalse(root.hasPendingChanges()); }
public void testUserCanModifyItsOwnProperties() throws RepositoryException, NotExecutableException { User u = (User) uMgr.getAuthorizable(uID); if (u == null) { fail("User " +uID+ "hast not been removed and must be visible to the Session created with its credentials."); } if (!uSession.hasPermission(((UserImpl) u).getNode().getPath(), "set_property")) { throw new NotExecutableException("Users should be able to modify their properties -> Check repository config."); } // single valued properties u.setProperty("Email", new StringValue("tu@security.test")); save(uSession); assertNotNull(u.getProperty("Email")); assertEquals("tu@security.test", u.getProperty("Email")[0].getString()); u.removeProperty("Email"); save(uSession); assertNull(u.getProperty("Email")); // multivalued properties u.setProperty(propertyName1, new Value[] {uSession.getValueFactory().createValue("anyValue")}); save(uSession); assertNotNull(u.getProperty(propertyName1)); u.removeProperty(propertyName1); save(uSession); assertNull(u.getProperty(propertyName1)); }
UserManager userManager = getUserManager(systemRoot); User user = userManager.getAuthorizable(USER_ID, User.class); user.removeProperty(ExternalIdentityConstants.REP_EXTERNAL_PRINCIPAL_NAMES); systemRoot.commit();