没有弹簧靴的Spring Oauth2

时间:2017-05-11 02:58:10

标签: spring spring-security spring-security-oauth2 spring-restcontroller

我使用java配置为Spring Oauth2配置了我的Spring rest应用程序,但在访问路径/ oauth / token时找不到404文件。

任何人都可以为任何错过的配置提供任何建议。以下代码是我的配置。

@Configuration 
@EnableAuthorizationServer
public class AuthorizationServer extends AuthorizationServerConfigurerAdapter {

    @Autowired
    public AuthenticationManager authManager;

    @Override
    public void configure(AuthorizationServerEndpointsConfigurer endpoints) throws Exception {
        // TODO Auto-generated method stub

        endpoints.authenticationManager(authManager);

    }

    @Override
    public void configure(ClientDetailsServiceConfigurer clients) throws Exception {

        clients.inMemory().withClient("cl").secret("12").authorizedGrantTypes("password").scopes("read,write");
    }

}

用于安全配置

@Configuration
@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {

    protected void configure(AuthenticationManagerBuilder auth) throws Exception {

        auth.inMemoryAuthentication().withUser("test").password("123").authorities("USER");

    }

    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http.csrf().disable();
    }

    @Bean
    public AuthenticationManager authenticationManagerBean() throws Exception {
        // TODO Auto-generated method stub
        return super.authenticationManagerBean();
    }

}

这就是web.xml java配置

public class WebConf implements WebApplicationInitializer {

    @Override
    public void onStartup(ServletContext ctx) throws ServletException {

        AnnotationConfigWebApplicationContext ap = new AnnotationConfigWebApplicationContext();
        ap.register(AppConf.class);
        ServletRegistration.Dynamic serv = ctx.addServlet("dispatcherrservlet", new DispatcherServlet(ap));
        serv.setLoadOnStartup(1);
        serv.addMapping("/");

    }

}

0 个答案:

没有答案