use of org.apache.jackrabbit.oak.spi.security.SecurityProvider in project jackrabbit-oak by apache.
the class AbstractLoginModule method getPrincipalProvider.
/**
* Retrieves the {@link PrincipalProvider} that should be used to handle
* this authentication. If no principal provider has been configure this
* method returns {@code null}.
*
* @return A instance of {@code PrincipalProvider} or {@code null}.
*/
@CheckForNull
protected PrincipalProvider getPrincipalProvider() {
PrincipalProvider principalProvider = null;
SecurityProvider sp = getSecurityProvider();
Root r = getRoot();
if (r != null && sp != null) {
PrincipalConfiguration pc = sp.getConfiguration(PrincipalConfiguration.class);
principalProvider = pc.getPrincipalProvider(r, NamePathMapper.DEFAULT);
}
if (principalProvider == null && callbackHandler != null) {
try {
PrincipalProviderCallback principalCallBack = new PrincipalProviderCallback();
callbackHandler.handle(new Callback[] { principalCallBack });
principalProvider = principalCallBack.getPrincipalProvider();
} catch (IOException | UnsupportedCallbackException e) {
log.debug(e.getMessage());
}
}
return principalProvider;
}
use of org.apache.jackrabbit.oak.spi.security.SecurityProvider in project jackrabbit-oak by apache.
the class MutableRootTest method before.
@Before
public void before() {
SecurityProvider sp = new OpenSecurityProvider() {
@Nonnull
@Override
public <T> T getConfiguration(@Nonnull Class<T> configClass) {
if (AuthorizationConfiguration.class == configClass) {
return (T) new OpenAuthorizationConfiguration() {
@Nonnull
@Override
public PermissionProvider getPermissionProvider(@Nonnull Root root, @Nonnull String workspaceName, @Nonnull Set<Principal> principals) {
return permissionProvider;
}
};
} else {
return super.getConfiguration(configClass);
}
}
};
ContentSessionImpl cs = Mockito.mock(ContentSessionImpl.class);
when(cs.toString()).thenReturn("contentSession");
when(cs.getAuthInfo()).thenReturn(AuthInfoImpl.EMPTY);
when(cs.getWorkspaceName()).thenReturn("default");
root = new MutableRoot(store, new EmptyHook(), "default", new Subject(), sp, null, null, cs);
}
use of org.apache.jackrabbit.oak.spi.security.SecurityProvider in project jackrabbit-oak by apache.
the class AuthenticationConfigurationImplTest method testGetLoginCtxProviderWhiteboard.
@Test
public void testGetLoginCtxProviderWhiteboard() {
SecurityProvider sp = Mockito.mock(SecurityProvider.class, Mockito.withSettings().extraInterfaces(WhiteboardAware.class));
when(((WhiteboardAware) sp).getWhiteboard()).thenReturn(new DefaultWhiteboard());
authConfiguration.setSecurityProvider(sp);
assertNotNull(authConfiguration.getLoginContextProvider(repo));
}
use of org.apache.jackrabbit.oak.spi.security.SecurityProvider in project jackrabbit-oak by apache.
the class SecurityProviderRegistrationTest method testDeactivateWithoutPreconditions.
@Test
public void testDeactivateWithoutPreconditions() throws Exception {
registration.activate(context.bundleContext(), requiredServiceIdMap());
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));
}
use of org.apache.jackrabbit.oak.spi.security.SecurityProvider in project jackrabbit-oak by apache.
the class SecurityProviderRegistrationTest method testModified.
@Test
public void testModified() {
registration.activate(context.bundleContext(), requiredServiceIdMap("rpId", "authorizationId"));
registration.bindAuthorizationConfiguration(new AuthorizationConfigurationImpl(), ImmutableMap.of(Constants.SERVICE_PID, "authorizationId"));
assertNull(context.getService(SecurityProvider.class));
// modify requiredServiceIds by removing the rpId from the mandatory services
// => should re-register the security provider
registration.modified(requiredServiceIdMap("authorizationId"));
SecurityProvider service = context.getService(SecurityProvider.class);
assertNotNull(service);
RestrictionProvider rp = service.getConfiguration(AuthorizationConfiguration.class).getRestrictionProvider();
assertTrue(rp instanceof WhiteboardRestrictionProvider);
}
Aggregations