use of org.apache.jackrabbit.oak.spi.security.authentication.token.TokenProvider 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
}
}
use of org.apache.jackrabbit.oak.spi.security.authentication.token.TokenProvider in project jackrabbit-oak by apache.
the class TokenConfigurationImplTest method testGetTokenProvider.
@Test
public void testGetTokenProvider() {
TokenProvider tp = tc.getTokenProvider(root);
assertTrue(tp instanceof TokenProviderImpl);
}
use of org.apache.jackrabbit.oak.spi.security.authentication.token.TokenProvider in project jackrabbit-oak by apache.
the class TokenAuthenticationTest method testAuthenticateExpiredToken.
@Test
public void testAuthenticateExpiredToken() throws Exception {
TokenProvider tp = new TokenProviderImpl(root, ConfigurationParameters.of(TokenProvider.PARAM_TOKEN_EXPIRATION, 1), getUserConfiguration());
TokenInfo info = tp.createToken(userId, Collections.<String, Object>emptyMap());
waitUntilExpired(info);
try {
new TokenAuthentication(tp).authenticate(new TokenCredentials(info.getToken()));
fail("LoginException expected");
} catch (LoginException e) {
// success
}
// expired token must have been removed
assertNull(tp.getTokenInfo(info.getToken()));
}
use of org.apache.jackrabbit.oak.spi.security.authentication.token.TokenProvider in project jackrabbit-oak by apache.
the class Jackrabbit2ConfigurationTest method testValidTokenCredentials.
@Test
public void testValidTokenCredentials() throws Exception {
Root root = adminSession.getLatestRoot();
TokenConfiguration tc = getSecurityProvider().getConfiguration(TokenConfiguration.class);
TokenProvider tp = tc.getTokenProvider(root);
SimpleCredentials sc = (SimpleCredentials) getAdminCredentials();
TokenInfo info = tp.createToken(sc.getUserID(), Collections.<String, Object>emptyMap());
ContentSession cs = login(new TokenCredentials(info.getToken()));
try {
assertEquals(sc.getUserID(), cs.getAuthInfo().getUserID());
} finally {
cs.close();
}
}
use of org.apache.jackrabbit.oak.spi.security.authentication.token.TokenProvider in project jackrabbit-oak by apache.
the class TokenProviderCallbackTest method testCallback.
@Test
public void testCallback() {
TokenProviderCallback cb = new TokenProviderCallback();
TokenProvider tp = Mockito.mock(TokenProvider.class);
cb.setTokenProvider(tp);
assertSame(tp, cb.getTokenProvider());
}
Aggregations