Search in sources :

Example 26 with Value

use of javax.jcr.Value in project jackrabbit-oak by apache.

the class DefaultSyncContextTest method testCreateValueDouble.

@Test
public void testCreateValueDouble() throws Exception {
    Value v = syncCtx.createValue(Double.valueOf(1.1));
    assertNotNull(v);
    assertEquals(PropertyType.DOUBLE, v.getType());
    assertEquals(1.1, v.getDouble(), 0);
    v = syncCtx.createValue(Float.NaN);
    assertNotNull(v);
    assertEquals(PropertyType.DOUBLE, v.getType());
    assertEquals(Float.NaN, v.getDouble(), 0);
}
Also used : Value(javax.jcr.Value) AbstractExternalAuthTest(org.apache.jackrabbit.oak.spi.security.authentication.external.AbstractExternalAuthTest) Test(org.junit.Test)

Example 27 with Value

use of javax.jcr.Value in project jackrabbit-oak by apache.

the class DefaultSyncHandlerTest method testRequiresSyncExpiredSyncProperty.

@Test
public void testRequiresSyncExpiredSyncProperty() throws Exception {
    login(new SimpleCredentials(USER_ID, new char[0])).close();
    root.refresh();
    final Calendar nowCal = Calendar.getInstance();
    nowCal.setTimeInMillis(nowCal.getTimeInMillis() - 1000);
    Value nowValue = getValueFactory().createValue(nowCal);
    Authorizable a = userManager.getAuthorizable(USER_ID);
    a.setProperty(DefaultSyncContext.REP_LAST_SYNCED, nowValue);
    root.commit();
    SyncedIdentity id = syncHandler.findIdentity(userManager, USER_ID);
    assertNotNull("known authorizable should exist", id);
    assertTrue("synced id should require sync", syncHandler.requiresSync(id));
}
Also used : SimpleCredentials(javax.jcr.SimpleCredentials) Calendar(java.util.Calendar) Value(javax.jcr.Value) Authorizable(org.apache.jackrabbit.api.security.user.Authorizable) DefaultSyncedIdentity(org.apache.jackrabbit.oak.spi.security.authentication.external.basic.DefaultSyncedIdentity) SyncedIdentity(org.apache.jackrabbit.oak.spi.security.authentication.external.SyncedIdentity) Test(org.junit.Test)

Example 28 with Value

use of javax.jcr.Value in project jackrabbit-oak by apache.

the class DefaultSyncContextTest method testSyncPropertiesMappingConstants.

@Test
public void testSyncPropertiesMappingConstants() throws Exception {
    ExternalUser externalUser = idp.getUser(TestIdentityProvider.ID_SECOND_USER);
    sync(externalUser);
    Authorizable a = userManager.getAuthorizable(externalUser.getId());
    // create mapping that doesn't match to names in the external-properties
    // -> previously synced properties must be removed
    Map<String, String> mapping = new HashMap();
    Map<String, ?> extProps = externalUser.getProperties();
    for (String propName : extProps.keySet()) {
        mapping.put(propName, "\"any\"");
    }
    syncCtx.syncProperties(externalUser, a, mapping);
    Value anyValue = valueFactory.createValue("any");
    for (String propName : extProps.keySet()) {
        assertTrue(a.hasProperty(propName));
        assertEquals(anyValue, a.getProperty(propName)[0]);
    }
}
Also used : HashMap(java.util.HashMap) ExternalUser(org.apache.jackrabbit.oak.spi.security.authentication.external.ExternalUser) Value(javax.jcr.Value) Authorizable(org.apache.jackrabbit.api.security.user.Authorizable) AbstractExternalAuthTest(org.apache.jackrabbit.oak.spi.security.authentication.external.AbstractExternalAuthTest) Test(org.junit.Test)

Example 29 with Value

use of javax.jcr.Value in project jackrabbit-oak by apache.

the class DefaultSyncContextTest method testSyncPropertiesEmptyMapExistingProps.

