...
In order for the Authorization Server to use this Enhancer, you’ll need to create a @Configuration class which will extend AuthorizationServerConfigurerAdapter. In such class, you’ll override the method which configures the endpoints.
In this configure method, you’ll add the PluginTokenEnhancer itself to the existing Token Enhancer Chain:
...
In this way, your enhancer will be applied as the last link of the Enhancer Chain, before building the final JWT token.
In this Configuration class, you will declare a @PostConstruct to modify de TokenServices in order to add the enhancer:
Code Block |
---|
package com.minsait.onesait.platform.plugin.configuration; import java.util.Arrays; import javax.annotation.PostConstruct; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Lazy; import org.springframework.security.oauth2.provider.token.DefaultTokenServices; import org.springframework.security.oauth2.provider.token.TokenEnhancer; import org.springframework.security.oauth2.provider.token.TokenEnhancerChain; import org.springframework.security.oauth2.provider.token.store.JwtAccessTokenConverter; import com.minsait.onesait.platform.plugin.utils.PluginTokenEnhancer; @Configuration @Lazy(false) public class AuthorizationServerConfigurer { @Autowired DefaultTokenServices tokenServices; @Autowired private JwtAccessTokenConverter jwtAccessTokenConverter; @Autowired private TokenEnhancer tokenEnhancer; @PostConstruct public void modifyServices() { final TokenEnhancerChain chain = new TokenEnhancerChain(); chain.setTokenEnhancers(Arrays.asList(tokenEnhancer, jwtAccessTokenConverter, pluginTokenEnhancer())); tokenServices.setTokenEnhancer(chain); } public TokenEnhancer pluginTokenEnhancer() { return new PluginTokenEnhancer(); } } |
Build the JAR
Lightweight JAR
...