use of com.evolveum.midpoint.authentication.api.AuthModule in project midpoint by Evolveum.
the class AuthSequenceUtil method getSpecificModuleFilter.
private static List<AuthModule> getSpecificModuleFilter(AuthModuleRegistryImpl authRegistry, String urlSuffix, HttpServletRequest httpRequest, Map<Class<?>, Object> sharedObjects, AuthenticationModulesType authenticationModulesType, CredentialsPolicyType credentialPolicy) {
String localePath = httpRequest.getRequestURI().substring(httpRequest.getContextPath().length());
String channel = searchChannelByPath(localePath);
if (LOCAL_PATH_AND_CHANNEL.get("ws").equals(channel)) {
String header = httpRequest.getHeader("Authorization");
if (header != null) {
String type = header.split(" ")[0];
if (AuthenticationModuleNameConstants.CLUSTER.equalsIgnoreCase(type)) {
List<AuthModule> authModules = new ArrayList<>();
HttpClusterModuleFactory factory = authRegistry.findModelFactoryByClass(HttpClusterModuleFactory.class);
AbstractAuthenticationModuleType module = new AbstractAuthenticationModuleType() {
};
module.setName(AuthenticationModuleNameConstants.CLUSTER.toLowerCase() + "-module");
try {
authModules.add(factory.createModuleFilter(module, urlSuffix, httpRequest, sharedObjects, authenticationModulesType, credentialPolicy, null));
} catch (Exception e) {
LOGGER.error("Couldn't create module for cluster authentication");
return null;
}
return authModules;
}
}
}
return null;
}
use of com.evolveum.midpoint.authentication.api.AuthModule in project midpoint by Evolveum.
the class AuthSequenceUtil method buildModuleFilters.
public static List<AuthModule> buildModuleFilters(AuthModuleRegistryImpl authRegistry, AuthenticationSequenceType sequence, HttpServletRequest request, AuthenticationModulesType authenticationModulesType, CredentialsPolicyType credentialPolicy, Map<Class<?>, Object> sharedObjects, AuthenticationChannel authenticationChannel) {
Validate.notNull(authRegistry, "Registry for module factories is null");
if (isSpecificSequence(request)) {
return getSpecificModuleFilter(authRegistry, sequence.getChannel().getUrlSuffix(), request, sharedObjects, authenticationModulesType, credentialPolicy);
}
Validate.notEmpty(sequence.getModule(), "Sequence " + sequence.getName() + " don't contains authentication modules");
List<AuthenticationSequenceModuleType> sequenceModules = SecurityPolicyUtil.getSortedModules(sequence);
List<AuthModule> authModules = new ArrayList<>();
sequenceModules.forEach(sequenceModule -> {
try {
AbstractAuthenticationModuleType module = getModuleByName(sequenceModule.getName(), authenticationModulesType);
AbstractModuleFactory moduleFactory = authRegistry.findModelFactory(module, authenticationChannel);
AuthModule authModule = moduleFactory.createModuleFilter(module, sequence.getChannel().getUrlSuffix(), request, sharedObjects, authenticationModulesType, credentialPolicy, authenticationChannel);
authModules.add(authModule);
} catch (Exception e) {
LOGGER.error("Couldn't build filter for module moduleFactory", e);
}
});
if (authModules.isEmpty()) {
return null;
}
return authModules;
}
use of com.evolveum.midpoint.authentication.api.AuthModule in project midpoint by Evolveum.
the class MidpointAuthFilter method initAuthenticationModule.
private void initAuthenticationModule(MidpointAuthentication mpAuthentication, AuthenticationWrapper authWrapper, HttpServletRequest httpRequest) {
if (AuthSequenceUtil.isSpecificSequence(httpRequest)) {
if (authModulesOfSpecificSequences.containsKey(authWrapper.sequence.getName())) {
authWrapper.authModules = authModulesOfSpecificSequences.get(authWrapper.sequence.getName());
if (authWrapper.authModules != null) {
for (AuthModule authModule : authWrapper.authModules) {
if (authModule != null && ((AuthModuleImpl) authModule).getConfiguration() != null) {
authenticationManager.getProviders().clear();
for (AuthenticationProvider authenticationProvider : ((AuthModuleImpl) authModule).getConfiguration().getAuthenticationProviders()) {
authenticationManager.getProviders().add(authenticationProvider);
}
}
}
}
} else {
authWrapper.authModules = createAuthenticationModuleBySequence(mpAuthentication, authWrapper.sequence, httpRequest, authWrapper.authenticationsPolicy.getModules(), authWrapper.authenticationChannel, authWrapper.credentialsPolicy);
authModulesOfSpecificSequences.put(authWrapper.sequence.getName(), authWrapper.authModules);
}
} else {
authWrapper.authModules = createAuthenticationModuleBySequence(mpAuthentication, authWrapper.sequence, httpRequest, authWrapper.authenticationsPolicy.getModules(), authWrapper.authenticationChannel, authWrapper.credentialsPolicy);
}
}
use of com.evolveum.midpoint.authentication.api.AuthModule in project midpoint by Evolveum.
the class MidpointAnonymousAuthenticationFilter method createAuthentication.
protected Authentication createAuthentication(HttpServletRequest request) {
Authentication auth = createBasicAuthentication(request);
MidpointAuthentication authentication = new MidpointAuthentication(SecurityPolicyUtil.createDefaultSequence());
AuthenticationsPolicyType authenticationsPolicy;
try {
authenticationsPolicy = SecurityPolicyUtil.createDefaultAuthenticationPolicy(NO_CUSTOM_IGNORED_LOCAL_PATH, prismContext.getSchemaRegistry());
} catch (SchemaException e) {
LOGGER.error("Couldn't get default authentication policy");
throw new IllegalArgumentException("Couldn't get default authentication policy", e);
}
AuthenticationSequenceType sequence = SecurityPolicyUtil.createDefaultSequence();
AuthenticationChannel authenticationChannel = AuthSequenceUtil.buildAuthChannel(authChannelRegistry, sequence);
List<AuthModule> authModules = AuthSequenceUtil.buildModuleFilters(authRegistry, sequence, request, authenticationsPolicy.getModules(), null, new HashMap<>(), authenticationChannel);
authentication.setAuthModules(authModules);
if (authModules != null) {
ModuleAuthenticationImpl module = (ModuleAuthenticationImpl) authModules.get(0).getBaseModuleAuthentication();
module.setAuthentication(auth);
authentication.addAuthentications(module);
}
authentication.setPrincipal(auth.getPrincipal());
return authentication;
}
Aggregations