return initialContentImporter;
}
private AuthenticationProviders createAuthenticationProviders( AtomicBoolean useAnonymouOnFailedLogins ) {
// Prepare to create the authenticators and authorizers ...
AuthenticationProviders authenticators = new AuthenticationProviders();
Security securityConfig = config.getSecurity();
// Set up the JAAS providers ...
JaasSecurity jaasSecurity = securityConfig.getJaas();
if (jaasSecurity != null) {
String policyName = jaasSecurity.getPolicyName();
if (policyName != null && policyName.trim().length() != 0) {
try {
JaasProvider jaasProvider = new JaasProvider(policyName);
authenticators = authenticators.with(jaasProvider);
} catch (java.lang.SecurityException e) {
if (MISSING_JAAS_POLICIES.add(policyName)) {
warn(JcrI18n.loginConfigNotFound, policyName, RepositoryConfiguration.FieldName.SECURITY + "/"
+ RepositoryConfiguration.FieldName.JAAS_POLICY_NAME,
repositoryName());
}
} catch (javax.security.auth.login.LoginException e) {
if (MISSING_JAAS_POLICIES.add(policyName)) {
warn(JcrI18n.loginConfigNotFound, policyName, RepositoryConfiguration.FieldName.SECURITY + "/"
+ RepositoryConfiguration.FieldName.JAAS_POLICY_NAME,
repositoryName());
}
}
}
}
// Set up any custom AuthenticationProvider classes ...
for (Component component : securityConfig.getCustomProviders(problems())) {
try {
AuthenticationProvider provider = component.createInstance(getClass().getClassLoader());
authenticators = authenticators.with(provider);
if (provider instanceof AnonymousProvider) {
Object value = component.getDocument().get(FieldName.USE_ANONYMOUS_ON_FAILED_LOGINS);
if (Boolean.TRUE.equals(value)) {
useAnonymouOnFailedLogins.set(true);
}
}
} catch (Throwable t) {
logger.error(t, JcrI18n.unableToInitializeAuthenticationProvider, component, repositoryName(), t.getMessage());
}
}
// And last set up the anonymous provider ...
AnonymousSecurity anonSecurity = securityConfig.getAnonymous();
if (anonSecurity != null) {
// Set up the anonymous provider (if appropriate) ...
Set<String> anonRoles = anonSecurity.getAnonymousRoles();
if (!anonRoles.isEmpty()) {
String anonUsername = anonSecurity.getAnonymousUsername();
AnonymousProvider anonProvider = new AnonymousProvider(anonUsername, anonRoles);
authenticators = authenticators.with(anonProvider);
logger.debug("Enabling anonymous authentication and authorization.");
}
if (anonSecurity.useAnonymousOnFailedLogings()) {
useAnonymouOnFailedLogins.set(true);
}