Search in sources :

Example 1 with RepositoryCallback

use of org.apache.jackrabbit.oak.spi.security.authentication.callback.RepositoryCallback in project jackrabbit-oak by apache.

the class AbstractLoginModule method getRoot.

/**
     * Tries to obtain a {@code Root} object from the callback handler using
     * a new RepositoryCallback and keeps the value as private field.
     * If the callback handler isn't able to handle the RepositoryCallback
     * this method returns {@code null}.
     *
     * @return The {@code Root} associated with this {@code LoginModule} or
     *         {@code null}.
     */
@CheckForNull
protected Root getRoot() {
    if (root == null && callbackHandler != null) {
        try {
            final RepositoryCallback rcb = new RepositoryCallback();
            callbackHandler.handle(new Callback[] { rcb });
            final ContentRepository repository = rcb.getContentRepository();
            if (repository != null) {
                systemSession = Subject.doAs(SystemSubject.INSTANCE, new PrivilegedExceptionAction<ContentSession>() {

                    @Override
                    public ContentSession run() throws LoginException, NoSuchWorkspaceException {
                        return repository.login(null, rcb.getWorkspaceName());
                    }
                });
                root = systemSession.getLatestRoot();
            } else {
                log.debug("Unable to retrieve the Root via RepositoryCallback; ContentRepository not available.");
            }
        } catch (UnsupportedCallbackException | PrivilegedActionException | IOException e) {
            log.debug(e.getMessage());
        }
    }
    return root;
}
Also used : RepositoryCallback(org.apache.jackrabbit.oak.spi.security.authentication.callback.RepositoryCallback) PrivilegedActionException(java.security.PrivilegedActionException) ContentRepository(org.apache.jackrabbit.oak.api.ContentRepository) PrivilegedExceptionAction(java.security.PrivilegedExceptionAction) UnsupportedCallbackException(javax.security.auth.callback.UnsupportedCallbackException) IOException(java.io.IOException) CheckForNull(javax.annotation.CheckForNull)

Example 2 with RepositoryCallback

use of org.apache.jackrabbit.oak.spi.security.authentication.callback.RepositoryCallback in project jackrabbit-oak by apache.

the class AbstractLoginModule method getSecurityProvider.

/**
     * Tries to obtain the {@code SecurityProvider} object from the callback
     * handler using a new SecurityProviderCallback and keeps the value as
     * private field. If the callback handler isn't able to handle the
     * SecurityProviderCallback this method returns {@code null}.
     *
     * @return The {@code SecurityProvider} associated with this
     *         {@code LoginModule} or {@code null}.
     */
@CheckForNull
protected SecurityProvider getSecurityProvider() {
    if (securityProvider == null && callbackHandler != null) {
        RepositoryCallback rcb = new RepositoryCallback();
        try {
            callbackHandler.handle(new Callback[] { rcb });
            securityProvider = rcb.getSecurityProvider();
        } catch (Exception e) {
            log.debug("Unable to retrieve the SecurityProvider via callback", e);
        }
    }
    return securityProvider;
}
Also used : RepositoryCallback(org.apache.jackrabbit.oak.spi.security.authentication.callback.RepositoryCallback) LoginException(javax.security.auth.login.LoginException) UnsupportedCallbackException(javax.security.auth.callback.UnsupportedCallbackException) NoSuchWorkspaceException(javax.jcr.NoSuchWorkspaceException) PrivilegedActionException(java.security.PrivilegedActionException) IOException(java.io.IOException) CheckForNull(javax.annotation.CheckForNull)

Example 3 with RepositoryCallback

use of org.apache.jackrabbit.oak.spi.security.authentication.callback.RepositoryCallback in project jackrabbit-oak by apache.

the class CallbackHandlerImplTest method handleRepositoryCallback.

@Test
public void handleRepositoryCallback() throws Exception {
    RepositoryCallback cb = new RepositoryCallback();
    callbackHandler.handle(new Callback[] { cb });
    assertSame(getContentRepository(), cb.getContentRepository());
    assertSame(getSecurityProvider(), cb.getSecurityProvider());
    assertEquals(root.getContentSession().getWorkspaceName(), cb.getWorkspaceName());
}
Also used : RepositoryCallback(org.apache.jackrabbit.oak.spi.security.authentication.callback.RepositoryCallback) AbstractSecurityTest(org.apache.jackrabbit.oak.AbstractSecurityTest) Test(org.junit.Test)

Aggregations

RepositoryCallback (org.apache.jackrabbit.oak.spi.security.authentication.callback.RepositoryCallback)3 IOException (java.io.IOException)2 PrivilegedActionException (java.security.PrivilegedActionException)2 CheckForNull (javax.annotation.CheckForNull)2 UnsupportedCallbackException (javax.security.auth.callback.UnsupportedCallbackException)2 PrivilegedExceptionAction (java.security.PrivilegedExceptionAction)1 NoSuchWorkspaceException (javax.jcr.NoSuchWorkspaceException)1 LoginException (javax.security.auth.login.LoginException)1 AbstractSecurityTest (org.apache.jackrabbit.oak.AbstractSecurityTest)1 ContentRepository (org.apache.jackrabbit.oak.api.ContentRepository)1 Test (org.junit.Test)1