@Override
protected void doFilterInternal(final HttpServletRequest httpServletRequest, final HttpServletResponse httpServletResponse, final FilterChain filterChain) throws ServletException, IOException {
final boolean isNotConnected = userService.isConnected(userService.getCurrentUser());
String token = httpServletRequest.getParameter("token");
if (isNotConnected && StringUtils.isNotEmpty(token)) {
try {
final DecodedJWT jwt = verify(token);
String id = decodedJWT.getSubject();
helper.ssoLogin(httpServletRequest, httpServletResponse, id);
} catch (Exception e) {
// log exception
}
}
filterChain.doFilter(httpServletRequest, httpServletResponse);
}
< /code>
В конце этого фильтра я успешно аутентифицирован. Однако, как только запрос пройдет через фильтры безопасности Spring, пользователь становится анонимным. конец ssoconnectfilter: < /p>
аутентификация [principal=sso.test@stackoverflow.com, учетные данные = [защищен], аутентифицированный = true, detail = null, предоставлено Власти = [role_customergroup]] < /p>
< /blockquote>
А и вот результат после прохождения через SpringsecurityfilterChain: < /p>
AnonymousAuthenticationToken [Principal=anonymous, Credentials=[PROTECTED], Authenticated=true, Details=WebAuthenticationDetails [RemoteIpAddress=0:0:0:0:0:0:0:1, SessionId=C55080B50140AB87920815D195F4A3E1], Granted Authorities= [Role_anonymous]] < /p>
< /blockquote>
Вот порядок моих фильтров: < /p>
< /code>
Когда я достигаю другого Filter и пытаюсь проверить пользователя, я обнаружил, что пользователь является анонимным. < /p>
Мое требование состоит Spring Security Filters, чтобы они могли получить доступ к страницам, требующим аутентификации. Убедитесь, что пользователь остается аутентифицированным после фильтров безопасности Spring? пользователь < /p>
@Override
public void login(final User usr, final HttpServletRequest request, final HttpServletResponse response) {
try {
final UsernamePasswordAuthenticationToken token = new UsernamePasswordAuthenticationToken(usr.getUid(), usr.getPasswordEncoding());
// Set the current user in the user service
userService.setCurrentUser(usr);
// Define user roles and authorities
final ArrayList auth = new ArrayList();
auth.add(new SimpleGrantedAuthority("ROLE_" + Constants.USER.CUSTOMER_USERGROUP.toUpperCase()));
// Create an authentication object
final Authentication authentication = new GigyaAuthentication(usr, auth);
// Apply authentication-related security measures
fixation.onAuthentication(authentication, request, response);
// Store authentication in the SecurityContext
SecurityContextHolder.getContext().setAuthentication(authentication);
// Trigger login success processes
customerFacade.loginSuccess();
// Set session-related cookies
guidCookieStrategy.setCookie(request, response);
sessionTokenCookieGenerator.addCookie(response, chanelSessionTokenUtil.generateSessionToken());
// Handle the remember-me cookie mechanism
handleRememberMeCookie(request, response);
rememberMeServices.loginSuccess(request, response, token);
} catch (final Exception e) { // NOSONAR
// Clear authentication in case of failure
SecurityContextHolder.getContext().setAuthentication(null);
}
Я сталкиваюсь с проблемой, внедренной SSO в моем приложении, с Spring Security уже установлена. Class = "Lang-Java PrettyPrint-Override">[code]@Override protected void doFilterInternal(final HttpServletRequest httpServletRequest, final HttpServletResponse httpServletResponse, final FilterChain filterChain) throws ServletException, IOException {
final boolean isNotConnected = userService.isConnected(userService.getCurrentUser()); String token = httpServletRequest.getParameter("token");
if (isNotConnected && StringUtils.isNotEmpty(token)) { try { final DecodedJWT jwt = verify(token); String id = decodedJWT.getSubject();
helper.ssoLogin(httpServletRequest, httpServletResponse, id); } catch (Exception e) { // log exception } } filterChain.doFilter(httpServletRequest, httpServletResponse); } < /code> В конце этого фильтра я успешно аутентифицирован. Однако, как только запрос пройдет через фильтры безопасности Spring, пользователь становится анонимным. конец ssoconnectfilter: < /p>
аутентификация [principal=sso.test@stackoverflow.com, учетные данные = [защищен], аутентифицированный = true, detail = null, предоставлено Власти = [role_customergroup]] < /p> < /blockquote> А и вот результат после прохождения через SpringsecurityfilterChain: < /p>
AnonymousAuthenticationToken [Principal=anonymous, Credentials=[PROTECTED], Authenticated=true, Details=WebAuthenticationDetails [RemoteIpAddress=0:0:0:0:0:0:0:1, SessionId=C55080B50140AB87920815D195F4A3E1], Granted Authorities= [Role_anonymous]] < /p> < /blockquote> Вот порядок моих фильтров: < /p>
< /code> Когда я достигаю другого Filter и пытаюсь проверить пользователя, я обнаружил, что пользователь является анонимным. < /p> Мое требование состоит Spring Security Filters, чтобы они могли получить доступ к страницам, требующим аутентификации. Убедитесь, что пользователь остается аутентифицированным после фильтров безопасности Spring? пользователь < /p> @Override public void login(final User usr, final HttpServletRequest request, final HttpServletResponse response) { try { final UsernamePasswordAuthenticationToken token = new UsernamePasswordAuthenticationToken(usr.getUid(), usr.getPasswordEncoding());
// Set the current user in the user service userService.setCurrentUser(usr);
// Define user roles and authorities final ArrayList auth = new ArrayList(); auth.add(new SimpleGrantedAuthority("ROLE_" + Constants.USER.CUSTOMER_USERGROUP.toUpperCase()));
// Create an authentication object final Authentication authentication = new GigyaAuthentication(usr, auth);
// Set session-related cookies guidCookieStrategy.setCookie(request, response); sessionTokenCookieGenerator.addCookie(response, chanelSessionTokenUtil.generateSessionToken());