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