- 私とJSFのログインページを統合します。<strong>春 セキュリティ</strong>で<strong>JSF</strong> Webアプリケーションを統合しようとしている春のセキュリティ
現在、この メソッド内で認証し、ユーザーに基づいて宛先ページにリダイレクトする方法でログインしています。
ログインページ(login.xhtml):
<h:form id="login">
<h:outputLabel for="email" value="E-mail: "/>
<p:inputText id="email" value="#{loginManagedBean.usuario.email}" required="true"/>
<p:message for="email"/>
<h:outputLabel for="pass" value="Contraseña: "/>
<p:password id="pass" value="#{loginManagedBean.usuario.password}" required="true"/>
<p:message for="pass"/>
<!-- <input type="hidden" name="${_csrf.parameterName}" value="${_csrf.token}"/> -->
<p:commandButton value="Login" update="@form" action="#{loginManagedBean.autenticar()}"/>
</h:form>
loginManagedBean.autenticar()(を認証し、リダイレクト方法):私は置き換えることができますどのように
このページとSpringSecurityで動作するメソッドは?
SpringSecurityConfig:
@Override
protected void configure(HttpSecurity http) throws Exception {
//.csrf() is optional, enabled by default, if using WebSecurityConfigurerAdapter constructor
// Have to disable it for POST methods:
// http://stackoverflow.com/a/20608149/1199132
http.csrf().disable();
// Logout and redirection:
// http://stackoverflow.com/a/24987207/1199132
http
.logout()
.logoutRequestMatcher(new AntPathRequestMatcher("/logout"))
.deleteCookies("JSESSIONID")
.invalidateHttpSession(true)
.logoutSuccessUrl("/login.xhtml");
http
.authorizeRequests()
//Permit access for all to error and denied views
.antMatchers("/WEB-INF/errorpages/general.xhtml", "/WEB-INF/errorpages/accessDenied.xhtml", "/WEB-INF/errorpages/expired.html", "/login.xhtml")
.permitAll()
// Only access with admin role
.antMatchers("/admin/**")
.hasRole("ADMIN")
//Permit access only for some roles
.antMatchers("/alumno/**")
.hasRole("ALUMNO")
//Permit access only for some roles
.antMatchers("/profesor/**")
.hasRole("PROFESOR")
//If user doesn't have permission, forward him to login page
.and()
.formLogin()
.loginPage("/login.xhtml")
.usernameParameter("login:email")
.passwordParameter("login:pass")
.loginProcessingUrl("/login") //
.defaultSuccessUrl("/admin/homeAdmin.xhtml")
.and()
.exceptionHandling()
.accessDeniedPage("/WEB-INF/errorpages/accessDenied.xhtml");
}
ここにコードを入力しないでください。あなたが理解していない問題やコードの部分を引き起こしたコードを入れてください。さもなければ、それは答えにあまりにも退屈です。 –
春のセキュリティは、URLを超えて構成することができます。それとは別に、認証エンドポイントを提供するので、その認証エンドポイントへのPOST(JSF以外のプレーンフォームを使用)を実行し、ログインしたらアプリケーションURLに移動します。 –