use of com.evolveum.midpoint.authentication.api.config.ModuleAuthentication in project midpoint by Evolveum.
the class PageLogin 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.LOGIN_FORM.equals(moduleAuthentication.getNameOfModuleType()) || AuthenticationModuleNameConstants.LDAP.equals(moduleAuthentication.getNameOfModuleType()))) {
String prefix = moduleAuthentication.getPrefix();
return AuthUtil.stripSlashes(prefix) + "/spring_security_login";
}
}
return "./spring_security_login";
}
use of com.evolveum.midpoint.authentication.api.config.ModuleAuthentication in project midpoint by Evolveum.
the class AbstractPageRemoteAuthenticationSelect method initCustomLayer.
@Override
protected void initCustomLayer() {
List<IdentityProvider> providers = getProviders();
add(new ListView<IdentityProvider>(ID_PROVIDERS, providers) {
@Override
protected void populateItem(ListItem<IdentityProvider> item) {
item.add(new ExternalLink(ID_PROVIDER, item.getModelObject().getRedirectLink(), item.getModelObject().getLinkText()));
}
});
MidpointForm<?> form = new MidpointForm<>(ID_LOGOUT_FORM);
ModuleAuthentication actualModule = AuthUtil.getProcessingModuleIfExist();
if (actualModule != null) {
Authentication actualAuthentication = actualModule.getAuthentication();
String authName = actualModule.getNameOfModuleType();
form.add(new VisibleBehaviour(() -> existRemoteAuthentication(actualAuthentication, authName)));
String prefix = actualModule.getPrefix();
form.add(AttributeModifier.replace("action", (IModel<String>) () -> existRemoteAuthentication(actualAuthentication, authName) ? SecurityUtils.getPathForLogoutWithContextPath(getRequest().getContextPath(), prefix) : ""));
} else {
form.add(new VisibleBehaviour(() -> false));
}
add(form);
WebMarkupContainer csrfField = SecurityUtils.createHiddenInputForCsrf(ID_CSRF_FIELD);
form.add(csrfField);
}
use of com.evolveum.midpoint.authentication.api.config.ModuleAuthentication in project midpoint by Evolveum.
the class AbstractModelIntegrationTest method createMpAuthentication.
protected Authentication createMpAuthentication(Authentication authentication) {
MidpointAuthentication mpAuthentication = new MidpointAuthentication(SecurityPolicyUtil.createDefaultSequence());
ModuleAuthentication moduleAuthentication = new ModuleAuthentication() {
@Override
public String getNameOfModule() {
return SecurityPolicyUtil.DEFAULT_MODULE_NAME;
}
@Override
public String getNameOfModuleType() {
return AuthenticationModuleNameConstants.LOGIN_FORM;
}
@Override
public AuthenticationModuleState getState() {
return AuthenticationModuleState.SUCCESSFULLY;
}
@Override
public void setState(AuthenticationModuleState state) {
}
@Override
public Authentication getAuthentication() {
return authentication;
}
@Override
public void setAuthentication(Authentication authentication) {
}
@Override
public String getPrefix() {
return ModuleWebSecurityConfiguration.DEFAULT_PREFIX_OF_MODULE_WITH_SLASH + ModuleWebSecurityConfiguration.DEFAULT_PREFIX_FOR_DEFAULT_MODULE + SecurityPolicyUtil.DEFAULT_MODULE_NAME + "/";
}
@Override
public QName getFocusType() {
return null;
}
};
mpAuthentication.addAuthentications(moduleAuthentication);
mpAuthentication.setPrincipal(authentication.getPrincipal());
return mpAuthentication;
}
use of com.evolveum.midpoint.authentication.api.config.ModuleAuthentication in project midpoint by Evolveum.
the class MidpointAuthFilter method processingOfAuthenticatedRequest.
private void processingOfAuthenticatedRequest(MidpointAuthentication mpAuthentication, ServletRequest httpRequest, ServletResponse response, FilterChain chain) throws IOException, ServletException {
for (ModuleAuthentication moduleAuthentication : mpAuthentication.getAuthentications()) {
if (AuthenticationModuleState.SUCCESSFULLY.equals(moduleAuthentication.getState())) {
int i = mpAuthentication.getIndexOfModule(moduleAuthentication);
VirtualFilterChain vfc = new VirtualFilterChain(chain, ((AuthModuleImpl) mpAuthentication.getAuthModules().get(i)).getSecurityFilterChain().getFilters());
vfc.doFilter(httpRequest, response);
}
}
}
use of com.evolveum.midpoint.authentication.api.config.ModuleAuthentication in project midpoint by Evolveum.
the class MidpointAuthenticationFailureHandler method onAuthenticationFailure.
@Override
public void onAuthenticationFailure(HttpServletRequest request, HttpServletResponse response, AuthenticationException exception) throws IOException {
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
String urlSuffix = AuthConstants.DEFAULT_PATH_AFTER_LOGIN;
if (authentication instanceof MidpointAuthentication) {
MidpointAuthentication mpAuthentication = (MidpointAuthentication) authentication;
if (mpAuthentication.isAuthenticated()) {
getRedirectStrategy().sendRedirect(request, response, urlSuffix);
return;
}
ModuleAuthentication moduleAuthentication = mpAuthentication.getProcessingModuleAuthentication();
if (mpAuthentication.getAuthenticationChannel() != null) {
if (mpAuthentication.isLast(moduleAuthentication) && mpAuthentication.getAuthenticationChannel().isDefault()) {
urlSuffix = getPathAfterUnsuccessfulAuthentication(mpAuthentication.getAuthenticationChannel());
} else {
urlSuffix = mpAuthentication.getAuthenticationChannel().getPathDuringProccessing();
}
}
moduleAuthentication.setState(AuthenticationModuleState.FAILURE);
}
saveException(request, exception);
SavedRequest savedRequest = getRequestCache().getRequest(request, response);
if (savedRequest == null || StringUtils.isBlank(savedRequest.getRedirectUrl()) || ((DefaultSavedRequest) savedRequest).getServletPath().startsWith(ModuleWebSecurityConfiguration.DEFAULT_PREFIX_OF_MODULE_WITH_SLASH)) {
getRedirectStrategy().sendRedirect(request, response, urlSuffix);
return;
}
getRedirectStrategy().sendRedirect(request, response, savedRequest.getRedirectUrl());
}
Aggregations