Skip to content

Commit

Permalink
Merge pull request #4654 from planetf1/backport_pr4651
Browse files Browse the repository at this point in the history
Release 2.6 - Backport pr4651
  • Loading branch information
planetf1 authored Feb 2, 2021
2 parents 848e4a8 + c25f0bf commit f2dfdec
Show file tree
Hide file tree
Showing 8 changed files with 108 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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() {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
Expand Down Expand Up @@ -54,7 +55,7 @@ protected void configure(HttpSecurity http) throws Exception {
}

public LogoutSuccessHandler logoutSuccessHandler() {
return new TokenLogoutSuccessHandler(tokenRedisClient);
return new TokenLogoutSuccessHandler(tokenClient);
}

@Bean
Expand Down
Original file line number Diff line number Diff line change
@@ -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){ };
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand All @@ -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");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, String> connection;
Expand All @@ -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);
}
Expand All @@ -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);
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit f2dfdec

Please sign in to comment.