Я столкнулся с проблемой, которую я не смог решить ниже, это мой код.
@Configuration
@EnableWebSecurity
@EnableGlobalMethodSecurity(prePostEnabled = true)
public class SecurityConfiguration extends WebSecurityConfigurerAdapter{
@Autowired
private UserSecurityService userSecurityService;
private BCryptPasswordEncoder passwordEncoder() {
return SecurityUtility.passwordEncoder();
}
private static final String[] PUBLIC_MATCHERS = {
"/css/**",
"/images/**",
"/js/**",
"/",
"/myaccount"
};
@Override
protected void configure(HttpSecurity http) throws Exception{
http.authorizeRequests()
.antMatchers(PUBLIC_MATCHERS)
.permitAll().anyRequest().authenticated();
http
.csrf().disable().cors().disable()
.formLogin().failureUrl("/login?error")
.loginPage("/login").permitAll()
.and()
.logout().logoutRequestMatcher(new AntPathRequestMatcher("/logout"))
.logoutSuccessUrl("/?logout").deleteCookies("remember-me").permitAll()
.and()
.rememberMe();
}
@Autowired
public void configureGlobal(AuthenticationManagerBuilder authentication) throws Exception{
authentication.userDetailsService(userSecurityService).passwordEncoder(passwordEncoder());
}
}
Я пробовал много вещей, которые пытался отключить защиту в application.properties.когда я удалил этот бит кода из метода .permitAll (). anyRequest (). authenticated ();программа продолжается немного дальше и выдает еще одно исключение, предлагающее поставить hasRole () после antMatchers.Ниже мой код ошибки
2018-10-18 09:13:21.471 INFO 2660 --- [ main] org.hibernate.Version : HHH000412: Hibernate Core {5.2.17.Final}
2018-10-18 09:13:21.476 INFO 2660 --- [ main] org.hibernate.cfg.Environment : HHH000206: hibernate.properties not found
2018-10-18 09:13:21.578 INFO 2660 --- [ main] o.hibernate.annotations.common.Version : HCANN000001: Hibernate Commons Annotations {5.0.1.Final}
2018-10-18 09:13:21.925 INFO 2660 --- [ main] org.hibernate.dialect.Dialect : HHH000400: Using dialect: org.hibernate.dialect.MySQL5Dialect
Hibernate: alter table user_role add constraint FKa68196081fvovjhkek5m97n3y foreign key (role_id) references role (role_id)
Hibernate: alter table user_role add constraint FK859n2jvi8ivhui0rl0esws6o foreign key (user_id) references user (id)
2018-10-18 09:13:23.595 INFO 2660 --- [ main] j.LocalContainerEntityManagerFactoryBean : Initialized JPA EntityManagerFactory for persistence unit 'default'
2018-10-18 09:13:25.371 INFO 2660 --- [ main] o.s.s.web.DefaultSecurityFilterChain : Creating filter chain: org.springframework.security.web.util.matcher.AnyRequestMatcher@1, [org.springframework.security.web.context.request.async.WebAsyncManagerIntegrationFilter@611b35d6, org.springframework.security.web.context.SecurityContextPersistenceFilter@2047981, org.springframework.security.web.header.HeaderWriterFilter@456f7d9e, org.springframework.security.web.authentication.logout.LogoutFilter@19e21f89, org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter@1af4955e, org.springframework.security.web.savedrequest.RequestCacheAwareFilter@6f31df32, org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter@552cede7, org.springframework.security.web.authentication.rememberme.RememberMeAuthenticationFilter@ee21292, org.springframework.security.web.authentication.AnonymousAuthenticationFilter@2282400e, org.springframework.security.web.session.SessionManagementFilter@8f40022, org.springframework.security.web.access.ExceptionTranslationFilter@c8f97a7, org.springframework.security.web.access.intercept.FilterSecurityInterceptor@7d0100ea]