use of com.evolveum.midpoint.authentication.api.config.MidpointAuthentication in project midpoint by Evolveum.
the class OidcAuthorizationRequestRedirectFilter method unsuccessfulAuthentication.
protected void unsuccessfulAuthentication(HttpServletRequest request, HttpServletResponse response, AuthenticationException failed) throws IOException, ServletException {
String channel;
Authentication actualAuthentication = SecurityContextHolder.getContext().getAuthentication();
if (actualAuthentication instanceof MidpointAuthentication && ((MidpointAuthentication) actualAuthentication).getAuthenticationChannel() != null) {
channel = ((MidpointAuthentication) actualAuthentication).getAuthenticationChannel().getChannelId();
} else {
channel = SchemaConstants.CHANNEL_USER_URI;
}
auditProvider.auditLoginFailure("unknown user", null, ConnectionEnvironment.create(channel), "OIDC authentication module: " + failed.getMessage());
this.failureHandler.onAuthenticationFailure(request, response, failed);
}
use of com.evolveum.midpoint.authentication.api.config.MidpointAuthentication in project midpoint by Evolveum.
the class OidcAuthorizationRequestRedirectFilter method doFilterInternal.
@Override
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException {
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
if (authentication instanceof MidpointAuthentication) {
MidpointAuthentication mpAuthentication = (MidpointAuthentication) authentication;
OidcClientModuleAuthenticationImpl moduleAuthentication = (OidcClientModuleAuthenticationImpl) mpAuthentication.getProcessingModuleAuthentication();
try {
OAuth2AuthorizationRequest authorizationRequest = this.authorizationRequestResolver.resolve(request);
if (authorizationRequest != null) {
this.sendRedirectForAuthorization(request, response, authorizationRequest);
moduleAuthentication.setRequestState(RequestState.SENDED);
return;
}
} catch (Exception ex) {
unsuccessfulAuthentication(request, response, new InternalAuthenticationServiceException("web.security.provider.invalid", ex));
return;
}
try {
filterChain.doFilter(request, response);
} catch (IOException ex) {
throw ex;
} catch (Exception ex) {
// Check to see if we need to handle ClientAuthorizationRequiredException
Throwable[] causeChain = this.throwableAnalyzer.determineCauseChain(ex);
ClientAuthorizationRequiredException authzEx = (ClientAuthorizationRequiredException) this.throwableAnalyzer.getFirstThrowableOfType(ClientAuthorizationRequiredException.class, causeChain);
if (authzEx != null) {
try {
OAuth2AuthorizationRequest authorizationRequest = this.authorizationRequestResolver.resolve(request, authzEx.getClientRegistrationId());
if (authorizationRequest == null) {
throw authzEx;
}
this.sendRedirectForAuthorization(request, response, authorizationRequest);
moduleAuthentication.setRequestState(RequestState.SENDED);
this.requestCache.saveRequest(request, response);
} catch (Exception failed) {
unsuccessfulAuthentication(request, response, new InternalAuthenticationServiceException("web.security.provider.invalid", failed));
}
return;
}
if (ex instanceof ServletException) {
throw (ServletException) ex;
}
if (ex instanceof RuntimeException) {
throw (RuntimeException) ex;
}
throw new RuntimeException(ex);
}
} else {
throw new AuthenticationServiceException("Unsupported type of Authentication");
}
}
use of com.evolveum.midpoint.authentication.api.config.MidpointAuthentication in project midpoint by Evolveum.
the class OidcClientLogoutSuccessHandler method determineTargetUrl.
protected String determineTargetUrl(HttpServletRequest request, HttpServletResponse response, Authentication authentication) {
String targetUrl = null;
if (authentication instanceof MidpointAuthentication) {
MidpointAuthentication mPAuthentication = (MidpointAuthentication) authentication;
ModuleAuthentication moduleAuthentication = mPAuthentication.getProcessingModuleAuthentication();
if (moduleAuthentication instanceof OidcClientModuleAuthenticationImpl) {
Authentication internalAuthentication = moduleAuthentication.getAuthentication();
if (internalAuthentication instanceof PreAuthenticatedAuthenticationToken || internalAuthentication instanceof AnonymousAuthenticationToken) {
Object details = internalAuthentication.getDetails();
if (details instanceof OAuth2LoginAuthenticationToken && ((OAuth2LoginAuthenticationToken) details).getDetails() instanceof OidcUser) {
OAuth2LoginAuthenticationToken oidcAuthentication = (OAuth2LoginAuthenticationToken) details;
String registrationId = oidcAuthentication.getClientRegistration().getRegistrationId();
ClientRegistration clientRegistration = this.clientRegistrationRepository.findByRegistrationId(registrationId);
URI endSessionEndpoint = this.endSessionEndpoint(clientRegistration);
if (endSessionEndpoint != null) {
String idToken = this.idToken(oidcAuthentication);
String postLogoutRedirectUri = this.postLogoutRedirectUri(request);
targetUrl = this.endpointUri(endSessionEndpoint, idToken, postLogoutRedirectUri);
}
}
}
}
}
return targetUrl != null ? targetUrl : super.determineTargetUrl(request, response);
}
use of com.evolveum.midpoint.authentication.api.config.MidpointAuthentication in project midpoint by Evolveum.
the class MidPointLdapAuthenticationProvider method doAuthentication.
protected DirContextOperations doAuthentication(DirContextOperations originalDirContextOperations) {
if (originalDirContextOperations instanceof DirContextAdapter) {
Authentication actualAuthentication = SecurityContextHolder.getContext().getAuthentication();
if (actualAuthentication instanceof MidpointAuthentication) {
MidpointAuthentication mpAuthentication = (MidpointAuthentication) actualAuthentication;
ModuleAuthenticationImpl moduleAuthentication = (ModuleAuthenticationImpl) getProcessingModule(mpAuthentication);
if (moduleAuthentication instanceof LdapModuleAuthentication) {
// HACK because of NP in DirContextAdapter(DirContextAdapter master)
if (!originalDirContextOperations.isUpdateMode()) {
((DirContextAdapter) originalDirContextOperations).setUpdateMode(true);
((DirContextAdapter) originalDirContextOperations).setUpdateMode(false);
}
LdapDirContextAdapter mpDirContextAdapter = new LdapDirContextAdapter((DirContextAdapter) originalDirContextOperations);
mpDirContextAdapter.setNamingAttr(((LdapModuleAuthentication) moduleAuthentication).getNamingAttribute());
if (moduleAuthentication.getFocusType() != null) {
Class<FocusType> focusType = PrismContext.get().getSchemaRegistry().determineCompileTimeClass(moduleAuthentication.getFocusType());
mpDirContextAdapter.setFocusType(focusType);
}
return mpDirContextAdapter;
}
}
}
return originalDirContextOperations;
}
use of com.evolveum.midpoint.authentication.api.config.MidpointAuthentication in project midpoint by Evolveum.
the class MidPointLdapAuthenticationProvider method createSuccessfulAuthentication.
protected void createSuccessfulAuthentication(UsernamePasswordAuthenticationToken authentication, Authentication authNCtx) {
Object principal = authNCtx.getPrincipal();
if (!(principal instanceof MidPointPrincipal)) {
recordPasswordAuthenticationFailure(authentication.getName(), "not contains required assignment");
throw new BadCredentialsException("LdapAuthentication.incorrect.value");
}
MidPointPrincipal midPointPrincipal = (MidPointPrincipal) principal;
FocusType focusType = midPointPrincipal.getFocus();
Authentication actualAuthentication = SecurityContextHolder.getContext().getAuthentication();
if (actualAuthentication instanceof MidpointAuthentication) {
MidpointAuthentication mpAuthentication = (MidpointAuthentication) actualAuthentication;
List<ObjectReferenceType> requireAssignment = mpAuthentication.getSequence().getRequireAssignmentTarget();
if (!AuthenticationEvaluatorUtil.checkRequiredAssignment(focusType.getAssignment(), requireAssignment)) {
recordPasswordAuthenticationFailure(midPointPrincipal.getUsername(), "not contains required assignment");
throw new InternalAuthenticationServiceException("web.security.flexAuth.invalid.required.assignment");
}
}
recordPasswordAuthenticationSuccess(midPointPrincipal);
}
Aggregations