First commit - gcube-geoserver-connector

git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/data-access/gcube-geoserver-connector@148433 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
pasquale.vitale 2017-05-10 09:40:35 +00:00
parent 36f024a4e3
commit cfaf3cf859
4 changed files with 118 additions and 0 deletions

View File

@ -0,0 +1,61 @@
package org.gcube.data.access.connector;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Enumeration;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletRequestWrapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class AuthenticationRequest extends HttpServletRequestWrapper {
private final static String AUTHENTICATION = "Authentication";
private Logger logger;
public AuthenticationRequest(HttpServletRequest request) {
super(request);
this.logger = LoggerFactory.getLogger(this.getClass());
}
public String getHeader(String name) {
this.logger.debug("getHeader : " + name);
HttpServletRequest request = (HttpServletRequest) getRequest();
// if header name request is "Authorization" then update value
if (AUTHENTICATION.equals(name)) {
// TODO get authorization from IS
this.logger.debug("Set AUTHENTICATION");
return "BASIC YWRtaW46Z2Vvc2VydmVy";
}
return request.getHeader(name);
}
public Enumeration<String> getHeaderNames() {
this.logger.debug("getHeaderNames");
HttpServletRequest request = (HttpServletRequest) getRequest();
// modify list of headers
List<String> list = new ArrayList<String>();
Enumeration<String> e = request.getHeaderNames();
while (e.hasMoreElements()) {
// add the names of the request headers into the list
String n = (String) e.nextElement();
list.add(n);
}
// add Authentication
list.add(AUTHENTICATION);
this.logger.debug("add Authentication");
// create an enumeration from the list and return
Enumeration<String> en = Collections.enumeration(list);
return en;
}
}

View File

@ -0,0 +1,50 @@
package org.gcube.data.access.connector;
import java.util.Enumeration;
import javax.servlet.http.HttpServletRequest;
import javax.xml.bind.annotation.XmlRootElement;
import org.gcube.smartgears.handlers.application.RequestEvent;
import org.gcube.smartgears.handlers.application.RequestHandler;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@XmlRootElement (name= GeoServerConnectorRequestHandler.REQUEST_HANDLER_NAME)
public class GeoServerConnectorRequestHandler extends RequestHandler {
public static final String REQUEST_HANDLER_NAME = "authentication-filter";
private Logger logger;
public GeoServerConnectorRequestHandler() {
this.logger = LoggerFactory.getLogger(this.getClass());
}
@Override
public String getName() {
return REQUEST_HANDLER_NAME;
}
@Override
public void handleRequest(RequestEvent e) {
this.logger.debug("Handling request");
HttpServletRequest httpServletRequest = e.request();
// create the AuthenticationRequest object to wrap the HttpServletRequest
AuthenticationRequest request = new AuthenticationRequest(httpServletRequest);
// TODO delete (just to show the headers!!!)
Enumeration<String> en = request.getHeaderNames();
while (en.hasMoreElements()) {
String n = (String) en.nextElement();
String v = request.getHeader(n);
this.logger.debug(n + " : " + v + "\n");
}
}
@Override
public String toString() {
return getName();
}
}

View File

@ -0,0 +1,6 @@
Manifest-Version: 1.0
Archiver-Version: Plexus Archiver
Created-By: Apache Maven
Built-By: Pasquy
Build-Jdk: 1.7.0_75

View File

@ -0,0 +1 @@
org.gcube.data.access.connector.GeoServerConnectorRequestHandler