use of javax.jcr.Credentials in project jackrabbit-oak by apache.
the class TokenAuthenticationTest method testAuthenticateWithInvalidCredentials.
@Test
public void testAuthenticateWithInvalidCredentials() throws Exception {
List<Credentials> invalid = new ArrayList<Credentials>();
invalid.add(new GuestCredentials());
invalid.add(new SimpleCredentials(userId, new char[0]));
for (Credentials creds : invalid) {
assertFalse(authentication.authenticate(creds));
}
}
use of javax.jcr.Credentials in project jackrabbit-oak by apache.
the class TokenProviderImplTest method testCreateTokenFromCredentials.
@Test
public void testCreateTokenFromCredentials() throws Exception {
SimpleCredentials sc = new SimpleCredentials(userId, new char[0]);
List<Credentials> valid = new ArrayList<Credentials>();
valid.add(sc);
valid.add(new ImpersonationCredentials(sc, null));
for (Credentials creds : valid) {
TokenInfo info = tokenProvider.createToken(creds);
assertTokenInfo(info, userId);
}
}
use of javax.jcr.Credentials in project jackrabbit-oak by apache.
the class LoginModuleImplTest method testCustomUserAuthentication.
@Test
public void testCustomUserAuthentication() throws Exception {
LoginModuleImpl loginModule = new LoginModuleImpl();
UserAuthenticationFactory factory = new UserAuthenticationFactory() {
@CheckForNull
@Override
public Authentication getAuthentication(@Nonnull UserConfiguration configuration, @Nonnull Root root, @Nullable String userId) {
return new Authentication() {
@Override
public boolean authenticate(@Nullable Credentials credentials) throws LoginException {
return true;
}
@CheckForNull
@Override
public String getUserId() {
return null;
}
@CheckForNull
@Override
public Principal getUserPrincipal() {
return null;
}
};
}
};
CallbackHandler cbh = new TestCallbackHandler(factory);
SimpleCredentials creds = new SimpleCredentials("loginId", new char[0]);
Subject subject = new Subject(false, Sets.<Principal>newHashSet(), ImmutableSet.of(creds), Sets.newHashSet());
loginModule.initialize(subject, cbh, Maps.<String, Object>newHashMap(), Maps.<String, Object>newHashMap());
assertTrue(loginModule.login());
assertTrue(loginModule.commit());
AuthInfo authInfo = subject.getPublicCredentials(AuthInfo.class).iterator().next();
assertEquals("loginId", authInfo.getUserID());
}
use of javax.jcr.Credentials in project jackrabbit-oak by apache.
the class UserAuthenticationTest method testAuthenticateInvalidCredentials.
@Test
public void testAuthenticateInvalidCredentials() throws Exception {
List<Credentials> invalid = new ArrayList<Credentials>();
invalid.add(new TokenCredentials("token"));
invalid.add(new Credentials() {
});
for (Credentials creds : invalid) {
assertFalse(authentication.authenticate(creds));
}
}
use of javax.jcr.Credentials in project jackrabbit-oak by apache.
the class UserAuthenticationTest method testAuthenticateInvalidSimpleCredentials.
@Test
public void testAuthenticateInvalidSimpleCredentials() throws Exception {
List<Credentials> invalid = new ArrayList<Credentials>();
invalid.add(new SimpleCredentials(userId, "wrongPw".toCharArray()));
invalid.add(new SimpleCredentials(userId, "".toCharArray()));
invalid.add(new SimpleCredentials("unknownUser", "pw".toCharArray()));
for (Credentials creds : invalid) {
try {
authentication.authenticate(creds);
fail("LoginException expected");
} catch (LoginException e) {
// success
assertTrue(e instanceof FailedLoginException);
}
}
}
Aggregations