Renamed class to self-explain it and added UMA token use with audience

This commit is contained in:
Mauro Mugnaini 2020-07-09 14:33:54 +02:00
parent 52cf5393e4
commit c15cd4b718
1 changed files with 17 additions and 9 deletions

View File

@ -12,20 +12,24 @@ import org.gcube.oidc.rest.OpenIdConnectRESTHelper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class HTTPEventSender implements EventSender {
public class HTTPWithUMAAuthEventSender implements EventSender {
protected static final Logger log = LoggerFactory.getLogger(HTTPEventSender.class);
protected static final Logger log = LoggerFactory.getLogger(HTTPWithUMAAuthEventSender.class);
private URL baseEnndpointURL;
private String clientId;
private String clientSecret;
private URL tokenURL;
private String umaAudience;
public HTTPWithUMAAuthEventSender(URL baseEnndpointURL, String clientId, String clientSecret, URL tokenURL,
String umaAudience) {
public HTTPEventSender(URL baseEnndpointURL, String clientId, String clientSecret, URL tokenURL) {
this.baseEnndpointURL = baseEnndpointURL;
this.clientId = clientId;
this.clientSecret = clientSecret;
this.tokenURL = tokenURL;
this.umaAudience = umaAudience;
}
@Override
@ -57,10 +61,14 @@ public class HTTPEventSender implements EventSender {
public void run() {
try {
log.debug("Getting OIDC token for client: {}", clientId);
JWTToken token = null;
if (clientId != null && clientSecret != null && tokenURL != null) {
JWTToken umaToken = null;
if (clientId != null && clientSecret != null && tokenURL != null && umaAudience != null) {
log.debug("Getting OIDC token for clientId '{}' from: {}", clientId, tokenURL);
token = OpenIdConnectRESTHelper.queryClientToken(clientId, clientSecret, tokenURL);
JWTToken oidcToken = OpenIdConnectRESTHelper.queryClientToken(clientId, clientSecret, tokenURL);
log.debug("Getting UMA token for audience '{}' from: {}", umaAudience, tokenURL);
umaToken = OpenIdConnectRESTHelper.queryUMAToken(tokenURL, oidcToken.getAsBearer(), umaAudience, null);
} else {
log.debug("Can't get UMA token since not all the required params was provied");
}
log.debug("Performing HTTP POST to: {}", endpoint);
HttpURLConnection connection = (HttpURLConnection) endpoint.openConnection();
@ -73,9 +81,9 @@ public class HTTPEventSender implements EventSender {
// Commented out as per the Conductor issue: https://github.com/Netflix/conductor/issues/376
// connection.setRequestProperty("Accept", "application/json");
connection.setDoOutput(true);
if (token != null) {
log.debug("Setting authorization header as: {}", token.getAsBearer());
connection.setRequestProperty("Authorization", token.getAsBearer());
if (umaToken != null) {
log.debug("Setting authorization header as: {}", umaToken.getAsBearer());
connection.setRequestProperty("Authorization", umaToken.getAsBearer());
} else {
log.debug("Sending request without authorization header");
}