Skip to content
Permalink
Browse files

Added AuthorizationServer

  • Loading branch information...
borabilgin committed Jan 20, 2019
1 parent dad7090 commit aff44d4824dea1cc613d31b49f60b9c0106a23b8
Showing with 69 additions and 0 deletions.
  1. +69 −0 api/src/main/java/com/demo/imagebrowser/config/AuthorizationServerConfig.java
@@ -0,0 +1,69 @@
package com.demo.imagebrowser.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.authentication.AuthenticationManager;
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.TokenEnhancerChain;
import org.springframework.security.oauth2.provider.token.TokenStore;
import org.springframework.security.oauth2.provider.token.store.JwtAccessTokenConverter;

import java.util.Arrays;

@Configuration
@EnableAuthorizationServer
public class AuthorizationServerConfig extends AuthorizationServerConfigurerAdapter {

@Value("${security.jwt.client-id}")
private String jwtClientId;

@Value("${security.jwt.client-secret}")
private String jwtClientSecret;

@Value("${security.jwt.grant-type}")
private String jwtGrantType;

@Value("${security.jwt.scope-read}")
private String jwtScopeRead;

@Value("${security.jwt.scope-write}")
private String jwtScopeWrite;

@Value("${security.jwt.resource-ids}")
private String jwtResourceIds;

@Autowired
private TokenStore tokenStore;

@Autowired
private JwtAccessTokenConverter accessTokenConverter;

@Autowired
private AuthenticationManager authenticationManager;

@Override
public void configure(ClientDetailsServiceConfigurer configurer) throws Exception {
configurer
.inMemory()
.withClient(jwtClientId)
.secret(jwtClientSecret)
.authorizedGrantTypes(jwtGrantType)
.scopes(jwtScopeRead, jwtScopeWrite)
.resourceIds(jwtResourceIds);
}

@Override
public void configure(AuthorizationServerEndpointsConfigurer endpoints) throws Exception {
TokenEnhancerChain enhancerChain = new TokenEnhancerChain();
enhancerChain.setTokenEnhancers(Arrays.asList(accessTokenConverter));
endpoints.tokenStore(tokenStore)
.accessTokenConverter(accessTokenConverter)
.tokenEnhancer(enhancerChain)
.authenticationManager(authenticationManager);
}

}

0 comments on commit aff44d4

Please sign in to comment.
You can’t perform that action at this time.