Search in sources :

Example 1 with UserAuthenticationFactory

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

the class LoginModuleImpl method getUserAuthentication.

@CheckForNull
private Authentication getUserAuthentication(@Nullable String loginName) {
    SecurityProvider securityProvider = getSecurityProvider();
    Root root = getRoot();
    if (securityProvider != null && root != null) {
        UserConfiguration uc = securityProvider.getConfiguration(UserConfiguration.class);
        UserAuthenticationFactory factory = uc.getParameters().getConfigValue(UserConstants.PARAM_USER_AUTHENTICATION_FACTORY, null, UserAuthenticationFactory.class);
        if (factory != null) {
            return factory.getAuthentication(uc, root, loginName);
        } else {
            log.error("No user authentication factory configured in user configuration.");
        }
    }
    return null;
}
Also used : Root(org.apache.jackrabbit.oak.api.Root) UserAuthenticationFactory(org.apache.jackrabbit.oak.spi.security.user.UserAuthenticationFactory) SecurityProvider(org.apache.jackrabbit.oak.spi.security.SecurityProvider) UserConfiguration(org.apache.jackrabbit.oak.spi.security.user.UserConfiguration) CheckForNull(javax.annotation.CheckForNull)

Example 2 with UserAuthenticationFactory

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

the class SecurityProviderRegistrationTest method testUnbindOptionalCandidateAfterRegistration.

@Test
public void testUnbindOptionalCandidateAfterRegistration() {
    registration.activate(context.bundleContext(), configWithRequiredServiceIds("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 3 with UserAuthenticationFactory

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

the class SecurityProviderBuilder method with.

public SecurityProviderBuilder with(@Nonnull ConfigurationParameters configuration) {
    authenticationParams = configuration.getConfigValue(AuthenticationConfiguration.NAME, EMPTY);
    privilegeParams = configuration.getConfigValue(PrivilegeConfiguration.NAME, EMPTY);
    if (configuration.contains(UserConfiguration.NAME)) {
        userParams = configuration.getConfigValue(UserConfiguration.NAME, EMPTY);
    } else {
        AuthorizableActionProvider authorizableActionProvider = new DefaultAuthorizableActionProvider();
        AuthorizableNodeName authorizableNodeName = AuthorizableNodeName.DEFAULT;
        UserAuthenticationFactory userAuthenticationFactory = UserConfigurationImpl.getDefaultAuthenticationFactory();
        userParams = ConfigurationParameters.of(ConfigurationParameters.of(UserConstants.PARAM_AUTHORIZABLE_ACTION_PROVIDER, authorizableActionProvider), ConfigurationParameters.of(UserConstants.PARAM_AUTHORIZABLE_NODE_NAME, authorizableNodeName), ConfigurationParameters.of(UserConstants.PARAM_USER_AUTHENTICATION_FACTORY, userAuthenticationFactory));
    }
    if (configuration.contains(AuthorizationConfiguration.NAME)) {
        authorizationParams = configuration.getConfigValue(AuthorizationConfiguration.NAME, EMPTY);
    } else {
        RestrictionProvider restrictionProvider = new RestrictionProviderImpl();
        authorizationParams = ConfigurationParameters.of(AccessControlConstants.PARAM_RESTRICTION_PROVIDER, restrictionProvider);
    }
    principalParams = configuration.getConfigValue(PrincipalConfiguration.NAME, EMPTY);
    tokenParams = configuration.getConfigValue(TokenConfiguration.NAME, EMPTY);
    return this;
}
Also used : UserAuthenticationFactory(org.apache.jackrabbit.oak.spi.security.user.UserAuthenticationFactory) RestrictionProvider(org.apache.jackrabbit.oak.spi.security.authorization.restriction.RestrictionProvider) DefaultAuthorizableActionProvider(org.apache.jackrabbit.oak.spi.security.user.action.DefaultAuthorizableActionProvider) AuthorizableActionProvider(org.apache.jackrabbit.oak.spi.security.user.action.AuthorizableActionProvider) DefaultAuthorizableActionProvider(org.apache.jackrabbit.oak.spi.security.user.action.DefaultAuthorizableActionProvider) AuthorizableNodeName(org.apache.jackrabbit.oak.spi.security.user.AuthorizableNodeName) RestrictionProviderImpl(org.apache.jackrabbit.oak.security.authorization.restriction.RestrictionProviderImpl)

Example 4 with UserAuthenticationFactory

use of org.apache.jackrabbit.oak.spi.security.user.UserAuthenticationFactory 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 5 with UserAuthenticationFactory

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

the class SecurityProviderRegistrationTest method testDeactivateWithoutPreconditions.

@Test
public void testDeactivateWithoutPreconditions() throws Exception {
    registration.activate(context.bundleContext(), configWithRequiredServiceIds());
    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)

Aggregations

UserAuthenticationFactory (org.apache.jackrabbit.oak.spi.security.user.UserAuthenticationFactory)5 AbstractSecurityTest (org.apache.jackrabbit.oak.AbstractSecurityTest)3 SecurityProvider (org.apache.jackrabbit.oak.spi.security.SecurityProvider)3 Test (org.junit.Test)3 Root (org.apache.jackrabbit.oak.api.Root)2 UserConfiguration (org.apache.jackrabbit.oak.spi.security.user.UserConfiguration)2 AuthorizableActionProvider (org.apache.jackrabbit.oak.spi.security.user.action.AuthorizableActionProvider)2 CheckForNull (javax.annotation.CheckForNull)1 Nonnull (javax.annotation.Nonnull)1 Nullable (javax.annotation.Nullable)1 Credentials (javax.jcr.Credentials)1 GuestCredentials (javax.jcr.GuestCredentials)1 SimpleCredentials (javax.jcr.SimpleCredentials)1 Subject (javax.security.auth.Subject)1 CallbackHandler (javax.security.auth.callback.CallbackHandler)1 AuthInfo (org.apache.jackrabbit.oak.api.AuthInfo)1 RestrictionProviderImpl (org.apache.jackrabbit.oak.security.authorization.restriction.RestrictionProviderImpl)1 Authentication (org.apache.jackrabbit.oak.spi.security.authentication.Authentication)1 ImpersonationCredentials (org.apache.jackrabbit.oak.spi.security.authentication.ImpersonationCredentials)1 RestrictionProvider (org.apache.jackrabbit.oak.spi.security.authorization.restriction.RestrictionProvider)1