Search in sources :

Example 1 with AuthorizableNodeName

use of org.apache.jackrabbit.oak.spi.security.user.AuthorizableNodeName in project jackrabbit-oak by apache.

the class SecurityProviderRegistrationTest method testDeactivate.

@Test
public void testDeactivate() throws Exception {
    registration.activate(context.bundleContext(), requiredServiceIdMap("nodeName"));
    AuthorizableNodeName mock = Mockito.mock(AuthorizableNodeName.class);
    registration.bindAuthorizableNodeName(mock, ImmutableMap.of(Constants.SERVICE_PID, "nodeName"));
    SecurityProvider service = context.getService(SecurityProvider.class);
    assertNotNull(service);
    registration.deactivate();
    // provider must have been unregistered
    assertNull(context.getService(SecurityProvider.class));
}
Also used : SecurityProvider(org.apache.jackrabbit.oak.spi.security.SecurityProvider) AuthorizableNodeName(org.apache.jackrabbit.oak.spi.security.user.AuthorizableNodeName) AbstractSecurityTest(org.apache.jackrabbit.oak.AbstractSecurityTest) Test(org.junit.Test)

Example 2 with AuthorizableNodeName

use of org.apache.jackrabbit.oak.spi.security.user.AuthorizableNodeName in project jackrabbit-oak by apache.

the class SecurityProviderRegistrationTest method testDeactivateClearsPreconditions.

@Test
public void testDeactivateClearsPreconditions() throws Exception {
    Field f = registration.getClass().getDeclaredField("preconditions");
    f.setAccessible(true);
    registration.activate(context.bundleContext(), requiredServiceIdMap("nodeName"));
    assertFalse(((Preconditions) f.get(registration)).areSatisfied());
    AuthorizableNodeName mock = Mockito.mock(AuthorizableNodeName.class);
    registration.bindAuthorizableNodeName(mock, ImmutableMap.of(Constants.SERVICE_PID, "nodeName"));
    assertTrue(((Preconditions) f.get(registration)).areSatisfied());
    registration.deactivate();
    assertTrue(((Preconditions) f.get(registration)).areSatisfied());
}
Also used : Field(java.lang.reflect.Field) AuthorizableNodeName(org.apache.jackrabbit.oak.spi.security.user.AuthorizableNodeName) AbstractSecurityTest(org.apache.jackrabbit.oak.AbstractSecurityTest) Test(org.junit.Test)

Example 3 with AuthorizableNodeName

use of org.apache.jackrabbit.oak.spi.security.user.AuthorizableNodeName in project jackrabbit-oak by apache.

the class SecurityProviderRegistrationTest method testUnbindMandatoryCandidateOnPreconditions.

@Test
public void testUnbindMandatoryCandidateOnPreconditions() throws Exception {
    registration.activate(context.bundleContext(), requiredServiceIdMap("nodeName"));
    Field f = registration.getClass().getDeclaredField("preconditions");
    f.setAccessible(true);
    AuthorizableNodeName mock = Mockito.mock(AuthorizableNodeName.class);
    registration.bindAuthorizableNodeName(mock, ImmutableMap.of(Constants.SERVICE_PID, "nodeName"));
    registration.unbindAuthorizableNodeName(mock, ImmutableMap.of(Constants.SERVICE_PID, "nodeName"));
    Preconditions preconditions = (Preconditions) f.get(registration);
    assertFalse(preconditions.areSatisfied());
}
Also used : Field(java.lang.reflect.Field) AuthorizableNodeName(org.apache.jackrabbit.oak.spi.security.user.AuthorizableNodeName) AbstractSecurityTest(org.apache.jackrabbit.oak.AbstractSecurityTest) Test(org.junit.Test)

Example 4 with AuthorizableNodeName

use of org.apache.jackrabbit.oak.spi.security.user.AuthorizableNodeName in project jackrabbit-oak by apache.

the class WhiteboardAuthorizableNodeNameTest method testRegisteredImplementation.

@Test
public void testRegisteredImplementation() {
    authorizableNodeName.start(whiteboard);
    AuthorizableNodeName registered = new AuthorizableNodeName() {

        @Nonnull
        @Override
        public String generateNodeName(@Nonnull String authorizableId) {
            return "generated";
        }
    };
    whiteboard.register(AuthorizableNodeName.class, registered, ImmutableMap.of());
    assertEquals(registered.generateNodeName(TEST_ID), authorizableNodeName.generateNodeName(TEST_ID));
}
Also used : Nonnull(javax.annotation.Nonnull) AuthorizableNodeName(org.apache.jackrabbit.oak.spi.security.user.AuthorizableNodeName) Test(org.junit.Test)

Example 5 with AuthorizableNodeName

use of org.apache.jackrabbit.oak.spi.security.user.AuthorizableNodeName in project jackrabbit-oak by apache.

the class UserProviderTest method testCollisions.

@Test
public void testCollisions() throws Exception {
    ConfigurationParameters config = ConfigurationParameters.of(UserConstants.PARAM_AUTHORIZABLE_NODE_NAME, new AuthorizableNodeName() {

        @Nonnull
        @Override
        public String generateNodeName(@Nonnull String authorizableId) {
            return "aaa";
        }
    });
    UserProvider up = new UserProvider(root, config);
    try {
        Tree u1 = up.createUser("a", null);
        assertEquals("aaa", u1.getName());
        Tree u2 = up.createUser("b", null);
        assertEquals("aaa1", u2.getName());
        Tree u3 = up.createUser("c", null);
        assertEquals("aaa2", u3.getName());
        Tree u4 = up.createUser("d", null);
        assertEquals("aaa3", u4.getName());
    } finally {
        root.refresh();
    }
}
Also used : Nonnull(javax.annotation.Nonnull) Tree(org.apache.jackrabbit.oak.api.Tree) ConfigurationParameters(org.apache.jackrabbit.oak.spi.security.ConfigurationParameters) AuthorizableNodeName(org.apache.jackrabbit.oak.spi.security.user.AuthorizableNodeName) Test(org.junit.Test)

Aggregations

AuthorizableNodeName (org.apache.jackrabbit.oak.spi.security.user.AuthorizableNodeName)6 Test (org.junit.Test)6 AbstractSecurityTest (org.apache.jackrabbit.oak.AbstractSecurityTest)4 Field (java.lang.reflect.Field)2 Nonnull (javax.annotation.Nonnull)2 Tree (org.apache.jackrabbit.oak.api.Tree)1 RandomAuthorizableNodeName (org.apache.jackrabbit.oak.security.user.RandomAuthorizableNodeName)1 ConfigurationParameters (org.apache.jackrabbit.oak.spi.security.ConfigurationParameters)1 SecurityProvider (org.apache.jackrabbit.oak.spi.security.SecurityProvider)1