小编pin*_*aki的帖子

手动加载应用程序上下文以在spring启动应用程序中编写getBean()

在spring应用程序中,我们这样编写以通过手动加载spring应用程序上下文来获取bean.

ApplicationContext context = new ClassPathXmlApplicationContext("path/to/applicationContext.xml");
JobLauncher launcher=(JobLauncher)context.getBean("launcher");
Run Code Online (Sandbox Code Playgroud)

如何在春季靴子做类似的事情?作为一个新手...需要帮助

spring

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

spring boot OAuth2基于角色的授权

我们有一个扩展AuthorizationServerConfigurerAdapter的专用授权服务器,我们在其中设置了覆盖void configure(ClientDetailsS​​erviceConfigurer clients)方法的权限.

    @Configuration
    @EnableAuthorizationServer
    protected static class OAuth2Config extends AuthorizationServerConfigurerAdapter {

    @Value('${oauth.clientId}')
    private String clientId

    @Value('${oauth.secret:}')
    private String secret

    @Value('${oauth.resourceId}')
    private String resourceId

    @Autowired
    @Qualifier('authenticationManagerBean')
    private AuthenticationManager authenticationManager

    @Bean
    public JwtAccessTokenConverter accessTokenConverter() {
        return new JwtAccessTokenConverter();
    }

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

    @Override
    public void configure(AuthorizationServerEndpointsConfigurer endpoints) throws Exception {
        endpoints.authenticationManager(authenticationManager)
                .accessTokenConverter(accessTokenConverter())
    }

    @Override
    public void configure(ClientDetailsServiceConfigurer clients) throws Exception {
        clients.inMemory()
                .withClient(clientId)
                .secret(secret)
                .authorizedGrantTypes("password", "authorization_code", "refresh_token", "implicit")
                .authorities("USER", "ADMIN")
                .scopes("read", "write", "trust") …
Run Code Online (Sandbox Code Playgroud)

oauth-2.0 spring-boot spring-security-oauth2 spring-oauth2

7
推荐指数
1
解决办法
7041
查看次数