关于oauth实现,“URI不能为null”

时间:2017-09-19 07:20:18

标签: spring-security oauth-2.0 spring-security-oauth2

项目已使用资源服务器实施基于Oauth的身份验证。即使在传递url之后它也会抛出错误URI NULL。这是我正在使用的资源服务器配置。

@Configuration
@EnableResourceServer
public class ResourceServerConfiguration extends
        ResourceServerConfigurerAdapter {


     @Autowired
     private AuthenticationEntryPoint customAuthenticationEntryPoint;

    private CheckTokenEndpoint point;

    @Autowired
    Environment env;

    @Bean
    public PasswordEncoder passwordEncoder() {
        return new BCryptPasswordEncoder();
    }


    @Override
    public void configure(HttpSecurity httpSecurity) throws Exception {
        httpSecurity.exceptionHandling()
        .authenticationEntryPoint(customAuthenticationEntryPoint)
        .and()
        .sessionManagement()
        .sessionCreationPolicy(SessionCreationPolicy.STATELESS)
        .and().authorizeRequests()
         .antMatchers(HttpMethod.OPTIONS, "/**").permitAll()
         .antMatchers(HttpMethod.GET, "/","/node_modules/**", "/assets/**","/app/**").permitAll()
         .antMatchers(HttpMethod.GET, "/system-config.js","/init.js","/index.html").permitAll()
       //  .antMatchers(HttpMethod.GET, "/**").permitAll()
      //   .antMatchers(HttpMethod.GET, "/authenticate").permitAll()
         .anyRequest().authenticated()
         .and()
         .formLogin().permitAll();

        httpSecurity.addFilterBefore(getOAuth2AuthenticationProcessingFilter(), UsernamePasswordAuthenticationFilter.class);
        httpSecurity.headers().cacheControl();
    }


    private OAuth2AuthenticationProcessingFilter getOAuth2AuthenticationProcessingFilter() {
        BearerTokenExtractor tokenExtractor = new BearerTokenExtractor();
        OAuth2AuthenticationManager manager = new OAuth2AuthenticationManager();
        manager.setTokenServices(tokenService());
        OAuth2AuthenticationProcessingFilter filter = new OAuth2AuthenticationProcessingFilter();
        filter.setTokenExtractor(tokenExtractor);
        filter.setAuthenticationManager(manager);
        return filter;

    }


    @Bean
    @Primary
    public ResourceServerTokenServices tokenService() {
        RemoteTokenServices tokenServices = new RemoteTokenServices();
        tokenServices.setClientId(env.getProperty("oauth.clientid"));
        tokenServices.setClientSecret(env.getProperty("oauth.clientsecret"));
        tokenServices.setCheckTokenEndpointUrl(env.getProperty("oauth.token.url"));
        return tokenServices;
    }
}

使用有效令牌访问服务http://localhost:9190/irs/categoryMas

标题

Authorization   Bearer  bca03ed4-4608-499d-a3fe-60e6e671dea6

服务返回错误:

{
    "timestamp": 1505805120134,
    "status": 500,
    "error": "Internal Server Error",
    "exception": "java.lang.IllegalArgumentException",
    "message": "URI must not be null",
    "path": "/irs/categoryMast"
}

在调试时,uriTemplate为null。我该如何解决这个问题?

如果您需要更多详细信息,请与我们联系。

0 个答案:

没有答案