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
}
}
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());
}
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);
}
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));
}
}
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
}
}
Aggregations