|
|
|
@ -1,7 +1,6 @@
|
|
|
|
|
package org.gcube.smartgears.handlers.application.request;
|
|
|
|
|
|
|
|
|
|
import static org.gcube.common.authorization.client.Constants.authorizationService;
|
|
|
|
|
import static org.gcube.smartgears.Constants.oauth_secret;
|
|
|
|
|
import static org.gcube.smartgears.Constants.scope_header;
|
|
|
|
|
import static org.gcube.smartgears.Constants.token_header;
|
|
|
|
|
import static org.gcube.smartgears.handlers.application.request.RequestError.internal_server_error;
|
|
|
|
@ -28,6 +27,9 @@ public class RequestContextRetriever extends RequestHandler {
|
|
|
|
|
|
|
|
|
|
private static Logger log = LoggerFactory.getLogger(RequestContextRetriever.class);
|
|
|
|
|
|
|
|
|
|
private static final String BEARER_AUTH_PREFIX ="Bearer";
|
|
|
|
|
private static final String BASIC_AUTH_PREFIX ="Basic";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public String getName() {
|
|
|
|
@ -40,16 +42,18 @@ public class RequestContextRetriever extends RequestHandler {
|
|
|
|
|
String scope = call.request().getParameter(scope_header)==null? call.request().getHeader(scope_header):call.request().getParameter(scope_header);
|
|
|
|
|
|
|
|
|
|
if (token==null && call.request().getHeader(Constants.authorization_header)!=null){
|
|
|
|
|
String basicAuthorization = call.request().getHeader(Constants.authorization_header);
|
|
|
|
|
String base64Credentials = basicAuthorization.substring("Basic".length()).trim();
|
|
|
|
|
String credentials = new String(DatatypeConverter.parseBase64Binary(base64Credentials));
|
|
|
|
|
// credentials = username:password
|
|
|
|
|
final String[] values = credentials.split(":",2);
|
|
|
|
|
token = values[1];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (token==null && scope==null && call.request().getParameter(oauth_secret)!=null)
|
|
|
|
|
token = call.request().getParameter(oauth_secret);
|
|
|
|
|
String authorization = call.request().getHeader(Constants.authorization_header);
|
|
|
|
|
|
|
|
|
|
if (authorization.contains(BASIC_AUTH_PREFIX)) {
|
|
|
|
|
String base64Credentials = authorization.substring(BASIC_AUTH_PREFIX.length()).trim();
|
|
|
|
|
String credentials = new String(DatatypeConverter.parseBase64Binary(base64Credentials));
|
|
|
|
|
// credentials = username:password
|
|
|
|
|
final String[] values = credentials.split(":",2);
|
|
|
|
|
token = values[1];
|
|
|
|
|
} else if (authorization.contains(BEARER_AUTH_PREFIX))
|
|
|
|
|
token = authorization.substring(BEARER_AUTH_PREFIX.length()).trim();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//Gives priority to the token
|
|
|
|
|
if (token!=null)
|
|
|
|
|