use of org.apache.jackrabbit.oak.spi.security.authentication.token.TokenConfiguration in project jackrabbit-oak by apache.
the class SecurityProviderRegistrationTest method testBindOptionalCandidate.
@Test
public void testBindOptionalCandidate() throws Exception {
registration.activate(context.bundleContext(), configWithRequiredServiceIds("serviceId"));
Field f = registration.getClass().getDeclaredField("preconditions");
f.setAccessible(true);
TokenConfiguration tc = mockConfiguration(TokenConfiguration.class);
registration.bindTokenConfiguration(tc, ImmutableMap.of(Constants.SERVICE_PID, "otherServiceId"));
Preconditions preconditions = (Preconditions) f.get(registration);
assertFalse(preconditions.areSatisfied());
assertNull(context.getService(SecurityProvider.class));
}
use of org.apache.jackrabbit.oak.spi.security.authentication.token.TokenConfiguration in project jackrabbit-oak by apache.
the class SecurityProviderRegistrationTest method testBindMandatoryCandidate.
@Test
public void testBindMandatoryCandidate() throws Exception {
registration.activate(context.bundleContext(), configWithRequiredServiceIds("serviceId"));
Field f = registration.getClass().getDeclaredField("preconditions");
f.setAccessible(true);
TokenConfiguration tc = mockConfiguration(TokenConfiguration.class);
registration.bindTokenConfiguration(tc, ImmutableMap.of(Constants.SERVICE_PID, "serviceId"));
Preconditions preconditions = (Preconditions) f.get(registration);
assertTrue(preconditions.areSatisfied());
assertNotNull(context.getService(SecurityProvider.class));
}
use of org.apache.jackrabbit.oak.spi.security.authentication.token.TokenConfiguration 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());
}
use of org.apache.jackrabbit.oak.spi.security.authentication.token.TokenConfiguration 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();
}
}
}
Aggregations