Search in sources :

Example 1 with SecurityProvider

use of org.apache.jackrabbit.oak.spi.security.SecurityProvider 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 SecurityProvider

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

the class SecurityProviderRegistrationTest method testBindOptionalCandidateAfterRegistration.

@Test
public void testBindOptionalCandidateAfterRegistration() {
    registration.activate(context.bundleContext(), requiredServiceIdMap("serviceId"));
    registration.bindTokenConfiguration(mockConfiguration(TokenConfiguration.class), ImmutableMap.of(Constants.SERVICE_PID, "serviceId"));
    SecurityProvider service = context.getService(SecurityProvider.class);
    assertNotNull(service);
    // binding another (optional configuration) must not result in re-registration of the service
    registration.bindPrincipalConfiguration(mockConfiguration(PrincipalConfiguration.class), ImmutableMap.of(Constants.SERVICE_PID, "optionalService"));
    SecurityProvider service2 = context.getService(SecurityProvider.class);
    assertSame(service, service2);
}
Also used : CompositeTokenConfiguration(org.apache.jackrabbit.oak.spi.security.authentication.token.CompositeTokenConfiguration) TokenConfiguration(org.apache.jackrabbit.oak.spi.security.authentication.token.TokenConfiguration) CompositePrincipalConfiguration(org.apache.jackrabbit.oak.spi.security.principal.CompositePrincipalConfiguration) PrincipalConfiguration(org.apache.jackrabbit.oak.spi.security.principal.PrincipalConfiguration) SecurityProvider(org.apache.jackrabbit.oak.spi.security.SecurityProvider) AbstractSecurityTest(org.apache.jackrabbit.oak.AbstractSecurityTest) Test(org.junit.Test)

Example 3 with SecurityProvider

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

the class SecurityProviderRegistrationTest method testUnbindOptionalCandidateAfterRegistration.

@Test
public void testUnbindOptionalCandidateAfterRegistration() {
    registration.activate(context.bundleContext(), requiredServiceIdMap("serviceId"));
    UserAuthenticationFactory uaf = Mockito.mock(UserAuthenticationFactory.class);
    Map<String, Object> properties = ImmutableMap.of(Constants.SERVICE_PID, "notMandatory");
    registration.bindUserAuthenticationFactory(uaf, properties);
    assertNull(context.getService(SecurityProvider.class));
    registration.bindAuthorizableActionProvider(Mockito.mock(AuthorizableActionProvider.class), ImmutableMap.of(Constants.SERVICE_PID, "serviceId"));
    SecurityProvider service = context.getService(SecurityProvider.class);
    assertNotNull(service);
    // unbinding an optional configuration must not result in unrregistration of the service
    registration.unbindUserAuthenticationFactory(uaf, properties);
    SecurityProvider service2 = context.getService(SecurityProvider.class);
    assertSame(service, service2);
}
Also used : UserAuthenticationFactory(org.apache.jackrabbit.oak.spi.security.user.UserAuthenticationFactory) SecurityProvider(org.apache.jackrabbit.oak.spi.security.SecurityProvider) AuthorizableActionProvider(org.apache.jackrabbit.oak.spi.security.user.action.AuthorizableActionProvider) AbstractSecurityTest(org.apache.jackrabbit.oak.AbstractSecurityTest) Test(org.junit.Test)

Example 4 with SecurityProvider

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

the class SecurityProviderRegistrationTest method testBindRestrictionProviderWithoutAuthorizationConfig.

@Test
public void testBindRestrictionProviderWithoutAuthorizationConfig() {
    registration.activate(context.bundleContext(), requiredServiceIdMap("serviceId"));
    RestrictionProvider mockRp = Mockito.mock(RestrictionProvider.class);
    registration.bindRestrictionProvider(mockRp, ImmutableMap.of(Constants.SERVICE_PID, "serviceId"));
    SecurityProvider service = context.getService(SecurityProvider.class);
    assertNotNull(service);
    AuthorizationConfiguration ac = service.getConfiguration(AuthorizationConfiguration.class);
    assertTrue(ac instanceof CompositeAuthorizationConfiguration);
    // empty composite configuration => empty rp
    RestrictionProvider rp = ac.getRestrictionProvider();
    assertSame(RestrictionProvider.EMPTY, rp);
}
Also used : CompositeAuthorizationConfiguration(org.apache.jackrabbit.oak.security.authorization.composite.CompositeAuthorizationConfiguration) AuthorizationConfiguration(org.apache.jackrabbit.oak.spi.security.authorization.AuthorizationConfiguration) RestrictionProvider(org.apache.jackrabbit.oak.spi.security.authorization.restriction.RestrictionProvider) WhiteboardRestrictionProvider(org.apache.jackrabbit.oak.security.authorization.restriction.WhiteboardRestrictionProvider) SecurityProvider(org.apache.jackrabbit.oak.spi.security.SecurityProvider) CompositeAuthorizationConfiguration(org.apache.jackrabbit.oak.security.authorization.composite.CompositeAuthorizationConfiguration) AbstractSecurityTest(org.apache.jackrabbit.oak.AbstractSecurityTest) Test(org.junit.Test)

Example 5 with SecurityProvider

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

the class SecurityProviderRegistrationTest method testActivateWithRequiredId.

@Test
public void testActivateWithRequiredId() {
    registration.activate(context.bundleContext(), requiredServiceIdMap("serviceId"));
    SecurityProvider service = context.getService(SecurityProvider.class);
    assertNull(service);
    registration.bindAuthorizableNodeName(Mockito.mock(AuthorizableNodeName.class), ImmutableMap.of(Constants.SERVICE_PID, "serviceId"));
    service = context.getService(SecurityProvider.class);
    assertNotNull(service);
}
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)

Aggregations

SecurityProvider (org.apache.jackrabbit.oak.spi.security.SecurityProvider)33 Test (org.junit.Test)19 AbstractSecurityTest (org.apache.jackrabbit.oak.AbstractSecurityTest)15 Root (org.apache.jackrabbit.oak.api.Root)8 Nonnull (javax.annotation.Nonnull)6 ConfigurationParameters (org.apache.jackrabbit.oak.spi.security.ConfigurationParameters)6 WhiteboardRestrictionProvider (org.apache.jackrabbit.oak.security.authorization.restriction.WhiteboardRestrictionProvider)5 AuthorizationConfiguration (org.apache.jackrabbit.oak.spi.security.authorization.AuthorizationConfiguration)5 RestrictionProvider (org.apache.jackrabbit.oak.spi.security.authorization.restriction.RestrictionProvider)5 UserConfiguration (org.apache.jackrabbit.oak.spi.security.user.UserConfiguration)5 AuthorizableActionProvider (org.apache.jackrabbit.oak.spi.security.user.action.AuthorizableActionProvider)5 CheckForNull (javax.annotation.CheckForNull)4 AuthorizationConfigurationImpl (org.apache.jackrabbit.oak.security.authorization.AuthorizationConfigurationImpl)4 IOException (java.io.IOException)3 HashMap (java.util.HashMap)3 SimpleCredentials (javax.jcr.SimpleCredentials)3 UnsupportedCallbackException (javax.security.auth.callback.UnsupportedCallbackException)3 UserManager (org.apache.jackrabbit.api.security.user.UserManager)3 ContentSession (org.apache.jackrabbit.oak.api.ContentSession)3 SecurityProviderImpl (org.apache.jackrabbit.oak.security.SecurityProviderImpl)3