use of org.apache.servicecomb.authentication.provider.RSAProviderTokenManager in project incubator-servicecomb-java-chassis by apache.
the class TestRSAProviderTokenManager method testTokenExpried.
@Test
public void testTokenExpried() {
String tokenStr = "e8a04b54cf2711e7b701286ed488fc20@c8636e5acf1f11e7b701286ed488fc20@1511315597475@9t0tp8ce80SUM5ts6iRGjFJMvCdQ7uvhpyh0RM7smKm3p4wYOrojr4oT1Pnwx7xwgcgEFbQdwPJxIMfivpQ1rHGqiLp67cjACvJ3Ke39pmeAVhybsLADfid6oSjscFaJ@WBYouF6hXYrXzBA31HC3VX8Bw9PNgJUtVqOPAaeW9ye3q/D7WWb0M+XMouBIWxWY6v9Un1dGu5Rkjlx6gZbnlHkb2VO8qFR3Y6lppooWCirzpvEBRjlJQu8LPBur0BCfYGq8XYrEZA2NU6sg2zXieqCSiX6BnMnBHNn4cR9iZpk=";
RSAProviderTokenManager tokenManager = new RSAProviderTokenManager();
MicroserviceInstance microserviceInstance = new MicroserviceInstance();
Map<String, String> properties = new HashMap<>();
microserviceInstance.setProperties(properties);
properties.put(Const.INSTANCE_PUBKEY_PRO, "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCxKl5TNUTec7fL2degQcCk6vKf3c0wsfNK5V6elKzjWxm0MwbRj/UeR20VSnicBmVIOWrBS9LiERPPvjmmWUOSS2vxwr5XfhBhZ07gCAUNxBOTzgMo5nE45DhhZu5Jzt5qSV6o10Kq7+fCCBlDZ1UoWxZceHkUt5AxcrhEDulFjQIDAQAB");
Assert.assertFalse(tokenManager.valid(tokenStr));
}
use of org.apache.servicecomb.authentication.provider.RSAProviderTokenManager in project incubator-servicecomb-java-chassis by apache.
the class TestRSAProviderTokenManager method testTokenFromVaidatePool.
@Test
public void testTokenFromVaidatePool() {
RSAKeyPairEntry rsaKeyPairEntry = RSAUtils.generateRSAKeyPair();
RSAKeypair4Auth.INSTANCE.setPrivateKey(rsaKeyPairEntry.getPrivateKey());
RSAKeypair4Auth.INSTANCE.setPublicKey(rsaKeyPairEntry.getPublicKey());
RSAKeypair4Auth.INSTANCE.setPublicKeyEncoded(rsaKeyPairEntry.getPublicKeyEncoded());
String serviceId = "c8636e5acf1f11e7b701286ed488fc20";
String instanceId = "e8a04b54cf2711e7b701286ed488fc20";
RSAConsumerTokenManager rsaCoumserTokenManager = new RSAConsumerTokenManager();
MicroserviceInstance microserviceInstance = new MicroserviceInstance();
microserviceInstance.setInstanceId(instanceId);
Map<String, String> properties = new HashMap<>();
microserviceInstance.setProperties(properties);
properties.put(Const.INSTANCE_PUBKEY_PRO, rsaKeyPairEntry.getPublicKeyEncoded());
Microservice microservice = new Microservice();
microservice.setServiceId(serviceId);
new Expectations(RegistryUtils.class) {
{
RegistryUtils.getMicroservice();
result = microservice;
RegistryUtils.getMicroserviceInstance();
result = microserviceInstance;
}
};
// Test Consumer first create token
String token = rsaCoumserTokenManager.getToken();
Assert.assertNotNull(token);
// use cache token
Assert.assertEquals(token, rsaCoumserTokenManager.getToken());
new Expectations(MicroserviceInstanceCache.class) {
{
MicroserviceInstanceCache.getOrCreate(serviceId, instanceId);
result = microserviceInstance;
}
};
RSAProviderTokenManager rsaProviderTokenManager = new RSAProviderTokenManager();
// first validate need to verify use RSA
Assert.assertTrue(rsaProviderTokenManager.valid(token));
// second validate use validated pool
Assert.assertTrue(rsaProviderTokenManager.valid(token));
}
Aggregations