Search in sources :

Example 26 with SecurityProvider

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

the class SecurityProviderRegistrationTest method testModifiedPreconditionStillSatisfied.

@Test
public void testModifiedPreconditionStillSatisfied() {
    registration.activate(context.bundleContext(), requiredServiceIdMap("rpId", "authorizationId"));
    RestrictionProvider mockRp = Mockito.mock(RestrictionProvider.class);
    registration.bindRestrictionProvider(mockRp, ImmutableMap.of(Constants.SERVICE_PID, "rpId"));
    registration.bindAuthorizationConfiguration(new AuthorizationConfigurationImpl(), ImmutableMap.of(Constants.SERVICE_PID, "authorizationId"));
    SecurityProvider service = context.getService(SecurityProvider.class);
    assertNotNull(service);
    registration.modified(requiredServiceIdMap("authorizationId"));
    SecurityProvider service2 = context.getService(SecurityProvider.class);
    assertSame(service, service2);
}
Also used : RestrictionProvider(org.apache.jackrabbit.oak.spi.security.authorization.restriction.RestrictionProvider) WhiteboardRestrictionProvider(org.apache.jackrabbit.oak.security.authorization.restriction.WhiteboardRestrictionProvider) AuthorizationConfigurationImpl(org.apache.jackrabbit.oak.security.authorization.AuthorizationConfigurationImpl) SecurityProvider(org.apache.jackrabbit.oak.spi.security.SecurityProvider) AbstractSecurityTest(org.apache.jackrabbit.oak.AbstractSecurityTest) Test(org.junit.Test)

Example 27 with SecurityProvider

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

the class SecurityProviderRegistrationTest method testBindRestrictionProviderWithAuthorizationConfig.

@Test
public void testBindRestrictionProviderWithAuthorizationConfig() {
    registration.activate(context.bundleContext(), requiredServiceIdMap("rpId", "authorizationId"));
    RestrictionProvider mockRp = Mockito.mock(RestrictionProvider.class);
    registration.bindRestrictionProvider(mockRp, ImmutableMap.of(Constants.SERVICE_PID, "rpId"));
    registration.bindAuthorizationConfiguration(new AuthorizationConfigurationImpl(), ImmutableMap.of(Constants.SERVICE_PID, "authorizationId"));
    SecurityProvider service = context.getService(SecurityProvider.class);
    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) RestrictionProvider(org.apache.jackrabbit.oak.spi.security.authorization.restriction.RestrictionProvider) WhiteboardRestrictionProvider(org.apache.jackrabbit.oak.security.authorization.restriction.WhiteboardRestrictionProvider) AuthorizationConfigurationImpl(org.apache.jackrabbit.oak.security.authorization.AuthorizationConfigurationImpl) SecurityProvider(org.apache.jackrabbit.oak.spi.security.SecurityProvider) AbstractSecurityTest(org.apache.jackrabbit.oak.AbstractSecurityTest) Test(org.junit.Test)

Example 28 with SecurityProvider

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

the class SecurityProviderRegistrationTest method testActivateWithoutPreconditions.

@Test
public void testActivateWithoutPreconditions() {
    registration.activate(context.bundleContext(), requiredServiceIdMap());
    SecurityProvider service = context.getService(SecurityProvider.class);
    assertNotNull(service);
    assertEquals(3, Iterables.size(Iterables.filter(service.getConfigurations(), Predicates.notNull())));
}
Also used : SecurityProvider(org.apache.jackrabbit.oak.spi.security.SecurityProvider) AbstractSecurityTest(org.apache.jackrabbit.oak.AbstractSecurityTest) Test(org.junit.Test)

Example 29 with SecurityProvider

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

the class PrincipalConfigurationImplTest method testGetPrincipalProvider4.

