Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
2 changes: 1 addition & 1 deletion .github/workflows/maven.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ jobs:
- name: Set up JDK
uses: actions/setup-java@dded0888837ed1f317902acf8a20df0ad188d165 # v5.0.0
with:
java-version: 11
java-version: 17
distribution: temurin

- name: License Check
Expand Down
8 changes: 0 additions & 8 deletions bom/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,11 @@
<dependency>
<groupId>org.apache.shiro</groupId>
<artifactId>shiro-core</artifactId>
<classifier>jakarta</classifier>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.apache.shiro</groupId>
<artifactId>shiro-web</artifactId>
<classifier>jakarta</classifier>
<version>${project.version}</version>
<exclusions>
<exclusion>
Expand All @@ -54,7 +52,6 @@
<dependency>
<groupId>org.apache.shiro</groupId>
<artifactId>shiro-jakarta-ee</artifactId>
<classifier>jakarta</classifier>
<version>${project.version}</version>
<exclusions>
<exclusion>
Expand All @@ -66,7 +63,6 @@
<dependency>
<groupId>org.apache.shiro</groupId>
<artifactId>shiro-cdi</artifactId>
<classifier>jakarta</classifier>
<version>${project.version}</version>
<exclusions>
<exclusion>
Expand All @@ -78,7 +74,6 @@
<dependency>
<groupId>org.apache.shiro</groupId>
<artifactId>shiro-jaxrs</artifactId>
<classifier>jakarta</classifier>
<version>${project.version}</version>
<exclusions>
<exclusion>
Expand All @@ -90,7 +85,6 @@
<dependency>
<groupId>org.apache.shiro</groupId>
<artifactId>shiro-spring</artifactId>
<classifier>jakarta</classifier>
<version>${project.version}</version>
<exclusions>
<exclusion>
Expand All @@ -102,7 +96,6 @@
<dependency>
<groupId>org.apache.shiro</groupId>
<artifactId>shiro-spring-boot-web-starter</artifactId>
<classifier>jakarta</classifier>
<version>${project.version}</version>
<exclusions>
<exclusion>
Expand All @@ -114,7 +107,6 @@
<dependency>
<groupId>org.apache.shiro</groupId>
<artifactId>shiro-spring-boot-starter</artifactId>
<classifier>jakarta</classifier>
<version>${project.version}</version>
<exclusions>
<exclusion>
Expand Down
6 changes: 2 additions & 4 deletions config/core/src/main/java/org/apache/shiro/config/Ini.java
Original file line number Diff line number Diff line change
Expand Up @@ -446,8 +446,7 @@ protected static String getSectionName(String line) {
}

