use of com.evolveum.midpoint.authentication.api.config.MidpointAuthentication in project midpoint by Evolveum.
the class SelfRegistrationDto method init.
private void init(SecurityPolicyType securityPolicy, SelfRegistrationPolicyType selfRegistration) throws SchemaException {
this.name = selfRegistration.getName();
this.defaultRoles = selfRegistration.getDefaultRole();
this.initialLifecycleState = selfRegistration.getInitialLifecycleState();
this.requiredLifecycleState = selfRegistration.getRequiredLifecycleState();
this.additionalAuthentication = selfRegistration.getAdditionalAuthenticationSequence() == null ? selfRegistration.getAdditionalAuthenticationName() : selfRegistration.getAdditionalAuthenticationSequence();
this.authenticationPolicy = securityPolicy.getAuthentication();
this.formRef = selfRegistration.getFormRef();
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
CredentialModuleAuthentication mailModuleAuthentication = null;
if (authentication instanceof MidpointAuthentication) {
ModuleAuthentication moduleAuthentication = ((MidpointAuthentication) authentication).getProcessingModuleAuthentication();
if (moduleAuthentication instanceof CredentialModuleAuthentication && AuthenticationModuleNameConstants.MAIL_NONCE.equals(moduleAuthentication.getNameOfModuleType())) {
mailModuleAuthentication = (CredentialModuleAuthentication) moduleAuthentication;
}
}
if (mailModuleAuthentication != null && mailModuleAuthentication.getCredentialName() != null) {
noncePolicy = SecurityPolicyUtil.getCredentialPolicy(mailModuleAuthentication.getCredentialName(), securityPolicy);
} else {
AbstractAuthenticationPolicyType authPolicy = SecurityPolicyUtil.getAuthenticationPolicy(selfRegistration.getAdditionalAuthenticationSequence() == null ? selfRegistration.getAdditionalAuthenticationName() : selfRegistration.getAdditionalAuthenticationSequence(), securityPolicy);
if (authPolicy instanceof MailAuthenticationPolicyType) {
this.mailAuthenticationPolicy = (MailAuthenticationPolicyType) authPolicy;
noncePolicy = SecurityPolicyUtil.getCredentialPolicy(((MailAuthenticationPolicyType) authPolicy).getMailNonce(), securityPolicy);
} else if (authPolicy instanceof SmsAuthenticationPolicyType) {
this.smsAuthenticationPolicy = (SmsAuthenticationPolicyType) authPolicy;
noncePolicy = SecurityPolicyUtil.getCredentialPolicy(((SmsAuthenticationPolicyType) authPolicy).getSmsNonce(), securityPolicy);
}
}
}
use of com.evolveum.midpoint.authentication.api.config.MidpointAuthentication in project midpoint by Evolveum.
the class MidpointAuthFilter method doFilterInternal.
private void doFilterInternal(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
HttpServletRequest httpRequest = (HttpServletRequest) request;
if (isPermitAllPage(httpRequest)) {
chain.doFilter(request, response);
return;
}
MidpointAuthentication mpAuthentication = (MidpointAuthentication) SecurityContextHolder.getContext().getAuthentication();
AuthenticationWrapper authWrapper = defineAuthenticationWrapper();
if (AuthSequenceUtil.isIgnoredLocalPath(authWrapper.authenticationsPolicy, httpRequest)) {
chain.doFilter(request, response);
return;
}
initializeAuthenticationSequence(mpAuthentication, httpRequest, authWrapper);
if (authWrapper.sequence == null) {
IllegalArgumentException ex = new IllegalArgumentException(getMessageSequenceIsNull(httpRequest, authWrapper));
LOGGER.error(ex.getMessage(), ex);
((HttpServletResponse) response).sendRedirect(httpRequest.getContextPath());
return;
}
setLogoutPath(request, response);
authWrapper.authenticationChannel = AuthSequenceUtil.buildAuthChannel(authChannelRegistry, authWrapper.sequence);
try {
initAuthenticationModule(mpAuthentication, authWrapper, httpRequest);
if (isRequestAuthenticated(mpAuthentication, authWrapper)) {
processingOfAuthenticatedRequest(mpAuthentication, httpRequest, response, chain);
return;
}
if (wasNotFoundAuthModule(authWrapper)) {
if (LOGGER.isDebugEnabled()) {
LOGGER.debug(UrlUtils.buildRequestUrl(httpRequest) + "has no authentication module");
}
throw new AuthenticationServiceException("Couldn't find authentication module for sequence " + authWrapper.sequence.getName());
}
resolveErrorWithMoreModules(mpAuthentication, httpRequest);
int indexOfProcessingModule;
if (needCreateNewAuthenticationToken(mpAuthentication, httpRequest)) {
indexOfProcessingModule = initNewAuthenticationToken(authWrapper, httpRequest);
mpAuthentication = (MidpointAuthentication) SecurityContextHolder.getContext().getAuthentication();
} else {
indexOfProcessingModule = getIndexOfActualProcessingModule(mpAuthentication, httpRequest);
}
setAuthenticationChanel(mpAuthentication, authWrapper);
runFilters(authWrapper, indexOfProcessingModule, chain, httpRequest, response);
} finally {
removingFiltersAfterProcessing(mpAuthentication, httpRequest);
}
}
use of com.evolveum.midpoint.authentication.api.config.MidpointAuthentication in project midpoint by Evolveum.
the class MidpointAuthFilter method restartAuthFlow.
private int restartAuthFlow(HttpServletRequest httpRequest, AuthenticationWrapper authWrapper) {
createMpAuthentication(httpRequest, authWrapper);
MidpointAuthentication mpAuthentication = (MidpointAuthentication) SecurityContextHolder.getContext().getAuthentication();
return mpAuthentication.resolveParallelModules(httpRequest, 0);
}
use of com.evolveum.midpoint.authentication.api.config.MidpointAuthentication in project midpoint by Evolveum.
the class MidpointSaml2WebSsoAuthenticationRequestFilter method doFilterInternal.
@Override
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException {
super.doFilterInternal(request, response, filterChain);
RequestMatcher.MatchResult matcher = this.redirectMatcher.matcher(request);
if (!matcher.isMatch()) {
return;
}
Saml2AuthenticationRequestContext context = this.authenticationRequestContextResolver.resolve(request);
if (context == null) {
return;
}
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
if (authentication instanceof MidpointAuthentication) {
MidpointAuthentication mpAuthentication = (MidpointAuthentication) authentication;
Saml2ModuleAuthenticationImpl moduleAuthentication = (Saml2ModuleAuthenticationImpl) mpAuthentication.getProcessingModuleAuthentication();
moduleAuthentication.setRequestState(RequestState.SENDED);
}
}
use of com.evolveum.midpoint.authentication.api.config.MidpointAuthentication in project midpoint by Evolveum.
the class MailNonceProvider method illegalAuthentication.
private boolean illegalAuthentication() {
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
if (!(authentication instanceof MidpointAuthentication)) {
LOGGER.debug("Actual authentication isn't MidpointAuthentication");
return true;
}
ModuleAuthentication moduleAuth = ((MidpointAuthentication) authentication).getProcessingModuleAuthentication();
if (!(moduleAuth instanceof MailNonceModuleAuthenticationImpl)) {
LOGGER.debug("Actual processing authentication module isn't MailNonceModuleAuthentication");
return true;
}
String nameOfCredential = ((MailNonceModuleAuthenticationImpl) moduleAuth).getCredentialName();
if (nameOfCredential == null) {
LOGGER.debug("Name of credential in processing module is null");
return true;
}
return false;
}
Aggregations