use of org.apache.jackrabbit.oak.spi.security.authentication.token.TokenConfiguration 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.TokenConfiguration in project jackrabbit-oak by apache.
the class SecurityProviderRegistrationTest method testBindUnbindTokenConfiguration.
@Test
public void testBindUnbindTokenConfiguration() throws Exception {
Field f = registration.getClass().getDeclaredField("tokenConfiguration");
f.setAccessible(true);
assertTrue(f.get(registration) instanceof CompositeTokenConfiguration);
TokenConfiguration tc = mockConfiguration(TokenConfiguration.class);
registration.bindTokenConfiguration(tc, PROPS);
CompositeTokenConfiguration composite = (CompositeTokenConfiguration) f.get(registration);
assertEquals(1, composite.getConfigurations().size());
assertTrue(composite.getConfigurations().contains(tc));
registration.unbindTokenConfiguration(tc, PROPS);
composite = (CompositeTokenConfiguration) f.get(registration);
assertTrue(composite.getConfigurations().isEmpty());
}
use of org.apache.jackrabbit.oak.spi.security.authentication.token.TokenConfiguration 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.TokenConfiguration in project jackrabbit-oak by apache.
the class InternalSecurityProviderTest method testSetTokenConfiguration.
@Test
public void testSetTokenConfiguration() {
TokenConfiguration tc = Mockito.mock(TokenConfiguration.class);
when(tc.getParameters()).thenReturn(PARAMS);
securityProvider.setTokenConfiguration(tc);
assertSame(tc, securityProvider.getConfiguration(TokenConfiguration.class));
for (SecurityConfiguration sc : securityProvider.getConfigurations()) {
if (sc instanceof TokenConfiguration) {
assertSame(tc, sc);
}
}
assertEquals(PARAMS, securityProvider.getParameters(TokenConfiguration.NAME));
}
use of org.apache.jackrabbit.oak.spi.security.authentication.token.TokenConfiguration in project jackrabbit-oak by apache.
the class TokenLoginModule method getTokenProvider.
// ------------------------------------------------------------< private >---
/**
* Retrieve the token provider
* @return the token provider or {@code null}.
*/
@CheckForNull
private TokenProvider getTokenProvider() {
TokenProvider provider = null;
SecurityProvider securityProvider = getSecurityProvider();
Root root = getRoot();
if (root != null && securityProvider != null) {
TokenConfiguration tokenConfig = securityProvider.getConfiguration(TokenConfiguration.class);
provider = tokenConfig.getTokenProvider(root);
}
if (provider == null && callbackHandler != null) {
try {
TokenProviderCallback tcCallback = new TokenProviderCallback();
callbackHandler.handle(new Callback[] { tcCallback });
provider = tcCallback.getTokenProvider();
} catch (IOException e) {
log.warn(e.getMessage());
} catch (UnsupportedCallbackException e) {
log.warn(e.getMessage());
}
}
return provider;
}
Aggregations