Search in sources :

Example 11 with SecurityProvider

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

the class SecurityProviderRegistration method maybeRegister.

private void maybeRegister() {
    BundleContext context;
    log.info("Trying to register a SecurityProvider...");
    synchronized (this) {
        if (this.context == null) {
            log.info("Aborting: no BundleContext is available");
            return;
        }
        if (!preconditions.areSatisfied()) {
            log.info("Aborting: preconditions are not satisfied: {}", preconditions);
            return;
        }
        if (registration != null) {
            log.info("Aborting: a SecurityProvider is already registered");
            return;
        }
        if (registering) {
            log.info("Aborting: a SecurityProvider is already being registered");
            return;
        }
        // Mark the start of a registration process.
        registering = true;
        // Save the BundleContext for local usage.
        context = this.context;
    }
    // Register the SecurityProvider.
    Dictionary<String, Object> properties = new Hashtable<String, Object>();
    properties.put("type", "default");
    ServiceRegistration registration = context.registerService(SecurityProvider.class.getName(), createSecurityProvider(context), properties);
    synchronized (this) {
        this.registration = registration;
        this.registering = false;
    }
    log.info("SecurityProvider instance registered");
}
Also used : Hashtable(java.util.Hashtable) SecurityProvider(org.apache.jackrabbit.oak.spi.security.SecurityProvider) BundleContext(org.osgi.framework.BundleContext) ServiceRegistration(org.osgi.framework.ServiceRegistration)

Example 12 with SecurityProvider

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

the class SystemUserImplTest method getSecurityConfigParameters.

@Override
protected ConfigurationParameters getSecurityConfigParameters() {
    return ConfigurationParameters.of(UserConfiguration.NAME, ConfigurationParameters.of(UserConstants.PARAM_AUTHORIZABLE_ACTION_PROVIDER, new AuthorizableActionProvider() {

        @Nonnull
        @Override
        public List<? extends AuthorizableAction> getAuthorizableActions(@Nonnull SecurityProvider securityProvider) {
            AuthorizableAction action = new AccessControlAction();
            action.init(securityProvider, ConfigurationParameters.of(AccessControlAction.USER_PRIVILEGE_NAMES, new String[] { PrivilegeConstants.JCR_ALL }));
            return ImmutableList.of(action);
        }
    }));
}
Also used : AccessControlAction(org.apache.jackrabbit.oak.spi.security.user.action.AccessControlAction) Nonnull(javax.annotation.Nonnull) SecurityProvider(org.apache.jackrabbit.oak.spi.security.SecurityProvider) AuthorizableAction(org.apache.jackrabbit.oak.spi.security.user.action.AuthorizableAction) AuthorizableActionProvider(org.apache.jackrabbit.oak.spi.security.user.action.AuthorizableActionProvider)

Example 13 with SecurityProvider

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

the class WhiteboardAuthorizableActionProviderTest method testRegisteredImplementation.

@Test
public void testRegisteredImplementation() {
    actionProvider.start(whiteboard);
    AuthorizableActionProvider registered = new AuthorizableActionProvider() {

        @Nonnull
        @Override
        public List<? extends AuthorizableAction> getAuthorizableActions(@Nonnull SecurityProvider securityProvider) {
            return ImmutableList.of(new TestAction());
        }
    };
    whiteboard.register(AuthorizableActionProvider.class, registered, ImmutableMap.of());
    List<? extends AuthorizableAction> actions = actionProvider.getAuthorizableActions(Mockito.mock(SecurityProvider.class));
    assertNotNull(actions);
    assertEquals(1, actions.size());
    assertTrue(actions.get(0) instanceof TestAction);
}
Also used : Nonnull(javax.annotation.Nonnull) SecurityProvider(org.apache.jackrabbit.oak.spi.security.SecurityProvider) AuthorizableActionProvider(org.apache.jackrabbit.oak.spi.security.user.action.AuthorizableActionProvider) Test(org.junit.Test)

Example 14 with SecurityProvider

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

the class PasswordExpiryHistoryTest method getSecurityConfigParameters.

@Override
protected ConfigurationParameters getSecurityConfigParameters() {
    final PasswordValidationAction pwAction = new PasswordValidationAction();
    pwAction.init(null, ConfigurationParameters.of(PasswordValidationAction.CONSTRAINT, "^.*(?=.{4,}).*"));
    final AuthorizableActionProvider actionProvider = new AuthorizableActionProvider() {

        @Nonnull
        @Override
        public List<? extends AuthorizableAction> getAuthorizableActions(@Nonnull SecurityProvider securityProvider) {
            return ImmutableList.of(pwAction);
        }
    };
    ConfigurationParameters userConfig = ConfigurationParameters.of(ImmutableMap.of(UserConstants.PARAM_AUTHORIZABLE_ACTION_PROVIDER, actionProvider, UserConstants.PARAM_PASSWORD_MAX_AGE, 10, UserConstants.PARAM_PASSWORD_HISTORY_SIZE, 10));
    return ConfigurationParameters.of(UserConfiguration.NAME, userConfig);
}
Also used : PasswordValidationAction(org.apache.jackrabbit.oak.spi.security.user.action.PasswordValidationAction) Nonnull(javax.annotation.Nonnull) SecurityProvider(org.apache.jackrabbit.oak.spi.security.SecurityProvider) AuthorizableActionProvider(org.apache.jackrabbit.oak.spi.security.user.action.AuthorizableActionProvider) ConfigurationParameters(org.apache.jackrabbit.oak.spi.security.ConfigurationParameters)

Example 15 with SecurityProvider

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

the class DefaultAuthorizableActionProviderTest method getSecurityProvider.

private SecurityProvider getSecurityProvider() {
    AuthorizationConfiguration ac = Mockito.mock(AuthorizationConfiguration.class);
    when(ac.getParameters()).thenReturn(ConfigurationParameters.EMPTY);
    SecurityProvider sp = Mockito.mock(SecurityProvider.class);
    when(sp.getConfiguration(AuthorizationConfiguration.class)).thenReturn(ac);
    return sp;
}
Also used : AuthorizationConfiguration(org.apache.jackrabbit.oak.spi.security.authorization.AuthorizationConfiguration) SecurityProvider(org.apache.jackrabbit.oak.spi.security.SecurityProvider)

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