diff --git a/src/main/java/org/gcube/data/access/connector/GeoNetworkConnectorRequestHandler.java b/src/main/java/org/gcube/data/access/connector/GeoNetworkConnectorRequestHandler.java index 344286a..daf1e83 100644 --- a/src/main/java/org/gcube/data/access/connector/GeoNetworkConnectorRequestHandler.java +++ b/src/main/java/org/gcube/data/access/connector/GeoNetworkConnectorRequestHandler.java @@ -55,47 +55,41 @@ public class GeoNetworkConnectorRequestHandler extends RequestHandler { // get host from ApplicationContext String host = e.context().container().configuration().hostname(); -System.out.println("host : " + host); + // get token from request String token = getToken(httpServletRequest); logger.warn("Retrieve token from request = " + token); -System.out.println("token : " + token); + if (StringUtils.hasText(token)) { logger.warn("Token found: " + token); if (validateToken(token)) { - // retrieve endpoint to get credentials in GeoServer + // retrieve endpoint to get credentials in Geonetwork String endpoint = getEndpoint(token); logger.warn("Endpoint found: " + endpoint); -System.out.println("endpoint : " + endpoint); + // TODO - Can be the endpoint stored in the cache object? if (StringUtils.hasText(endpoint)) { String usernameCache = gCubeCache.get(AuthenticationUtils.USERNAME); String passwordCache = gCubeCache.get(AuthenticationUtils.PASSWORD); String tokenCache = gCubeCache.get(AuthenticationUtils.TOKEN_CACHE); -System.out.println("I'm using the cache: " +usernameCache +" "+ passwordCache +" "+ token); + // check current token with tokenCache if (token.equals(tokenCache)) { logger.warn("Set credentials attribute retrieved from cache " + usernameCache + " " + passwordCache); -System.out.println("Set credentials attribute retrieved from cache " + usernameCache + " " + passwordCache); httpServletRequest.setAttribute(AuthenticationUtils.USERNAME, usernameCache); httpServletRequest.setAttribute(AuthenticationUtils.PASSWORD, passwordCache); } else { //get credentials + logger.warn("RETRIEVE CREDENTIALS IN GENERAL MODE = " + GENERAL); AccessibleCredentialsEntity accessibleCredentials = getAccessibleCredentials(endpoint, host, token, GENERAL); logger.warn("Credentials: " + accessibleCredentials.getUsername() + "/" + accessibleCredentials.getPassword()); -System.out.println("********* REAL CREDENTIALS ************"); -System.out.println(accessibleCredentials.getUsername() + " / " + accessibleCredentials.getPassword()); + httpServletRequest.setAttribute(AuthenticationUtils.USERNAME, accessibleCredentials.getUsername()); httpServletRequest.setAttribute(AuthenticationUtils.PASSWORD, accessibleCredentials.getPassword()); - //TODO by pass the authentication -// System.out.println("********* by pass the authentication ************"); -// httpServletRequest.setAttribute(AuthenticationUtils.USERNAME, "admin"); -// httpServletRequest.setAttribute(AuthenticationUtils.PASSWORD, "admin"); - // set/update data in the cache logger.warn("Put token in the cache: " + token); gCubeCache.put(AuthenticationUtils.TOKEN_CACHE, token); @@ -103,10 +97,6 @@ System.out.println(accessibleCredentials.getUsername() + " / " + accessibleCrede logger.warn("Put also username and password in the cache"); gCubeCache.put(AuthenticationUtils.USERNAME, accessibleCredentials.getUsername()); gCubeCache.put(AuthenticationUtils.PASSWORD, accessibleCredentials.getPassword()); - - //TODO remove explicit set of credentials -// gCubeCache.put(AuthenticationUtils.USERNAME, "admin"); -// gCubeCache.put(AuthenticationUtils.PASSWORD, "admin"); } } } else { diff --git a/src/main/java/org/gcube/data/access/connector/GeoNetworkFilter.java b/src/main/java/org/gcube/data/access/connector/GeoNetworkFilter.java index 7a654d7..1da9bf2 100644 --- a/src/main/java/org/gcube/data/access/connector/GeoNetworkFilter.java +++ b/src/main/java/org/gcube/data/access/connector/GeoNetworkFilter.java @@ -23,14 +23,12 @@ public class GeoNetworkFilter implements Filter { @Override public void init(FilterConfig filterConfig) throws ServletException { logger.warn("init() method"); - System.out.println("***************************** init() method *****************************"); } @Override public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException { logger.warn("doFilter() method"); - System.out.println("***************************** doFilter() method *****************************"); ServletRequestWrapper request = new ServletRequestWrapper((HttpServletRequest) servletRequest); HttpServletResponse response = (HttpServletResponse) servletResponse; @@ -38,9 +36,8 @@ public class GeoNetworkFilter implements Filter { // get credentials String username = (String) request.getAttribute(AuthenticationUtils.USERNAME); String password = (String) request.getAttribute(AuthenticationUtils.PASSWORD); -System.out.println("credentials: " + username +"/"+ password); - if (StringUtils.hasText(username) && StringUtils.hasText(password)){ -System.out.println("Accept"); + + if (StringUtils.hasText(username) && StringUtils.hasText(password)){ request.addHeader("Accept", "application/json"); // set authorization header @@ -48,13 +45,12 @@ System.out.println("Accept"); String basic_authentication = AuthenticationUtils.BASIC + AuthenticationUtils.WHITESPACE + Base64.getEncoder().encodeToString(token.getBytes()); -System.out.println("basic_authentication " + basic_authentication); request.addHeader(AuthenticationUtils.AUTHORIZATION, basic_authentication); logger.warn("Added authorization header : " + request.getHeader(AuthenticationUtils.AUTHORIZATION)); request.addParameter(AuthenticationUtils.USERNAME, username); request.addParameter(AuthenticationUtils.PASSWORD, password); - logger.warn("Added parameters in the request : " + username +"/" + password); + logger.warn("Added parameters in the request : " + username + "/" + password); } filterChain.doFilter(request, response);