use of javax.security.auth.callback.CallbackHandler in project jackrabbit-oak by apache.
the class LoginContextProviderImpl method getLoginContext.
@Override
@Nonnull
public LoginContext getLoginContext(Credentials credentials, String workspaceName) throws LoginException {
Subject subject = getSubject();
if (subject != null && credentials == null) {
log.debug("Found pre-authenticated subject: No further login actions required.");
return new PreAuthContext(subject);
}
if (subject == null) {
subject = new Subject();
}
CallbackHandler handler = getCallbackHandler(credentials, workspaceName);
return new JaasLoginContext(appName, subject, handler, getConfiguration());
}
use of javax.security.auth.callback.CallbackHandler in project jackrabbit-oak by apache.
the class AbstractLoginModuleTest method testGetCredentialsFromCallbackHandler.
@Test
public void testGetCredentialsFromCallbackHandler() {
CallbackHandler cbh = new CallbackHandler() {
@Override
public void handle(Callback[] callbacks) {
for (Callback cb : callbacks) {
if (cb instanceof CredentialsCallback) {
((CredentialsCallback) cb).setCredentials(new TestCredentials());
}
}
}
};
AbstractLoginModule lm = initLoginModule(TestCredentials.class, cbh);
assertTrue(lm.getCredentials() instanceof TestCredentials);
lm = initLoginModule(SimpleCredentials.class, cbh);
assertNull(lm.getCredentials());
}
use of javax.security.auth.callback.CallbackHandler in project jackrabbit-oak by apache.
the class GuestLoginModuleTest method testSimpleCredentials.
@Test
public void testSimpleCredentials() throws LoginException {
Subject subject = new Subject();
CallbackHandler cbh = new TestCallbackHandler(new SimpleCredentials("test", new char[0]));
Map sharedState = new HashMap();
guestLoginModule.initialize(subject, cbh, sharedState, Collections.<String, Object>emptyMap());
assertFalse(guestLoginModule.login());
assertFalse(sharedState.containsKey(AbstractLoginModule.SHARED_KEY_CREDENTIALS));
assertFalse(guestLoginModule.commit());
assertTrue(subject.getPrincipals().isEmpty());
assertTrue(subject.getPublicCredentials().isEmpty());
assertFalse(guestLoginModule.logout());
}
use of javax.security.auth.callback.CallbackHandler in project jackrabbit-oak by apache.
the class GuestLoginModuleTest method testGuestCredentials.
@Test
public void testGuestCredentials() throws LoginException {
Subject subject = new Subject();
CallbackHandler cbh = new TestCallbackHandler(new GuestCredentials());
Map sharedState = new HashMap();
guestLoginModule.initialize(subject, cbh, sharedState, Collections.<String, Object>emptyMap());
assertFalse(guestLoginModule.login());
assertFalse(sharedState.containsKey(AbstractLoginModule.SHARED_KEY_CREDENTIALS));
assertFalse(guestLoginModule.commit());
assertTrue(subject.getPrincipals().isEmpty());
assertTrue(subject.getPublicCredentials().isEmpty());
assertFalse(guestLoginModule.logout());
}
use of javax.security.auth.callback.CallbackHandler in project jackrabbit-oak by apache.
the class GuestLoginModuleTest method testThrowingCallbackhandler.
@Test
public void testThrowingCallbackhandler() throws LoginException {
Subject subject = new Subject();
CallbackHandler cbh = new ThrowingCallbackHandler(true);
Map sharedState = new HashMap();
guestLoginModule.initialize(subject, cbh, sharedState, Collections.<String, Object>emptyMap());
assertFalse(guestLoginModule.login());
assertFalse(sharedState.containsKey(AbstractLoginModule.SHARED_KEY_CREDENTIALS));
assertFalse(guestLoginModule.commit());
assertTrue(subject.getPublicCredentials(GuestCredentials.class).isEmpty());
assertFalse(guestLoginModule.logout());
}
Aggregations