SpringBoot(Security) ãã°ã¤ã³èªè¨¼ã試ã 1.è¨å®
WebSecurityConfigurerAdapterãç¶æ¿ããã¯ã©ã¹ã§è¨å®ãè¡ã
Â
- å¶éãé©ç¨ããªããªã½ã¼ã¹ãè¨å®
 @Override
public void configure(WebSecurity web) throws Exception { // å¶éãé©ç¨ããªããã¹ãè¨å®
 web.ignoring().antMatchers("/js/ââ", "/css/ââ");
}
- ãã°ã¤ã³èªè¨¼ã®è¨å®
@Override
protected void configure(HttpSecurity http) throws Exception { // ãã°ã¤ã³ä¸è¦ãã¼ã¸ã®è¨å®
 http.authorizeRequests()
  .antMatchers("/loginform", "/error" ).permitAll() //permitAll() ã§ãã°ã¤ã³ããªãã¦ãã¢ã¯ã»ã¹ã§ãããã¹ãè¨å®ï¼ãã°ã¤ã³ç»é¢ã¨ãï¼
  .antMatchers("/admin/**").hasAuthority("ROLE_ADMIN") //ã¢ããã³æ¨©éã«è¨±å¯
  .antMatchers("/user/**").hasRole("USER") //ã¦ã¼ã¶æ¨©éã«è¨±å¯ãhasRoleã¯ãROLE_ããè£å®
  .anyRequest().authenticated(); //ãã®ä»ã¯ãã°ã¤ã³ããªãã¨ã¢ã¯ã»ã¹ä¸å¯Â
 //ãã°ã¤ã³å¦çã®è¨å®
 http.formLogin()
  .loginProcessingUrl("/login") //ãã°ã¤ã³å¦çã®ãã¹
  .loginPage("/loginform") //ãã°ã¤ã³ãã¼ã¸ã®ãã¹
  .failureUrl("/loginform") //ãã°ã¤ã³å¤±ææã®é·ç§»å
  .usernameParameter("email") //ãã°ã¤ã³ã®ã¦ã¼ã¶ã¼ID
  .passwordParameter("password") //ãã°ã¤ã³ã®ãã¹ã¯ã¼ã
  .defaultSuccessUrl("/", true); //ãã°ã¤ã³æåå¾ã®é·ç§»å ï¼true:å¿ ãTOPãfalse:ãã°ã¤ã³åã«æå®ãã¦ãããã¼ã¸ã«é·ç§»ï¼Â
 //ãã°ã¢ã¦ãå¦çã®è¨å®
 http.logout()
  .logoutRequestMatcher(new AntPathRequestMatcher("/logout")) // ãã°ã¢ã¦ãå¦çã®ãã¹ãlogoutUrlã¯getã«ããé©ç¨ãããªã
  .logoutSuccessUrl("/login"); //ãã°ã¢ã¦ãæåå¾ã®URL
  .deleteCookies("JSESSIONID") // ãã°ã¢ã¦ãæã«ã¯ããã¼åé¤
  .invalidateHttpSession(true); // ãã°ã¢ã¦ãæã«ã»ãã·ã§ã³ç ´æ£Â http.sessionManagement().invalidSessionUrl("/loginform"); // ã»ãã·ã§ã³åãã®å ´åã®é·ç§»å
}
Â