Skip to content

Commit 75dbc53

Browse files
committed
chore(auth): performance of authorization related hash code and equals impls [PPUC-318]
1 parent 99c050e commit 75dbc53

File tree

5 files changed

+16
-8
lines changed

5 files changed

+16
-8
lines changed

core/src/main/java/org/pentaho/platform/engine/security/authorization/core/AbstractAuthorizationUser.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ public boolean equals( Object o ) {
3333
// possible to put principals of various types into a map.
3434
@Override
3535
public int hashCode() {
36-
return Objects.hash( IAuthorizationUser.class, getName() );
36+
int result = IAuthorizationUser.class.hashCode();
37+
result = 31 * result + Objects.hashCode( getName() );
38+
return result;
3739
}
3840
}

core/src/main/java/org/pentaho/platform/engine/security/authorization/core/AuthorizationRequest.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,9 @@ public boolean equals( Object o ) {
7777

7878
@Override
7979
public int hashCode() {
80-
return Objects.hash( principal, action );
80+
int result = principal.hashCode();
81+
result = 31 * result + action.hashCode();
82+
return result;
8183
}
8284

8385
@Override

core/src/main/java/org/pentaho/platform/engine/security/authorization/core/AuthorizationRole.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ public boolean equals( Object o ) {
4949
// possible to put principals of various types into a map.
5050
@Override
5151
public int hashCode() {
52-
return Objects.hash( IAuthorizationRole.class, getName() );
52+
int result = IAuthorizationRole.class.hashCode();
53+
result = 31 * result + name.hashCode();
54+
return result;
5355
}
5456
}

core/src/main/java/org/pentaho/platform/engine/security/authorization/core/resources/GenericAuthorizationResource.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,9 @@ public boolean equals( Object o ) {
5858

5959
@Override
6060
public int hashCode() {
61-
return Objects.hash( typeId, id );
61+
int result = typeId.hashCode();
62+
result = 31 * result + id.hashCode();
63+
return result;
6264
}
6365

6466
@Override

core/src/main/java/org/pentaho/platform/engine/security/authorization/core/resources/ResourceAuthorizationRequest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@
2121
import org.pentaho.platform.engine.security.authorization.core.AuthorizationRequest;
2222
import org.springframework.util.Assert;
2323

24-
import java.util.Objects;
25-
2624
/**
2725
* The {@code ResourceAuthorizationRequest} class represents an authorization request for a specific resource.
2826
* It extends the basic authorization request to include resource-specific authorization context.
@@ -89,12 +87,14 @@ public boolean equals( Object o ) {
8987
}
9088

9189
IResourceAuthorizationRequest that = (IResourceAuthorizationRequest) o;
92-
return Objects.equals( resource, that.getResource() );
90+
return resource.equals( that.getResource() );
9391
}
9492

9593
@Override
9694
public int hashCode() {
97-
return Objects.hash( super.hashCode(), resource );
95+
int result = super.hashCode();
96+
result = 31 * result + resource.hashCode();
97+
return result;
9898
}
9999

100100
@Override

0 commit comments

Comments
 (0)