@SuppressWarnings("PMD.SignatureDeclareThrowsException") private RequestHeaderAuthenticationFilter requestHeaderAuthenticationFilter() throws Exception { RequestHeaderAuthenticationFilter f = new RequestHeaderAuthenticationFilter(); f.setPrincipalRequestHeader("X-Forwarded-User"); f.setCredentialsRequestHeader("X-Forwarded-Access-Token"); f.setAuthenticationManager(authenticationManager()); f.setAuthenticationDetailsSource( (AuthenticationDetailsSource<HttpServletRequest, PreAuthenticatedGrantedAuthoritiesWebAuthenticationDetails>) (request) ->new PreAuthenticatedGrantedAuthoritiesWebAuthenticationDetails( request, AuthorityUtils.createAuthorityList("ROLE_AUTHENTICATED") ) ); f.setAuthenticationFailureHandler(new SimpleUrlAuthenticationFailureHandler()); f.setExceptionIfHeaderMissing(false); return f; }
@Override public GrantedAuthoritiesContainer buildDetails(HttpServletRequest request) { List gal = new ArrayList(); try { GrantedAuthority ga = null; if (StringUtils.hasLength(request.getHeader("uid"))) { ga = new SimpleGrantedAuthority("ROLE_USER"); } else { ga = new SimpleGrantedAuthority("ROLE_ANONYMOUS"); } log.debug("UID=" + request.getHeader("uid") + "|Granted:" + ga); gal.add(ga); } catch (Exception e) { throw new AuthenticationServiceException("Error..", e); } return new PreAuthenticatedGrantedAuthoritiesWebAuthenticationDetails(request, gal); }
private AuthenticationDetailsSource<HttpServletRequest, ?> detailsSource() { return (request) -> { Collection<? extends GrantedAuthority> authorities = Collections.singleton(new SimpleGrantedAuthority("ROLE_USER")); return new PreAuthenticatedGrantedAuthoritiesWebAuthenticationDetails(request, authorities); }; }