Search in sources :

Example 1 with PrincipalConfiguration

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

the class InternalSecurityProviderTest method testSetPrincipalConfiguration.

@Test
public void testSetPrincipalConfiguration() {
    PrincipalConfiguration pc = Mockito.mock(PrincipalConfiguration.class);
    when(pc.getParameters()).thenReturn(PARAMS);
    securityProvider.setPrincipalConfiguration(pc);
    assertSame(pc, securityProvider.getConfiguration(PrincipalConfiguration.class));
    for (SecurityConfiguration sc : securityProvider.getConfigurations()) {
        if (sc instanceof PrincipalConfiguration) {
            assertSame(pc, sc);
        }
    }
    assertTrue(Iterables.contains(securityProvider.getConfigurations(), pc));
    assertEquals(PARAMS, securityProvider.getParameters(PrincipalConfiguration.NAME));
}
Also used : PrincipalConfiguration(org.apache.jackrabbit.oak.spi.security.principal.PrincipalConfiguration) SecurityConfiguration(org.apache.jackrabbit.oak.spi.security.SecurityConfiguration) Test(org.junit.Test)

Example 2 with PrincipalConfiguration

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

the class CugImporter method init.

//----------------------------------------------< ProtectedItemImporter >---
@Override
public boolean init(@Nonnull Session session, @Nonnull Root root, @Nonnull NamePathMapper namePathMapper, boolean isWorkspaceImport, int uuidBehavior, @Nonnull ReferenceChangeTracker referenceTracker, @Nonnull SecurityProvider securityProvider) {
    if (initialized) {
        throw new IllegalStateException("Already initialized");
    }
    try {
        ConfigurationParameters config = securityProvider.getConfiguration(AuthorizationConfiguration.class).getParameters();
        supportedPaths = CugUtil.getSupportedPaths(config, mountInfoProvider);
        importBehavior = CugUtil.getImportBehavior(config);
        if (isWorkspaceImport) {
            PrincipalConfiguration pConfig = securityProvider.getConfiguration(PrincipalConfiguration.class);
            principalManager = pConfig.getPrincipalManager(root, namePathMapper);
        } else {
            principalManager = ((JackrabbitSession) session).getPrincipalManager();
        }
        initialized = true;
    } catch (RepositoryException e) {
        log.warn("Error while initializing cug importer", e);
    }
    return initialized;
}
Also used : AuthorizationConfiguration(org.apache.jackrabbit.oak.spi.security.authorization.AuthorizationConfiguration) PrincipalConfiguration(org.apache.jackrabbit.oak.spi.security.principal.PrincipalConfiguration) RepositoryException(javax.jcr.RepositoryException) ConfigurationParameters(org.apache.jackrabbit.oak.spi.security.ConfigurationParameters)

Example 3 with PrincipalConfiguration

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

the class AccessControlImporter method init.

//----------------------------------------------< ProtectedItemImporter >---
@Override
public boolean init(@Nonnull Session session, @Nonnull Root root, @Nonnull NamePathMapper namePathMapper, boolean isWorkspaceImport, int uuidBehavior, @Nonnull ReferenceChangeTracker referenceTracker, @Nonnull SecurityProvider securityProvider) {
    if (initialized) {
        throw new IllegalStateException("Already initialized");
    }
    if (!(session instanceof JackrabbitSession)) {
        return false;
    }
    try {
        AuthorizationConfiguration config = securityProvider.getConfiguration(AuthorizationConfiguration.class);
        importBehavior = Util.getImportBehavior(config);
        if (isWorkspaceImport) {
            acMgr = config.getAccessControlManager(root, namePathMapper);
            PrincipalConfiguration pConfig = securityProvider.getConfiguration(PrincipalConfiguration.class);
            principalManager = pConfig.getPrincipalManager(root, namePathMapper);
        } else {
            acMgr = session.getAccessControlManager();
            principalManager = ((JackrabbitSession) session).getPrincipalManager();
        }
        ntMgr = ReadOnlyNodeTypeManager.getInstance(root, namePathMapper);
        initialized = true;
    } catch (RepositoryException e) {
        log.warn("Error while initializing access control importer", e);
    }
    return initialized;
}
Also used : AuthorizationConfiguration(org.apache.jackrabbit.oak.spi.security.authorization.AuthorizationConfiguration) PrincipalConfiguration(org.apache.jackrabbit.oak.spi.security.principal.PrincipalConfiguration) RepositoryException(javax.jcr.RepositoryException) JackrabbitSession(org.apache.jackrabbit.api.JackrabbitSession)

