use of org.apache.jackrabbit.oak.spi.security.user.UserAuthenticationFactory in project jackrabbit-oak by apache.
the class LoginModuleImpl method getUserAuthentication.
@CheckForNull
private Authentication getUserAuthentication(@Nullable String loginName) {
SecurityProvider securityProvider = getSecurityProvider();
Root root = getRoot();
if (securityProvider != null && root != null) {
UserConfiguration uc = securityProvider.getConfiguration(UserConfiguration.class);
UserAuthenticationFactory factory = uc.getParameters().getConfigValue(UserConstants.PARAM_USER_AUTHENTICATION_FACTORY, null, UserAuthenticationFactory.class);
if (factory != null) {
return factory.getAuthentication(uc, root, loginName);
} else {
log.error("No user authentication factory configured in user configuration.");
}
}
return null;
}
use of org.apache.jackrabbit.oak.spi.security.user.UserAuthenticationFactory in project jackrabbit-oak by apache.
the class SecurityProviderRegistrationTest method testUnbindOptionalCandidateAfterRegistration.
@Test
public void testUnbindOptionalCandidateAfterRegistration() {
registration.activate(context.bundleContext(), configWithRequiredServiceIds("serviceId"));
UserAuthenticationFactory uaf = Mockito.mock(UserAuthenticationFactory.class);
Map<String, Object> properties = ImmutableMap.of(Constants.SERVICE_PID, "notMandatory");
registration.bindUserAuthenticationFactory(uaf, properties);
assertNull(context.getService(SecurityProvider.class));
registration.bindAuthorizableActionProvider(Mockito.mock(AuthorizableActionProvider.class), ImmutableMap.of(Constants.SERVICE_PID, "serviceId"));
SecurityProvider service = context.getService(SecurityProvider.class);
assertNotNull(service);
// unbinding an optional configuration must not result in unrregistration of the service
registration.unbindUserAuthenticationFactory(uaf, properties);
SecurityProvider service2 = context.getService(SecurityProvider.class);
assertSame(service, service2);
}
use of org.apache.jackrabbit.oak.spi.security.user.UserAuthenticationFactory in project jackrabbit-oak by apache.
the class SecurityProviderBuilder method with.
public SecurityProviderBuilder with(@Nonnull ConfigurationParameters configuration) {
authenticationParams = configuration.getConfigValue(AuthenticationConfiguration.NAME, EMPTY);
privilegeParams = configuration.getConfigValue(PrivilegeConfiguration.NAME, EMPTY);
if (configuration.contains(UserConfiguration.NAME)) {
userParams = configuration.getConfigValue(UserConfiguration.NAME, EMPTY);
} else {
AuthorizableActionProvider authorizableActionProvider = new DefaultAuthorizableActionProvider();
AuthorizableNodeName authorizableNodeName = AuthorizableNodeName.DEFAULT;
UserAuthenticationFactory userAuthenticationFactory = UserConfigurationImpl.getDefaultAuthenticationFactory();
userParams = ConfigurationParameters.of(ConfigurationParameters.of(UserConstants.PARAM_AUTHORIZABLE_ACTION_PROVIDER, authorizableActionProvider), ConfigurationParameters.of(UserConstants.PARAM_AUTHORIZABLE_NODE_NAME, authorizableNodeName), ConfigurationParameters.of(UserConstants.PARAM_USER_AUTHENTICATION_FACTORY, userAuthenticationFactory));
}
if (configuration.contains(AuthorizationConfiguration.NAME)) {
authorizationParams = configuration.getConfigValue(AuthorizationConfiguration.NAME, EMPTY);
} else {
RestrictionProvider restrictionProvider = new RestrictionProviderImpl();
authorizationParams = ConfigurationParameters.of(AccessControlConstants.PARAM_RESTRICTION_PROVIDER, restrictionProvider);
}
principalParams = configuration.getConfigValue(PrincipalConfiguration.NAME, EMPTY);
tokenParams = configuration.getConfigValue(TokenConfiguration.NAME, EMPTY);
return this;
}
use of org.apache.jackrabbit.oak.spi.security.user.UserAuthenticationFactory in project jackrabbit-oak by apache.
the class LoginModuleImplTest method testCustomUserAuthentication.
@Test
public void testCustomUserAuthentication() throws Exception {
LoginModuleImpl loginModule = new LoginModuleImpl();
UserAuthenticationFactory factory = new UserAuthenticationFactory() {
@CheckForNull
@Override
public Authentication getAuthentication(@Nonnull UserConfiguration configuration, @Nonnull Root root, @Nullable String userId) {
return new Authentication() {
@Override
public boolean authenticate(@Nullable Credentials credentials) throws LoginException {
return true;
}
@CheckForNull
@Override
public String getUserId() {
return null;
}
@CheckForNull
@Override
public Principal getUserPrincipal() {
return null;
}
};
}
};
CallbackHandler cbh = new TestCallbackHandler(factory);
SimpleCredentials creds = new SimpleCredentials("loginId", new char[0]);
Subject subject = new Subject(false, Sets.<Principal>newHashSet(), ImmutableSet.of(creds), Sets.newHashSet());
loginModule.initialize(subject, cbh, Maps.<String, Object>newHashMap(), Maps.<String, Object>newHashMap());
assertTrue(loginModule.login());
assertTrue(loginModule.commit());
AuthInfo authInfo = subject.getPublicCredentials(AuthInfo.class).iterator().next();
assertEquals("loginId", authInfo.getUserID());
}
use of org.apache.jackrabbit.oak.spi.security.user.UserAuthenticationFactory in project jackrabbit-oak by apache.
the class SecurityProviderRegistrationTest method testDeactivateWithoutPreconditions.
@Test
public void testDeactivateWithoutPreconditions() throws Exception {
registration.activate(context.bundleContext(), configWithRequiredServiceIds());
UserAuthenticationFactory mock = Mockito.mock(UserAuthenticationFactory.class);
registration.bindUserAuthenticationFactory(mock, ImmutableMap.of(Constants.SERVICE_PID, "nodeName"));
assertNotNull(context.getService(SecurityProvider.class));
registration.deactivate();
// securityprovider must have been unregistered
assertNull(context.getService(SecurityProvider.class));
}
Aggregations