Skip to content

OpenAM AMKeyProvider.java performance - openam-shared  #368

@bagnos

Description

@bagnos

Is your feature request related to a problem? Please describe.
Hi All,

We noticed a performance issue about access_token and user_info api in openid connect scenario, we are using openam 14.5.3.
In this case we noticed, by jprofile istrumentations, a performance issue in AMKeyProvider.getKeyPair(alias) in greater detail in getPrivateKey() method.
I suggest you to use a ConcurrentHashMap about caching the private key after the first recovery from keystore.

You can see the jprofile details in attachment.

Describe the solution you'd like
I suggest you to change the code like this below.
private static Map<String, PrivateKey> mapKey = new ConcurrentHashMap<>();
public KeyPair getKeyPair(String certAlias) {

    PublicKey publicKey = getPublicKey(certAlias);
    PrivateKey privateKey=null;
    if (mapKey.containsKey(certAlias))
    {
    	privateKey=mapKey.get(certAlias);
    }
    else
    {
    	privateKey = getPrivateKey(certAlias);
    	mapKey.putIfAbsent(certAlias, privateKey);
    }

    if (publicKey != null && privateKey != null) {
        return new KeyPair(publicKey, privateKey);
    } else {
        return null;
    }
}

Describe alternatives you've considered

Additional context
OpenAMKeyPair

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions