SHARE
TWEET

Untitled

a guest Feb 26th, 2020 89 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package com.sunwell.authentication.config;
  2.  
  3. import javax.sql.DataSource;
  4.  
  5.  
  6. import org.springframework.beans.factory.annotation.Autowired;
  7. import org.springframework.beans.factory.annotation.Qualifier;
  8. import org.springframework.cglib.proxy.NoOp;
  9. import org.springframework.context.annotation.Bean;
  10. import org.springframework.context.annotation.Configuration;
  11. import org.springframework.context.annotation.Profile;
  12. import org.springframework.core.annotation.Order;
  13. import org.springframework.core.env.Environment;
  14. import org.springframework.security.authentication.AuthenticationManager;
  15. import org.springframework.security.crypto.password.NoOpPasswordEncoder;
  16. import org.springframework.security.oauth2.config.annotation.configurers.ClientDetailsServiceConfigurer;
  17. import org.springframework.security.oauth2.config.annotation.web.configuration.AuthorizationServerConfigurerAdapter;
  18. import org.springframework.security.oauth2.config.annotation.web.configuration.EnableAuthorizationServer;
  19. import org.springframework.security.oauth2.config.annotation.web.configurers.AuthorizationServerEndpointsConfigurer;
  20. import org.springframework.security.oauth2.config.annotation.web.configurers.AuthorizationServerSecurityConfigurer;
  21. import org.springframework.security.oauth2.provider.approval.UserApprovalHandler;
  22. import org.springframework.security.oauth2.provider.token.TokenStore;
  23. import org.springframework.security.oauth2.provider.token.store.JdbcTokenStore;
  24.  
  25. //@Profile("production")
  26. @Configuration
  27. @EnableAuthorizationServer
  28. //@Order(0)
  29. public class AuthServerConfig  extends AuthorizationServerConfigurerAdapter {
  30.    
  31.     @Autowired
  32.     DataSource datasource;
  33.    
  34.     @Autowired
  35.     private Environment env;
  36.    
  37. //  @Autowired
  38. //    private UserApprovalHandler userApprovalHandler;
  39.  
  40.     @Autowired
  41.     @Qualifier("authenticationManagerBean")
  42.     private AuthenticationManager authenticationManager;
  43.  
  44.     @Override
  45.     public void configure(
  46.       AuthorizationServerSecurityConfigurer oauthServer) throws Exception {
  47.        
  48.         System.out.println("!!!!!! CON !!!!!!!: " + env.getProperty("spring.datasource.url"));
  49.        
  50.         oauthServer
  51.           .tokenKeyAccess("permitAll()")
  52. //          .checkTokenAccess("permitAll()");
  53.           .checkTokenAccess("isAuthenticated()");
  54.     }
  55.  
  56.     @Override
  57.     public void configure(ClientDetailsServiceConfigurer clients)
  58.       throws Exception {
  59.         System.out.println("!!!!!!!!!!!!!!!!!!!! C O N F I G  CALLED");;
  60.         clients
  61.             .jdbc(datasource)
  62.             .passwordEncoder(NoOpPasswordEncoder.getInstance())
  63.           .withClient("sampleClientId")
  64.           .authorizedGrantTypes("implicit")
  65.           .scopes("read")
  66.           .autoApprove(true)
  67.           .and()
  68.           .withClient("clientIdPassword")
  69.           .secret("{noop}secret")
  70.           .authorizedGrantTypes(
  71.             "password","authorization_code", "refresh_token")
  72.           .scopes("read");
  73. //      clients.inMemory()
  74. //        .withClient("sampleClientId")
  75. //        .authorizedGrantTypes("implicit")
  76. //        .scopes("read", "write", "foo", "bar")
  77. //        .autoApprove(false).accessTokenValiditySeconds(3600)
  78. //
  79. //        .and()
  80. //        .withClient("fooClientIdPassword")
  81. //        .secret("{noop}secret")
  82. //        .authorizedGrantTypes("password", "authorization_code", "refresh_token")
  83. //        .scopes("foo", "read", "write")
  84. //        .accessTokenValiditySeconds(3600) // 1 hour
  85. //        .refreshTokenValiditySeconds(2592000) // 30 days
  86. //
  87. //        .and()
  88. //        .withClient("barClientIdPassword")
  89. //        .secret("{noop}secret")
  90. //        .authorizedGrantTypes("password", "authorization_code", "refresh_token")
  91. //        .scopes("bar", "read", "write")
  92. //        .accessTokenValiditySeconds(3600) // 1 hour
  93. //        .refreshTokenValiditySeconds(2592000) // 30 days
  94.       ;
  95.        
  96.     }
  97.  
  98.     @Override
  99.     public void configure(
  100.       AuthorizationServerEndpointsConfigurer endpoints)
  101.       throws Exception {
  102.        
  103.         System.out.println("IS AUTHEN MANAGER NULL = " + (authenticationManager == null ? "null" : "not null"));
  104.         endpoints
  105.           .tokenStore(tokenStore())
  106. //          .userApprovalHandler(userApprovalHandler)
  107.           .authenticationManager(authenticationManager);
  108.     }
  109.  
  110.     @Bean
  111.     public TokenStore tokenStore() {
  112.         return new JdbcTokenStore(datasource);
  113.     }
  114. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top