Search in sources :

Example 11 with UserConfiguration

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

the class SecurityProviderImplTest method testBindUserConfiguration.

@Test
public void testBindUserConfiguration() {
    UserConfiguration uc = Mockito.mock(UserConfiguration.class);
    securityProvider.bindUserConfiguration(uc);
    assertSame(uc, securityProvider.getConfiguration(UserConfiguration.class));
    for (SecurityConfiguration sc : securityProvider.getConfigurations()) {
        if (sc instanceof UserConfiguration) {
            assertSame(uc, sc);
        }
    }
}
Also used : SecurityConfiguration(org.apache.jackrabbit.oak.spi.security.SecurityConfiguration) UserConfiguration(org.apache.jackrabbit.oak.spi.security.user.UserConfiguration) Test(org.junit.Test)

Example 12 with UserConfiguration

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

the class LoginModuleImplTest method testCustomUserAuthentication.

@Test
public void testCustomUserAuthentication() throws Exception {
    LoginModuleImpl loginModule = new LoginModuleImpl();
    UserAuthenticationFactory factory = new UserAuthenticationFactory() {

        @CheckForNull
        @Override
        public Authentication getAuthentication(@Nonnull UserConfiguration configuration, @Nonnull Root root, @Nullable String userId) {
            return new Authentication() {

                @Override
                public boolean authenticate(@Nullable Credentials credentials) throws LoginException {
                    return true;
                }

                @CheckForNull
                @Override
                public String getUserId() {
                    return null;
                }

                @CheckForNull
                @Override
                public Principal getUserPrincipal() {
                    return null;
                }
            };
        }
    };
    CallbackHandler cbh = new TestCallbackHandler(factory);
    SimpleCredentials creds = new SimpleCredentials("loginId", new char[0]);
    Subject subject = new Subject(false, Sets.<Principal>newHashSet(), ImmutableSet.of(creds), Sets.newHashSet());
    loginModule.initialize(subject, cbh, Maps.<String, Object>newHashMap(), Maps.<String, Object>newHashMap());
    assertTrue(loginModule.login());
    assertTrue(loginModule.commit());
    AuthInfo authInfo = subject.getPublicCredentials(AuthInfo.class).iterator().next();
    assertEquals("loginId", authInfo.getUserID());
}
Also used : CallbackHandler(javax.security.auth.callback.CallbackHandler) AuthInfo(org.apache.jackrabbit.oak.api.AuthInfo) UserAuthenticationFactory(org.apache.jackrabbit.oak.spi.security.user.UserAuthenticationFactory) Root(org.apache.jackrabbit.oak.api.Root) Nonnull(javax.annotation.Nonnull) Subject(javax.security.auth.Subject) SimpleCredentials(javax.jcr.SimpleCredentials) Authentication(org.apache.jackrabbit.oak.spi.security.authentication.Authentication) Nullable(javax.annotation.Nullable) GuestCredentials(javax.jcr.GuestCredentials) ImpersonationCredentials(org.apache.jackrabbit.oak.spi.security.authentication.ImpersonationCredentials) SimpleCredentials(javax.jcr.SimpleCredentials) Credentials(javax.jcr.Credentials) UserConfiguration(org.apache.jackrabbit.oak.spi.security.user.UserConfiguration) AbstractSecurityTest(org.apache.jackrabbit.oak.AbstractSecurityTest) Test(org.junit.Test)

Example 13 with UserConfiguration

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

the class InternalSecurityProviderTest method testSetUserConfiguration.

@Test
public void testSetUserConfiguration() {
    UserConfiguration uc = Mockito.mock(UserConfiguration.class);
    when(uc.getParameters()).thenReturn(PARAMS);
    securityProvider.setUserConfiguration(uc);
    assertSame(uc, securityProvider.getConfiguration(UserConfiguration.class));
    for (SecurityConfiguration sc : securityProvider.getConfigurations()) {
        if (sc instanceof UserConfiguration) {
            assertSame(uc, sc);
        }
    }
    assertEquals(PARAMS, securityProvider.getParameters(UserConfiguration.NAME));
}
Also used : SecurityConfiguration(org.apache.jackrabbit.oak.spi.security.SecurityConfiguration) UserConfiguration(org.apache.jackrabbit.oak.spi.security.user.UserConfiguration) Test(org.junit.Test)

Example 14 with UserConfiguration

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

Example 15 with UserConfiguration

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

the class UserPrincipalProviderWithCacheTest method changeUserConfiguration.

private UserConfiguration changeUserConfiguration(ConfigurationParameters params) {
    UserConfiguration userConfig = getUserConfiguration();
    ((ConfigurationBase) userConfig).setParameters(params);
    return userConfig;
}
Also used : ConfigurationBase(org.apache.jackrabbit.oak.spi.security.ConfigurationBase) UserConfiguration(org.apache.jackrabbit.oak.spi.security.user.UserConfiguration)

Aggregations

UserConfiguration (org.apache.jackrabbit.oak.spi.security.user.UserConfiguration)15 Root (org.apache.jackrabbit.oak.api.Root)7 Test (org.junit.Test)7 UserManager (org.apache.jackrabbit.api.security.user.UserManager)4 AbstractSecurityTest (org.apache.jackrabbit.oak.AbstractSecurityTest)4 SecurityProvider (org.apache.jackrabbit.oak.spi.security.SecurityProvider)4 InitialContent (org.apache.jackrabbit.oak.InitialContent)3 PropertyIndexEditorProvider (org.apache.jackrabbit.oak.plugins.index.property.PropertyIndexEditorProvider)3 PropertyIndexProvider (org.apache.jackrabbit.oak.plugins.index.property.PropertyIndexProvider)3 TypeEditorProvider (org.apache.jackrabbit.oak.plugins.nodetype.TypeEditorProvider)3 SecurityProviderImpl (org.apache.jackrabbit.oak.security.SecurityProviderImpl)3 SecurityConfiguration (org.apache.jackrabbit.oak.spi.security.SecurityConfiguration)3 IOException (java.io.IOException)2 HashMap (java.util.HashMap)2 CheckForNull (javax.annotation.CheckForNull)2 Nonnull (javax.annotation.Nonnull)2 GuestCredentials (javax.jcr.GuestCredentials)2 RepositoryException (javax.jcr.RepositoryException)2 SimpleCredentials (javax.jcr.SimpleCredentials)2 LoginException (javax.security.auth.login.LoginException)2