Skip to content

Commit

Permalink
[id] add new modules: 'skean-id-oauth-authsrv','skean-id-oauth-ressrv…
Browse files Browse the repository at this point in the history
…-spring-boot-starter'
  • Loading branch information
0xffff00 committed Feb 22, 2018
1 parent b2e7739 commit ead88de
Show file tree
Hide file tree
Showing 30 changed files with 382 additions and 45 deletions.
4 changes: 3 additions & 1 deletion settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@ include 'skean-jdbc-core'
include 'skean-jdbc-spring-boot-starter'
include 'skean-web'
include 'skean-web-spring-boot-starter'
include 'skean-id-oauth-server'
include 'skean-id-oauth-authsrv'
include 'skean-id-oauth-ressrv-spring-boot-starter'
include 'skean-dict'
include 'skean-id-spring-boot-starter'
include 'skean-samples'
include 'skean-samples:navyapp'

File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -52,16 +52,14 @@ public TokenStore tokenStore() {
public JwtAccessTokenConverter accessTokenConverter() {
JwtAccessTokenConverter converter = new JwtAccessTokenConverter();
converter.setSigningKey(authServerConfigProperties.getJwtSigningKey());
//converter.setVerifierKey("123");
//converter.setJwtClaimsSetVerifier(jwtClaimsSetVerifier());
return converter;
}

@Bean
public DefaultTokenServices tokenServices() {
DefaultTokenServices defaultTokenServices = new DefaultTokenServices();
defaultTokenServices.setTokenStore(tokenStore());
defaultTokenServices.setTokenEnhancer(tokenEnhancer());
defaultTokenServices.setTokenEnhancer(accessTokenConverter());
defaultTokenServices.setSupportRefreshToken(true);
defaultTokenServices.setAccessTokenValiditySeconds(authServerConfigProperties.getAccessTokenValiditySeconds());
return defaultTokenServices;
Expand All @@ -70,16 +68,11 @@ public DefaultTokenServices tokenServices() {
@Override
public void configure(AuthorizationServerEndpointsConfigurer endpoints) throws Exception {
endpoints
.tokenStore(tokenStore())
.tokenServices(tokenServices())
.authenticationManager(authenticationManager); //required

}

@Bean
public TokenEnhancer tokenEnhancer() {
return new JwtAccessTokenConverter();
}


}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,18 @@
import org.springframework.context.annotation.Configuration;

@Configuration
@ConfigurationProperties("skean.auth-server")
@ConfigurationProperties("skean.id.oauth-auth-server")
public class AuthServerConfigProperties {
private String clientId = "skean-id-0";
private String clientId = "skean-id-authsrv-0";
private String clientSecret;

private String userPasswordStyle = "encrypt";
private String inMemoryUserConfFilePath = "classpath:users.conf.json";

private int accessTokenValiditySeconds = 3600;
private int refreshTokenValiditySeconds = 3600 * 24 * 30;
private int refreshTokenValiditySeconds = 3600 * 24 * 60; // default 60 days.

private int accessTokenValiditySeconds = 3600 * 24 * 7; // default 7 days.

private String jwtSigningKey;

public String getClientId() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import party.threebody.skean.id.oauth.domain.SkUser;
import party.threebody.skean.misc.SkeanInvalidArgumentException;
import party.threebody.skean.misc.SkeanNotImplementedException;
import party.threebody.skean.web.util.SkeanResources;

import java.util.List;
import java.util.stream.Collectors;
Expand Down
14 changes: 14 additions & 0 deletions skean-id-oauth-authsrv/src/main/resources/application.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
server:
port: 8910

skean:
id:
oauth-auth-server:
client-id: c1
client-secret: '$2a$10$G4OlUys4SJH4KmLtmq8Cqep1.XOlRghB4e47ApJbxviMMyQxbp01W' # a bcrypt output of 123456

user-password-style: encrypted #plain or encrypted
#user-password-storingStyle: inMemory
jwt-signing-key: 888

#logging.level.org.springframework.security: DEBUG
19 changes: 19 additions & 0 deletions skean-id-oauth-ressrv-spring-boot-starter/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
apply plugin: 'java'
dependencies {
compile project(':skean-web')
// compile project(':skean-dict')

compile group: 'org.springframework.boot', name: 'spring-boot-devtools', version: versions.'spring-boot'
compile group: 'org.springframework.boot', name: 'spring-boot-starter-security', version: versions.'spring-boot'
compile group: 'org.springframework.boot', name: 'spring-boot-starter-web', version: versions.'spring-boot'
//compile group: 'org.springframework.boot', name: 'spring-boot-configuration-processor', vversions.'spring-boot'

compile group: 'org.springframework.security', name: 'spring-security-jwt', version: '1.0.9.RELEASE'
compile group: 'org.springframework.security.oauth', name: 'spring-security-oauth2', version: '2.2.1.RELEASE'
compile group: 'io.jsonwebtoken', name: 'jjwt', version: '0.9.0'
}





Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package party.threebody.skean.id.oauth.ressrv.autoconfigure;

import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.oauth2.config.annotation.web.configuration.EnableResourceServer;
import org.springframework.security.oauth2.config.annotation.web.configuration.ResourceServerConfigurerAdapter;
import org.springframework.security.oauth2.config.annotation.web.configurers.ResourceServerSecurityConfigurer;
import org.springframework.security.oauth2.provider.token.DefaultTokenServices;
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;

@Configuration
@EnableConfigurationProperties(ResServerConfigProperties.class)
@EnableResourceServer
public class ResServerAutoConfiguration extends ResourceServerConfigurerAdapter{

private final ResServerConfigProperties resServerConfigProperties;

public ResServerAutoConfiguration(ResServerConfigProperties resServerConfigProperties) {
this.resServerConfigProperties = resServerConfigProperties;
}

@Override
public void configure(ResourceServerSecurityConfigurer resources) throws Exception {
resources.tokenServices(tokenServices());
}

@Override
public void configure(HttpSecurity http) throws Exception {
super.configure(http);
}

@Bean
public TokenStore tokenStore() {
return new JwtTokenStore(accessTokenConverter());
}

@Bean
public JwtAccessTokenConverter accessTokenConverter() {
JwtAccessTokenConverter converter = new JwtAccessTokenConverter();
converter.setSigningKey(resServerConfigProperties.getJwtSigningKey());
return converter;
}


@Bean
@Primary
public DefaultTokenServices tokenServices() {
DefaultTokenServices defaultTokenServices = new DefaultTokenServices();
defaultTokenServices.setTokenStore(tokenStore());
return defaultTokenServices;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package party.threebody.skean.id.oauth.ressrv.autoconfigure;

import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration;

@Configuration
@ConfigurationProperties("skean.id.oauth-res-server")
public class ResServerConfigProperties {

private String jwtSigningKey;


public String getJwtSigningKey() {
return jwtSigningKey;
}

public void setJwtSigningKey(String jwtSigningKey) {
this.jwtSigningKey = jwtSigningKey;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
org.springframework.boot.autoconfigure.EnableAutoConfiguration=party.threebody.skean.id.oauth.ressrv.autoconfigure.ResServerAutoConfiguration
13 changes: 0 additions & 13 deletions skean-id-oauth-server/src/main/resources/application.yml

This file was deleted.

4 changes: 3 additions & 1 deletion skean-id-spring-boot-starter/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@ apply plugin: 'groovy'
apply plugin: 'org.springframework.boot'
dependencies {
compile project(':skean-web-spring-boot-starter')

compile group: 'org.springframework.boot', name: 'spring-boot-devtools', version: versions.'spring-boot'
compile group: 'org.springframework.boot', name: 'spring-boot-starter-security', version: versions.'spring-boot'
compile group: 'org.springframework.boot', name: 'spring-boot-starter-web', version: versions.'spring-boot'
compile group: 'org.springframework.boot', name: 'spring-boot-configuration-processor', version: versions.'spring-boot'


testCompile group: 'org.springframework.boot', name: 'spring-boot-starter-test', version: versions.'spring-boot'

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

@Configuration
@ConfigurationProperties("skean.id")
public class SkeanIdConfigProperties {
public class SkeanIdConfigProperties {

private String userConfFilePath = "classpath:users.conf.json";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
Expand All @@ -25,13 +26,19 @@

@Configuration
@EnableWebSecurity
public class WebSecurityConfiguration extends WebSecurityConfigurerAdapter {
@EnableConfigurationProperties(SkeanIdConfigProperties.class)
public class SkeanWebSecurityConfiguration extends WebSecurityConfigurerAdapter {

@Autowired SkeanIdConfigProperties skeanIdConf;
static final Logger logger = LoggerFactory.getLogger(SkeanWebSecurityConfiguration.class);

static final Logger logger = LoggerFactory.getLogger(WebSecurityConfiguration.class);
private final SkeanIdConfigProperties skeanIdConf;
@Autowired ApplicationContext applicationContext;


public SkeanWebSecurityConfiguration(SkeanIdConfigProperties skeanIdConf) {
this.skeanIdConf = skeanIdConf;
}

@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
auth.userDetailsService(userDetailsService())
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
org.springframework.boot.autoconfigure.EnableAutoConfiguration=party.threebody.skean.id.autoconfigure.SkeanWebSecurityConfiguration
6 changes: 5 additions & 1 deletion skean-samples/navyapp/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,16 @@ group 'party.threebody.skean.samples'
dependencies {
compile project(':skean-jdbc-spring-boot-starter')
compile project(':skean-web-spring-boot-starter')
compile project(':skean-id-spring-boot-starter')
compile project(':skean-id-oauth-ressrv-spring-boot-starter')

//compile project(':skean-id-spring-boot-starter')
// compile group: 'org.springframework.boot', name: 'spring-boot-starter-security', version: versions.'spring-boot'

testCompile group: 'org.springframework.boot', name: 'spring-boot-devtools', version: versions.'spring-boot'
testCompile group: 'org.springframework.boot', name: 'spring-boot-starter-test', version: versions.'spring-boot'



testCompile group: 'com.h2database', name: 'h2', version: versions.h2

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package party.threebody.skean.samples.navyapp;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.oauth2.config.annotation.web.configuration.EnableResourceServer;
import org.springframework.security.oauth2.config.annotation.web.configuration.ResourceServerConfigurerAdapter;
import org.springframework.security.oauth2.config.annotation.web.configurers.ResourceServerSecurityConfigurer;
import org.springframework.security.oauth2.provider.token.DefaultTokenServices;
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;

@Deprecated
//@Configuration
//@EnableResourceServer
public class ResourceServerConfig extends ResourceServerConfigurerAdapter {
@Override
public void configure(ResourceServerSecurityConfigurer resources) throws Exception {
resources.tokenServices(tokenServices());
}

@Override
public void configure(HttpSecurity http) throws Exception {
super.configure(http);
}

@Bean
public TokenStore tokenStore() {
return new JwtTokenStore(accessTokenConverter());
}

@Bean
public JwtAccessTokenConverter accessTokenConverter() {
JwtAccessTokenConverter converter = new JwtAccessTokenConverter();
converter.setSigningKey("888");
return converter;
}


@Bean
@Primary
public DefaultTokenServices tokenServices() {
DefaultTokenServices defaultTokenServices = new DefaultTokenServices();
defaultTokenServices.setTokenStore(tokenStore());
return defaultTokenServices;
}

}
Loading

0 comments on commit ead88de

Please sign in to comment.