使用SSO spring服务器配置jsf web应用程序

使用SSO spring服务器配置jsf web应用程序,jsf,spring-security,primefaces,spring-security-oauth2,Jsf,Spring Security,Primefaces,Spring Security Oauth2,我有web应用程序,我在其中使用jsf和bean,还有SSOSpring服务器。 这是SSO server.java的代码: @SpringBootApplication @EnableResourceServer public class SsoServerApplication { public static void main(String[] args) { SpringApplication.run(SsoServerApplication.class, ar

我有web应用程序,我在其中使用jsf和bean,还有SSOSpring服务器。 这是SSO server.java的代码:

@SpringBootApplication
@EnableResourceServer
public class SsoServerApplication {

    public static void main(String[] args) {
        SpringApplication.run(SsoServerApplication.class, args);
    }

    @Configuration
    protected static class LoginConfig extends WebSecurityConfigurerAdapter {

        @Override
        protected void configure(HttpSecurity http) throws Exception {
            http.requestMatchers()
                    .antMatchers("/login", "/oauth/authorize")
                    .and()
                    .authorizeRequests()
                    .anyRequest().authenticated()
                    .and()
                    .formLogin().permitAll();
        }

        @Override
        protected void configure(AuthenticationManagerBuilder auth) throws Exception {
            auth.inMemoryAuthentication()
                    .withUser("user")
                    .password("password")
                    .roles("USER");
        }
    }

    @Configuration
    @EnableAuthorizationServer
    protected static class OAuth2Config extends AuthorizationServerConfigurerAdapter {
        @Autowired
        private AuthenticationManager authenticationManager;

        @Override
        public void configure(ClientDetailsServiceConfigurer clients) throws Exception {
            clients.inMemory()
                    .withClient("foo")
                    .secret("bar")
                    .authorizedGrantTypes("authorization_code", "refresh_token", "password")
                    .scopes("user_info")
                    .autoApprove(true);
        }

        @Override
        public void configure(AuthorizationServerSecurityConfigurer oauthServer) throws Exception {
            oauthServer
                    .tokenKeyAccess("permitAll()")
                    .checkTokenAccess("isAuthenticated()");
        }

        @Override
        public void configure(AuthorizationServerEndpointsConfigurer endpoints) throws Exception {
            endpoints.authenticationManager(authenticationManager);
        }
    }
}
这是web应用程序中aaapplication.yml的代码:

server:
    port: 9999
    context-path: /app4
security:
  basic:
    enabled: false
  oauth2:
    client:
      clientId: foo
      clientSecret: bar
      accessTokenUri: http://localhost:8080/sso-server/oauth/token
      userAuthorizationUri: http://localhost:8080/sso-server/oauth/authorize
    resource:
      userInfoUri: http://localhost:8080/sso-server/user/me
@EnableOAuth2Sso
@ManagedBean(name = "home")
@SessionScoped

public class Home extends WebMvcConfigurerAdapter {

    private String str = "str";

    @Override
    public void addViewControllers(ViewControllerRegistry registry) {
        registry.addViewController("/").setViewName("index");
    }

    public String getStr() {

        System.out.println(str);
        return str;
    }

    public void setStr(String str) {
        this.str = str;
    }
}
最后,这是web应用程序中的bean代码:

server:
    port: 9999
    context-path: /app4
security:
  basic:
    enabled: false
  oauth2:
    client:
      clientId: foo
      clientSecret: bar
      accessTokenUri: http://localhost:8080/sso-server/oauth/token
      userAuthorizationUri: http://localhost:8080/sso-server/oauth/authorize
    resource:
      userInfoUri: http://localhost:8080/sso-server/user/me
@EnableOAuth2Sso
@ManagedBean(name = "home")
@SessionScoped

public class Home extends WebMvcConfigurerAdapter {

    private String str = "str";

    @Override
    public void addViewControllers(ViewControllerRegistry registry) {
        registry.addViewController("/").setViewName("index");
    }

    public String getStr() {

        System.out.println(str);
        return str;
    }

    public void setStr(String str) {
        this.str = str;
    }
}
我的代码不工作,当调用web应用程序url时,服务器未授权