@Test
public void testGetPrincipalProvider4() {
    PrincipalConfigurationImpl pc3 = new PrincipalConfigurationImpl();
    final SecurityProvider sp = new SecurityProvider() {

        @Nonnull
        @Override
        public ConfigurationParameters getParameters(@Nullable String name) {
            return ConfigurationParameters.EMPTY;
        }

        @Nonnull
        @Override
        public Iterable<? extends SecurityConfiguration> getConfigurations() {
            return ImmutableList.of();
        }

        @Nonnull
        @Override
        public <T> T getConfiguration(@Nonnull Class<T> configClass) {
            if (configClass.equals(UserConfiguration.class)) {
                return (T) new UserConfigurationImpl(this) {

                    @Nullable
                    @Override
                    public PrincipalProvider getUserPrincipalProvider(@Nonnull Root root, @Nonnull NamePathMapper namePathMapper) {
                        return null;
                    }
                };
            } else {
                throw new IllegalArgumentException();
            }
        }
    };
    pc3.setSecurityProvider(sp);
    PrincipalProvider pp = pc3.getPrincipalProvider(root, NamePathMapper.DEFAULT);
    assertTrue(pp instanceof PrincipalProviderImpl);
}
Also used : PrincipalProvider(org.apache.jackrabbit.oak.spi.security.principal.PrincipalProvider) Root(org.apache.jackrabbit.oak.api.Root) Nonnull(javax.annotation.Nonnull) NamePathMapper(org.apache.jackrabbit.oak.namepath.NamePathMapper) SecurityProvider(org.apache.jackrabbit.oak.spi.security.SecurityProvider) UserConfigurationImpl(org.apache.jackrabbit.oak.security.user.UserConfigurationImpl) Nullable(javax.annotation.Nullable) AbstractSecurityTest(org.apache.jackrabbit.oak.AbstractSecurityTest) Test(org.junit.Test)

Example 30 with SecurityProvider

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

the class UserInitializerTest method testAdminConfiguration.

/**
     * @since OAK 1.0 The configuration defines if the password of the
     * admin user is being set.
     */
@Test
public void testAdminConfiguration() throws Exception {
    Map<String, Object> userParams = new HashMap();
    userParams.put(UserConstants.PARAM_ADMIN_ID, "admin");
    userParams.put(UserConstants.PARAM_OMIT_ADMIN_PW, true);
    ConfigurationParameters params = ConfigurationParameters.of(UserConfiguration.NAME, ConfigurationParameters.of(userParams));
    SecurityProvider sp = new SecurityProviderImpl(params);
    final ContentRepository repo = new Oak().with(new InitialContent()).with(new PropertyIndexEditorProvider()).with(new PropertyIndexProvider()).with(new TypeEditorProvider()).with(sp).createContentRepository();
    ContentSession cs = Subject.doAs(SystemSubject.INSTANCE, new PrivilegedExceptionAction<ContentSession>() {

        @Override
        public ContentSession run() throws Exception {
            return repo.login(null, null);
        }
    });
    try {
        Root root = cs.getLatestRoot();
        UserConfiguration uc = sp.getConfiguration(UserConfiguration.class);
        UserManager umgr = uc.getUserManager(root, NamePathMapper.DEFAULT);
        Authorizable adminUser = umgr.getAuthorizable("admin");
        assertNotNull(adminUser);
        Tree adminTree = root.getTree(adminUser.getPath());
        assertTrue(adminTree.exists());
        assertNull(adminTree.getProperty(UserConstants.REP_PASSWORD));
    } finally {
        cs.close();
    }
    // login as admin should fail
    ContentSession adminSession = null;
    try {
        adminSession = repo.login(new SimpleCredentials("admin", new char[0]), null);
        fail();
    } catch (LoginException e) {
    //success
    } finally {
        if (adminSession != null) {
            adminSession.close();
        }
    }
}
Also used : Root(org.apache.jackrabbit.oak.api.Root) HashMap(java.util.HashMap) PropertyIndexEditorProvider(org.apache.jackrabbit.oak.plugins.index.property.PropertyIndexEditorProvider) ConfigurationParameters(org.apache.jackrabbit.oak.spi.security.ConfigurationParameters) LoginException(javax.security.auth.login.LoginException) InitialContent(org.apache.jackrabbit.oak.InitialContent) PropertyIndexProvider(org.apache.jackrabbit.oak.plugins.index.property.PropertyIndexProvider) SimpleCredentials(javax.jcr.SimpleCredentials) TypeEditorProvider(org.apache.jackrabbit.oak.plugins.nodetype.TypeEditorProvider) UserManager(org.apache.jackrabbit.api.security.user.UserManager) SecurityProvider(org.apache.jackrabbit.oak.spi.security.SecurityProvider) ContentRepository(org.apache.jackrabbit.oak.api.ContentRepository) Oak(org.apache.jackrabbit.oak.Oak) ContentSession(org.apache.jackrabbit.oak.api.ContentSession) Authorizable(org.apache.jackrabbit.api.security.user.Authorizable) Tree(org.apache.jackrabbit.oak.api.Tree) LoginException(javax.security.auth.login.LoginException) SecurityProviderImpl(org.apache.jackrabbit.oak.security.SecurityProviderImpl) UserConfiguration(org.apache.jackrabbit.oak.spi.security.user.UserConfiguration) 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