use of org.apache.jackrabbit.oak.spi.security.authentication.token.TokenProvider in project jackrabbit-oak by apache.
the class TokenLoginModuleTest method testValidTokenCredentials.
@Test
public void testValidTokenCredentials() throws Exception {
Root root = adminSession.getLatestRoot();
TokenConfiguration tokenConfig = getSecurityProvider().getConfiguration(TokenConfiguration.class);
TokenProvider tp = tokenConfig.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 TokenProviderImplTest method testValidTokenCredentialsWithConflict.
/**
*@see <a href="https://issues.apache.org/jira/browse/OAK-1697">OAK-1697</a>
*/
@Test
public void testValidTokenCredentialsWithConflict() throws Exception {
ExecutorService pool = Executors.newFixedThreadPool(10);
List<ContentSession> sessions = new ArrayList<ContentSession>();
try {
TokenConfiguration tc = getSecurityProvider().getConfiguration(TokenConfiguration.class);
SimpleCredentials sc = (SimpleCredentials) getAdminCredentials();
List<TokenProvider> tokenProviders = new ArrayList<TokenProvider>();
for (int i = 0; i < 10; i++) {
ContentSession session = login(getAdminCredentials());
Root r = session.getLatestRoot();
tokenProviders.add(tc.getTokenProvider(r));
sessions.add(session);
}
ArrayList<DataFuture> list = new ArrayList<DataFuture>();
for (TokenProvider tokenProvider : tokenProviders) {
list.add(createDataFuture(pool, tokenProvider, sc.getUserID(), Collections.<String, Object>emptyMap()));
}
for (DataFuture df : list) {
assertNotNull(df.future.get());
}
} finally {
for (ContentSession session : sessions) {
if (session != null) {
session.close();
}
}
if (pool != null) {
pool.shutdown();
}
}
}
use of org.apache.jackrabbit.oak.spi.security.authentication.token.TokenProvider in project jackrabbit-oak by apache.
the class TokenProviderImplTest method testTokenValidationIsCaseInsensitive.
/**
* @see <a href="https://issues.apache.org/jira/browse/OAK-1985">OAK-1985</a>
*/
@Test
public void testTokenValidationIsCaseInsensitive() throws Exception {
Root root = adminSession.getLatestRoot();
TokenConfiguration tokenConfig = getSecurityProvider().getConfiguration(TokenConfiguration.class);
TokenProvider tp = tokenConfig.getTokenProvider(root);
String userId = ((SimpleCredentials) getAdminCredentials()).getUserID();
TokenInfo info = tp.createToken(userId.toUpperCase(), Collections.<String, Object>emptyMap());
assertTrue(info.matches(new TokenCredentials(info.getToken())));
assertEquals(userId, info.getUserId());
info = tp.getTokenInfo(info.getToken());
assertTrue(info.matches(new TokenCredentials(info.getToken())));
assertEquals(userId, info.getUserId());
}
Aggregations