Search in sources :

Example 16 with Credentials

use of javax.jcr.Credentials in project jackrabbit by apache.

the class BasicCredentialsProviderTest method testMissingDefaultHeader.

public void testMissingDefaultHeader() throws ServletException {
    CredentialsProvider cb = new BasicCredentialsProvider(null);
    try {
        Credentials creds = cb.getCredentials(new RequestImpl(null));
        fail("LoginException expected");
    } catch (LoginException e) {
    // ok
    }
}
Also used : LoginException(javax.jcr.LoginException) GuestCredentials(javax.jcr.GuestCredentials) SimpleCredentials(javax.jcr.SimpleCredentials) Credentials(javax.jcr.Credentials)

Example 17 with Credentials

use of javax.jcr.Credentials in project jackrabbit by apache.

the class RepositoryServiceImpl method impersonate.

/**
     * {@inheritDoc}
     */
public SessionInfo impersonate(SessionInfo sessionInfo, Credentials credentials) throws LoginException, RepositoryException {
    Credentials duplicate = SessionInfoImpl.duplicateCredentials(credentials);
    SessionInfoImpl sInfo = getSessionInfoImpl(sessionInfo);
    return new SessionInfoImpl(sInfo.getSession().impersonate(credentials), duplicate, getNameFactory(), getPathFactory());
}
Also used : Credentials(javax.jcr.Credentials) GuestCredentials(javax.jcr.GuestCredentials)

Example 18 with Credentials

use of javax.jcr.Credentials in project jackrabbit-oak by apache.

the class ExternalLoginModule method createAuthInfo.

@Nonnull
private AuthInfo createAuthInfo(@Nonnull String userId, @Nonnull Set<? extends Principal> principals) {
    Credentials creds;
    if (credentials instanceof ImpersonationCredentials) {
        creds = ((ImpersonationCredentials) credentials).getBaseCredentials();
    } else {
        creds = credentials;
    }
    Map<String, Object> attributes = new HashMap<String, Object>();
    Object shared = sharedState.get(SHARED_KEY_ATTRIBUTES);
    if (shared instanceof Map) {
        for (Map.Entry entry : ((Map<?, ?>) shared).entrySet()) {
            attributes.put(entry.getKey().toString(), entry.getValue());
        }
    } else if (creds != null) {
        attributes.putAll(credentialsSupport.getAttributes(creds));
    }
    return new AuthInfoImpl(userId, attributes, principals);
}
Also used : AuthInfoImpl(org.apache.jackrabbit.oak.spi.security.authentication.AuthInfoImpl) ImpersonationCredentials(org.apache.jackrabbit.oak.spi.security.authentication.ImpersonationCredentials) HashMap(java.util.HashMap) HashMap(java.util.HashMap) Map(java.util.Map) ImpersonationCredentials(org.apache.jackrabbit.oak.spi.security.authentication.ImpersonationCredentials) Credentials(javax.jcr.Credentials) Nonnull(javax.annotation.Nonnull)

Example 19 with Credentials

use of javax.jcr.Credentials in project jackrabbit-oak by apache.

the class TokenProviderImplTest method testCreateTokenFromInvalidCredentials.

@Test
public void testCreateTokenFromInvalidCredentials() throws Exception {
    List<Credentials> invalid = new ArrayList<Credentials>();
    invalid.add(new GuestCredentials());
    invalid.add(new TokenCredentials("sometoken"));
    invalid.add(new ImpersonationCredentials(new GuestCredentials(), null));
    invalid.add(new SimpleCredentials("unknownUserId", new char[0]));
    for (Credentials creds : invalid) {
        assertNull(tokenProvider.createToken(creds));
    }
}
Also used : SimpleCredentials(javax.jcr.SimpleCredentials) ImpersonationCredentials(org.apache.jackrabbit.oak.spi.security.authentication.ImpersonationCredentials) ArrayList(java.util.ArrayList) GuestCredentials(javax.jcr.GuestCredentials) TokenCredentials(org.apache.jackrabbit.api.security.authentication.token.TokenCredentials) ImpersonationCredentials(org.apache.jackrabbit.oak.spi.security.authentication.ImpersonationCredentials) SimpleCredentials(javax.jcr.SimpleCredentials) Credentials(javax.jcr.Credentials) GuestCredentials(javax.jcr.GuestCredentials) TokenCredentials(org.apache.jackrabbit.api.security.authentication.token.TokenCredentials) Test(org.junit.Test)

Example 20 with Credentials

use of javax.jcr.Credentials in project jackrabbit-oak by apache.

the class TokenLoginModuleTest method testCreateTokenFailed.

@Test
public void testCreateTokenFailed() throws Exception {
    TokenProvider tp = new TokenProvider() {

        @Override
        public boolean doCreateToken(@Nonnull Credentials credentials) {
            return true;
        }

        @CheckForNull
        @Override
        public TokenInfo createToken(@Nonnull Credentials credentials) {
            return null;
        }

        @CheckForNull
        @Override
        public TokenInfo createToken(@Nonnull String userId, @Nonnull Map<String, ?> attributes) {
            return null;
        }

        @CheckForNull
        @Override
        public TokenInfo getTokenInfo(@Nonnull String token) {
            return null;
        }
    };
    TokenLoginModule lm = new TokenLoginModule();
    lm.initialize(new Subject(), new TestCallbackHandler(tp), ImmutableMap.<String, Object>of(AbstractLoginModule.SHARED_KEY_CREDENTIALS, new Credentials() {
    }), ImmutableMap.<String, Object>of());
    lm.login();
    try {
        lm.commit();
        fail("LoginException expected");
    } catch (LoginException e) {
    // success
    }
}
Also used : TokenProvider(org.apache.jackrabbit.oak.spi.security.authentication.token.TokenProvider) Nonnull(javax.annotation.Nonnull) LoginException(javax.security.auth.login.LoginException) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) GuestCredentials(javax.jcr.GuestCredentials) TokenCredentials(org.apache.jackrabbit.api.security.authentication.token.TokenCredentials) SimpleCredentials(javax.jcr.SimpleCredentials) Credentials(javax.jcr.Credentials) Subject(javax.security.auth.Subject) AbstractSecurityTest(org.apache.jackrabbit.oak.AbstractSecurityTest) Test(org.junit.Test)

Aggregations

Credentials (javax.jcr.Credentials)86 SimpleCredentials (javax.jcr.SimpleCredentials)53 Test (org.junit.Test)33 GuestCredentials (javax.jcr.GuestCredentials)26 Session (javax.jcr.Session)17 TokenCredentials (org.apache.jackrabbit.api.security.authentication.token.TokenCredentials)14 AbstractSecurityTest (org.apache.jackrabbit.oak.AbstractSecurityTest)13 RepositoryException (javax.jcr.RepositoryException)12 User (org.apache.jackrabbit.api.security.user.User)12 ImpersonationCredentials (org.apache.jackrabbit.oak.spi.security.authentication.ImpersonationCredentials)12 LoginException (javax.security.auth.login.LoginException)8 ArrayList (java.util.ArrayList)7 LoginException (javax.jcr.LoginException)6 Subject (javax.security.auth.Subject)6 IOException (java.io.IOException)5 HashMap (java.util.HashMap)5 Repository (javax.jcr.Repository)5 ContentSession (org.apache.jackrabbit.oak.api.ContentSession)5 Principal (java.security.Principal)4 Map (java.util.Map)4