@Configuration
-@EnableAuthorizationServer
+
+
public class AuthorizationServerConfig extends AuthorizationServerConfigurerAdapter {
@Value("${security.jwt.client-id}")
private String clientId;
@Value("${security.jwt.client-secret}")
- private String clientSecret;
+ private String clientSecret = "password";
@Value("${security.jwt.grant-type}")
+ private String grantType = "password";
private String grantType;
@Value("${security.jwt.scope-read}")
@@ -41,15 +49,17 @@ public class AuthorizationServerConfig extends AuthorizationServerConfigurerAdap
@Value("${security.jwt.resource-ids}")
private String resourceIds;
- @Autowired
- private TokenStore tokenStore;
+
@Autowired
- private JwtAccessTokenConverter accessTokenConverter;
+ private CustomUserDetailsService userDetailsService;
@Autowired
private AuthenticationManager authenticationManager;
+ @Autowired
+ private TokenStore tokenStore;
+
@Autowired
private PasswordEncoder passwordEncoder;
@@ -57,21 +67,41 @@ public class AuthorizationServerConfig extends AuthorizationServerConfigurerAdap
public void configure(ClientDetailsServiceConfigurer configurer) throws Exception {
configurer
.inMemory()
- .withClient(clientId)
- .secret(passwordEncoder.encode(clientSecret))
+ .withClient(clientId)
+ .secret(passwordEncoder.encode(clientSecret))
.authorizedGrantTypes(grantType)
- .scopes(scopeRead, scopeWrite)
- .resourceIds(resourceIds);
+ .scopes(scopeRead, scopeWrite);
+// .resourceIds(resourceIds);
}
@Override
public void configure(AuthorizationServerEndpointsConfigurer endpoints) throws Exception {
TokenEnhancerChain enhancerChain = new TokenEnhancerChain();
- enhancerChain.setTokenEnhancers(Arrays.asList(accessTokenConverter));
endpoints.tokenStore(tokenStore)
- .accessTokenConverter(accessTokenConverter)
+ .accessTokenConverter(jwtAccessTokenConverter())
.tokenEnhancer(enhancerChain)
- .authenticationManager(authenticationManager);
+ .userDetailsService(userDetailsService)
+ .authenticationManager(authenticationManager())
+ .pathMapping("/oauth/token", "/api/oauth/token");
}
-}
+
+// @Override
+// public void configure(AuthorizationServerSecurityConfigurer security) throws Exception {
+// security.tokenKeyAccess("isAuthenticated()")
+// .checkTokenAccess("isAuthenticated()");
+// }
+
+// @Bean
+// public AuthenticationManager authenticationManager() {
+// return new AuthenticationManager();
+// }
+ @Bean
+ public JwtAccessTokenConverter jwtAccessTokenConverter() {
+ JwtAccessTokenConverter converter = new JwtAccessTokenConverter();
+ converter.setSigningKey("1234567890abcdef");
+ return converter;
+ DefaultAccessTokenConverter converter = new DefaultAccessTokenConverter();
+ converter.setUserTokenConverter(new UserAuthenticationConverter());
+ return converter;
+ }
\ No newline at end of file
diff --git a/src/main/java/com/nouhoun/springboot/jwt/integration/config/SecurityConfig.java b/src/main/java/com/nouhoun/springboot/jwt/integration/config/SecurityConfig.java
index 8d71cb221..d9fa97e5c 100644
--- a/src/main/java/com/nouhoun/springboot/jwt/integration/config/SecurityConfig.java
+++ b/src/main/java/com/nouhoun/springboot/jwt/integration/config/SecurityConfig.java
@@ -60,8 +60,8 @@ protected void configure(HttpSecurity http) throws Exception {
@Bean
public JwtAccessTokenConverter accessTokenConverter() {
- JwtAccessTokenConverter converter = new JwtAccessTokenConverter();
converter.setSigningKey(signingKey);
+ JwtAccessTokenConverter converter = new JwtAccessTokenConverter();
return converter;
}
@@ -78,4 +78,4 @@ public DefaultTokenServices tokenServices() {
defaultTokenServices.setSupportRefreshToken(true);
return defaultTokenServices;
}
-}
+}
\ No newline at end of file
diff --git a/src/main/java/com/nouhoun/springboot/jwt/integration/service/impl/AppUserDetailsService.java b/src/main/java/com/nouhoun/springboot/jwt/integration/service/impl/AppUserDetailsService.java
index 5592acc2a..d2603d9e0 100644
--- a/src/main/java/com/nouhoun/springboot/jwt/integration/service/impl/AppUserDetailsService.java
+++ b/src/main/java/com/nouhoun/springboot/jwt/integration/service/impl/AppUserDetailsService.java
@@ -39,4 +39,4 @@ public UserDetails loadUserByUsername(String s) throws UsernameNotFoundException
return userDetails;
}
-}
+}
\ No newline at end of file
diff --git a/src/main/java/com/nouhoun/springboot/jwt/integration/service/impl/GenericServiceImpl.java b/src/main/java/com/nouhoun/springboot/jwt/integration/service/impl/GenericServiceImpl.java
index 0af2e35d9..833e7e79c 100644
--- a/src/main/java/com/nouhoun/springboot/jwt/integration/service/impl/GenericServiceImpl.java
+++ b/src/main/java/com/nouhoun/springboot/jwt/integration/service/impl/GenericServiceImpl.java
@@ -28,11 +28,11 @@ public User findByUsername(String username) {
@Override
public List