#23113 added gettoken interface
This commit is contained in:
parent
86b9fdd95a
commit
7a1c5ef622
|
@ -4,6 +4,10 @@
|
|||
All notable changes to this project will be documented in this file.
|
||||
This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
||||
|
||||
## [v2-7.2-SNAPSHOT] - 2022-04-05
|
||||
|
||||
- [#23113] Implemented a new legacy-token resolver interface
|
||||
|
||||
## [v2-7.1-SNAPSHOT] - 2022-03-29
|
||||
|
||||
**New**
|
||||
|
|
2
pom.xml
2
pom.xml
|
@ -9,7 +9,7 @@
|
|||
</parent>
|
||||
<groupId>org.gcube.data.transfer</groupId>
|
||||
<artifactId>uri-resolver</artifactId>
|
||||
<version>2.7.1-SNAPSHOT</version>
|
||||
<version>2.7.2-SNAPSHOT</version>
|
||||
<packaging>war</packaging>
|
||||
<description>The URI Resolver is an HTTP URI resolver implemented as a REST service which gives access trough HTTP to different gcube Resolvers and gCube Applications.</description>
|
||||
|
||||
|
|
|
@ -204,9 +204,6 @@ public class AnalyticsCreateResolver {
|
|||
this.getClass(), helpURI);
|
||||
}
|
||||
|
||||
// FileContainer fileContainer = shc.getWSRoot().uploadFile(new FileInputStream(tempInvocationFile), tempInvocationFile.getName(), "DataMinerInvocation Request created by "+this.getClass().getSimpleName());
|
||||
// logger.info("UPLOADED FILE at: "+fileContainer.getPublicLink());
|
||||
// URL thePublicLink = fileContainer.getPublicLink();
|
||||
publicLinkToDMInvFile = thePublicLink != null ? thePublicLink.toString() : null;
|
||||
} catch (Exception e) {
|
||||
|
||||
|
|
|
@ -0,0 +1,72 @@
|
|||
package org.gcube.datatransfer.resolver.services;
|
||||
|
||||
import static org.gcube.common.authorization.client.Constants.authorizationService;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.ws.rs.GET;
|
||||
import javax.ws.rs.Path;
|
||||
import javax.ws.rs.Produces;
|
||||
import javax.ws.rs.WebApplicationException;
|
||||
import javax.ws.rs.core.Context;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
import javax.ws.rs.core.Response;
|
||||
|
||||
import org.gcube.common.authorization.library.provider.AuthorizationProvider;
|
||||
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
|
||||
import org.gcube.common.authorization.library.provider.UserInfo;
|
||||
import org.gcube.common.scope.api.ScopeProvider;
|
||||
import org.gcube.datatransfer.resolver.requesthandler.RequestHandler;
|
||||
import org.gcube.datatransfer.resolver.services.error.ExceptionManager;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
@Path("goat")
|
||||
public class GoatResolver {
|
||||
|
||||
private static Logger LOG = LoggerFactory.getLogger(GoatResolver.class);
|
||||
|
||||
@GET
|
||||
@Path("/gettoken")
|
||||
@Produces(MediaType.TEXT_PLAIN)
|
||||
public Response getLegacyToken(@Context HttpServletRequest req) throws WebApplicationException {
|
||||
LOG.info(this.getClass().getSimpleName() + " GET starts...");
|
||||
|
||||
try {
|
||||
|
||||
String oldToken = SecurityTokenProvider.instance.get();
|
||||
String scope = ScopeProvider.instance.get();
|
||||
LOG.info("ScopeProvider has scope: " + scope);
|
||||
|
||||
String appToken = req.getServletContext().getInitParameter(RequestHandler.ROOT_APP_TOKEN);
|
||||
|
||||
if (oldToken.compareTo(appToken) == 0) {
|
||||
LOG.error("Token not passed, SecurityTokenProvider contains the root app token: "
|
||||
+ appToken.substring(0, 10) + "...");
|
||||
throw ExceptionManager.unauthorizedException(req,
|
||||
"You are not authorized. You must pass a valid D4Science token", this.getClass(), "");
|
||||
}
|
||||
|
||||
String username = AuthorizationProvider.instance.get().getClient().getId();
|
||||
UserInfo userInfo = new UserInfo(username, new ArrayList<>());
|
||||
String userToken = authorizationService().generateUserToken(userInfo, scope);
|
||||
String msgToken = userToken.substring(0, 10) + "_MASKED_TOKEN";
|
||||
LOG.info("returning legacy token {} for user {}", msgToken, username);
|
||||
return Response.ok(userToken).build();
|
||||
} catch (Exception e) {
|
||||
|
||||
if (!(e instanceof WebApplicationException)) {
|
||||
// UNEXPECTED EXCEPTION managing it as WebApplicationException
|
||||
String error = "Error occurred on getting legacy token. Please, contact the support!";
|
||||
if (e.getCause() != null)
|
||||
error += "\n\nCaused: " + e.getCause().getMessage();
|
||||
throw ExceptionManager.internalErrorException(req, error, this.getClass(), null);
|
||||
}
|
||||
// ALREADY MANAGED AS WebApplicationException
|
||||
LOG.error("Exception:", e);
|
||||
throw (WebApplicationException) e;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -6,4 +6,5 @@
|
|||
<include>/analytics/create/*</include>
|
||||
<include>/knime/create/*</include>
|
||||
<include>/wekeo/gettoken/*</include>
|
||||
<include>/goat/gettoken/*</include>
|
||||
</application>
|
Loading…
Reference in New Issue