Fixed getUsername
This commit is contained in:
parent
1c10f36883
commit
d8b9fecee2
|
@ -169,7 +169,7 @@ public class JWTSecret extends Secret {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getUsername() throws Exception {
|
public String getUsername() throws Exception {
|
||||||
return accessToken.getPreferredUsername();
|
return getAccessToken().getPreferredUsername();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -21,7 +21,7 @@ public class KeycloakUser extends AccessToken implements User {
|
||||||
@Override
|
@Override
|
||||||
@JsonIgnore
|
@JsonIgnore
|
||||||
public String getUsername() {
|
public String getUsername() {
|
||||||
return (String) getOtherClaims().getOrDefault("preferred_username", getId());
|
return getPreferredUsername();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -37,6 +37,9 @@ public class ContextTest {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//DEFAULT_TEST_SCOPE_NAME = "/pred4s/preprod/preVRE";
|
||||||
|
// DEFAULT_TEST_SCOPE_NAME = "/gcube/devsec/devVRE";
|
||||||
|
|
||||||
ROOT = "/gcube";
|
ROOT = "/gcube";
|
||||||
// VO = ROOT + "/devsec";
|
// VO = ROOT + "/devsec";
|
||||||
// VRE = VO + "/devVRE";
|
// VRE = VO + "/devVRE";
|
||||||
|
|
|
@ -3,6 +3,7 @@ package org.gcube.common.authorization.utils.manager;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import org.gcube.common.authorization.utils.ContextTest;
|
import org.gcube.common.authorization.utils.ContextTest;
|
||||||
|
import org.gcube.common.authorization.utils.secret.JWTSecret;
|
||||||
import org.gcube.common.authorization.utils.secret.Secret;
|
import org.gcube.common.authorization.utils.secret.Secret;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
|
@ -25,4 +26,11 @@ public class SecretManagerTest extends ContextTest {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testApptoken() throws Exception {
|
||||||
|
Secret secret = new JWTSecret("eyJhbGciOiJSUzI1NiIsInR5cCIgOiAiSldUIiwia2lkIiA6ICJSSklZNEpoNF9qdDdvNmREY0NlUDFfS1l0akcxVExXVW9oMkQ2Tzk1bFNBIn0.eyJleHAiOjE2NDgwNDU2NjMsImlhdCI6MTY0ODA0NTM2MywianRpIjoiZTRmZDgyMmUtY2E3MS00MDA5LTkxYjctZTg4NzgyNGEzZDM3IiwiaXNzIjoiaHR0cHM6Ly9hY2NvdW50cy5kZXYuZDRzY2llbmNlLm9yZy9hdXRoL3JlYWxtcy9kNHNjaWVuY2UiLCJhdWQiOiIlMkZnY3ViZSUyRmRldnNlYyUyRmRldlZSRSIsInN1YiI6ImE5YTJhZTBiLTY5YzktNDFiNy05ZTRhLThhNGIyMmFhNWRkZSIsInR5cCI6IkJlYXJlciIsImF6cCI6IkJsdWUtQ2xvdWQtRU9TQy1vbmJvYXJkaW5nIiwic2Vzc2lvbl9zdGF0ZSI6IjBlYjkyMGU1LWViYzItNDdjYS05NGMzLTFjNjI0MTYzNjUyNiIsImFjciI6IjEiLCJhbGxvd2VkLW9yaWdpbnMiOlsiLyoiXSwicmVzb3VyY2VfYWNjZXNzIjp7IiUyRmdjdWJlJTJGZGV2c2VjJTJGZGV2VlJFIjp7InJvbGVzIjpbIkNhdGFsb2d1ZS1FZGl0b3IiLCJNZW1iZXIiXX19LCJhdXRob3JpemF0aW9uIjp7InBlcm1pc3Npb25zIjpbeyJyc2lkIjoiNTcyODU1MTAtMzkzOS00ZGU3LThmYzEtZTNhOWQzY2NlMjgxIiwicnNuYW1lIjoiRGVmYXVsdCBSZXNvdXJjZSJ9XX0sInNjb3BlIjoiZW1haWwgcHJvZmlsZSIsImNsaWVudEhvc3QiOiIxNDYuNDguODcuMTgzIiwiZW1haWxfdmVyaWZpZWQi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ib2FyZGluZyIsInNlc3Npb25fc3RhdGUiOiIwZWI5MjBlNS1lYmMyLTQ3Y2EtOTRjMy0xYzYyNDE2MzY1MjYiLCJhdXRob3JpemF0aW9uIjp7InBlcm1pc3Npb25zIjpbeyJyc2lkIjoiNTcyODU1MTAtMzkzOS00ZGU3LThmYzEtZTNhOWQzY2NlMjgxIiwicnNuYW1lIjoiRGVmYXVsdCBSZXNvdXJjZSJ9XX0sInNjb3BlIjoiZW1haWwgcHJvZmlsZSJ9.t1yYIMzxrUC2UeiVxZ-LATSP-tYT2RsOD2");
|
||||||
|
String username = secret.getUsername();
|
||||||
|
String anotherUsername = secret.getUser().getUsername();
|
||||||
|
logger.debug("{} - {}", username, anotherUsername);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue