Я видел такие вопросы, но я не видел ответа на свой конкретный вопрос.Весенняя безопасность jsf не перенаправляется после успешных логинов
Я использую весеннюю безопасность 2.1 и jsf 2.1. У меня есть пользовательский jsf-логин, который я разрабатываю для обработки входа из файла xhtml.
Вот метод Логин:
public String login() throws ServletException, IOException {
ExternalContext context = FacesContext.getCurrentInstance()
.getExternalContext();
RequestDispatcher dispatcher = ((ServletRequest) context.getRequest())
.getRequestDispatcher("/j_spring_security_check");
dispatcher.forward((ServletRequest) context.getRequest(),
(ServletResponse) context.getResponse());
FacesContext.getCurrentInstance().responseComplete();
Exception e = (Exception) FacesContext.getCurrentInstance().
getExternalContext().getSessionMap().get(WebAttributes.AUTHENTICATION_EXCEPTION);
// It's OK to return null here because Faces is just going to exit.
return null;
}
Я вытащил пример кода из другого поста.
Вот моя конфигурация пружины:
<http use-expressions="true" auto-config="true">
<!-- <intercept-url pattern="/signin.xhtml" access="permitAll" /> -->
<intercept-url pattern="/internal/private/**" access="hasRole('USER')" />
<!-- <intercept-url pattern="/scheduling/internal/private/**" access="hasAnyRole('ADMIN','USER')"
/> -->
<!--<intercept-url pattern="/javax.faces.resource/**" access="permitAll"/>
<intercept-url pattern="/**" access="permitAll" /> -->
<form-login default-target-url="/internal/private/landing.xhtml"
login-page="/signin.xhtml" />
</http>
Как вы можете видеть, что мой целевой URL по умолчанию является "/internal/private/landing.xhtml". Я включил debug и вижу, что аутентификация прошла, но никогда не перенаправляется на страницу по умолчанию.
Вот является пропущено из журнала, который показывает переадресации вызова из Spring:
08:58:03,701 DEBUG [org.springframework.security.web.authentication.session.SessionFixationProtectionStrategy] (http-localhost-127.0.0.1-8080-2) Invalidating session with Id 'qPg2MdmRgSpTcV6CVT7cb-9M.undefined' and migrating attributes.
08:58:03,703 DEBUG [org.springframework.security.web.authentication.session.SessionFixationProtectionStrategy] (http-localhost-127.0.0.1-8080-2) Started new session: GFoQyvUtbd+lmZiNw0QKRrI-.undefined
08:58:03,705 DEBUG [org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter] (http-localhost-127.0.0.1-8080-2) Authentication success. Updating SecurityContextHolder to contain: org.springframew[email protected]d9fa0ad7: Principal: [email protected]: Username: roland.jones; Password: [PROTECTED]; Enabled: true; AccountNonExpired: true; credentialsNonExpired: true; AccountNonLocked: true; Granted Authorities: ADMIN,USER; Credentials: [PROTECTED]; Authenticated: true; Details: org.sprin[email protected]fffe3f86: RemoteIpAddress: 127.0.0.1; SessionId: qPg2MdmRgSpTcV6CVT7cb-9M.undefined; Granted Authorities: ADMIN, USER
08:58:03,714 DEBUG [org.springframework.security.web.authentication.SavedRequestAwareAuthenticationSuccessHandler] (http-localhost-127.0.0.1-8080-2) Using default Url: /internal/private/landing.html
08:58:03,716 DEBUG [org.springframework.security.web.DefaultRedirectStrategy] (http-localhost-127.0.0.1-8080-2) Redirecting to '/scheduling/internal/private/landing.html'
08:58:03,718 DEBUG [org.springframework.security.web.context.HttpSessionSecurityContextRepository] (http-localhost-127.0.0.1-8080-2) SecurityContext stored to HttpSession: '[email protected]fa0ad7: Authentication: org.springframew[email protected]d9fa0ad7: Principal: [email protected]: Username: roland.jones; Password: [PROTECTED]; Enabled: true; AccountNonExpired: true; credentialsNonExpired: true; AccountNonLocked: true; Granted Authorities: ADMIN,USER; Credentials: [PROTECTED]; Authenticated: true; Details: org.sprin[email protected]fffe3f86: RemoteIpAddress: 127.0.0.1; SessionId: qPg2MdmRgSpTcV6CVT7cb-9M.undefined; Granted Authorities: ADMIN, USER'
08:58:03,727 DEBUG [org.springframework.security.web.context.HttpSessionSecurityContextRepository] (http-localhost-127.0.0.1-8080-2) SecurityContext stored to HttpSession: '[email protected]fa0ad7: Authentication: org.springframew[email protected]d9fa0ad7: Principal: [email protected]: Username: roland.jones; Password: [PROTECTED]; Enabled: true; AccountNonExpired: true; credentialsNonExpired: true; AccountNonLocked: true; Granted Authorities: ADMIN,USER; Credentials: [PROTECTED]; Authenticated: true; Details: org.sprin[email protected]fffe3f86: RemoteIpAddress: 127.0.0.1; SessionId: qPg2MdmRgSpTcV6CVT7cb-9M.undefined; Granted Authorities: ADMIN, USER'
08:58:05,156 DEBUG [org.springframework.security.web.access.ExceptionTranslationFilter] (http-localhost-127.0.0.1-8080-2) Chain processed normally
После того как я пытаюсь войти в систему, если я печатаю в URL по умолчанию в адресе она идет там не проблема, так что я знаю аутентификация прошла.
Пожалуйста, помогите. Благодаря!
Таким образом, я использую Spring Security 3.1, и я создал специальный обработчик успеха, подобный вышеприведенному, и до сих пор не перенаправляет. Есть ли другая конфигурация, которую мне нужно сделать. – braveheart1996
Спасибо, что помогли, но я это понял. Я использовал кнопку «Прайвры», и по какой-то причине Spring не нравится. Когда я перешел на обычную кнопку jsf, она работала нормально. Могу ли я задать вопрос весной об этом. – braveheart1996