Search in sources :

Example 6 with ImpersonationCredentials

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

the class UserAuthenticationTest method testAuthenticateImpersonationCredentials.

@Test
public void testAuthenticateImpersonationCredentials() throws Exception {
    SimpleCredentials sc = new SimpleCredentials(userId, new char[0]);
    assertTrue(authentication.authenticate(new ImpersonationCredentials(sc, adminSession.getAuthInfo())));
}
Also used : SimpleCredentials(javax.jcr.SimpleCredentials) ImpersonationCredentials(org.apache.jackrabbit.oak.spi.security.authentication.ImpersonationCredentials) AbstractSecurityTest(org.apache.jackrabbit.oak.AbstractSecurityTest) Test(org.junit.Test)

Example 7 with ImpersonationCredentials

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

the class SystemUserImplTest method testImpersonateDisabledSystemUser.

@Test
public void testImpersonateDisabledSystemUser() throws Exception {
    User user = createUser(null);
    user.disable("disabled");
    root.commit();
    try {
        ContentSession cs = login(new ImpersonationCredentials(new SimpleCredentials(uid, new char[0]), adminSession.getAuthInfo()));
        cs.close();
        fail();
    } catch (LoginException e) {
    // success
    }
}
Also used : SimpleCredentials(javax.jcr.SimpleCredentials) User(org.apache.jackrabbit.api.security.user.User) ImpersonationCredentials(org.apache.jackrabbit.oak.spi.security.authentication.ImpersonationCredentials) ContentSession(org.apache.jackrabbit.oak.api.ContentSession) LoginException(javax.security.auth.login.LoginException) AbstractSecurityTest(org.apache.jackrabbit.oak.AbstractSecurityTest) Test(org.junit.Test)

Example 8 with ImpersonationCredentials

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

the class SystemUserImplTest method testImpersonateSystemUser.

@Test
public void testImpersonateSystemUser() throws Exception {
    createUser(null);
    ContentSession cs = login(new ImpersonationCredentials(new SimpleCredentials(uid, new char[0]), adminSession.getAuthInfo()));
    cs.close();
}
Also used : SimpleCredentials(javax.jcr.SimpleCredentials) ImpersonationCredentials(org.apache.jackrabbit.oak.spi.security.authentication.ImpersonationCredentials) ContentSession(org.apache.jackrabbit.oak.api.ContentSession) AbstractSecurityTest(org.apache.jackrabbit.oak.AbstractSecurityTest) Test(org.junit.Test)

Example 9 with ImpersonationCredentials

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

the class SessionImpl method impersonate.

@Override
@Nonnull
public Session impersonate(Credentials credentials) throws RepositoryException {
    checkAlive();
    ImpersonationCredentials impCreds = new ImpersonationCredentials(checkNotNull(credentials), sd.getAuthInfo());
    return getRepository().login(impCreds, sd.getWorkspaceName());
}
Also used : ImpersonationCredentials(org.apache.jackrabbit.oak.spi.security.authentication.ImpersonationCredentials) Nonnull(javax.annotation.Nonnull)

Example 10 with ImpersonationCredentials

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

the class LoginModuleImpl method getLoginId.

//--------------------------------------------------------------------------
@CheckForNull
private String getLoginId(@CheckForNull PreAuthenticatedLogin preAuthenticatedLogin) {
    if (preAuthenticatedLogin != null) {
        return preAuthenticatedLogin.getUserId();
    }
    String uid = null;
    if (credentials != null) {
        if (credentials instanceof SimpleCredentials) {
            uid = ((SimpleCredentials) credentials).getUserID();
        } else if (credentials instanceof GuestCredentials) {
            uid = getAnonymousId();
        } else if (credentials instanceof ImpersonationCredentials) {
            Credentials bc = ((ImpersonationCredentials) credentials).getBaseCredentials();
            if (bc instanceof SimpleCredentials) {
                uid = ((SimpleCredentials) bc).getUserID();
            }
        } else {
            try {
                NameCallback callback = new NameCallback("User-ID: ");
                callbackHandler.handle(new Callback[] { callback });
                uid = callback.getName();
            } catch (UnsupportedCallbackException e) {
                log.warn("Credentials- or NameCallback must be supported");
            } catch (IOException e) {
                log.error("Name-Callback failed: " + e.getMessage());
            }
        }
    }
    if (uid == null) {
        uid = getSharedLoginName();
    }
    return uid;
}
Also used : SimpleCredentials(javax.jcr.SimpleCredentials) NameCallback(javax.security.auth.callback.NameCallback) ImpersonationCredentials(org.apache.jackrabbit.oak.spi.security.authentication.ImpersonationCredentials) UnsupportedCallbackException(javax.security.auth.callback.UnsupportedCallbackException) IOException(java.io.IOException) GuestCredentials(javax.jcr.GuestCredentials) GuestCredentials(javax.jcr.GuestCredentials) ImpersonationCredentials(org.apache.jackrabbit.oak.spi.security.authentication.ImpersonationCredentials) SimpleCredentials(javax.jcr.SimpleCredentials) Credentials(javax.jcr.Credentials) CheckForNull(javax.annotation.CheckForNull)

Aggregations

ImpersonationCredentials (org.apache.jackrabbit.oak.spi.security.authentication.ImpersonationCredentials)17 SimpleCredentials (javax.jcr.SimpleCredentials)15 Test (org.junit.Test)12 AbstractSecurityTest (org.apache.jackrabbit.oak.AbstractSecurityTest)10 Credentials (javax.jcr.Credentials)7 ContentSession (org.apache.jackrabbit.oak.api.ContentSession)7 GuestCredentials (javax.jcr.GuestCredentials)6 AuthInfo (org.apache.jackrabbit.oak.api.AuthInfo)5 LoginException (javax.security.auth.login.LoginException)4 TokenCredentials (org.apache.jackrabbit.api.security.authentication.token.TokenCredentials)4 AuthInfoImpl (org.apache.jackrabbit.oak.spi.security.authentication.AuthInfoImpl)4 ArrayList (java.util.ArrayList)3 Principal (java.security.Principal)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 Nonnull (javax.annotation.Nonnull)2 FailedLoginException (javax.security.auth.login.FailedLoginException)2 User (org.apache.jackrabbit.api.security.user.User)2 IOException (java.io.IOException)1 CheckForNull (javax.annotation.CheckForNull)1