當用戶點擊http://localhost:8080時,我有要求通過春季安全顯示基於自定義的登錄表單(/auth/login.html)。如果用戶以管理員角色成功登錄,請將用戶重定向到/admin/adminsuccess.html。一旦admin用戶重定向到/adminsuccess.html,我需要允許admin用戶訪問其他頁面,例如(/admin/assetallocate.html,/admin/assetdeallocate.html..)If用戶不具有管理員的角色登錄,顯示有錯誤相同的登錄頁面..春季安全螞蟻匹配家庭根/ - 春季啓動1.4.2發佈版本
下面是我的代碼:
@Configuration
public class AssetWebConfig extends WebMvcConfigurerAdapter {
@Override
public void addViewControllers(ViewControllerRegistry registry) {
registry.addViewController("/login").setViewName("auth/login");
registry.addViewController("/admin/adminsuccess").setViewName("admin/auth-success");
registry.setOrder(Ordered.HIGHEST_PRECEDENCE);
}
}
@Configuration
@EnableWebSecurity
@Order(SecurityProperties.ACCESS_OVERRIDE_ORDER)
public class SecurityConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.authorizeRequests()
.antMatchers("/login").permitAll()
.antMatchers("/admin/**").access("hasRole('ROLE_ADMIN')")
.antMatchers("/**").access("hasRole('ROLE_ADMIN')")
.and()
.formLogin()
.loginPage("/login")
.usernameParameter("username")
.passwordParameter("password")
.defaultSuccessUrl("/admin/adminsuccess")
.and()
.logout()
.logoutSuccessUrl("/login?logout")
.permitAll()
.and()
.csrf().disable();
}
}
/auth/login.html
<form name="loginform" th:action="@{/login}" method="post" class="form-signin">
上面的代碼無論我寫不符合預期的工作。這可能是螞蟻匹配模式的問題。請指導。
更新: 當我點擊「http://localhost:8080」時,自定義登錄頁面正在顯示。但是,當我輸入正確的憑據時,它不會重定向到基於AssetWebConfig.java配置查看名稱「/admin/auth-success.html」。如果我輸入正確的憑證,下面是當前的迴應。
This application has no explicit mapping for /error, so you are seeing this as a fallback.
Wed Nov 23 11:42:59 IST 2016
There was an unexpected error (type=Not Found, status=404).
No message available
它不工作: ( – user2057006
你可以發佈你的服務器日誌或堆棧跟蹤,如果你得到一個異常 –
我編輯我的帖子與所需的細節。請幫助。 – user2057006