public boolean equals(Object obj) {
if (obj instanceof Ini) {
Ini ini = (Ini) obj;
if (obj instanceof Ini ini) {
return this.sections.equals(ini.sections);
}
return false;
Expand Down Expand Up @@ -710,8 +709,7 @@ public String toString() {

@Override
public boolean equals(Object obj) {
if (obj instanceof Section) {
Section other = (Section) obj;
if (obj instanceof Section other) {
return getName().equals(other.getName()) && this.props.equals(other.props);
}
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -232,23 +232,23 @@ protected EventBus findEventBus(Map<String, ?> objects) {

//prefer a named object first:
Object value = objects.get(EVENT_BUS_NAME);
if (value instanceof EventBus) {
return (EventBus) value;
if (value instanceof EventBus bus) {
return bus;
}

//couldn't find a named 'eventBus' EventBus object. Try to find the first typed value we can:
for (Object v : objects.values()) {
if (v instanceof EventBus) {
return (EventBus) v;
if (v instanceof EventBus bus) {
return bus;
}
}

return null;
}

private boolean applyEventBusIfNecessary(Object value) {
if (value instanceof EventBusAware) {
((EventBusAware) value).setEventBus(this.eventBus);
if (value instanceof EventBusAware aware) {
aware.setEventBus(this.eventBus);
return true;
}
return false;
Expand Down Expand Up @@ -357,8 +357,8 @@ protected void createNewInstance(Map<String, Object> objects, String name, Strin
Object instance;
try {
instance = ClassUtils.newInstance(value);
if (instance instanceof Nameable) {
((Nameable) instance).setName(name);
if (instance instanceof Nameable nameable) {
nameable.setName(name);
}
} catch (Exception e) {
instance = alternateObjectSupplier.apply(value);
Expand Down Expand Up @@ -455,8 +455,8 @@ protected Object resolveReference(String reference) {
String id = getId(reference);
LOGGER.debug("Encountered object reference '{}'. Looking up object with id '{}'", reference, id);
final Object referencedObject = getReferencedObject(id);
if (referencedObject instanceof Factory) {
return ((Factory) referencedObject).getInstance();
if (referencedObject instanceof Factory factory) {
return factory.getInstance();
}
return referencedObject;
}
Expand Down Expand Up @@ -492,8 +492,8 @@ protected Set<?> toSet(String sValue) {
//SHIRO-423: check to see if the value is a referenced Set already, and if so, return it immediately:
if (tokens.length == 1 && isReference(tokens[0])) {
Object reference = resolveReference(tokens[0]);
if (reference instanceof Set) {
return (Set) reference;
if (reference instanceof Set set) {
return set;
}
}

Expand All @@ -518,8 +518,8 @@ protected Set<?> toSet(String sValue) {
//SHIRO-423: check to see if the value is a referenced Map already, and if so, return it immediately:
if (tokens.length == 1 && isReference(tokens[0])) {
Object reference = resolveReference(tokens[0]);
if (reference instanceof Map) {
return (Map) reference;
if (reference instanceof Map map) {
return map;
}
}

Expand Down Expand Up @@ -556,8 +556,8 @@ protected Collection<?> toCollection(String sValue) {
//SHIRO-423: check to see if the value is a referenced Collection already, and if so, return it immediately:
if (tokens.length == 1 && isReference(tokens[0])) {
Object reference = resolveReference(tokens[0]);
if (reference instanceof Collection) {
return (Collection) reference;
if (reference instanceof Collection collection) {
return collection;
}
}

Expand All @@ -579,8 +579,8 @@ protected List<?> toList(String sValue) {
//SHIRO-423: check to see if the value is a referenced List already, and if so, return it immediately:
if (tokens.length == 1 && isReference(tokens[0])) {
Object reference = resolveReference(tokens[0]);
if (reference instanceof List) {
return (List) reference;
if (reference instanceof List list) {
return list;
}
}

Expand Down Expand Up @@ -806,8 +806,7 @@ public void add(Statement statement) {
//we execute bean configuration statements in the order they are declared.
statements.add(statement);

if (statement instanceof InstantiationStatement) {
InstantiationStatement is = (InstantiationStatement) statement;
if (statement instanceof InstantiationStatement is) {
beanConfigurations.add(new BeanConfiguration(is));
} else {
AssignmentStatement as = (AssignmentStatement) statement;
Expand Down
1 change: 0 additions & 1 deletion config/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,3 @@
</modules>

</project>

Original file line number Diff line number Diff line change
Expand Up @@ -203,8 +203,8 @@ public final AuthenticationInfo authenticate(AuthenticationToken token) throws A
}
} catch (Throwable t) {
AuthenticationException ae = null;
if (t instanceof AuthenticationException) {
ae = (AuthenticationException) t;
if (t instanceof AuthenticationException exception) {
ae = exception;
}
if (ae == null) {
//Exception thrown was not an expected AuthenticationException. Therefore it is probably a little more
Expand Down
8 changes: 3 additions & 5 deletions core/src/main/java/org/apache/shiro/authc/SimpleAccount.java
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public SimpleAccount(Object principal, Object credentials, String realmName) {
* @since 1.1
*/
public SimpleAccount(Object principal, Object hashedCredentials, ByteSource credentialsSalt, String realmName) {
this(principal instanceof PrincipalCollection ? (PrincipalCollection) principal
this(principal instanceof PrincipalCollection pc ? pc
: ImmutablePrincipalCollection.ofSinglePrincipal(principal, realmName),
hashedCredentials, credentialsSalt);
}
Expand Down Expand Up @@ -448,8 +448,7 @@ public void merge(AuthenticationInfo info) {
authcInfo.merge(info);

// Merge SimpleAccount specific info
if (info instanceof SimpleAccount) {
SimpleAccount otherAccount = (SimpleAccount) info;
if (info instanceof SimpleAccount otherAccount) {
if (otherAccount.isLocked()) {
setLocked(true);
}
Expand Down Expand Up @@ -482,8 +481,7 @@ public boolean equals(Object o) {
if (o == this) {
return true;
}
if (o instanceof SimpleAccount) {
SimpleAccount sa = (SimpleAccount) o;
if (o instanceof SimpleAccount sa) {
//principal should be unique across the application, so only check this for equality:
return (getPrincipals() != null ? getPrincipals().equals(sa.getPrincipals()) : sa.getPrincipals() == null);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import org.apache.shiro.subject.ImmutablePrincipalCollection;
import org.apache.shiro.subject.PrincipalCollection;

import java.io.Serial;
import java.util.Collection;
import java.util.HashSet;
import java.util.Objects;
Expand All @@ -38,6 +39,7 @@
*/
public class SimpleAuthenticationInfo implements MergableAuthenticationInfo, SaltedAuthenticationInfo {

@Serial
private static final long serialVersionUID = 5390456512469696779L;
/**
* The principals identifying the account associated with this AuthenticationInfo instance.
Expand Down Expand Up @@ -220,8 +222,8 @@ public void merge(AuthenticationInfo info) {
//is null, then it can't hurt to pull in a non-null value if one exists.
//
//since 1.1:
if (this.credentialsSalt == null && info instanceof SaltedAuthenticationInfo) {
this.credentialsSalt = ((SaltedAuthenticationInfo) info).getCredentialsSalt();
if (this.credentialsSalt == null && info instanceof SaltedAuthenticationInfo authenticationInfo) {
this.credentialsSalt = authenticationInfo.getCredentialsSalt();
}

Object thisCredentials = getCredentials();
Expand All @@ -245,10 +247,8 @@ public void merge(AuthenticationInfo info) {
// At this point, the credentials should be a collection
@SuppressWarnings("unchecked")
Collection<Object> credentialCollection = (Collection<Object>) getCredentials();
if (otherCredentials instanceof Collection) {
@SuppressWarnings("unchecked")
Collection<Object> otherCredentialsCollection = (Collection<Object>) otherCredentials;
credentialCollection.addAll(otherCredentialsCollection);
if (otherCredentials instanceof Collection<?> collection) {
credentialCollection.addAll(collection);
} else {
credentialCollection.add(otherCredentials);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,9 +169,7 @@ public boolean passwordsMatch(Object submittedPlaintext, String saved) {
//configuration changes.
HashFormat discoveredFormat = this.hashFormatFactory.getInstance(saved);

if (discoveredFormat instanceof ParsableHashFormat) {

ParsableHashFormat parsableHashFormat = (ParsableHashFormat) discoveredFormat;
if (discoveredFormat instanceof ParsableHashFormat parsableHashFormat) {
Hash savedHash = parsableHashFormat.parse(saved);

return passwordsMatch(submittedPlaintext, savedHash);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -402,8 +402,8 @@ public boolean doCredentialsMatch(AuthenticationToken token, AuthenticationInfo
*/
protected Object hashProvidedCredentials(AuthenticationToken token, AuthenticationInfo info) {
final Object salt;
if (info instanceof SaltedAuthenticationInfo) {
salt = ((SaltedAuthenticationInfo) info).getCredentialsSalt();
if (info instanceof SaltedAuthenticationInfo authenticationInfo) {
salt = authenticationInfo.getCredentialsSalt();
} else if (isHashSalted()) {
//retain 1.0 backwards compatibility:
salt = getSalt(token);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,7 @@ public boolean doCredentialsMatch(AuthenticationToken token, AuthenticationInfo
Object storedCredentials = getStoredPassword(info);
assertStoredCredentialsType(storedCredentials);

if (storedCredentials instanceof Hash) {
Hash hashedPassword = (Hash) storedCredentials;
if (storedCredentials instanceof Hash hashedPassword) {
return hashedPassword.matchesPassword(ByteSource.Util.bytes(submittedPassword));
}
//otherwise they are a String (asserted in the 'assertStoredCredentialsType' method call above):
Expand Down Expand Up @@ -84,8 +83,8 @@ private void assertStoredCredentialsType(Object credentials) {
protected Object getStoredPassword(AuthenticationInfo storedAccountInfo) {
Object stored = storedAccountInfo != null ? storedAccountInfo.getCredentials() : null;
//fix for https://issues.apache.org/jira/browse/SHIRO-363
if (stored instanceof char[]) {
stored = new String((char[]) stored);
if (stored instanceof char[] chars) {
stored = new String(chars);
}
return stored;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ public AuthenticationInfo afterAttempt(Realm realm, AuthenticationToken token,
* {@link org.apache.shiro.authc.MergableAuthenticationInfo MergableAuthenticationInfo} is not desired for some reason.
*/
protected AuthenticationInfo merge(AuthenticationInfo info, AuthenticationInfo aggregate) {
if (aggregate instanceof MergableAuthenticationInfo) {
((MergableAuthenticationInfo) aggregate).merge(info);
if (aggregate instanceof MergableAuthenticationInfo authenticationInfo) {
authenticationInfo.merge(info);
return aggregate;
} else {
throw new IllegalArgumentException("Attempt to merge authentication info from multiple realms, but aggregate "
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,9 @@ public AuthenticationInfo afterAttempt(Realm realm, AuthenticationToken token,
AuthenticationInfo info, AuthenticationInfo aggregate, Throwable t)
throws AuthenticationException {
if (t != null) {
if (t instanceof AuthenticationException) {
if (t instanceof AuthenticationException exception) {
//propagate:
throw ((AuthenticationException) t);
throw exception;
} else {
String msg = "Unable to acquire account data from realm [" + realm + "]. The ["
+ getClass().getName() + " implementation requires all configured realm(s) to operate successfully "
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -294,8 +294,8 @@ public void onLogout(PrincipalCollection principals) {
Collection<Realm> realms = getRealms();
if (!CollectionUtils.isEmpty(realms)) {
for (Realm realm : realms) {
if (realm instanceof LogoutAware) {
((LogoutAware) realm).onLogout(principals);
if (realm instanceof LogoutAware aware) {
aware.onLogout(principals);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,8 @@ protected void applyPermissionResolverToRealms() {
Collection<Realm> realms = getRealms();
if (resolver != null && realms != null && !realms.isEmpty()) {
for (Realm realm : realms) {
if (realm instanceof PermissionResolverAware) {
((PermissionResolverAware) realm).setPermissionResolver(resolver);
if (realm instanceof PermissionResolverAware aware) {
aware.setPermissionResolver(resolver);
}
}
}
Expand Down Expand Up @@ -193,8 +193,8 @@ protected void applyRolePermissionResolverToRealms() {
Collection<Realm> realms = getRealms();
if (resolver != null && realms != null && !realms.isEmpty()) {
for (Realm realm : realms) {
if (realm instanceof RolePermissionResolverAware) {
((RolePermissionResolverAware) realm).setRolePermissionResolver(resolver);
if (realm instanceof RolePermissionResolverAware aware) {
aware.setRolePermissionResolver(resolver);
}
}
}
Expand Down
3 changes: 1 addition & 2 deletions core/src/main/java/org/apache/shiro/authz/SimpleRole.java
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,7 @@ public boolean equals(Object o) {
if (o == this) {
return true;
}
if (o instanceof SimpleRole) {
SimpleRole sr = (SimpleRole) o;
if (o instanceof SimpleRole sr) {
//only check name, since role names should be unique across an entire application:
return (getName() != null ? getName().equals(sr.getName()) : sr.getName() == null);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import org.apache.shiro.authz.UnauthenticatedException;
import org.apache.shiro.authz.UnauthorizedException;

import javax.annotation.security.DenyAll;
import jakarta.annotation.security.DenyAll;
import java.lang.annotation.Annotation;

/**
Expand Down
Loading