@Test
public void testSyncPropertiesEmptyMapExistingProps() throws Exception {
    ExternalUser externalUser = idp.getUser(TestIdentityProvider.ID_SECOND_USER);
    Authorizable a = syncCtx.createUser(externalUser);
    Value anyValue = valueFactory.createValue("any");
    Map<String, ?> extProps = externalUser.getProperties();
    for (String propName : extProps.keySet()) {
        a.setProperty(propName, anyValue);
    }
    syncCtx.syncProperties(externalUser, a, ImmutableMap.<String, String>of());
    for (String propName : extProps.keySet()) {
        assertTrue(a.hasProperty(propName));
        assertEquals(anyValue, a.getProperty(propName)[0]);
    }
}
Also used : ExternalUser(org.apache.jackrabbit.oak.spi.security.authentication.external.ExternalUser) Value(javax.jcr.Value) Authorizable(org.apache.jackrabbit.api.security.user.Authorizable) AbstractExternalAuthTest(org.apache.jackrabbit.oak.spi.security.authentication.external.AbstractExternalAuthTest) Test(org.junit.Test)

Example 30 with Value

use of javax.jcr.Value in project jackrabbit by apache.

the class AbstractEntryTest method testCreateFromBase.

public void testCreateFromBase() throws RepositoryException, NotExecutableException {
    Map<String, Value> testRestrictions = getTestRestrictions();
    JackrabbitAccessControlEntry base = createEntry(testPrincipal, privilegesFromName(Privilege.JCR_READ), false, testRestrictions);
    assertEquals(testPrincipal, base.getPrincipal());
    assertTrue(Arrays.equals(privilegesFromName(Privilege.JCR_READ), base.getPrivileges()));
    assertFalse(base.isAllow());
    Map<String, Value> baseRestrictions = new HashMap<String, Value>();
    for (String name : base.getRestrictionNames()) {
        baseRestrictions.put(name, base.getRestriction(name));
    }
    assertEquals(testRestrictions, baseRestrictions);
    JackrabbitAccessControlEntry entry = createEntryFromBase(base, privilegesFromName(Privilege.JCR_WRITE), true);
    assertEquals(testPrincipal, entry.getPrincipal());
    assertTrue(Arrays.equals(privilegesFromName(Privilege.JCR_WRITE), entry.getPrivileges()));
    assertTrue(entry.isAllow());
    Map<String, Value> entryRestrictions = new HashMap<String, Value>();
    for (String name : entry.getRestrictionNames()) {
        entryRestrictions.put(name, entry.getRestriction(name));
    }
    assertEquals(testRestrictions, entryRestrictions);
}
Also used : JackrabbitAccessControlEntry(org.apache.jackrabbit.api.security.JackrabbitAccessControlEntry) HashMap(java.util.HashMap) Value(javax.jcr.Value)

Aggregations

Value (javax.jcr.Value)600 Node (javax.jcr.Node)158 Test (org.junit.Test)118 Property (javax.jcr.Property)99 RepositoryException (javax.jcr.RepositoryException)82 NotExecutableException (org.apache.jackrabbit.test.NotExecutableException)82 PropertyDefinition (javax.jcr.nodetype.PropertyDefinition)70 Session (javax.jcr.Session)63 NodeType (javax.jcr.nodetype.NodeType)57 ValueFormatException (javax.jcr.ValueFormatException)53 ValueFactory (javax.jcr.ValueFactory)51 QValue (org.apache.jackrabbit.spi.QValue)51 HashMap (java.util.HashMap)46 ArrayList (java.util.ArrayList)31 ConstraintViolationException (javax.jcr.nodetype.ConstraintViolationException)30 Privilege (javax.jcr.security.Privilege)30 InputStream (java.io.InputStream)29 JackrabbitNode (org.apache.jackrabbit.api.JackrabbitNode)29 Authorizable (org.apache.jackrabbit.api.security.user.Authorizable)29 QValueValue (org.apache.jackrabbit.spi.commons.value.QValueValue)27