Example 4 with PrincipalConfiguration

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

the class SecurityProviderImplTest method testBindPrincipalConfiguration.

@Test
public void testBindPrincipalConfiguration() {
    PrincipalConfiguration defaultConfig = securityProvider.getConfiguration(PrincipalConfiguration.class);
    assertTrue(defaultConfig instanceof CompositePrincipalConfiguration);
    CompositePrincipalConfiguration cpc = (CompositePrincipalConfiguration) defaultConfig;
    PrincipalConfiguration pc = Mockito.mock(PrincipalConfiguration.class);
    when(pc.getParameters()).thenReturn(ConfigurationParameters.EMPTY);
    securityProvider.bindPrincipalConfiguration(pc);
    assertNotSame(pc, securityProvider.getConfiguration(PrincipalConfiguration.class));
    assertSame(defaultConfig, securityProvider.getConfiguration(PrincipalConfiguration.class));
    for (SecurityConfiguration sc : securityProvider.getConfigurations()) {
        if (sc instanceof PrincipalConfiguration) {
            assertSame(defaultConfig, sc);
        }
    }
    assertTrue(cpc.getConfigurations().contains(pc));
}
Also used : CompositePrincipalConfiguration(org.apache.jackrabbit.oak.spi.security.principal.CompositePrincipalConfiguration) CompositePrincipalConfiguration(org.apache.jackrabbit.oak.spi.security.principal.CompositePrincipalConfiguration) PrincipalConfiguration(org.apache.jackrabbit.oak.spi.security.principal.PrincipalConfiguration) SecurityConfiguration(org.apache.jackrabbit.oak.spi.security.SecurityConfiguration) Test(org.junit.Test)

Example 5 with PrincipalConfiguration

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

Aggregations

PrincipalConfiguration (org.apache.jackrabbit.oak.spi.security.principal.PrincipalConfiguration)8 Test (org.junit.Test)5 CompositePrincipalConfiguration (org.apache.jackrabbit.oak.spi.security.principal.CompositePrincipalConfiguration)3 RepositoryException (javax.jcr.RepositoryException)2 SecurityConfiguration (org.apache.jackrabbit.oak.spi.security.SecurityConfiguration)2 AuthorizationConfiguration (org.apache.jackrabbit.oak.spi.security.authorization.AuthorizationConfiguration)2 IOException (java.io.IOException)1 Field (java.lang.reflect.Field)1 CheckForNull (javax.annotation.CheckForNull)1 UnsupportedCallbackException (javax.security.auth.callback.UnsupportedCallbackException)1 JackrabbitSession (org.apache.jackrabbit.api.JackrabbitSession)1 AbstractSecurityTest (org.apache.jackrabbit.oak.AbstractSecurityTest)1 Root (org.apache.jackrabbit.oak.api.Root)1 Tree (org.apache.jackrabbit.oak.api.Tree)1 PrincipalConfigurationImpl (org.apache.jackrabbit.oak.security.principal.PrincipalConfigurationImpl)1 ConfigurationParameters (org.apache.jackrabbit.oak.spi.security.ConfigurationParameters)1 Context (org.apache.jackrabbit.oak.spi.security.Context)1 SecurityProvider (org.apache.jackrabbit.oak.spi.security.SecurityProvider)1 PrincipalProviderCallback (org.apache.jackrabbit.oak.spi.security.authentication.callback.PrincipalProviderCallback)1 PrincipalProvider (org.apache.jackrabbit.oak.spi.security.principal.PrincipalProvider)1