Skip to content

Conversation

@coolhongluo
Copy link
Contributor

As a developer, I need to have authentication in service provider to protect the microservice from unauthorized access

@coveralls
Copy link

Coverage Status

Changes Unknown when pulling cf76cbe on coolhongluo:serviceauth_rsatoken into ** on ServiceComb:master**.

kf = KeyFactory.getInstance(RSA_ALG);
}catch(NoSuchAlgorithmException e)
{
LOGGER.error("init keyfactory error");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code not well formated

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

new code ,forget to format

public static String sign(String content, PrivateKey privateKey)
throws NoSuchAlgorithmException, InvalidKeySpecException, SignatureException, InvalidKeyException {
Signature signature = Signature.getInstance(SIGN_ALG);
signature.initSign(privateKey);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Public and private key may not change in every call, for performance we can cache the init values. It is fine now and need more test data to evaluate

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is a good idea,but i think the RSAUtils is a common function;
if have performance problem ,i will refactor it


@Override
public boolean equals(Object obj) {
if (null == obj || !(obj instanceof RSAAuthenticationToken)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

redundant expression

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

accept

public void handle(Invocation invocation, AsyncResponse asyncResp) throws Exception {

Optional<String> token = Optional.ofNullable(athenticationTokenManager.getToken());
if(!token.isPresent())
Copy link
Contributor

@liubao68 liubao68 Nov 29, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think, we can delete all these instructions. 38-44

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe,but i think can reduce send request to server if do it

} catch (InvalidKeyException | NoSuchAlgorithmException | InvalidKeySpecException | SignatureException e) {
logger.error("create token error", e);
throw new Error("create token error");
}
Copy link
Contributor

@liubao68 liubao68 Nov 29, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lock is not properly released in some situation. I think we do not need lock at all at this part. e.g. we just add a one time task to do the creation of the key. And we need to do some protection when service center service is not available at the creation moment, that's to say, we need use the old key & new key for 15 minutes.

}

private String getPublicKey(String instanceId, String serviceId) {
Optional<MicroserviceInstance> instances = Optional
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is just a null check, why need using Optional?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

accept

private static Cache<String, MicroserviceInstance> instances = CacheBuilder.newBuilder().maximumSize(1000)
.expireAfterAccess(30, TimeUnit.MINUTES).build();

public static MicroserviceInstance getOrCreate(String serviceId, String instanceId) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do you use the code template under $HOME/etc folder?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

accept ; forget to format

@@ -0,0 +1,32 @@
package io.servicecomb.foundation.common.utils;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

copy right

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

accept

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.06%) to 86.904% when pulling 2ee157c on coolhongluo:serviceauth_rsatoken into 47414d0 on ServiceComb:master.

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.1%) to 86.886% when pulling d66a9a5 on coolhongluo:serviceauth_rsatoken into 7ddf345 on ServiceComb:master.

Copy link
Contributor Author

@coolhongluo coolhongluo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe need double check here

@WillemJiang WillemJiang merged commit 856657d into apache:master Nov 30, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants