Search in sources :

Example 1 with CredentialsSupport

use of org.apache.jackrabbit.oak.spi.security.authentication.credentials.CredentialsSupport in project jackrabbit-oak by apache.

the class ExternalLoginModule method initialize.

//--------------------------------------------------------< LoginModule >---
@Override
public void initialize(Subject subject, CallbackHandler callbackHandler, Map<String, ?> sharedState, Map<String, ?> opts) {
    super.initialize(subject, callbackHandler, sharedState, opts);
    // merge options with osgi options if needed
    if (osgiConfig != null) {
        options = ConfigurationParameters.of(osgiConfig, options);
    }
    Whiteboard whiteboard = getWhiteboard();
    if (whiteboard == null) {
        log.error("External login module needs whiteboard. Will not be used for login.");
        return;
    }
    String idpName = options.getConfigValue(PARAM_IDP_NAME, "");
    if (idpName.isEmpty()) {
        log.error("External login module needs IPD name. Will not be used for login.");
    } else {
        if (idpManager == null) {
            idpManager = WhiteboardUtils.getService(whiteboard, ExternalIdentityProviderManager.class);
        }
        if (idpManager == null) {
            log.error("External login module needs IDPManager. Will not be used for login.");
        } else {
            idp = idpManager.getProvider(idpName);
            if (idp == null) {
                log.error("No IDP found with name {}. Will not be used for login.", idpName);
            }
        }
    }
    String syncHandlerName = options.getConfigValue(PARAM_SYNC_HANDLER_NAME, "");
    if (syncHandlerName.isEmpty()) {
        log.error("External login module needs SyncHandler name. Will not be used for login.");
    } else {
        if (syncManager == null) {
            syncManager = WhiteboardUtils.getService(whiteboard, SyncManager.class);
        }
        if (syncManager == null) {
            log.error("External login module needs SyncManager. Will not be used for login.");
        } else {
            syncHandler = syncManager.getSyncHandler(syncHandlerName);
            if (syncHandler == null) {
                log.error("No SyncHandler found with name {}. Will not be used for login.", syncHandlerName);
            }
        }
    }
    if (idp instanceof CredentialsSupport) {
        credentialsSupport = (CredentialsSupport) idp;
    } else {
        log.debug("No 'SupportedCredentials' configured. Using default implementation supporting 'SimpleCredentials'.");
    }
}
Also used : SimpleCredentialsSupport(org.apache.jackrabbit.oak.spi.security.authentication.credentials.SimpleCredentialsSupport) CredentialsSupport(org.apache.jackrabbit.oak.spi.security.authentication.credentials.CredentialsSupport) SyncManager(org.apache.jackrabbit.oak.spi.security.authentication.external.SyncManager) ExternalIdentityProviderManager(org.apache.jackrabbit.oak.spi.security.authentication.external.ExternalIdentityProviderManager) Whiteboard(org.apache.jackrabbit.oak.spi.whiteboard.Whiteboard)

Example 2 with CredentialsSupport

use of org.apache.jackrabbit.oak.spi.security.authentication.credentials.CredentialsSupport in project jackrabbit-oak by apache.

the class TokenConfigurationImplOSGiTest method testUnbindCredentialsSupport.

@Test
public void testUnbindCredentialsSupport() {
    CredentialsSupport testSupport = new TestCredentialsSupport(sc.getUserID());
    ServiceRegistration registration = context.bundleContext().registerService(CredentialsSupport.class.getName(), testSupport, new Hashtable());
    TokenProvider tp = tokenConfiguration.getTokenProvider(root);
    assertFalse(tp.doCreateToken(sc));
    assertTrue(tp.doCreateToken(new TestCredentialsSupport.Creds()));
    registration.unregister();
    tp = tokenConfiguration.getTokenProvider(root);
    assertTrue(tp.doCreateToken(sc));
    assertFalse(tp.doCreateToken(new TestCredentialsSupport.Creds()));
}
Also used : CredentialsSupport(org.apache.jackrabbit.oak.spi.security.authentication.credentials.CredentialsSupport) TokenProvider(org.apache.jackrabbit.oak.spi.security.authentication.token.TokenProvider) Hashtable(java.util.Hashtable) ServiceRegistration(org.osgi.framework.ServiceRegistration) AbstractSecurityTest(org.apache.jackrabbit.oak.AbstractSecurityTest) Test(org.junit.Test)

Aggregations

CredentialsSupport (org.apache.jackrabbit.oak.spi.security.authentication.credentials.CredentialsSupport)2 Hashtable (java.util.Hashtable)1 AbstractSecurityTest (org.apache.jackrabbit.oak.AbstractSecurityTest)1 SimpleCredentialsSupport (org.apache.jackrabbit.oak.spi.security.authentication.credentials.SimpleCredentialsSupport)1 ExternalIdentityProviderManager (org.apache.jackrabbit.oak.spi.security.authentication.external.ExternalIdentityProviderManager)1 SyncManager (org.apache.jackrabbit.oak.spi.security.authentication.external.SyncManager)1 TokenProvider (org.apache.jackrabbit.oak.spi.security.authentication.token.TokenProvider)1 Whiteboard (org.apache.jackrabbit.oak.spi.whiteboard.Whiteboard)1 Test (org.junit.Test)1 ServiceRegistration (org.osgi.framework.ServiceRegistration)1