use of org.apache.servicecomb.foundation.common.utils.RSAKeyPairEntry in project incubator-servicecomb-java-chassis by apache.
the class AuthHandlerBoot method onBootEvent.
@Override
public void onBootEvent(BootEvent event) {
if (EventType.BEFORE_REGISTRY.equals(event.getEventType())) {
RSAKeyPairEntry rsaKeyPairEntry = RSAUtils.generateRSAKeyPair();
RSAKeypair4Auth.INSTANCE.setPrivateKey(rsaKeyPairEntry.getPrivateKey());
RSAKeypair4Auth.INSTANCE.setPublicKey(rsaKeyPairEntry.getPublicKey());
RSAKeypair4Auth.INSTANCE.setPublicKeyEncoded(rsaKeyPairEntry.getPublicKeyEncoded());
RegistryUtils.getMicroserviceInstance().getProperties().put(Const.INSTANCE_PUBKEY_PRO, rsaKeyPairEntry.getPublicKeyEncoded());
}
}
use of org.apache.servicecomb.foundation.common.utils.RSAKeyPairEntry 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