私はスプリングブートアプリケーションでスプリングセキュリティを実装しようとしています。 しかし、私がログインするたびに、私は無限のクエリを取得して、最終的にはstackoverflowエラーが発生します。ここで スプリングブート、セキュリティログインの無限クエリ
Hibernate: select useraccoun0_.id as id1_1_, useraccoun0_.email as email2_1_, useraccoun0_.first_name as first_na3_1_, useraccoun0_.last_name as last_nam4_1_, useraccoun0_.password as password5_1_, useraccoun0_.status as status6_1_ from user_account useraccoun0_ where useraccoun0_.email=?
Hibernate: select roles0_.userid as userid1_1_0_, roles0_.roleid as roleid2_2_0_, role1_.id as id1_0_1_, role1_.name as name2_0_1_ from user_roles roles0_ inner join role role1_ on roles0_.roleid=role1_.id where roles0_.userid=?
Hibernate: select user0_.roleid as roleid2_0_0_, user0_.userid as userid1_2_0_, useraccoun1_.id as id1_1_1_, useraccoun1_.email as email2_1_1_, useraccoun1_.first_name as first_na3_1_1_, useraccoun1_.last_name as last_nam4_1_1_, useraccoun1_.password as password5_1_1_, useraccoun1_.status as status6_1_1_ from user_roles user0_ inner join user_account useraccoun1_ on user0_.userid=useraccoun1_.id where user0_.roleid=?
Hibernate: select roles0_.userid as userid1_1_0_, roles0_.roleid as roleid2_2_0_, role1_.id as id1_0_1_, role1_.name as name2_0_1_ from user_roles roles0_ inner join role role1_ on roles0_.roleid=role1_.id where roles0_.userid=?
Hibernate: select user0_.roleid as roleid2_0_0_, user0_.userid as userid1_2_0_, useraccoun1_.id as id1_1_1_, useraccoun1_.email as email2_1_1_, useraccoun1_.first_name as first_na3_1_1_, useraccoun1_.last_name as last_nam4_1_1_, useraccoun1_.password as password5_1_1_, useraccoun1_.status as status6_1_1_ from user_roles user0_ inner join user_account useraccoun1_ on user0_.userid=useraccoun1_.id where user0_.roleid=?
Hibernate: select roles0_.userid as userid1_1_0_, roles0_.roleid as roleid2_2_0_, role1_.id as id1_0_1_, role1_.name as name2_0_1_ from user_roles roles0_ inner join role role1_ on roles0_.roleid=role1_.id where roles0_.userid=?
Hibernate: select user0_.roleid as roleid2_0_0_, user0_.userid as userid1_2_0_, useraccoun1_.id as id1_1_1_, useraccoun1_.email as email2_1_1_, useraccoun1_.first_name as first_na3_1_1_, useraccoun1_.last_name as last_nam4_1_1_, useraccoun1_.password as password5_1_1_, useraccoun1_.status as status6_1_1_ from user_roles user0_ inner join user_account useraccoun1_ on user0_.userid=useraccoun1_.id where user0_.roleid=?
Hibernate: select roles0_.userid as userid1_1_0_, roles0_.roleid as roleid2_2_0_, role1_.id as id1_0_1_, role1_.name as name2_0_1_ from user_roles roles0_ inner join role role1_ on roles0_.roleid=role1_.id where roles0_.userid=?
Hibernate: select user0_.roleid as roleid2_0_0_, user0_.userid as userid1_2_0_, useraccoun1_.id as id1_1_1_, useraccoun1_.email as email2_1_1_, useraccoun1_.first_name as first_na3_1_1_, useraccoun1_.last_name as last_nam4_1_1_, useraccoun1_.password as password5_1_1_, useraccoun1_.status as status6_1_1_ from user_roles user0_ inner join user_account useraccoun1_ on user0_.userid=useraccoun1_.id where user0_.roleid=?
Hibernate: select roles0_.userid as userid1_1_0_, roles0_.roleid as roleid2_2_0_, role1_.id as id1_0_1_, role1_.name as name2_0_1_ from user_roles roles0_ inner join role role1_ on roles0_.roleid=role1_.id where roles0_.userid=?
Hibernate: select user0_.roleid as roleid2_0_0_, user0_.userid as userid1_2_0_, useraccoun1_.id as id1_1_1_, useraccoun1_.email as email2_1_1_, useraccoun1_.first_name as first_na3_1_1_, useraccoun1_.last_name as last_nam4_1_1_, useraccoun1_.password as password5_1_1_, useraccoun1_.status as status6_1_1_ from user_roles user0_ inner join user_account useraccoun1_ on user0_.userid=useraccoun1_.id where user0_.roleid=?
Hibernate: select roles0_.userid as userid1_1_0_, roles0_.roleid as roleid2_2_0_, role1_.id as id1_0_1_, role1_.name as name2_0_1_ from user_roles roles0_ inner join role role1_ on roles0_.roleid=role1_.id where roles0_.userid=?
Hibernate: select user0_.roleid as roleid2_0_0_, user0_.userid as userid1_2_0_, useraccoun1_.id as id1_1_1_, useraccoun1_.email as email2_1_1_, useraccoun1_.first_name as first_na3_1_1_, useraccoun1_.last_name as last_nam4_1_1_, useraccoun1_.password as password5_1_1_, useraccoun1_.status as status6_1_1_ from user_roles user0_ inner join user_account useraccoun1_ on user0_.userid=useraccoun1_.id where user0_.roleid=?
Hibernate: select roles0_.userid as userid1_1_0_, roles0_.roleid as roleid2_2_0_, role1_.id as id1_0_1_, role1_.name as name2_0_1_ from user_roles roles0_ inner join role role1_ on roles0_.roleid=role1_.id where roles0_.userid=?
Hibernate: select user0_.roleid as roleid2_0_0_, user0_.userid as userid1_2_0_, useraccoun1_.id as id1_1_1_, useraccoun1_.email as email2_1_1_, useraccoun1_.first_name as first_na3_1_1_, useraccoun1_.last_name as last_nam4_1_1_, useraccoun1_.password as password5_1_1_, useraccoun1_.status as status6_1_1_ from user_roles user0_ inner join user_account useraccoun1_ on user0_.userid=useraccoun1_.id where user0_.roleid=?
Hibernate: select user0_.roleid as roleid2_0_0_, user0_.userid as userid1_2_0_, useraccoun1_.id as id1_1_1_, useraccoun1_.email as email2_1_1_, useraccoun1_.first_name as first_na3_1_1_, useraccoun1_.last_name as last_nam4_1_1_, useraccoun1_.password as password5_1_1_, useraccoun1_.status as status6_1_1_ from user_roles user0_ inner join user_account useraccoun1_ on user0_.userid=useraccoun1_.id where user0_.roleid=?
Hibernate: select roles0_.userid as userid1_1_0_, roles0_.roleid as roleid2_2_0_, role1_.id as id1_0_1_, role1_.name as name2_0_1_ from user_roles roles0_ inner join role role1_ on roles0_.roleid=role1_.id where roles0_.userid=?
Hibernate: select user0_.roleid as roleid2_0_0_, user0_.userid as userid1_2_0_, useraccoun1_.id as id1_1_1_, useraccoun1_.email as email2_1_1_, useraccoun1_.first_name as first_na3_1_1_, useraccoun1_.last_name as last_nam4_1_1_, useraccoun1_.password as password5_1_1_, useraccoun1_.status as status6_1_1_ from user_roles user0_ inner join user_account useraccoun1_ on user0_.userid=useraccoun1_.id where user0_.roleid=?
はここ
@Data
@Entity
public class Role {
@Id
@GeneratedValue
private int id;
private String name;
@ManyToMany(mappedBy = "roles", fetch = FetchType.EAGER)
private Set<UserAccount> user = new HashSet<>();
}
は私CustomUserDetailsServiceである私のロールDTO
@Data
@ToString(exclude = "password")
@Entity
public class UserAccount {
public static final PasswordEncoder PASSWORD_ENCODER = new BCryptPasswordEncoder();
@Id
@GeneratedValue
private long id;
private String email;
private String firstName;
private String lastName;
@JsonIgnore
private String password;
@ManyToMany(fetch = FetchType.EAGER)
@JoinTable(name = "user_roles", joinColumns = @JoinColumn(name = "userID"), inverseJoinColumns = @JoinColumn(name = "roleID"))
private Set<Role> roles = new HashSet<>();
@Enumerated(EnumType.ORDINAL)
private Status status;
public void setPassword(String password) {
this.password = PASSWORD_ENCODER.encode(password);
}
}
DTO私ユーザーで、ここで
こことは、私のSecurityConfig
@Configuration
@EnableWebSecurity
@EnableGlobalMethodSecurity(prePostEnabled = true)
public class SecurityConfiguration extends WebSecurityConfigurerAdapter {
@Autowired
UserDetailsServiceImpl userDetailsService;
@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
auth.userDetailsService(userDetailsService).passwordEncoder(UserAccount.PASSWORD_ENCODER);
}
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.authorizeRequests()
.antMatchers("/built/**", "/css/main.css","/css/vendor/flexboxgrid.css").permitAll()
.anyRequest().authenticated()
.and()
.formLogin()
.defaultSuccessUrl("/", true)
.permitAll()
.and()
.httpBasic()
.and()
.csrf().disable()
.logout()
.logoutSuccessUrl("/");
}
である私は本当に私の設定が間違って何を見つけることができません。事前に助けてくれてありがとう。
しかし、 'one to many'を宣言すると、3番目のテーブルはありません。 – pat3ck029
第3のテーブル? – 11thdimension
'user_roles'の3番目のテーブルは' userid'と 'roleid'を含んでいます。たとえば、 'user1'は' role1'と 'role2'を持ち、' user2'は 'role1'しか持てません。 – pat3ck029