-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5fd1154
commit 1dd21aa
Showing
40 changed files
with
1,281 additions
and
154 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
target/ | ||
|
||
# Created by .ignore support plugin (hsz.mobi) | ||
### VisualStudioCode template | ||
.vscode/* | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 0 additions & 13 deletions
13
security-auth-app/src/main/java/io/github/donespeak/springsecuritykit/App.java
This file was deleted.
Oops, something went wrong.
28 changes: 28 additions & 0 deletions
28
...h-app/src/main/java/io/github/donespeak/springsecuritykit/app/oauth/JwtTokenEnhancer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package io.github.donespeak.springsecuritykit.app.oauth; | ||
|
||
import org.springframework.security.oauth2.common.DefaultOAuth2AccessToken; | ||
import org.springframework.security.oauth2.common.OAuth2AccessToken; | ||
import org.springframework.security.oauth2.provider.OAuth2Authentication; | ||
import org.springframework.security.oauth2.provider.token.TokenEnhancer; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
/** | ||
* @author Yang Guanrong | ||
* @date 2020/01/12 20:23 | ||
*/ | ||
public class JwtTokenEnhancer implements TokenEnhancer { | ||
|
||
@Override | ||
public OAuth2AccessToken enhance(OAuth2AccessToken oAuth2AccessToken, OAuth2Authentication oAuth2Authentication) { | ||
// 可以在这里为jwt增加附加字段 | ||
Map<String, Object> info = new HashMap<>(); | ||
info.put("author", "donespeak"); | ||
|
||
((DefaultOAuth2AccessToken)oAuth2AccessToken).setAdditionalInformation(info); | ||
|
||
return oAuth2AccessToken; | ||
} | ||
} | ||
|
78 changes: 78 additions & 0 deletions
78
.../java/io/github/donespeak/springsecuritykit/app/oauth/OAuthAuthorizationServerConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
package io.github.donespeak.springsecuritykit.app.oauth; | ||
|
||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.security.authentication.AuthenticationManager; | ||
import org.springframework.security.core.userdetails.UserDetailsService; | ||
import org.springframework.security.oauth2.config.annotation.builders.InMemoryClientDetailsServiceBuilder; | ||
import org.springframework.security.oauth2.config.annotation.configurers.ClientDetailsServiceConfigurer; | ||
import org.springframework.security.oauth2.config.annotation.web.configuration.AuthorizationServerConfigurerAdapter; | ||
import org.springframework.security.oauth2.config.annotation.web.configuration.EnableAuthorizationServer; | ||
import org.springframework.security.oauth2.config.annotation.web.configurers.AuthorizationServerEndpointsConfigurer; | ||
import org.springframework.security.oauth2.config.annotation.web.configurers.AuthorizationServerSecurityConfigurer; | ||
import org.springframework.security.oauth2.provider.token.TokenEnhancer; | ||
import org.springframework.security.oauth2.provider.token.TokenEnhancerChain; | ||
import org.springframework.security.oauth2.provider.token.TokenStore; | ||
import org.springframework.security.oauth2.provider.token.store.JwtAccessTokenConverter; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
/** | ||
* @author Yang Guanrong | ||
* @date 2020/01/12 20:09 | ||
*/ | ||
@Configuration | ||
@EnableAuthorizationServer | ||
public class OAuthAuthorizationServerConfig extends AuthorizationServerConfigurerAdapter { | ||
|
||
@Autowired | ||
private UserDetailsService userDetailsService; | ||
|
||
@Autowired | ||
private AuthenticationManager authenticationManager; | ||
|
||
@Autowired | ||
private TokenStore tokenStore; | ||
|
||
@Autowired(required = false) | ||
private JwtAccessTokenConverter jwtAccessTokenConverter; | ||
|
||
@Autowired(required = false) | ||
private TokenEnhancer jwtTokenEnhancer; | ||
|
||
/** | ||
* tokenKey的访问权限表达式配置 | ||
*/ | ||
@Override | ||
public void configure(AuthorizationServerSecurityConfigurer security) throws Exception { | ||
// TODO 为什么没有生效? | ||
// security.tokenKeyAccess("permitAll()"); | ||
} | ||
|
||
@Override | ||
public void configure(ClientDetailsServiceConfigurer clients) throws Exception { | ||
InMemoryClientDetailsServiceBuilder builder = clients.inMemory(); | ||
builder.withClient("app") | ||
.authorizedGrantTypes("password", "refresh_token") | ||
.accessTokenValiditySeconds(7200) | ||
.refreshTokenValiditySeconds(7200) | ||
.scopes("all"); | ||
} | ||
|
||
@Override | ||
public void configure(AuthorizationServerEndpointsConfigurer endpoints) throws Exception { | ||
endpoints.tokenStore(tokenStore) | ||
.authenticationManager(authenticationManager) | ||
.userDetailsService(userDetailsService); | ||
|
||
if(jwtAccessTokenConverter != null && jwtTokenEnhancer != null) { | ||
TokenEnhancerChain tokenEnhancerChain = new TokenEnhancerChain(); | ||
List<TokenEnhancer> enhancerList = new ArrayList<>(); | ||
enhancerList.add(jwtAccessTokenConverter); | ||
enhancerList.add(jwtTokenEnhancer); | ||
tokenEnhancerChain.setTokenEnhancers(enhancerList); | ||
endpoints.tokenEnhancer(tokenEnhancerChain).accessTokenConverter(jwtAccessTokenConverter); | ||
} | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
.../main/java/io/github/donespeak/springsecuritykit/app/oauth/OAuthResourceServerConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package io.github.donespeak.springsecuritykit.app.oauth; | ||
|
||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.security.oauth2.config.annotation.web.configuration.EnableResourceServer; | ||
import org.springframework.security.oauth2.config.annotation.web.configuration.ResourceServerConfigurerAdapter; | ||
|
||
/** | ||
* @author Yang Guanrong | ||
* @date 2020/01/12 20:10 | ||
*/ | ||
@Configuration | ||
@EnableResourceServer | ||
public class OAuthResourceServerConfig extends ResourceServerConfigurerAdapter { | ||
|
||
|
||
} |
39 changes: 39 additions & 0 deletions
39
...h-app/src/main/java/io/github/donespeak/springsecuritykit/app/oauth/TokenStoreConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package io.github.donespeak.springsecuritykit.app.oauth; | ||
|
||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.security.oauth2.provider.token.TokenEnhancer; | ||
import org.springframework.security.oauth2.provider.token.TokenStore; | ||
import org.springframework.security.oauth2.provider.token.store.JwtAccessTokenConverter; | ||
import org.springframework.security.oauth2.provider.token.store.JwtTokenStore; | ||
|
||
/** | ||
* @author Yang Guanrong | ||
* @date 2020/01/12 20:27 | ||
*/ | ||
@Configuration | ||
public class TokenStoreConfig { | ||
|
||
@Configuration | ||
public static class JwtTokenStoreConfig { | ||
|
||
@Bean | ||
public TokenStore jwtTokenStore() { | ||
return new JwtTokenStore(jwtAccessTokenConverter()); | ||
} | ||
|
||
@Bean | ||
public JwtAccessTokenConverter jwtAccessTokenConverter() { | ||
JwtAccessTokenConverter converter = new JwtAccessTokenConverter(); | ||
converter.setSigningKey("jinwandalaohu"); | ||
return converter; | ||
} | ||
|
||
@Bean | ||
@ConditionalOnMissingBean(TokenEnhancer.class) | ||
public JwtTokenEnhancer jwtTokenEnhancer() { | ||
return new JwtTokenEnhancer(); | ||
} | ||
} | ||
} |
20 changes: 0 additions & 20 deletions
20
security-auth-app/src/test/java/io/github/donespeak/springsecuritykit/AppTest.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 0 additions & 13 deletions
13
security-auth-browser/src/main/java/io/github/donespeak/springsecuritykit/App.java
This file was deleted.
Oops, something went wrong.
20 changes: 0 additions & 20 deletions
20
security-auth-browser/src/test/java/io/github/donespeak/springsecuritykit/AppTest.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 0 additions & 13 deletions
13
security-auth-core/src/main/java/io/github/donespeak/springsecuritykit/App.java
This file was deleted.
Oops, something went wrong.
16 changes: 16 additions & 0 deletions
16
...uth-core/src/main/java/io/github/donespeak/springsecuritykit/core/SecurityCoreConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package io.github.donespeak.springsecuritykit.core; | ||
|
||
import org.springframework.boot.context.properties.EnableConfigurationProperties; | ||
import org.springframework.context.annotation.Configuration; | ||
|
||
import io.github.donespeak.springsecuritykit.core.properties.SecurityProperties; | ||
|
||
/** | ||
* @author Yang Guanrong | ||
* @date 2020/01/12 20:03 | ||
*/ | ||
@Configuration | ||
@EnableConfigurationProperties(SecurityProperties.class) | ||
public class SecurityCoreConfig { | ||
|
||
} |
Oops, something went wrong.