git-svn-id: https://svn.d4science-ii.research-infrastructures.eu/gcube/branches/common/common-smartgears/2.1@178646 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
55d3199615
commit
1aeb1af66a
|
@ -15,11 +15,13 @@
|
||||||
<attributes>
|
<attributes>
|
||||||
<attribute name="optional" value="true"/>
|
<attribute name="optional" value="true"/>
|
||||||
<attribute name="maven.pomderived" value="true"/>
|
<attribute name="maven.pomderived" value="true"/>
|
||||||
|
<attribute name="test" value="true"/>
|
||||||
</attributes>
|
</attributes>
|
||||||
</classpathentry>
|
</classpathentry>
|
||||||
<classpathentry excluding="**" kind="src" output="target/test-classes" path="src/test/resources">
|
<classpathentry excluding="**" kind="src" output="target/test-classes" path="src/test/resources">
|
||||||
<attributes>
|
<attributes>
|
||||||
<attribute name="maven.pomderived" value="true"/>
|
<attribute name="maven.pomderived" value="true"/>
|
||||||
|
<attribute name="test" value="true"/>
|
||||||
</attributes>
|
</attributes>
|
||||||
</classpathentry>
|
</classpathentry>
|
||||||
<classpathentry kind="src" path="target/generated-sources">
|
<classpathentry kind="src" path="target/generated-sources">
|
||||||
|
|
|
@ -1,4 +1,7 @@
|
||||||
<ReleaseNotes>
|
<ReleaseNotes>
|
||||||
|
<Changeset component="common-smartgears-2.1.8" date="2019-03-21">
|
||||||
|
<Change>Support oauth2 protocol accepting token in the auhtorization header field</Change>
|
||||||
|
</Changeset>
|
||||||
<Changeset component="common-smartgears-2.1.7" date="2017-01-16">
|
<Changeset component="common-smartgears-2.1.7" date="2017-01-16">
|
||||||
<Change>Added Proxy Address to Application Configuration</Change>
|
<Change>Added Proxy Address to Application Configuration</Change>
|
||||||
<Change>Added protocol to Container Configuration (http by default)</Change>
|
<Change>Added protocol to Container Configuration (http by default)</Change>
|
||||||
|
|
2
pom.xml
2
pom.xml
|
@ -10,7 +10,7 @@
|
||||||
|
|
||||||
<groupId>org.gcube.core</groupId>
|
<groupId>org.gcube.core</groupId>
|
||||||
<artifactId>common-smartgears</artifactId>
|
<artifactId>common-smartgears</artifactId>
|
||||||
<version>2.1.7-SNAPSHOT</version>
|
<version>2.1.8-SNAPSHOT</version>
|
||||||
<name>SmartGears</name>
|
<name>SmartGears</name>
|
||||||
|
|
||||||
<dependencyManagement>
|
<dependencyManagement>
|
||||||
|
|
|
@ -168,12 +168,6 @@ public class Constants {
|
||||||
*/
|
*/
|
||||||
public static final String token_header="gcube-token";
|
public static final String token_header="gcube-token";
|
||||||
|
|
||||||
/**
|
|
||||||
* The name of the oauth secret parameter
|
|
||||||
*/
|
|
||||||
public static final String oauth_secret="client_secret";
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The event for token registration for app.
|
* The event for token registration for app.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
package org.gcube.smartgears.handlers.application.request;
|
package org.gcube.smartgears.handlers.application.request;
|
||||||
|
|
||||||
import static org.gcube.common.authorization.client.Constants.authorizationService;
|
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.scope_header;
|
||||||
import static org.gcube.smartgears.Constants.token_header;
|
import static org.gcube.smartgears.Constants.token_header;
|
||||||
import static org.gcube.smartgears.handlers.application.request.RequestError.internal_server_error;
|
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 Logger log = LoggerFactory.getLogger(RequestContextRetriever.class);
|
||||||
|
|
||||||
|
private static final String BEARER_AUTH_PREFIX ="Bearer";
|
||||||
|
private static final String BASIC_AUTH_PREFIX ="Basic";
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getName() {
|
public String getName() {
|
||||||
|
@ -40,17 +42,19 @@ public class RequestContextRetriever extends RequestHandler {
|
||||||
String scope = call.request().getParameter(scope_header)==null? call.request().getHeader(scope_header):call.request().getParameter(scope_header);
|
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){
|
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 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));
|
String credentials = new String(DatatypeConverter.parseBase64Binary(base64Credentials));
|
||||||
// credentials = username:password
|
// credentials = username:password
|
||||||
final String[] values = credentials.split(":",2);
|
final String[] values = credentials.split(":",2);
|
||||||
token = values[1];
|
token = values[1];
|
||||||
|
} else if (authorization.contains(BEARER_AUTH_PREFIX))
|
||||||
|
token = authorization.substring(BEARER_AUTH_PREFIX.length()).trim();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (token==null && scope==null && call.request().getParameter(oauth_secret)!=null)
|
|
||||||
token = call.request().getParameter(oauth_secret);
|
|
||||||
|
|
||||||
//Gives priority to the token
|
//Gives priority to the token
|
||||||
if (token!=null)
|
if (token!=null)
|
||||||
this.retreiveAndSetInfo(token, call);
|
this.retreiveAndSetInfo(token, call);
|
||||||
|
|
Loading…
Reference in New Issue