Update: addParameter method in the wrapper to make also the login via web interface
git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/data-access/gcube-geoserver-connector@150454 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
cb5a826051
commit
fe954745ef
|
@ -74,7 +74,7 @@ public class GeoServerConnectorRequestHandler extends RequestHandler {
|
|||
|
||||
//check current token with tokenCache
|
||||
if (token.equals(tokenCache)){
|
||||
logger.warn("Set credentials from cache " + usernameCache + " " + passwordCache);
|
||||
logger.warn("Set credentials attribute retrieved from cache " + usernameCache + " " + passwordCache);
|
||||
httpServletRequest.setAttribute(AuthenticationUtils.USERNAME, usernameCache);
|
||||
httpServletRequest.setAttribute(AuthenticationUtils.PASSWORD, passwordCache);
|
||||
}else{
|
||||
|
@ -111,7 +111,7 @@ public class GeoServerConnectorRequestHandler extends RequestHandler {
|
|||
|
||||
// retrieve the Token from request
|
||||
private String getToken(HttpServletRequest httpServletRequest) {
|
||||
|
||||
|
||||
// case 1 - get token from gcube-token query-string
|
||||
String gCubeToken = httpServletRequest.getParameter(AuthenticationUtils.GCUBE_QUERY_STRING);
|
||||
if (StringUtils.hasText(gCubeToken)) {
|
||||
|
@ -140,6 +140,13 @@ public class GeoServerConnectorRequestHandler extends RequestHandler {
|
|||
return values[1];
|
||||
}
|
||||
|
||||
// case 4 - get token from HTML form in the password field
|
||||
gCubeToken = httpServletRequest.getParameter(AuthenticationUtils.PASSWORD);
|
||||
if (StringUtils.hasText(gCubeToken)) {
|
||||
logger.warn("Get token from HTML form (in the password field)");
|
||||
return gCubeToken;
|
||||
}
|
||||
|
||||
logger.warn("gcube-token not found in query-string, in header and in basic authorization header");
|
||||
return null;
|
||||
}
|
||||
|
|
|
@ -44,8 +44,13 @@ public class GeoServerFilter implements Filter {
|
|||
+ Base64.encodeBase64String(token.getBytes());
|
||||
|
||||
request.addHeader(AuthenticationUtils.AUTHORIZATION, basic_authentication);
|
||||
logger.warn("Added Authorization : " + request.getHeader(AuthenticationUtils.AUTHORIZATION));
|
||||
}
|
||||
logger.warn("Added authorization header : " + request.getHeader(AuthenticationUtils.AUTHORIZATION));
|
||||
|
||||
logger.warn("Added parameters in the request : " + username +"/" + password);
|
||||
|
||||
request.addParameter(AuthenticationUtils.USERNAME, username);
|
||||
request.addParameter(AuthenticationUtils.PASSWORD, password);
|
||||
}
|
||||
|
||||
filterChain.doFilter(request, response);
|
||||
}
|
||||
|
|
|
@ -14,10 +14,12 @@ import javax.servlet.http.HttpServletRequestWrapper;
|
|||
public class ServletRequestWrapper extends HttpServletRequestWrapper {
|
||||
|
||||
private Map<String, String> headerMap;
|
||||
private Map<String, String> paramsMap;
|
||||
|
||||
public ServletRequestWrapper(HttpServletRequest request) {
|
||||
super(request);
|
||||
headerMap = new HashMap<String, String>();
|
||||
paramsMap = new HashMap<String, String>();
|
||||
}
|
||||
|
||||
public void addHeader(String name, String value) {
|
||||
|
@ -61,4 +63,18 @@ public class ServletRequestWrapper extends HttpServletRequestWrapper {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
public void addParameter(String name, String value) {
|
||||
paramsMap.put(name, value);
|
||||
}
|
||||
|
||||
public String getParameter(String name) {
|
||||
// if we added one, return that one
|
||||
if (paramsMap.get(name) != null) {
|
||||
return paramsMap.get(name);
|
||||
}
|
||||
// otherwise return what's in the original request
|
||||
HttpServletRequest req = (HttpServletRequest) super.getRequest();
|
||||
return req.getParameter(name);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue