Skip to content

Commit f2fadf2

Browse files
rgcvCopilotlprimak
authored
[#1585] Migrate to Jakarta EE 10 (3.x) (#2018)
* Update to 3.0.0 Includes version bumps: - Java: 11 -> 17 - Ehcache: 2.6 -> 3.10 - Guice: 6 -> 7 - Jetty: 9.4.56.v2024.. -> 12.0 - `org.eclipse.jetty` -> `org.eclipse.jetty.ee10` - Jakarta EE: 8 -> 10 - Activation: 1.2 -> 2.1 - Annotation: 1.3 -> 2.1 - Enterprise CDI API: 2.0 -> 4.0 - JSON API: 1.1 -> 2.1 - JSON Bind: 1.0 -> 3.0 - Servlet: 4.0 -> 6.0 - Servlet JSP API: 2.2 -> 3.1 - Validation API: 2.0 -> 3.0 - WS RS API: 2.1 -> 3.1 - XML Bind: 2.3 -> 4.0 - Omnifaces: 4.6.1 - CXF RT Client: 3.6 -> 4.0 - Glassfish JAXB RT: 2.3 -> 4.0 - Spring: 5.3 -> 6.2 - Spring Boot: 2.7 -> 3.4 - Hibernate: 5.6 -> 6.6 (sample project) Concerns: - Ehcache migration most certainly needs revision - CI untested (specially Jenkins CD) - `flowlogix`, `omnifaces`, and a few other libs I have no knowledge of, certainly need attention - Spring remoting seems to have been dropped from Spring Context, not sure if replaceable Known issues: - No immediate suitable replacement for `org.eclipse.jetty:apache-jstl` - Ehcache 3.10 is pulling earlier version of jaxb runtime -> conflicting - Added exclusion to circumvent woes - Some web integration tests aren't up to speed - Embedded jetty-based ITs fail, server reports 503 - Arquillian IT fails - Meecrowave support missing (solved in unreleased 2.0.0?) * Remove lingering guice3 IT pom.xml * Suppress unchecked cast warning * Revert ill merge in test case * Properly disable meecrowave-based IT * Remove Shiro Spring remoting test * Remove lingering jetty injection argument from IT test case * Restore dependency details lost in translation * Remove stray type for runtime type inference / reification attempt Shouldn't have included this 🤦 This was a miserable attempt to obtain the concrete `Class<?>` instance for the request key and value types for caches. Please excuse my desperation. * fix(lang): Fix resource retrieval as URL instead of stream * fix: Fix typos in schema locations Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * fix(javadoc): Fix jakarta servlet javadoc reference * jakarta-related cleanup * fixed ehcache.xml --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Co-authored-by: lprimak <lenny@flowlogix.com>
1 parent b215136 commit f2fadf2

185 files changed

Lines changed: 823 additions & 1778 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/maven.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ jobs:
3838
- name: Set up JDK
3939
uses: actions/setup-java@f2beeb24e141e01a676f977032f5a29d81c9e27e # v5.1.0
4040
with:
41-
java-version: 11
41+
java-version: 17
4242
distribution: temurin
4343

4444
- name: License Check

config/core/src/main/java/org/apache/shiro/config/Ini.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -446,8 +446,7 @@ protected static String getSectionName(String line) {
446446
}
447447

448448
public boolean equals(Object obj) {
449-
if (obj instanceof Ini) {
450-
Ini ini = (Ini) obj;
449+
if (obj instanceof Ini ini) {
451450
return this.sections.equals(ini.sections);
452451
}
453452
return false;
@@ -710,8 +709,7 @@ public String toString() {
710709

711710
@Override
712711
public boolean equals(Object obj) {
713-
if (obj instanceof Section) {
714-
Section other = (Section) obj;
712+
if (obj instanceof Section other) {
715713
return getName().equals(other.getName()) && this.props.equals(other.props);
716714
}
717715
return false;

config/ogdl/src/main/java/org/apache/shiro/config/ogdl/ReflectionBuilder.java

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -232,23 +232,23 @@ protected EventBus findEventBus(Map<String, ?> objects) {
232232

233233
//prefer a named object first:
234234
Object value = objects.get(EVENT_BUS_NAME);
235-
if (value instanceof EventBus) {
236-
return (EventBus) value;
235+
if (value instanceof EventBus bus) {
236+
return bus;
237237
}
238238

239239
//couldn't find a named 'eventBus' EventBus object. Try to find the first typed value we can:
240240
for (Object v : objects.values()) {
241-
if (v instanceof EventBus) {
242-
return (EventBus) v;
241+
if (v instanceof EventBus bus) {
242+
return bus;
243243
}
244244
}
245245

246246
return null;
247247
}
248248

249249
private boolean applyEventBusIfNecessary(Object value) {
250-
if (value instanceof EventBusAware) {
251-
((EventBusAware) value).setEventBus(this.eventBus);
250+
if (value instanceof EventBusAware aware) {
251+
aware.setEventBus(this.eventBus);
252252
return true;
253253
}
254254
return false;
@@ -357,8 +357,8 @@ protected void createNewInstance(Map<String, Object> objects, String name, Strin
357357
Object instance;
358358
try {
359359
instance = ClassUtils.newInstance(value);
360-
if (instance instanceof Nameable) {
361-
((Nameable) instance).setName(name);
360+
if (instance instanceof Nameable nameable) {
361+
nameable.setName(name);
362362
}
363363
} catch (Exception e) {
364364
instance = alternateObjectSupplier.apply(value);
@@ -455,8 +455,8 @@ protected Object resolveReference(String reference) {
455455
String id = getId(reference);
456456
LOGGER.debug("Encountered object reference '{}'. Looking up object with id '{}'", reference, id);
457457
final Object referencedObject = getReferencedObject(id);
458-
if (referencedObject instanceof Factory) {
459-
return ((Factory) referencedObject).getInstance();
458+
if (referencedObject instanceof Factory factory) {
459+
return factory.getInstance();
460460
}
461461
return referencedObject;
462462
}
@@ -492,8 +492,8 @@ protected Set<?> toSet(String sValue) {
492492
//SHIRO-423: check to see if the value is a referenced Set already, and if so, return it immediately:
493493
if (tokens.length == 1 && isReference(tokens[0])) {
494494
Object reference = resolveReference(tokens[0]);
495-
if (reference instanceof Set) {
496-
return (Set) reference;
495+
if (reference instanceof Set set) {
496+
return set;
497497
}
498498
}
499499

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

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

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

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

809-
if (statement instanceof InstantiationStatement) {
810-
InstantiationStatement is = (InstantiationStatement) statement;
809+
if (statement instanceof InstantiationStatement is) {
811810
beanConfigurations.add(new BeanConfiguration(is));
812811
} else {
813812
AssignmentStatement as = (AssignmentStatement) statement;

core/src/main/java/org/apache/shiro/authc/AbstractAuthenticator.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -203,8 +203,8 @@ public final AuthenticationInfo authenticate(AuthenticationToken token) throws A
203203
}
204204
} catch (Throwable t) {
205205
AuthenticationException ae = null;
206-
if (t instanceof AuthenticationException) {
207-
ae = (AuthenticationException) t;
206+
if (t instanceof AuthenticationException exception) {
207+
ae = exception;
208208
}
209209
if (ae == null) {
210210
//Exception thrown was not an expected AuthenticationException. Therefore it is probably a little more

core/src/main/java/org/apache/shiro/authc/SimpleAccount.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ public SimpleAccount(Object principal, Object credentials, String realmName) {
9999
* @since 1.1
100100
*/
101101
public SimpleAccount(Object principal, Object hashedCredentials, ByteSource credentialsSalt, String realmName) {
102-
this(principal instanceof PrincipalCollection ? (PrincipalCollection) principal
102+
this(principal instanceof PrincipalCollection pc ? pc
103103
: ImmutablePrincipalCollection.ofSinglePrincipal(principal, realmName),
104104
hashedCredentials, credentialsSalt);
105105
}
@@ -448,8 +448,7 @@ public void merge(AuthenticationInfo info) {
448448
authcInfo.merge(info);
449449

450450
// Merge SimpleAccount specific info
451-
if (info instanceof SimpleAccount) {
452-
SimpleAccount otherAccount = (SimpleAccount) info;
451+
if (info instanceof SimpleAccount otherAccount) {
453452
if (otherAccount.isLocked()) {
454453
setLocked(true);
455454
}
@@ -482,8 +481,7 @@ public boolean equals(Object o) {
482481
if (o == this) {
483482
return true;
484483
}
485-
if (o instanceof SimpleAccount) {
486-
SimpleAccount sa = (SimpleAccount) o;
484+
if (o instanceof SimpleAccount sa) {
487485
//principal should be unique across the application, so only check this for equality:
488486
return (getPrincipals() != null ? getPrincipals().equals(sa.getPrincipals()) : sa.getPrincipals() == null);
489487
}

core/src/main/java/org/apache/shiro/authc/SimpleAuthenticationInfo.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import org.apache.shiro.subject.ImmutablePrincipalCollection;
2424
import org.apache.shiro.subject.PrincipalCollection;
2525

26+
import java.io.Serial;
2627
import java.util.Collection;
2728
import java.util.HashSet;
2829
import java.util.Objects;
@@ -38,6 +39,7 @@
3839
*/
3940
public class SimpleAuthenticationInfo implements MergableAuthenticationInfo, SaltedAuthenticationInfo {
4041

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

227229
Object thisCredentials = getCredentials();
@@ -245,10 +247,8 @@ public void merge(AuthenticationInfo info) {
245247
// At this point, the credentials should be a collection
246248
@SuppressWarnings("unchecked")
247249
Collection<Object> credentialCollection = (Collection<Object>) getCredentials();
248-
if (otherCredentials instanceof Collection) {
249-
@SuppressWarnings("unchecked")
250-
Collection<Object> otherCredentialsCollection = (Collection<Object>) otherCredentials;
251-
credentialCollection.addAll(otherCredentialsCollection);
250+
if (otherCredentials instanceof Collection<?> collection) {
251+
credentialCollection.addAll(collection);
252252
} else {
253253
credentialCollection.add(otherCredentials);
254254
}

core/src/main/java/org/apache/shiro/authc/credential/DefaultPasswordService.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -169,9 +169,7 @@ public boolean passwordsMatch(Object submittedPlaintext, String saved) {
169169
//configuration changes.
170170
HashFormat discoveredFormat = this.hashFormatFactory.getInstance(saved);
171171

172-
if (discoveredFormat instanceof ParsableHashFormat) {
173-
174-
ParsableHashFormat parsableHashFormat = (ParsableHashFormat) discoveredFormat;
172+
if (discoveredFormat instanceof ParsableHashFormat parsableHashFormat) {
175173
Hash savedHash = parsableHashFormat.parse(saved);
176174

177175
return passwordsMatch(submittedPlaintext, savedHash);

core/src/main/java/org/apache/shiro/authc/credential/HashedCredentialsMatcher.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -402,8 +402,8 @@ public boolean doCredentialsMatch(AuthenticationToken token, AuthenticationInfo
402402
*/
403403
protected Object hashProvidedCredentials(AuthenticationToken token, AuthenticationInfo info) {
404404
final Object salt;
405-
if (info instanceof SaltedAuthenticationInfo) {
406-
salt = ((SaltedAuthenticationInfo) info).getCredentialsSalt();
405+
if (info instanceof SaltedAuthenticationInfo authenticationInfo) {
406+
salt = authenticationInfo.getCredentialsSalt();
407407
} else if (isHashSalted()) {
408408
//retain 1.0 backwards compatibility:
409409
salt = getSalt(token);

core/src/main/java/org/apache/shiro/authc/credential/PasswordMatcher.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,7 @@ public boolean doCredentialsMatch(AuthenticationToken token, AuthenticationInfo
4949
Object storedCredentials = getStoredPassword(info);
5050
assertStoredCredentialsType(storedCredentials);
5151

52-
if (storedCredentials instanceof Hash) {
53-
Hash hashedPassword = (Hash) storedCredentials;
52+
if (storedCredentials instanceof Hash hashedPassword) {
5453
return hashedPassword.matchesPassword(ByteSource.Util.bytes(submittedPassword));
5554
}
5655
//otherwise they are a String (asserted in the 'assertStoredCredentialsType' method call above):
@@ -89,8 +88,8 @@ private void assertStoredCredentialsType(Object credentials) {
8988
protected Object getStoredPassword(AuthenticationInfo storedAccountInfo) {
9089
Object stored = storedAccountInfo != null ? storedAccountInfo.getCredentials() : null;
9190
//fix for https://issues.apache.org/jira/browse/SHIRO-363
92-
if (stored instanceof char[]) {
93-
stored = new String((char[]) stored);
91+
if (stored instanceof char[] chars) {
92+
stored = new String(chars);
9493
}
9594
return stored;
9695
}

core/src/main/java/org/apache/shiro/authc/pam/AbstractAuthenticationStrategy.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,8 @@ public AuthenticationInfo afterAttempt(Realm realm, AuthenticationToken token,
8787
* {@link org.apache.shiro.authc.MergableAuthenticationInfo MergableAuthenticationInfo} is not desired for some reason.
8888
*/
8989
protected AuthenticationInfo merge(AuthenticationInfo info, AuthenticationInfo aggregate) {
90-
if (aggregate instanceof MergableAuthenticationInfo) {
91-
((MergableAuthenticationInfo) aggregate).merge(info);
90+
if (aggregate instanceof MergableAuthenticationInfo authenticationInfo) {
91+
authenticationInfo.merge(info);
9292
return aggregate;
9393
} else {
9494
throw new IllegalArgumentException("Attempt to merge authentication info from multiple realms, but aggregate "

0 commit comments

Comments
 (0)