solved a bug with scope maps
This commit is contained in:
parent
f62a477b84
commit
d0a7c0520a
|
@ -27,7 +27,6 @@
|
||||||
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
|
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
|
||||||
<attributes>
|
<attributes>
|
||||||
<attribute name="maven.pomderived" value="true"/>
|
<attribute name="maven.pomderived" value="true"/>
|
||||||
<attribute name="org.eclipse.jst.component.dependency" value="/WEB-INF/lib"/>
|
|
||||||
</attributes>
|
</attributes>
|
||||||
</classpathentry>
|
</classpathentry>
|
||||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
|
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
|
||||||
|
|
|
@ -3,7 +3,9 @@ org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
|
||||||
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
|
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
|
||||||
org.eclipse.jdt.core.compiler.compliance=1.8
|
org.eclipse.jdt.core.compiler.compliance=1.8
|
||||||
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
|
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
|
||||||
|
org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
|
||||||
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
|
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
|
||||||
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
|
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
|
||||||
|
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=ignore
|
||||||
org.eclipse.jdt.core.compiler.release=disabled
|
org.eclipse.jdt.core.compiler.release=disabled
|
||||||
org.eclipse.jdt.core.compiler.source=1.8
|
org.eclipse.jdt.core.compiler.source=1.8
|
||||||
|
|
1
pom.xml
1
pom.xml
|
@ -61,7 +61,6 @@
|
||||||
<groupId>org.gcube.core</groupId>
|
<groupId>org.gcube.core</groupId>
|
||||||
<artifactId>common-scope-maps</artifactId>
|
<artifactId>common-scope-maps</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.gcube.core</groupId>
|
<groupId>org.gcube.core</groupId>
|
||||||
<artifactId>common-scope</artifactId>
|
<artifactId>common-scope</artifactId>
|
||||||
|
|
|
@ -36,6 +36,7 @@ import org.gcube.common.authorizationservice.util.Constants;
|
||||||
import org.gcube.common.authorizationservice.util.TokenPersistence;
|
import org.gcube.common.authorizationservice.util.TokenPersistence;
|
||||||
import org.gcube.common.scope.api.ScopeProvider;
|
import org.gcube.common.scope.api.ScopeProvider;
|
||||||
import org.gcube.common.scope.api.ServiceMap;
|
import org.gcube.common.scope.api.ServiceMap;
|
||||||
|
import org.gcube.common.scope.impl.ScopedServiceMap;
|
||||||
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
||||||
|
@ -62,8 +63,15 @@ public class TokenManager {
|
||||||
CalledMethodProvider.instance.set("retrieve");
|
CalledMethodProvider.instance.set("retrieve");
|
||||||
log.info("token retreiver called with token {}",token);
|
log.info("token retreiver called with token {}",token);
|
||||||
|
|
||||||
AuthorizationEntry info = persistence.getAuthorizationEntry(token);
|
AuthorizationEntry info = null;
|
||||||
|
try {
|
||||||
|
info = persistence.getAuthorizationEntry(token);
|
||||||
|
|
||||||
|
} catch ( Throwable t) {
|
||||||
|
log.error("erorr on authorization", t);
|
||||||
|
throw new WebApplicationException(Response.status(Response.Status.INTERNAL_SERVER_ERROR)
|
||||||
|
.entity("error on authorization").type(MediaType.TEXT_PLAIN).build());
|
||||||
|
}
|
||||||
log.info("info retrieved {}",info);
|
log.info("info retrieved {}",info);
|
||||||
|
|
||||||
if (info == null){
|
if (info == null){
|
||||||
|
@ -71,21 +79,23 @@ public class TokenManager {
|
||||||
throw new WebApplicationException(Response.status(Response.Status.NOT_FOUND)
|
throw new WebApplicationException(Response.status(Response.Status.NOT_FOUND)
|
||||||
.entity("token "+token+" not found").type(MediaType.TEXT_PLAIN).build());
|
.entity("token "+token+" not found").type(MediaType.TEXT_PLAIN).build());
|
||||||
}
|
}
|
||||||
|
|
||||||
try{
|
try{
|
||||||
ScopeProvider.instance.set(info.getContext());
|
ScopeProvider.instance.set(info.getContext());
|
||||||
ServiceMap map = ServiceMap.instance;
|
log.info("current context is {}", info.getContext());
|
||||||
|
ServiceMap map = ((ScopedServiceMap)ServiceMap.instance).currentMap();
|
||||||
|
log.info("map is {}", map);
|
||||||
ScopeProvider.instance.reset();
|
ScopeProvider.instance.reset();
|
||||||
info.setMap(map);
|
info.setMap(map);
|
||||||
}catch(Exception e){
|
log.info("map set");
|
||||||
|
}catch(Throwable e){
|
||||||
log.error("error retrieving map for {}", info.getContext(), e);
|
log.error("error retrieving map for {}", info.getContext(), e);
|
||||||
}
|
}
|
||||||
|
|
||||||
log.debug("returning info {}", info);
|
log.debug("returning info {}", info);
|
||||||
return info;
|
return info;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* retrieves the AuthorzationEntry connected to the specified token
|
* retrieves the AuthorzationEntry connected to the specified token
|
||||||
|
@ -104,16 +114,19 @@ public class TokenManager {
|
||||||
for (String token : tokens ) {
|
for (String token : tokens ) {
|
||||||
try {
|
try {
|
||||||
AuthorizationEntry info = persistence.getAuthorizationEntry(token);
|
AuthorizationEntry info = persistence.getAuthorizationEntry(token);
|
||||||
|
|
||||||
try{
|
try{
|
||||||
ScopeProvider.instance.set(info.getContext());
|
ScopeProvider.instance.set(info.getContext());
|
||||||
ServiceMap map = ServiceMap.instance;
|
ServiceMap map = ((ScopedServiceMap)ServiceMap.instance).currentMap();
|
||||||
ScopeProvider.instance.reset();
|
ScopeProvider.instance.reset();
|
||||||
info.setMap(map);
|
info.setMap(map);
|
||||||
}catch(Exception e){
|
}catch(Throwable e){
|
||||||
log.error("error retrieving map for {}", info.getContext(), e);
|
log.error("error retrieving map for {}", info.getContext(), e);
|
||||||
}
|
}
|
||||||
toReturn.add(info);
|
toReturn.add(info);
|
||||||
}catch(Exception e) {}
|
}catch(Exception t) {
|
||||||
|
log.error("erorr on authorization", t);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
log.info("info retrieved {}",toReturn);
|
log.info("info retrieved {}",toReturn);
|
||||||
|
|
||||||
|
@ -122,13 +135,13 @@ public class TokenManager {
|
||||||
throw new WebApplicationException(Response.status(Response.Status.NOT_FOUND)
|
throw new WebApplicationException(Response.status(Response.Status.NOT_FOUND)
|
||||||
.entity("no tokens poassed have been found ").type(MediaType.TEXT_PLAIN).build());
|
.entity("no tokens poassed have been found ").type(MediaType.TEXT_PLAIN).build());
|
||||||
}
|
}
|
||||||
|
|
||||||
return new AuthorizationEntryList(toReturn);
|
return new AuthorizationEntryList(toReturn);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* retrieves the AuthorzationEntry connected to the specified token
|
* retrieves the AuthorzationEntry connected to the specified token
|
||||||
|
@ -141,16 +154,16 @@ public class TokenManager {
|
||||||
public String getTokenByUserAndContext(@NotNull @PathParam("user") String user, @QueryParam("context") String context ) {
|
public String getTokenByUserAndContext(@NotNull @PathParam("user") String user, @QueryParam("context") String context ) {
|
||||||
CalledMethodProvider.instance.set("retrieve");
|
CalledMethodProvider.instance.set("retrieve");
|
||||||
log.info("resolving token for user {} in context {}",user, context);
|
log.info("resolving token for user {} in context {}",user, context);
|
||||||
|
|
||||||
if (context==null){
|
if (context==null){
|
||||||
log.error("null context found");
|
log.error("null context found");
|
||||||
throw new WebApplicationException(Response.status(Response.Status.NOT_FOUND)
|
throw new WebApplicationException(Response.status(Response.Status.NOT_FOUND)
|
||||||
.entity("null context found").type(MediaType.TEXT_PLAIN).build());
|
.entity("null context found").type(MediaType.TEXT_PLAIN).build());
|
||||||
}
|
}
|
||||||
|
|
||||||
String token = persistence.getExistingToken(user, context, Constants.DEFAULT_TOKEN_QUALIFIER);
|
String token = persistence.getExistingToken(user, context, Constants.DEFAULT_TOKEN_QUALIFIER);
|
||||||
|
|
||||||
|
|
||||||
if (token == null){
|
if (token == null){
|
||||||
log.error("token {} not found ", token);
|
log.error("token {} not found ", token);
|
||||||
throw new WebApplicationException(Response.status(Response.Status.NOT_FOUND)
|
throw new WebApplicationException(Response.status(Response.Status.NOT_FOUND)
|
||||||
|
@ -171,7 +184,7 @@ public class TokenManager {
|
||||||
return token;
|
return token;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* Generates a token for a user (saving the passed roles) if it doesn't exist yet.
|
* Generates a token for a user (saving the passed roles) if it doesn't exist yet.
|
||||||
|
@ -206,7 +219,7 @@ public class TokenManager {
|
||||||
.entity("Error Generating Token: "+e.getMessage()).type(MediaType.TEXT_PLAIN).build());
|
.entity("Error Generating Token: "+e.getMessage()).type(MediaType.TEXT_PLAIN).build());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* Generates a token for a user (saving the passed roles) if it doesn't exist yet.
|
* Generates a token for a user (saving the passed roles) if it doesn't exist yet.
|
||||||
|
@ -234,8 +247,8 @@ public class TokenManager {
|
||||||
.entity("Error setting roles to token: "+e.getMessage()).type(MediaType.TEXT_PLAIN).build());
|
.entity("Error setting roles to token: "+e.getMessage()).type(MediaType.TEXT_PLAIN).build());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* REmoves a token for a user.
|
* REmoves a token for a user.
|
||||||
|
@ -257,14 +270,14 @@ public class TokenManager {
|
||||||
if (clientId.split(":").length>1) throw new Exception("invalid user id: "+clientId);
|
if (clientId.split(":").length>1) throw new Exception("invalid user id: "+clientId);
|
||||||
|
|
||||||
persistence.removeAllAuthorizationsEntryForClientId(context, clientId);
|
persistence.removeAllAuthorizationsEntryForClientId(context, clientId);
|
||||||
|
|
||||||
}catch(Exception e){
|
}catch(Exception e){
|
||||||
log.error("error generating token ",e);
|
log.error("error generating token ",e);
|
||||||
throw new WebApplicationException(Response.status(Response.Status.BAD_REQUEST)
|
throw new WebApplicationException(Response.status(Response.Status.BAD_REQUEST)
|
||||||
.entity("Error removing Token: "+e.getMessage()).type(MediaType.TEXT_PLAIN).build());
|
.entity("Error removing Token: "+e.getMessage()).type(MediaType.TEXT_PLAIN).build());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* Generates a token for a service if it doesn't exist yet.
|
* Generates a token for a service if it doesn't exist yet.
|
||||||
|
@ -308,25 +321,25 @@ public class TokenManager {
|
||||||
CalledMethodProvider.instance.set("generate");
|
CalledMethodProvider.instance.set("generate");
|
||||||
log.info("calling generate service token bunch");
|
log.info("calling generate service token bunch");
|
||||||
try{
|
try{
|
||||||
|
|
||||||
AuthorizationEntry callerInfo = (AuthorizationEntry)req.getAttribute(AuthorizedCallFilter.AUTH_ATTRIBUTE);
|
AuthorizationEntry callerInfo = (AuthorizationEntry)req.getAttribute(AuthorizedCallFilter.AUTH_ATTRIBUTE);
|
||||||
|
|
||||||
List<String> tokensToReturn = new ArrayList<String>();
|
List<String> tokensToReturn = new ArrayList<String>();
|
||||||
|
|
||||||
for (String token: entity.getContainerTokens()) {
|
for (String token: entity.getContainerTokens()) {
|
||||||
AuthorizationEntry authInfo = this.retrieveToken(token);
|
AuthorizationEntry authInfo = this.retrieveToken(token);
|
||||||
|
|
||||||
if (authInfo==null) continue;
|
if (authInfo==null) continue;
|
||||||
|
|
||||||
if (!authInfo.getClientInfo().getId().equals(callerInfo.getClientInfo().getId()))
|
if (!authInfo.getClientInfo().getId().equals(callerInfo.getClientInfo().getId()))
|
||||||
log.warn("a token with a different ContainerInfo of the caller used, skipping it");
|
log.warn("a token with a different ContainerInfo of the caller used, skipping it");
|
||||||
else {
|
else {
|
||||||
String genToken = generateTokenForServiceInfo(entity.getInfo(), authInfo);
|
String genToken = generateTokenForServiceInfo(entity.getInfo(), authInfo);
|
||||||
tokensToReturn.add(genToken);
|
tokensToReturn.add(genToken);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return new ListMapper(tokensToReturn);
|
return new ListMapper(tokensToReturn);
|
||||||
}catch(Exception e){
|
}catch(Exception e){
|
||||||
log.error("error generating tokens ",e);
|
log.error("error generating tokens ",e);
|
||||||
|
@ -391,7 +404,7 @@ public class TokenManager {
|
||||||
.entity("Error Generating Token: "+e.getMessage()).type(MediaType.TEXT_PLAIN).build());
|
.entity("Error Generating Token: "+e.getMessage()).type(MediaType.TEXT_PLAIN).build());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Path("node")
|
@Path("node")
|
||||||
@PUT
|
@PUT
|
||||||
@Consumes(MediaType.APPLICATION_XML)
|
@Consumes(MediaType.APPLICATION_XML)
|
||||||
|
@ -399,16 +412,16 @@ public class TokenManager {
|
||||||
@Context HttpServletRequest req) {
|
@Context HttpServletRequest req) {
|
||||||
CalledMethodProvider.instance.set("generate");
|
CalledMethodProvider.instance.set("generate");
|
||||||
try{
|
try{
|
||||||
|
|
||||||
AuthorizationEntry info = (AuthorizationEntry)req.getAttribute(AuthorizedCallFilter.AUTH_ATTRIBUTE);
|
AuthorizationEntry info = (AuthorizationEntry)req.getAttribute(AuthorizedCallFilter.AUTH_ATTRIBUTE);
|
||||||
|
|
||||||
if (context!=null)
|
if (context!=null)
|
||||||
return generateTokenForContainerInfo(containerInfo, context);
|
return generateTokenForContainerInfo(containerInfo, context);
|
||||||
else if (info!=null){
|
else if (info!=null){
|
||||||
log.info("generator called for node {} in context {} ",containerInfo.getId(), info.getContext());
|
log.info("generator called for node {} in context {} ",containerInfo.getId(), info.getContext());
|
||||||
return generateTokenForContainerInfo(containerInfo, info);
|
return generateTokenForContainerInfo(containerInfo, info);
|
||||||
}
|
}
|
||||||
|
|
||||||
throw new Exception("error trying to activate node (token and context are empty)");
|
throw new Exception("error trying to activate node (token and context are empty)");
|
||||||
}catch(Exception e){
|
}catch(Exception e){
|
||||||
log.error("error generating token ",e);
|
log.error("error generating token ",e);
|
||||||
|
@ -429,7 +442,7 @@ public class TokenManager {
|
||||||
}
|
}
|
||||||
return token;
|
return token;
|
||||||
}
|
}
|
||||||
|
|
||||||
private String generateTokenForContainerInfo(ContainerInfo containerInfo, AuthorizationEntry authInfo) throws Exception{
|
private String generateTokenForContainerInfo(ContainerInfo containerInfo, AuthorizationEntry authInfo) throws Exception{
|
||||||
if (containerInfo.getId().split(":").length!=2) throw new Exception("invalid container id: "+containerInfo.getId());
|
if (containerInfo.getId().split(":").length!=2) throw new Exception("invalid container id: "+containerInfo.getId());
|
||||||
|
|
||||||
|
@ -442,7 +455,7 @@ public class TokenManager {
|
||||||
}
|
}
|
||||||
return token;
|
return token;
|
||||||
}
|
}
|
||||||
|
|
||||||
private String generateTokenForServiceInfo(ServiceInfo serviceInfo, AuthorizationEntry authInfo) throws Exception{
|
private String generateTokenForServiceInfo(ServiceInfo serviceInfo, AuthorizationEntry authInfo) throws Exception{
|
||||||
if (serviceInfo.getId().split(":").length!=3) throw new Exception("invalid service id: "+serviceInfo.getId());
|
if (serviceInfo.getId().split(":").length!=3) throw new Exception("invalid service id: "+serviceInfo.getId());
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue