diff --git a/core/src/main/java/org/springframework/security/authentication/jaas/JaasGrantedAuthority.java b/core/src/main/java/org/springframework/security/authentication/jaas/JaasGrantedAuthority.java index d0d76b89d1f..8096947840e 100644 --- a/core/src/main/java/org/springframework/security/authentication/jaas/JaasGrantedAuthority.java +++ b/core/src/main/java/org/springframework/security/authentication/jaas/JaasGrantedAuthority.java @@ -58,9 +58,8 @@ public boolean equals(Object obj) { if (this == obj) { return true; } - if (obj instanceof JaasGrantedAuthority) { - JaasGrantedAuthority jga = (JaasGrantedAuthority) obj; - return this.role.equals(jga.role) && this.principal.equals(jga.principal); + if (obj instanceof JaasGrantedAuthority jga) { + return this.role.equals(jga.getAuthority()) && this.principal.equals(jga.getPrincipal()); } return false; } diff --git a/core/src/main/java/org/springframework/security/core/authority/SimpleGrantedAuthority.java b/core/src/main/java/org/springframework/security/core/authority/SimpleGrantedAuthority.java index 71719d48010..54b889e6177 100644 --- a/core/src/main/java/org/springframework/security/core/authority/SimpleGrantedAuthority.java +++ b/core/src/main/java/org/springframework/security/core/authority/SimpleGrantedAuthority.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2023 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -50,8 +50,8 @@ public boolean equals(Object obj) { if (this == obj) { return true; } - if (obj instanceof SimpleGrantedAuthority) { - return this.role.equals(((SimpleGrantedAuthority) obj).role); + if (obj instanceof SimpleGrantedAuthority sga) { + return this.role.equals(sga.getAuthority()); } return false; } diff --git a/ldap/src/main/java/org/springframework/security/ldap/userdetails/LdapAuthority.java b/ldap/src/main/java/org/springframework/security/ldap/userdetails/LdapAuthority.java index 9e89a5d6313..e08678b2a45 100644 --- a/ldap/src/main/java/org/springframework/security/ldap/userdetails/LdapAuthority.java +++ b/ldap/src/main/java/org/springframework/security/ldap/userdetails/LdapAuthority.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2014 the original author or authors. + * Copyright 2002-2023 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -113,14 +113,13 @@ public boolean equals(Object obj) { if (this == obj) { return true; } - if (!(obj instanceof LdapAuthority)) { + if (!(obj instanceof LdapAuthority other)) { return false; } - LdapAuthority other = (LdapAuthority) obj; - if (!this.dn.equals(other.dn)) { + if (!this.dn.equals(other.getDn())) { return false; } - return this.role.equals(other.role); + return this.role.equals(other.getAuthority()); } @Override diff --git a/web/src/main/java/org/springframework/security/web/authentication/switchuser/SwitchUserGrantedAuthority.java b/web/src/main/java/org/springframework/security/web/authentication/switchuser/SwitchUserGrantedAuthority.java index a05155e9e07..4be683e554f 100644 --- a/web/src/main/java/org/springframework/security/web/authentication/switchuser/SwitchUserGrantedAuthority.java +++ b/web/src/main/java/org/springframework/security/web/authentication/switchuser/SwitchUserGrantedAuthority.java @@ -64,9 +64,8 @@ public boolean equals(Object obj) { if (this == obj) { return true; } - if (obj instanceof SwitchUserGrantedAuthority) { - SwitchUserGrantedAuthority swa = (SwitchUserGrantedAuthority) obj; - return this.role.equals(swa.role) && this.source.equals(swa.source); + if (obj instanceof SwitchUserGrantedAuthority swa) { + return this.role.equals(swa.getAuthority()) && this.source.equals(swa.getSource()); } return false; }