Skip to content

Commit

Permalink
6-8
Browse files Browse the repository at this point in the history
  • Loading branch information
jojozhai committed Sep 11, 2017
1 parent 575e8a0 commit feddfea
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,50 @@
*/
package com.imooc.security.app;

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.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.provider.token.TokenStore;

/**
* @author zhailiang
*
*/
@Configuration
@EnableAuthorizationServer
public class ImoocAuthorizationServerConfig {
public class ImoocAuthorizationServerConfig extends AuthorizationServerConfigurerAdapter {

@Autowired
private UserDetailsService userDetailsService;

@Autowired
private AuthenticationManager authenticationManager;

@Autowired
private TokenStore tokenStore;

@Override
public void configure(AuthorizationServerEndpointsConfigurer endpoints) throws Exception {
endpoints.tokenStore(tokenStore)
.authenticationManager(authenticationManager)
.userDetailsService(userDetailsService);
}

@Override
public void configure(ClientDetailsServiceConfigurer clients) throws Exception {
clients.inMemory()
.withClient("test")
.secret("test")
.accessTokenValiditySeconds(600)
.and()
.withClient("imooc")
.secret("imoocsecret")
.accessTokenValiditySeconds(1200);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/**
*
*/
package com.imooc.security.app;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.security.oauth2.provider.token.TokenStore;
import org.springframework.security.oauth2.provider.token.store.redis.RedisTokenStore;

/**
* @author zhailiang
*
*/
@Configuration
public class TokenStoreConfig {

@Autowired
private RedisConnectionFactory redisConnectionFactory;

@Bean
public TokenStore tokenStore() {
return new RedisTokenStore(redisConnectionFactory);
}

}

0 comments on commit feddfea

Please sign in to comment.