use of org.apache.jackrabbit.api.security.authentication.token.TokenCredentials in project jackrabbit-oak by apache.
the class TokenAuthenticationTest method testGetUserPrincipal.
@Test
public void testGetUserPrincipal() throws Exception {
TokenInfo info = tokenProvider.createToken(userId, Collections.<String, Object>emptyMap());
assertTrue(authentication.authenticate(new TokenCredentials(info.getToken())));
assertEquals(getTestUser().getPrincipal(), authentication.getUserPrincipal());
}
use of org.apache.jackrabbit.api.security.authentication.token.TokenCredentials 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.api.security.authentication.token.TokenCredentials 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.api.security.authentication.token.TokenCredentials in project jackrabbit-oak by apache.
the class TokenLoginModuleCredentialsSupportTest method testCustomCredentials.
@Test
public void testCustomCredentials() throws Exception {
TestCredentialsSupport.Creds credentials = new TestCredentialsSupport.Creds();
ContentSession cs = login(credentials);
try {
assertEquals(userId, cs.getAuthInfo().getUserID());
Map<String, ?> attributes = credentialsSupport.getAttributes(credentials);
String token = attributes.get(TokenConstants.TOKEN_ATTRIBUTE).toString();
assertFalse(token.isEmpty());
cs.close();
cs = login(new TokenCredentials(token));
assertEquals(userId, cs.getAuthInfo().getUserID());
} finally {
cs.close();
}
}
use of org.apache.jackrabbit.api.security.authentication.token.TokenCredentials in project jackrabbit-oak by apache.
the class TokenLoginModule method login.
// --------------------------------------------------------< LoginModule >---
@Override
public boolean login() throws LoginException {
tokenProvider = getTokenProvider();
if (tokenProvider == null) {
return false;
}
Credentials credentials = getCredentials();
if (credentials instanceof TokenCredentials) {
TokenCredentials tc = (TokenCredentials) credentials;
TokenAuthentication authentication = new TokenAuthentication(tokenProvider);
if (authentication.authenticate(tc)) {
tokenCredentials = tc;
tokenInfo = authentication.getTokenInfo();
userId = authentication.getUserId();
principal = authentication.getUserPrincipal();
log.debug("Login: adding login name to shared state.");
sharedState.put(SHARED_KEY_LOGIN_NAME, userId);
return true;
}
}
return false;
}
Aggregations