Fixed code
This commit is contained in:
parent
19053a5492
commit
9181862d3c
2
pom.xml
2
pom.xml
|
@ -3,7 +3,7 @@
|
||||||
<parent>
|
<parent>
|
||||||
<artifactId>maven-parent</artifactId>
|
<artifactId>maven-parent</artifactId>
|
||||||
<groupId>org.gcube.tools</groupId>
|
<groupId>org.gcube.tools</groupId>
|
||||||
<version>1.2.0</version>
|
<version>1.1.0</version>
|
||||||
<relativePath />
|
<relativePath />
|
||||||
</parent>
|
</parent>
|
||||||
<groupId>org.gcube.common</groupId>
|
<groupId>org.gcube.common</groupId>
|
||||||
|
|
|
@ -26,9 +26,10 @@ public class ContextUtility {
|
||||||
public static String getCurrentContextFullName() {
|
public static String getCurrentContextFullName() {
|
||||||
String context = ScopeProvider.instance.get();
|
String context = ScopeProvider.instance.get();
|
||||||
if(context==null) {
|
if(context==null) {
|
||||||
logger.trace("ScopeProvider is null. Going to get context from AccessTokenProvider.");
|
logger.trace("ScopeProvider is null. Going to get context from SecurityTokenProvider.");
|
||||||
String token = SecurityTokenProvider.instance.get();
|
String token = SecurityTokenProvider.instance.get();
|
||||||
if(token!=null) {
|
if(token!=null) {
|
||||||
|
logger.trace("Found SecurityTokenProvider");
|
||||||
try {
|
try {
|
||||||
AuthorizationEntry authorizationEntry = Constants.authorizationService().get(token);
|
AuthorizationEntry authorizationEntry = Constants.authorizationService().get(token);
|
||||||
return authorizationEntry.getContext();
|
return authorizationEntry.getContext();
|
||||||
|
@ -36,9 +37,10 @@ public class ContextUtility {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
}else {
|
}else {
|
||||||
logger.trace("ScopeProvider AND AccessTokenProvider are null. Going to get context from SecurityTokenProvider.");
|
logger.trace("ScopeProvider AND SecurityTokenProvider are null. Going to get context from AccessTokenProvider.");
|
||||||
token = AccessTokenProvider.instance.get();
|
token = AccessTokenProvider.instance.get();
|
||||||
if(token!=null) {
|
if(token!=null) {
|
||||||
|
logger.trace("Found AccessTokenProvider");
|
||||||
String realUmaTokenEncoded = token.split("\\.")[1];
|
String realUmaTokenEncoded = token.split("\\.")[1];
|
||||||
String realUmaToken = new String(Base64.getDecoder().decode(realUmaTokenEncoded.getBytes()));
|
String realUmaToken = new String(Base64.getDecoder().decode(realUmaTokenEncoded.getBytes()));
|
||||||
ObjectMapper mapper = new ObjectMapper();
|
ObjectMapper mapper = new ObjectMapper();
|
||||||
|
@ -67,6 +69,7 @@ public class ContextUtility {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
logger.trace("Found ScopeProvider");
|
||||||
return context;
|
return context;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -32,21 +32,19 @@ public class ContextUtilityTest extends ContextTest {
|
||||||
ScopeProvider.instance.reset();
|
ScopeProvider.instance.reset();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
String oldToken = ContextTest.properties.getProperty("old_token_gcube");
|
String oldToken = ContextTest.properties.getProperty("old_token_gcube");
|
||||||
AccessTokenProvider.instance.set(oldToken);
|
SecurityTokenProvider.instance.set(oldToken);
|
||||||
gotContext = ContextUtility.getCurrentContextFullName();
|
|
||||||
logger.debug("Expected context is {} - Got Context is {}", context, gotContext);
|
|
||||||
Assert.assertTrue(context.compareTo(gotContext)==0);
|
|
||||||
AccessTokenProvider.instance.reset();
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
SecurityTokenProvider.instance.set(newToken);
|
|
||||||
gotContext = ContextUtility.getCurrentContextFullName();
|
gotContext = ContextUtility.getCurrentContextFullName();
|
||||||
logger.debug("Expected context is {} - Got Context is {}", context, gotContext);
|
logger.debug("Expected context is {} - Got Context is {}", context, gotContext);
|
||||||
Assert.assertTrue(context.compareTo(gotContext)==0);
|
Assert.assertTrue(context.compareTo(gotContext)==0);
|
||||||
SecurityTokenProvider.instance.reset();
|
SecurityTokenProvider.instance.reset();
|
||||||
|
|
||||||
|
|
||||||
|
AccessTokenProvider.instance.set(newToken);
|
||||||
|
gotContext = ContextUtility.getCurrentContextFullName();
|
||||||
|
logger.debug("Expected context is {} - Got Context is {}", context, gotContext);
|
||||||
|
Assert.assertTrue(context.compareTo(gotContext)==0);
|
||||||
|
AccessTokenProvider.instance.reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue