我有一個問題,我的Spring Security春季安全HTTP FormLogin
@Configuration
@EnableWebSecurity
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
@Autowired
private UsuarioService usuarioService;
@Autowired
private PasswordEncoder passwordEncoder;
@Override
protected void configure(HttpSecurity http) throws Exception {
// @formatter:off
http
.authorizeRequests()
.antMatchers(
"/",
"/index/**",
"/register",
"/doregister",
"/login",
"/dologin",
"/logout-success",
"/confirmregister",
"/invaliduser",
"/expiredtoken",
"/userstatuslog",
"/verifyemail")
.permitAll()
.anyRequest()
.authenticated()
.and()
.authorizeRequests()
.antMatchers(
"/login",
"logout")
.permitAll()
.and()
.authorizeRequests()
.antMatchers(
"/static/css/**",
"/css/custom.css",
"/js/**",
"/images/**"
)
.permitAll()
.and()
.authorizeRequests()
.antMatchers(
"/forbidden",
"/edit-profile-about",
"/doeditprofileabout",
"/profile"
)
.hasRole("USER")
.and()
.authorizeRequests()
.antMatchers(
"/controlpanel",
"/forbidden",
"/edit-profile-about",
"/doeditprofileabout",
"/profile"
)
.hasRole("ADMIN")
.and()
.formLogin()
.loginPage("/login")
.defaultSuccessUrl("/")
.permitAll()
.and()
.logout()
.deleteCookies("remove")
.invalidateHttpSession(true)
.logoutUrl("/logout")
.logoutSuccessUrl("/logout-success")
.logoutRequestMatcher(new AntPathRequestMatcher("/logout"));
// @formatter:on
}
@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
auth.userDetailsService(usuarioService).passwordEncoder(passwordEncoder);
}
每次,我登錄它發送我的引導文件...
本地主機:8080/CSS /引導-3.3.7-DIST/CSS/bootstrap.min.css
或...
本地主機:8080/CSS/custom.css
或...
本地主機:8080/JS/jQuery的2.1.4.min.js
但不到同一個(它似乎是隨機的! :-)
然後有時CSS有效,有時不。在登錄表單中它沒有樣式,但有時只有,因爲當我運行應用程序時,它具有樣式。而且當我登錄時,但不是當我註銷或嘗試再次登錄時。因此,當用戶正確登錄時,它又具有樣式。
當我試圖訪問「/ controlpanel」與用戶(與ROLE_USER)它允許訪問(它不應該),但是當我與用戶(Role_ADMIN)它做的很好。
謝謝,但它不起作用。我在這些路徑中包含靜態,CSS,js,圖像,但它不起作用。你知道我可以查看的任何文檔嗎?再次感謝。 – Mike
這是什麼意思,它不工作?在加載頁面時(在Webdeveloper工具中,選項卡網絡中),當您查看讀取什麼資源時,是否會爲您的靜態內容文件看到「HTTP 401」?還是其他什麼?添加更多細節。 – Artegon
謝謝,它現在有效 – Mike