package com.konkerlabs.platform.registry.api.config.oauth;

import java.util.HashMap;
import java.util.Map;

import org.apache.commons.lang3.RandomStringUtils;
import org.springframework.security.oauth2.common.DefaultOAuth2AccessToken;
import org.springframework.security.oauth2.common.OAuth2AccessToken;
import org.springframework.security.oauth2.provider.OAuth2Authentication;
import org.springframework.security.oauth2.provider.token.TokenEnhancer;

public class CustomTokenEnhancer implements TokenEnhancer {

	@Override
	public OAuth2AccessToken enhance(OAuth2AccessToken accessToken, OAuth2Authentication authentication) {
		Map<String, Object> additionalInfo = new HashMap<>();
		((DefaultOAuth2AccessToken) accessToken).setAdditionalInformation(additionalInfo);
		return accessToken;
	}

}

@@ -57,108 +57,8 @@
 h;%0A%0A
-import java.util.HashMap;%0Aimport java.util.Map;%0A%0Aimport org.apache.commons.lang3.RandomStringUtils;%0A
 impo
@@ -121,32 +121,32 @@
 th2AccessToken;%0A
+
 import org.sprin
@@ -346,16 +346,145 @@
 ancer;%0A%0A
+import java.time.LocalDateTime;%0Aimport java.time.ZoneId;%0Aimport java.util.Date;%0Aimport java.util.HashMap;%0Aimport java.util.Map;%0A%0A
 public c
@@ -798,26 +798,258 @@
 ;%0A%09%09
-return accessToken
+((DefaultOAuth2AccessToken) accessToken).setExpiration(tokenExpiresOn());%0A%09%09return accessToken;%0A%09%7D%0A%0A%09private Date tokenExpiresOn() %7B%0A%09%09return Date.from(LocalDateTime%0A%09%09%09%09.now()%0A%09%09%09%09.plusMonths(12)%0A%09%09%09%09.atZone(ZoneId.systemDefault())%0A%09%09%09%09.toInstant())
 ;%0A%09%7D

increase user token expiration to 1 year