這是我第一次用OAuth2方法開發應用程序。我開始基於一定的教程,我正在從這裏前進(http://websystique.com/spring-security/secure-spring-rest-api-using-oauth2/)。如何使用redis來使用spring-security-oauth2持久化令牌
我會將應用程序部署到集羣WebSpheres,所以,據我所知in-memory將無法工作(... clients.inMemory()。withClient ...)。
我想使用Redis(我的第一次使用),我有點困惑如何將其設置在某些沒有xml java配置應用程序。
我發現了一些類似的問題與XML,但我仍然沒有北方第一次嘗試(Redis Token Store)。有趣的是,在這裏,所有者談到「Spring-Security OAuth,即2.8.0提供RedisTokenStore」的問題,但是我發現「2.0.12.RELEASE」作爲最新的mvn發佈版本。
這就是說,我的直接問題是:我怎樣才能調整代碼,以依靠Redis而不是內存?
關於如何設置RedisTokenStore波紋管的任何評論將被讚賞。
此外,如果很容易添加這樣的附加評論,「.passwordEncoder」和「.secret」之間的區別是什麼?代碼波紋管依賴於「.secret」硬編碼的表達式(固定值),而我看到使用JDBC與「.passwordEncoder填充在由springframework.security.crypto.bcrypt.BCryptPasswordEncoder」,這似乎更有意義幾個例子。當我猜想我使用「.secret」或「.passwordEncoder」時,我是對的嗎?當我認爲祕密代表固定值和密碼編碼器用於動態密碼時,我是對的嗎?
(使用 「.passwordEncoder」 和clients.jdbc https://github.com/spring-projects/spring-security-oauth/blob/master/tests/annotation/jdbc/src/main/java/demo/Application.java#L102例子)
@Configuration
@EnableAuthorizationServer
public class AuthorizationServerConfiguration extends AuthorizationServerConfigurerAdapter {
private static String REALM="MY_OAUTH_REALM";
@Autowired
private TokenStore tokenStore;
@Autowired
private UserApprovalHandler userApprovalHandler;
@Autowired
@Qualifier("authenticationManagerBean")
private AuthenticationManager authenticationManager;
@Override
public void configure(ClientDetailsServiceConfigurer clients) throws Exception {
clients.inMemory()
.withClient("abc-trusted-client")
.authorizedGrantTypes("password", "authorization_code", "refresh_token", "implicit")
.authorities("ROLE_CLIENT", "ROLE_TRUSTED_CLIENT")
.scopes("read", "write", "trust")
.secret("abc-secret")
.accessTokenValiditySeconds(120).//Access token is only valid for 2 minutes.
refreshTokenValiditySeconds(600);//Refresh token is only valid for 10 minutes.
}
@Override
public void configure(AuthorizationServerEndpointsConfigurer endpoints) throws Exception {
endpoints.tokenStore(tokenStore).userApprovalHandler(userApprovalHandler)
.authenticationManager(authenticationManager);
}
@Override
public void configure(AuthorizationServerSecurityConfigurer oauthServer) throws Exception {
oauthServer.realm(REALM+"/client");
}
}
這個作品,謝謝! –