Доступ запрещен при входе в систему под учетной записью администратора в Oauth2 - PullRequest
0 голосов
/ 06 апреля 2020

Этот код помогает мне сгенерировать токен доступа, но не позволяет войти в систему для администратора.

Класс ResourceServerConfig:

@Override
    public void configure(final HttpSecurity http) throws Exception {
        http
                .authorizeRequests()
                .antMatchers("/").permitAll()
                .antMatchers("/login").permitAll()
                .antMatchers("/registration/*").anonymous()
                .antMatchers("/admin/home").hasAnyAuthority("ADMIN")
                .antMatchers("/seller/home").hasAnyRole("ADMIN","SELLER")
                .antMatchers("/customer/home").hasAnyRole("ADMIN","CUSTOMER")
                .antMatchers("/doLogout").hasAnyRole("ADMIN","SELLER","CUSTOMER")
                .anyRequest().authenticated()
                .and()
                .sessionManagement()
                .sessionCreationPolicy(SessionCreationPolicy.STATELESS).and()
                .csrf().disable();
    }
}

Класс UserDao:

@Service
public class UserDao {

    @Autowired
    UserRepository userRepository;

    public User loadUserByUsername(String username) {
        User user = userRepository.findByEmail(username);
        if (user == null) throw new UsernameNotFoundException(username);
        List<GrantAuthorityImpl> grantAuthorityList = new ArrayList<>();
        List<Role> roleList = user.getRoles();

        roleList.forEach(role -> grantAuthorityList.add(new GrantAuthorityImpl(role.getAuthority())));


        if (username != null) {
            return new User(user.getEmail(), user.getPassword(), grantAuthorityList);
        } else {
            throw new RuntimeException();
        }

    }
}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...