Skip to content

[Enhancement] Do some code optimization[AuthTokenUtils] #3515

Closed
@Alonexc

Description

@Alonexc

Search before asking

  • I had searched in the issues and found no similar issues.

Enhancement Request

located at:
eventmesh-security-plugin/eventmesh-security-auth-token/src/main/java/org/apache/eventmesh/auth/token/impl/auth/AuthTokenUtils.java
analysis and explanation:
a. The logic of "authTokenByPublicKey" and "helloTaskAuthTokenByPublicKey" method in lines "54-87" and "99-132" is the same, so it can be extracted as one method.
b. Variable 'validationKeyBytes' initializer 'new byte[0]' is redundant.[line 66,111]
c. Argument 'publicKeyUrl' might be null.[line 68,113]
image

d. 'if' statement can be simplified.[line 146]
image

e. The "{}" is redundant.[line 90,134]
image

Describe the solution you'd like

a. Repeat the logic code extracted as a method.
b. Remove redundant initializers.
c. Use 'Objects.requireNonNull()' to avoid an NPE.
image

d. Replace this if-then-else statement by a single return statement
image

e. Remove the extra "{}".
image

Are you willing to submit PR?

  • Yes I am willing to submit a PR!

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requestgood first issueIssues for first-time contributors

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions