All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.springframework.security.web.authentication.SavedRequestAwareAuthenticationSuccessHandlerCustom Maven / Gradle / Ivy

The newest version!
package org.springframework.security.web.authentication;

import java.io.IOException;
import java.util.Enumeration;
import java.util.Map;

import javax.servlet.ServletException;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.security.core.Authentication;
import org.springframework.util.CollectionUtils;
import org.springframework.util.LinkedCaseInsensitiveMap;
import org.springframework.util.StringUtils;
import org.springframework.web.util.WebUtils;

/**
 * 
 * Collection> collection = new LinkedHashSet>(Collections.emptyMap().entrySet());
 * DEFAULT_MAX_AGE = 31536000; // 60*60*24*365
 * 
* * @see org.springframework.util.ConcurrentReferenceHashMap.Entry */ public class SavedRequestAwareAuthenticationSuccessHandlerCustom extends SavedRequestAwareAuthenticationSuccessHandler { private Map include = new LinkedCaseInsensitiveMap(); @Override public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication) throws ServletException, IOException { for (java.util.Map.Entry entry : getMap(request).entrySet()) { WebUtils.setSessionAttribute(request, entry.getKey(), entry.getValue()); } super.onAuthenticationSuccess(request, response, authentication); } public Map getMap(HttpServletRequest request) { Map map = new LinkedCaseInsensitiveMap(); if (CollectionUtils.isEmpty(this.include)) { return map; } Cookie[] cookies = request.getCookies(); if (cookies != null) { for (Cookie cookie : cookies) { String value = this.include.get(cookie.getName()); if (StringUtils.hasText(value)) { map.put(value, cookie.getValue()); } } } Enumeration headerNames = request.getHeaderNames(); if (headerNames != null) { while (headerNames.hasMoreElements()) { String headerName = headerNames.nextElement(); String value = this.include.get(headerName); if (StringUtils.hasText(value)) { map.put(value, request.getHeader(headerName)); } } } Enumeration parameterNames = request.getParameterNames(); if (parameterNames != null) { while (parameterNames.hasMoreElements()) { String parameterName = parameterNames.nextElement(); String value = this.include.get(parameterName); if (StringUtils.hasText(value)) { map.put(value, request.getParameter(parameterName)); } } } return map; } public Map getInclude() { return include; } public void setInclude(Map include) { this.include = include; } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy