use of com.evolveum.midpoint.authentication.api.config.MidpointAuthentication in project midpoint by Evolveum.
the class AbstractPageRemoteAuthenticationSelect method getProviders.
private List<IdentityProvider> getProviders() {
List<IdentityProvider> providers = new ArrayList<>();
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
if (authentication instanceof MidpointAuthentication) {
MidpointAuthentication mpAuthentication = (MidpointAuthentication) authentication;
ModuleAuthentication moduleAuthentication = mpAuthentication.getProcessingModuleAuthentication();
if (moduleAuthentication instanceof RemoteModuleAuthentication) {
providers = ((RemoteModuleAuthentication) moduleAuthentication).getProviders();
if (providers.isEmpty()) {
String key = getErrorKeyEmptyProviders();
error(getString(key));
}
return providers;
}
String key = getErrorKeyUnsupportedType();
error(getString(key));
return providers;
}
String key = "web.security.flexAuth.unsupported.auth.type";
error(getString(key));
return providers;
}
use of com.evolveum.midpoint.authentication.api.config.MidpointAuthentication in project midpoint by Evolveum.
the class AbstractPageLogin method getSequenceName.
private String getSequenceName() {
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
if (authentication instanceof MidpointAuthentication) {
MidpointAuthentication mpAuthentication = (MidpointAuthentication) authentication;
AuthenticationSequenceType sequence = mpAuthentication.getSequence();
if (sequence != null && sequence.getChannel() != null && !Boolean.TRUE.equals(sequence.getChannel().isDefault()) && SecurityPolicyUtil.DEFAULT_CHANNEL.equals(sequence.getChannel().getChannelId())) {
return sequence.getDisplayName() != null ? sequence.getDisplayName() : sequence.getName();
}
}
return null;
}
use of com.evolveum.midpoint.authentication.api.config.MidpointAuthentication in project midpoint by Evolveum.
the class PageEmailNonse method getMailNoncePolicy.
private NonceCredentialsPolicyType getMailNoncePolicy(PrismObject<UserType> user) {
SecurityPolicyType securityPolicy = resolveSecurityPolicy(user);
LOGGER.trace("Found security policy: {}", securityPolicy);
if (securityPolicy == null) {
getSession().error(getString("PageForgotPassword.send.nonce.failed"));
LOGGER.error("No security policy, cannot process nonce credential");
// we do not want to provide any information to the attacker.
throw new RestartResponseException(PageEmailNonse.class);
}
if (securityPolicy.getCredentials() == null) {
getSession().error(getString("PageForgotPassword.send.nonce.failed"));
LOGGER.error("No credential for security policy, cannot process nonce credential");
// we do not want to provide any information to the attacker.
throw new RestartResponseException(PageEmailNonse.class);
}
if (securityPolicy.getCredentials().getNonce() == null) {
getSession().error(getString("PageForgotPassword.send.nonce.failed"));
LOGGER.error("No nonce credential for security policy, cannot process nonce credential");
// we do not want to provide any information to the attacker.
throw new RestartResponseException(PageEmailNonse.class);
}
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
if (!(authentication instanceof MidpointAuthentication)) {
getSession().error(getString("PageForgotPassword.send.nonce.failed"));
LOGGER.error("Bad type of authentication, support only MidpointAuthentication, but is " + authentication != null ? authentication.getClass().getName() : null);
throw new RestartResponseException(PageEmailNonse.class);
}
ModuleAuthentication moduleAuthentication = ((MidpointAuthentication) authentication).getProcessingModuleAuthentication();
if (!(moduleAuthentication instanceof CredentialModuleAuthentication) && !AuthenticationModuleNameConstants.MAIL_NONCE.equals(moduleAuthentication.getNameOfModuleType())) {
getSession().error(getString("PageForgotPassword.send.nonce.failed"));
LOGGER.error("Bad type of module authentication, support only EmailNonceModuleAuthentication, but is " + moduleAuthentication != null ? moduleAuthentication.getClass().getName() : null);
throw new RestartResponseException(PageEmailNonse.class);
}
CredentialModuleAuthentication nonceAuth = (CredentialModuleAuthentication) moduleAuthentication;
String credentialName = nonceAuth.getCredentialName();
if (credentialName == null) {
getSession().error(getString("PageForgotPassword.send.nonce.failed"));
LOGGER.error("EmailNonceModuleAuthentication " + nonceAuth.getNameOfModule() + " haven't define name of credential");
throw new RestartResponseException(PageEmailNonse.class);
}
NonceCredentialsPolicyType credentialByName = null;
for (NonceCredentialsPolicyType credential : securityPolicy.getCredentials().getNonce()) {
if (credentialName != null && credentialName.equals(credential.getName())) {
credentialByName = credential;
}
}
if (credentialByName == null) {
getSession().error(getString("PageForgotPassword.send.nonce.failed"));
LOGGER.error("Couldn't find nonce credentials by name " + credentialName);
throw new RestartResponseException(PageEmailNonse.class);
}
return credentialByName;
}
use of com.evolveum.midpoint.authentication.api.config.MidpointAuthentication in project midpoint by Evolveum.
the class PageResetPasswordConfirmation method init.
private void init(final PageParameters pageParameters) {
PageParameters params = pageParameters;
if (params == null) {
params = getPageParameters();
}
OperationResult result = new OperationResult(OPERATION_FINISH_REGISTRATION);
if (params == null) {
LOGGER.error("Confirmation link is not valid. No credentials provided in it");
String msg = createStringResource("PageSelfRegistration.invalid.registration.link").getString();
getSession().error(createStringResource(msg));
result.recordFatalError(msg);
initLayout(result);
return;
}
StringValue userNameValue = params.get(SchemaConstants.USER_ID);
Validate.notEmpty(userNameValue.toString());
StringValue tokenValue = params.get(SchemaConstants.TOKEN);
Validate.notEmpty(tokenValue.toString());
UsernamePasswordAuthenticationToken token = authenticateUser(userNameValue.toString(), tokenValue.toString(), result);
if (token == null) {
initLayout(result);
return;
} else {
// SecurityContextHolder.getContext().setAuthentication(token);
MidPointPrincipal principal = (MidPointPrincipal) token.getPrincipal();
Collection<Authorization> authz = principal.getAuthorities();
if (authz != null) {
for (Authorization authzI : authz) {
authzI.getAction().removeIf(action -> action.contains(AuthorizationConstants.NS_AUTHORIZATION_UI));
}
}
AuthorizationType authorizationType = new AuthorizationType();
authorizationType.getAction().add(AuthorizationConstants.AUTZ_UI_SELF_CREDENTIALS_URL);
Authorization selfServiceCredentialsAuthz = new Authorization(authorizationType);
authz.add(selfServiceCredentialsAuthz);
AuthenticationSequenceType sequence = SecurityPolicyUtil.createPasswordResetSequence();
Map<Class<?>, Object> sharedObjects = new HashMap<>();
AuthenticationModulesType modules = new AuthenticationModulesType();
LoginFormAuthenticationModuleType loginForm = new LoginFormAuthenticationModuleType();
loginForm.name(SecurityPolicyUtil.DEFAULT_MODULE_NAME);
modules.loginForm(loginForm);
AuthModule authModule = null;
AuthenticationChannel channel = null;
try {
channel = channelFactory.createAuthChannel(sequence.getChannel());
authModule = moduleFactory.createModuleFilter(loginForm, sequence.getChannel().getUrlSuffix(), null, sharedObjects, modules, null, channel);
} catch (Exception e) {
LOGGER.error("Couldn't build filter for module moduleFactory", e);
}
MidpointAuthentication mpAuthentication = new MidpointAuthentication(sequence);
List<AuthModule> authModules = new ArrayList<>();
authModules.add(authModule);
mpAuthentication.setAuthModules(authModules);
mpAuthentication.setSessionId(Session.get().getId());
ModuleAuthentication moduleAuthentication = authModule.getBaseModuleAuthentication();
moduleAuthentication.setAuthentication(token);
moduleAuthentication.setState(AuthenticationModuleState.SUCCESSFULLY);
mpAuthentication.addAuthentications(moduleAuthentication);
mpAuthentication.setPrincipal(principal);
mpAuthentication.setAuthorities(token.getAuthorities());
mpAuthentication.setAuthenticationChannel(channel);
SecurityContextHolder.getContext().setAuthentication(mpAuthentication);
setResponsePage(PageResetPassword.class);
}
initLayout(result);
}
use of com.evolveum.midpoint.authentication.api.config.MidpointAuthentication in project midpoint by Evolveum.
the class PageSecurityQuestions method getUrlProcessingLogin.
private String getUrlProcessingLogin() {
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
if (authentication instanceof MidpointAuthentication) {
MidpointAuthentication mpAuthentication = (MidpointAuthentication) authentication;
ModuleAuthentication moduleAuthentication = mpAuthentication.getProcessingModuleAuthentication();
if (moduleAuthentication != null && AuthenticationModuleNameConstants.SECURITY_QUESTIONS_FORM.equals(moduleAuthentication.getNameOfModuleType())) {
String prefix = moduleAuthentication.getPrefix();
return AuthUtil.stripSlashes(prefix) + "/spring_security_login";
}
}
String key = "web.security.flexAuth.unsupported.auth.type";
error(getString(key));
return "/midpoint/spring_security_login";
}
Aggregations