相关疑难解决方法(0)

未调用自定义身份验证提供程序

我正在尝试使用Spring Security设置客户AuthenticationProvider,但没有太多运气让它运行起来.我正在使用Java配置,所以我可能会遗漏一些简单的东西,但由于大多数学习材料都是基于XML配置的,所以它不会向我跳出来.

这是使用Spring v4.0.1.RELEASE但使用Spring Security v3.2.2.RELEASE.版本号冲突也许?

据我所知,我所要做的就是创建我的提供者:

public class KBServicesAuthProvider implements AuthenticationProvider {
  @Autowired
  private ApplicationConfig applicationConfig;

  @Autowired
  private SessionServiceClient sessionServiceClient;

  @Override
  public Authentication authenticate(Authentication authentication) throws AuthenticationException {
    String email = (String) authentication.getPrincipal();
    String password = (String) authentication.getCredentials();

    try {
      KBSessionInfo sessionInfo = sessionServiceClient.login(applicationConfig.getKbServicesPresenceId(), email,
          password);

      List<GrantedAuthority> grantedRoles = new ArrayList<>();
      for (KBRoleMembership role : sessionInfo.getAuthenticatedUser().getRoleMemberships()) {
        grantedRoles.add(new SimpleGrantedAuthority(role.getRoleId()));
      }

      return new UsernamePasswordAuthenticationToken(email, password, grantedRoles);
    } catch (InvalidSessionException e) {
      throw new AuthenticationCredentialsNotFoundException("Username or password was not …
Run Code Online (Sandbox Code Playgroud)

java spring spring-security

16
推荐指数
2
解决办法
2万
查看次数

标签 统计

java ×1

spring ×1

spring-security ×1