Search in sources :

Example 21 with SecurityProvider

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

the class AbstractLoginModule method getPrincipalProvider.

/**
     * Retrieves the {@link PrincipalProvider} that should be used to handle
     * this authentication. If no principal provider has been configure this
     * method returns {@code null}.
     *
     * @return A instance of {@code PrincipalProvider} or {@code null}.
     */
@CheckForNull
protected PrincipalProvider getPrincipalProvider() {
    PrincipalProvider principalProvider = null;
    SecurityProvider sp = getSecurityProvider();
    Root r = getRoot();
    if (r != null && sp != null) {
        PrincipalConfiguration pc = sp.getConfiguration(PrincipalConfiguration.class);
        principalProvider = pc.getPrincipalProvider(r, NamePathMapper.DEFAULT);
    }
    if (principalProvider == null && callbackHandler != null) {
        try {
            PrincipalProviderCallback principalCallBack = new PrincipalProviderCallback();
            callbackHandler.handle(new Callback[] { principalCallBack });
            principalProvider = principalCallBack.getPrincipalProvider();
        } catch (IOException | UnsupportedCallbackException e) {
            log.debug(e.getMessage());
        }
    }
    return principalProvider;
}
Also used : PrincipalProvider(org.apache.jackrabbit.oak.spi.security.principal.PrincipalProvider) Root(org.apache.jackrabbit.oak.api.Root) PrincipalConfiguration(org.apache.jackrabbit.oak.spi.security.principal.PrincipalConfiguration) PrincipalProviderCallback(org.apache.jackrabbit.oak.spi.security.authentication.callback.PrincipalProviderCallback) SecurityProvider(org.apache.jackrabbit.oak.spi.security.SecurityProvider) IOException(java.io.IOException) UnsupportedCallbackException(javax.security.auth.callback.UnsupportedCallbackException) CheckForNull(javax.annotation.CheckForNull)

Example 22 with SecurityProvider

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

the class MutableRootTest method before.

@Before
public void before() {
    SecurityProvider sp = new OpenSecurityProvider() {

        @Nonnull
        @Override
        public <T> T getConfiguration(@Nonnull Class<T> configClass) {
            if (AuthorizationConfiguration.class == configClass) {
                return (T) new OpenAuthorizationConfiguration() {

                    @Nonnull
                    @Override
                    public PermissionProvider getPermissionProvider(@Nonnull Root root, @Nonnull String workspaceName, @Nonnull Set<Principal> principals) {
                        return permissionProvider;
                    }
                };
            } else {
                return super.getConfiguration(configClass);
            }
        }
    };
    ContentSessionImpl cs = Mockito.mock(ContentSessionImpl.class);
    when(cs.toString()).thenReturn("contentSession");
    when(cs.getAuthInfo()).thenReturn(AuthInfoImpl.EMPTY);
    when(cs.getWorkspaceName()).thenReturn("default");
    root = new MutableRoot(store, new EmptyHook(), "default", new Subject(), sp, null, null, cs);
}
Also used : Root(org.apache.jackrabbit.oak.api.Root) Nonnull(javax.annotation.Nonnull) PermissionProvider(org.apache.jackrabbit.oak.spi.security.authorization.permission.PermissionProvider) OpenSecurityProvider(org.apache.jackrabbit.oak.spi.security.OpenSecurityProvider) Subject(javax.security.auth.Subject) OpenAuthorizationConfiguration(org.apache.jackrabbit.oak.spi.security.authorization.OpenAuthorizationConfiguration) SecurityProvider(org.apache.jackrabbit.oak.spi.security.SecurityProvider) OpenSecurityProvider(org.apache.jackrabbit.oak.spi.security.OpenSecurityProvider) EmptyHook(org.apache.jackrabbit.oak.spi.commit.EmptyHook) Principal(java.security.Principal) Before(org.junit.Before)

Example 23 with SecurityProvider

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

the class AuthenticationConfigurationImplTest method testGetLoginCtxProviderWhiteboard.

@Test
public void testGetLoginCtxProviderWhiteboard() {
    SecurityProvider sp = Mockito.mock(SecurityProvider.class, Mockito.withSettings().extraInterfaces(WhiteboardAware.class));
    when(((WhiteboardAware) sp).getWhiteboard()).thenReturn(new DefaultWhiteboard());
    authConfiguration.setSecurityProvider(sp);
    assertNotNull(authConfiguration.getLoginContextProvider(repo));
}
Also used : WhiteboardAware(org.apache.jackrabbit.oak.spi.whiteboard.WhiteboardAware) DefaultWhiteboard(org.apache.jackrabbit.oak.spi.whiteboard.DefaultWhiteboard) SecurityProvider(org.apache.jackrabbit.oak.spi.security.SecurityProvider) Test(org.junit.Test)

Example 24 with SecurityProvider

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

the class SecurityProviderRegistrationTest method testDeactivateWithoutPreconditions.

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

Example 25 with SecurityProvider

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

the class SecurityProviderRegistrationTest method testModified.

@Test
public void testModified() {
    registration.activate(context.bundleContext(), requiredServiceIdMap("rpId", "authorizationId"));
    registration.bindAuthorizationConfiguration(new AuthorizationConfigurationImpl(), ImmutableMap.of(Constants.SERVICE_PID, "authorizationId"));
    assertNull(context.getService(SecurityProvider.class));
    // modify requiredServiceIds by removing the rpId from the mandatory services
    // => should re-register the security provider
    registration.modified(requiredServiceIdMap("authorizationId"));
    SecurityProvider service = context.getService(SecurityProvider.class);
    assertNotNull(service);
    RestrictionProvider rp = service.getConfiguration(AuthorizationConfiguration.class).getRestrictionProvider();
    assertTrue(rp instanceof WhiteboardRestrictionProvider);
}
Also used : WhiteboardRestrictionProvider(org.apache.jackrabbit.oak.security.authorization.restriction.WhiteboardRestrictionProvider) CompositeAuthorizationConfiguration(org.apache.jackrabbit.oak.security.authorization.composite.CompositeAuthorizationConfiguration) AuthorizationConfiguration(org.apache.jackrabbit.oak.spi.security.authorization.AuthorizationConfiguration) AuthorizationConfigurationImpl(org.apache.jackrabbit.oak.security.authorization.AuthorizationConfigurationImpl) 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) 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