私は私の春のセキュリティ春のセキュリティ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);
}
毎回に問題がある、私はそれがブートストラップファイルに私を送り、ログインしない...
はlocalhost:8080/CSS /ブートストラップ-3.3.7-DIST/CSS/bootstrap.min.css
か...
はlocalhost:8080/CSS /のcustom.css
か...
はlocalhost:8080/JS/jqueryの-2.1.4.min.js
ではなく、同じものに(ランダムに見える! :-)
時々、のCSSが機能しないことがあります。ログインフォームにはスタイルはありませんが、アプリを実行するとスタイルがあるため、ときどきしかありません。私はログインするときも、ログアウトするときやログインをやり直すときはしません。したがって、ユーザーが正しくログインすると、スタイルが再び反映されます。
ユーザーが「ROLE_USER」で「/ controlpanel」にアクセスしようとしたときにアクセスが許可されているはずですが、ユーザー(Role_ADMIN)と操作するとうまく動作します。
ありがとう、それは動作しません。私はこれらのパスに静的なCSS、JS、イメージを入れていますが、動作しません。あなたは私が見てみることができる任意のドキュメントを知っていますか?再度、感謝します。 – Mike
それは動作しないとはどういう意味ですか?ページがロードされている間に読み込まれるリソース(Web Developerツールの「Network」タブ)を見ると、静的コンテンツ・ファイルの「HTTP 401」が表示されますか?それとも何か?詳細を追加してください。 – Artegon
ありがとうございます、今すぐ動作します – Mike