diff --git a/open-metadata-implementation/user-interfaces/ui-chassis/ui-chassis-spring/src/main/java/org/odpi/openmetadata/userinterface/uichassis/springboot/EgeriaUIPlatform.java b/open-metadata-implementation/user-interfaces/ui-chassis/ui-chassis-spring/src/main/java/org/odpi/openmetadata/userinterface/uichassis/springboot/EgeriaUIPlatform.java index abc8593f578..b7ed680a577 100644 --- a/open-metadata-implementation/user-interfaces/ui-chassis/ui-chassis-spring/src/main/java/org/odpi/openmetadata/userinterface/uichassis/springboot/EgeriaUIPlatform.java +++ b/open-metadata-implementation/user-interfaces/ui-chassis/ui-chassis-spring/src/main/java/org/odpi/openmetadata/userinterface/uichassis/springboot/EgeriaUIPlatform.java @@ -6,10 +6,7 @@ import org.odpi.openmetadata.accessservices.glossaryview.client.GlossaryViewClient; import org.odpi.openmetadata.governanceservers.openlineage.client.OpenLineageClient; import org.odpi.openmetadata.http.HttpHelper; -import org.odpi.openmetadata.userinterface.uichassis.springboot.auth.AuthService; -import org.odpi.openmetadata.userinterface.uichassis.springboot.auth.RedisAuthService; -import org.odpi.openmetadata.userinterface.uichassis.springboot.auth.SessionAuthService; -import org.odpi.openmetadata.userinterface.uichassis.springboot.auth.TokenAuthService; +import org.odpi.openmetadata.userinterface.uichassis.springboot.auth.*; import org.odpi.openmetadata.userinterface.uichassis.springboot.service.ComponentService; import org.odpi.openmetadata.userinterface.uichassis.springboot.service.LineageGraphDisplayRulesService; import org.slf4j.Logger; @@ -19,6 +16,7 @@ import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.cloud.netflix.zuul.EnableZuulProxy; import org.springframework.context.annotation.Bean; @@ -86,6 +84,13 @@ public AuthService getAuthService(@Value("${authentication.mode:token}") String return new SessionAuthService(); } + @Bean(value = "tokenClient") + @ConditionalOnProperty(value = "authentication.mode", havingValue = "token", matchIfMissing = true) + public TokenClient stateLessTokenClient(){ + return new TokenClient() { + }; + } + @PostConstruct private void configureTrustStore() { diff --git a/open-metadata-implementation/user-interfaces/ui-chassis/ui-chassis-spring/src/main/java/org/odpi/openmetadata/userinterface/uichassis/springboot/api/LogoutController.java b/open-metadata-implementation/user-interfaces/ui-chassis/ui-chassis-spring/src/main/java/org/odpi/openmetadata/userinterface/uichassis/springboot/api/LogoutController.java index 7e7cfe1c1a4..9a6a3360fc0 100644 --- a/open-metadata-implementation/user-interfaces/ui-chassis/ui-chassis-spring/src/main/java/org/odpi/openmetadata/userinterface/uichassis/springboot/api/LogoutController.java +++ b/open-metadata-implementation/user-interfaces/ui-chassis/ui-chassis-spring/src/main/java/org/odpi/openmetadata/userinterface/uichassis/springboot/api/LogoutController.java @@ -3,10 +3,8 @@ package org.odpi.openmetadata.userinterface.uichassis.springboot.api; import org.odpi.openmetadata.userinterface.uichassis.springboot.auth.AuthService; -import org.odpi.openmetadata.userinterface.uichassis.springboot.auth.redis.TokenRedisClient; +import org.odpi.openmetadata.userinterface.uichassis.springboot.auth.TokenClient; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; -import org.springframework.context.annotation.Bean; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; @@ -19,21 +17,16 @@ public class LogoutController { @Autowired(required = false) - TokenRedisClient tokenRedisClient; + TokenClient tokenClient; @GetMapping public void logout(HttpServletRequest request) throws HttpClientErrorException { String token = request.getHeader(AuthService.AUTH_HEADER_NAME); - if(tokenRedisClient != null && token != null){ - tokenRedisClient.del(token); + if(tokenClient != null && token != null){ + tokenClient.del(token); } } - @Bean - @ConditionalOnProperty(value = "authentication.mode", havingValue = "token", matchIfMissing = true) - public TokenRedisClient tokenRedisClient(){ - return null; - } } diff --git a/open-metadata-implementation/user-interfaces/ui-chassis/ui-chassis-spring/src/main/java/org/odpi/openmetadata/userinterface/uichassis/springboot/auth/AuthService.java b/open-metadata-implementation/user-interfaces/ui-chassis/ui-chassis-spring/src/main/java/org/odpi/openmetadata/userinterface/uichassis/springboot/auth/AuthService.java index c1173ec0455..175761d720b 100644 --- a/open-metadata-implementation/user-interfaces/ui-chassis/ui-chassis-spring/src/main/java/org/odpi/openmetadata/userinterface/uichassis/springboot/auth/AuthService.java +++ b/open-metadata-implementation/user-interfaces/ui-chassis/ui-chassis-spring/src/main/java/org/odpi/openmetadata/userinterface/uichassis/springboot/auth/AuthService.java @@ -61,8 +61,8 @@ default TokenUser parseUserFromToken(String token, String secret) { /** * - * @param user - * @param secret + * @param user the user to create token for + * @param secret the secret for signature * @return jwt token */ default String createTokenForUser(User user, String secret) { diff --git a/open-metadata-implementation/user-interfaces/ui-chassis/ui-chassis-spring/src/main/java/org/odpi/openmetadata/userinterface/uichassis/springboot/auth/SecurityConfig.java b/open-metadata-implementation/user-interfaces/ui-chassis/ui-chassis-spring/src/main/java/org/odpi/openmetadata/userinterface/uichassis/springboot/auth/SecurityConfig.java index b8921b5d05b..e9fe7c2ab45 100644 --- a/open-metadata-implementation/user-interfaces/ui-chassis/ui-chassis-spring/src/main/java/org/odpi/openmetadata/userinterface/uichassis/springboot/auth/SecurityConfig.java +++ b/open-metadata-implementation/user-interfaces/ui-chassis/ui-chassis-spring/src/main/java/org/odpi/openmetadata/userinterface/uichassis/springboot/auth/SecurityConfig.java @@ -4,6 +4,7 @@ import org.odpi.openmetadata.userinterface.uichassis.springboot.auth.redis.TokenRedisClient; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.context.annotation.Bean; import org.springframework.security.authentication.AuthenticationManager; import org.springframework.security.config.annotation.web.builders.HttpSecurity; @@ -18,8 +19,8 @@ public abstract class SecurityConfig extends WebSecurityConfigurerAdapter { @Autowired private AuthService authService; - @Autowired - TokenRedisClient tokenRedisClient; + @Autowired(required = false) + TokenClient tokenClient; public SecurityConfig() { super(true); @@ -54,7 +55,7 @@ protected void configure(HttpSecurity http) throws Exception { } public LogoutSuccessHandler logoutSuccessHandler() { - return new TokenLogoutSuccessHandler(tokenRedisClient); + return new TokenLogoutSuccessHandler(tokenClient); } @Bean diff --git a/open-metadata-implementation/user-interfaces/ui-chassis/ui-chassis-spring/src/main/java/org/odpi/openmetadata/userinterface/uichassis/springboot/auth/TokenClient.java b/open-metadata-implementation/user-interfaces/ui-chassis/ui-chassis-spring/src/main/java/org/odpi/openmetadata/userinterface/uichassis/springboot/auth/TokenClient.java new file mode 100644 index 00000000000..be5119b216f --- /dev/null +++ b/open-metadata-implementation/user-interfaces/ui-chassis/ui-chassis-spring/src/main/java/org/odpi/openmetadata/userinterface/uichassis/springboot/auth/TokenClient.java @@ -0,0 +1,70 @@ +/* SPDX-License-Identifier: Apache-2.0 */ +/* Copyright Contributors to the ODPi Egeria project. */ +package org.odpi.openmetadata.userinterface.uichassis.springboot.auth; + +/** + * TokenOption is used to have statefull webtoken by using persistence and expiration validation + */ +public interface TokenClient { + + /** + * shut down client connection + */ + default void shutdownClient(){}; + + /** + * + * @param token the token + * @param seconds for absolute timeout + * @param expiration representation of expiration + * @return the persistence response + */ + default String set(String token, long seconds, String expiration){ + return null; + }; + + /** + * + * @param token the token + * @param expiration representation of expiration + * @return the persistence response + */ + default String set(String token, String expiration){ + return null; + }; + + /** + * Used to postpone expiration but keep existing absolute timeout + * @param token the token + * @param expiration representation of expiration + * @return the persistence response + */ + default String setKeepTTL(String token, String expiration){ + return null; + }; + + + /** + * retrieve expiration from persistence + * @param token the token + * @return expiration or null if token doesn't exist + */ + default String get(String token){ + return null; + }; + + /** + * retrieve the absolute timeout of token in seconds + * @param token the token to determine ttl for + * @return the ttl for the token + */ + default Long ttl(String token){ + return null; + }; + + /** + * + * @param tokens the tokens to be removed from persistence + */ + default void del(String... tokens){ }; +} diff --git a/open-metadata-implementation/user-interfaces/ui-chassis/ui-chassis-spring/src/main/java/org/odpi/openmetadata/userinterface/uichassis/springboot/auth/TokenLogoutSuccessHandler.java b/open-metadata-implementation/user-interfaces/ui-chassis/ui-chassis-spring/src/main/java/org/odpi/openmetadata/userinterface/uichassis/springboot/auth/TokenLogoutSuccessHandler.java index 8ec3364ffff..0eeb896798f 100644 --- a/open-metadata-implementation/user-interfaces/ui-chassis/ui-chassis-spring/src/main/java/org/odpi/openmetadata/userinterface/uichassis/springboot/auth/TokenLogoutSuccessHandler.java +++ b/open-metadata-implementation/user-interfaces/ui-chassis/ui-chassis-spring/src/main/java/org/odpi/openmetadata/userinterface/uichassis/springboot/auth/TokenLogoutSuccessHandler.java @@ -2,7 +2,6 @@ /* Copyright Contributors to the ODPi Egeria project. */ package org.odpi.openmetadata.userinterface.uichassis.springboot.auth; -import org.odpi.openmetadata.userinterface.uichassis.springboot.auth.redis.TokenRedisClient; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.security.core.Authentication; @@ -19,10 +18,10 @@ public class TokenLogoutSuccessHandler extends private static final Logger log = LoggerFactory.getLogger( TokenLogoutSuccessHandler.class ); - private TokenRedisClient tokenRedisClient; + private TokenClient tokenClient; - TokenLogoutSuccessHandler(TokenRedisClient tokenRedisClient){ - this.tokenRedisClient = tokenRedisClient; + TokenLogoutSuccessHandler(TokenClient tokenClient){ + this.tokenClient = tokenClient; } @Override @@ -38,8 +37,8 @@ public void onLogoutSuccess( String token = request.getHeader(AuthService.AUTH_HEADER_NAME); - if(tokenRedisClient!=null && token != null ){ - tokenRedisClient.del(token); + if(tokenClient!=null && token != null ){ + tokenClient.del(token); } response.addHeader(AuthService.AUTH_HEADER_NAME,""); response.sendRedirect("login?logoutSuccessful"); diff --git a/open-metadata-implementation/user-interfaces/ui-chassis/ui-chassis-spring/src/main/java/org/odpi/openmetadata/userinterface/uichassis/springboot/auth/redis/TokenRedisClient.java b/open-metadata-implementation/user-interfaces/ui-chassis/ui-chassis-spring/src/main/java/org/odpi/openmetadata/userinterface/uichassis/springboot/auth/redis/TokenRedisClient.java index 71af4ac091d..72762e46726 100644 --- a/open-metadata-implementation/user-interfaces/ui-chassis/ui-chassis-spring/src/main/java/org/odpi/openmetadata/userinterface/uichassis/springboot/auth/redis/TokenRedisClient.java +++ b/open-metadata-implementation/user-interfaces/ui-chassis/ui-chassis-spring/src/main/java/org/odpi/openmetadata/userinterface/uichassis/springboot/auth/redis/TokenRedisClient.java @@ -7,8 +7,9 @@ import io.lettuce.core.SetArgs; import io.lettuce.core.api.StatefulRedisConnection; import io.lettuce.core.api.sync.RedisCommands; +import org.odpi.openmetadata.userinterface.uichassis.springboot.auth.TokenClient; -public class TokenRedisClient { +public class TokenRedisClient implements TokenClient { private RedisClient redisClient; private StatefulRedisConnection connection; @@ -21,31 +22,33 @@ public TokenRedisClient(String host, int port){ commands = connection.sync(); } - public void shutdownRedisClient(){ + @Override + public void shutdownClient(){ connection.close(); redisClient.shutdown(); } + @Override public String set(String key, long seconds, String value){ return commands.setex(key, seconds, value); } + @Override public String set(String key, String value){ return commands.set(key, value); } + @Override public String setKeepTTL(String key, String value){ return commands.set(key, value, SetArgs.Builder.keepttl()); } - public Boolean expire(String key, long seconds){ - return commands.expire(key, seconds); - } - + @Override public String get(String key){ return commands.get(key); } + @Override public Long ttl(String key){ return commands.ttl(key); } @@ -54,8 +57,9 @@ public Long exists(String... keys){ return commands.exists(keys); } - public Long del(String... keys){ - return commands.del(keys); + @Override + public void del(String... keys){ + commands.del(keys); } diff --git a/open-metadata-implementation/user-interfaces/ui-chassis/ui-chassis-spring/src/main/java/org/odpi/openmetadata/userinterface/uichassis/springboot/service/OpenLineageService.java b/open-metadata-implementation/user-interfaces/ui-chassis/ui-chassis-spring/src/main/java/org/odpi/openmetadata/userinterface/uichassis/springboot/service/OpenLineageService.java index 1008a0598e4..0dc7f8b7497 100644 --- a/open-metadata-implementation/user-interfaces/ui-chassis/ui-chassis-spring/src/main/java/org/odpi/openmetadata/userinterface/uichassis/springboot/service/OpenLineageService.java +++ b/open-metadata-implementation/user-interfaces/ui-chassis/ui-chassis-spring/src/main/java/org/odpi/openmetadata/userinterface/uichassis/springboot/service/OpenLineageService.java @@ -51,6 +51,7 @@ public class OpenLineageService { /** * @param openLineageClient client to connect to open lineage services + * @param lineageGraphDisplayRulesService the rules for display */ @Autowired public OpenLineageService(OpenLineageClient openLineageClient, LineageGraphDisplayRulesService lineageGraphDisplayRulesService) { @@ -157,6 +158,7 @@ public Graph getSourceAndDestination(String userId, /** * @param response string returned from Open Lineage Services to be processed + * @param guid the guid to process * @return map of nodes and edges describing the end to end flow */ private Graph processResponse(LineageVerticesAndEdges response, String guid) {