[java-identity-provider] branch main updated: Fix some bugs flagged by null analyzer.
Scott Cantor
cantor.2 at osu.edu
Wed Oct 18 19:21:22 UTC 2023
This is an automated email from the git hooks/post-receive script.
scantor pushed a commit to branch main
in repository java-identity-provider.
View the commit online:
http://git.shibboleth.net/view/?p=java-identity-provider.git;a=commit;h=5c9680889bff83122e83e5c11f088ad09779279c
The following commit(s) were added to refs/heads/main by this push:
new 5c9680889 Fix some bugs flagged by null analyzer.
5c9680889 is described below
commit 5c9680889bff83122e83e5c11f088ad09779279c
Author: Scott Cantor <cantor.2 at osu.edu>
AuthorDate: Wed Oct 18 15:21:19 2023 -0400
Fix some bugs flagged by null analyzer.
---
.../StorageBackedAccountLockoutManagerTest.java | 1 +
.../idp/cas/ticket/impl/AbstractTicketService.java | 13 +++++++-
.../impl/AbstractTicketSerializer.java | 36 ++++++++++++----------
.../cas/ticket/impl/SimpleTicketServiceTest.java | 13 +++++---
4 files changed, 41 insertions(+), 22 deletions(-)
diff --git a/idp-authn-impl/src/test/java/net/shibboleth/idp/authn/impl/StorageBackedAccountLockoutManagerTest.java b/idp-authn-impl/src/test/java/net/shibboleth/idp/authn/impl/StorageBackedAccountLockoutManagerTest.java
index 0d40c166c..7525572e8 100644
--- a/idp-authn-impl/src/test/java/net/shibboleth/idp/authn/impl/StorageBackedAccountLockoutManagerTest.java
+++ b/idp-authn-impl/src/test/java/net/shibboleth/idp/authn/impl/StorageBackedAccountLockoutManagerTest.java
@@ -134,6 +134,7 @@ public class StorageBackedAccountLockoutManagerTest extends BaseAuthenticationCo
final List<String> candidates = CollectionSupport.listOf("jdoe!192.168.1.1", "jdoe!192.168.1.2");
final Iterable<String> keys = manager.enumerate(prc);
+ assert keys != null;
for (final String key : keys) {
assertTrue(candidates.contains(key));
}
diff --git a/idp-cas-impl/src/main/java/net/shibboleth/idp/cas/ticket/impl/AbstractTicketService.java b/idp-cas-impl/src/main/java/net/shibboleth/idp/cas/ticket/impl/AbstractTicketService.java
index 271c130d2..f0f152402 100644
--- a/idp-cas-impl/src/main/java/net/shibboleth/idp/cas/ticket/impl/AbstractTicketService.java
+++ b/idp-cas-impl/src/main/java/net/shibboleth/idp/cas/ticket/impl/AbstractTicketService.java
@@ -159,6 +159,7 @@ public abstract class AbstractTicketService implements TicketService {
* @return Storage service serializer.
*/
@Nonnull protected static <T extends Ticket> StorageSerializer<T> serializer(@Nonnull final Class<T> clazz) {
+ @SuppressWarnings("unchecked")
final StorageSerializer<T> result = (StorageSerializer<T>) Constraint.isNotNull(SERIALIZER_MAP.get(clazz),
"Serializer for " + clazz + " not found");
return result;
@@ -177,6 +178,9 @@ public abstract class AbstractTicketService implements TicketService {
final String ticketCtx;
if (sessionId != null) {
final String context = context(ticket.getClass());
+ if (context == null) {
+ throw new IOException("Context for ticket class " + ticket.getClass() + " was null");
+ }
log.debug("Storing mapping of {} to {} in context {}", ticket, sessionId, context);
if (!storageService.create(context, ticket.getId(), sessionId, expiry)) {
throw new RuntimeException("Failed to store ticket " + ticket);
@@ -208,8 +212,12 @@ public abstract class AbstractTicketService implements TicketService {
log.debug("Reading {}", id);
final T ticket;
try {
+ final String ticketContext = context(clazz);
+ if (ticketContext == null) {
+ throw new IOException("Context for ticket class " + clazz + " was null");
+ }
final String context;
- final StorageRecord<T> sessionRecord = storageService.read(context(clazz), id);
+ final StorageRecord<T> sessionRecord = storageService.read(ticketContext, id);
if (sessionRecord != null) {
context = sessionRecord.getValue();
log.debug("{} bound to session {}", id, context);
@@ -245,6 +253,9 @@ public abstract class AbstractTicketService implements TicketService {
}
try {
final String context = context(clazz);
+ if (context == null) {
+ throw new IOException("Context for ticket class " + ticket.getClass() + " was null");
+ }
final String sessionId = ticket.getSessionId();
final String ticketCtx;
if (sessionId != null) {
diff --git a/idp-cas-impl/src/main/java/net/shibboleth/idp/cas/ticket/serialization/impl/AbstractTicketSerializer.java b/idp-cas-impl/src/main/java/net/shibboleth/idp/cas/ticket/serialization/impl/AbstractTicketSerializer.java
index d64648297..8fa4e289b 100644
--- a/idp-cas-impl/src/main/java/net/shibboleth/idp/cas/ticket/serialization/impl/AbstractTicketSerializer.java
+++ b/idp-cas-impl/src/main/java/net/shibboleth/idp/cas/ticket/serialization/impl/AbstractTicketSerializer.java
@@ -110,26 +110,28 @@ public abstract class AbstractTicketSerializer<T extends Ticket> implements Stor
if (ticket.getTicketState() != null) {
final TicketState state = ticket.getTicketState();
- gen.writeStartObject(STATE_FIELD);
- if (state.getSessionId() != null) {
- gen.write(SESSION_FIELD, state.getSessionId());
- } else {
- gen.writeNull(SESSION_FIELD);
- }
- gen.write(PRINCIPAL_FIELD, state.getPrincipalName())
- .write(AUTHN_INSTANT_FIELD, state.getAuthenticationInstant().toEpochMilli())
- .write(AUTHN_METHOD_FIELD, state.getAuthenticationMethod());
-
- final Set<String> consentedIds = state.getConsentedAttributeIds();
- if (consentedIds != null) {
- gen.writeStartArray(CONSENTED_ATTRS_FIELD);
- for (final String id : consentedIds) {
- gen.write(id);
+ if (state != null) {
+ gen.writeStartObject(STATE_FIELD);
+ if (state.getSessionId() != null) {
+ gen.write(SESSION_FIELD, state.getSessionId());
+ } else {
+ gen.writeNull(SESSION_FIELD);
+ }
+ gen.write(PRINCIPAL_FIELD, state.getPrincipalName())
+ .write(AUTHN_INSTANT_FIELD, state.getAuthenticationInstant().toEpochMilli())
+ .write(AUTHN_METHOD_FIELD, state.getAuthenticationMethod());
+
+ final Set<String> consentedIds = state.getConsentedAttributeIds();
+ if (consentedIds != null) {
+ gen.writeStartArray(CONSENTED_ATTRS_FIELD);
+ for (final String id : consentedIds) {
+ gen.write(id);
+ }
+ gen.writeEnd();
}
+
gen.writeEnd();
}
-
- gen.writeEnd();
}
serializeInternal(gen, ticket);
gen.writeEnd();
diff --git a/idp-cas-impl/src/test/java/net/shibboleth/idp/cas/ticket/impl/SimpleTicketServiceTest.java b/idp-cas-impl/src/test/java/net/shibboleth/idp/cas/ticket/impl/SimpleTicketServiceTest.java
index 91f418e1a..dfd996b8f 100644
--- a/idp-cas-impl/src/test/java/net/shibboleth/idp/cas/ticket/impl/SimpleTicketServiceTest.java
+++ b/idp-cas-impl/src/test/java/net/shibboleth/idp/cas/ticket/impl/SimpleTicketServiceTest.java
@@ -59,8 +59,10 @@ public class SimpleTicketServiceTest {
public void testCreateRemoveServiceTicket() throws Exception {
final ServiceTicket st = createServiceTicket(TEST_SESSION_ID);
assertNotNull(st);
- assertNotNull(st.getTicketState().getSessionId());
- assertNotNull(st.getTicketState().getPrincipalName());
+ final TicketState state = st.getTicketState();
+ assert state != null;
+ assertNotNull(state.getSessionId());
+ assertNotNull(state.getPrincipalName());
final ServiceTicket st2 = ticketService.removeServiceTicket(st.getId());
assert st2 != null;
assertEquals(st, st2);
@@ -74,10 +76,13 @@ public class SimpleTicketServiceTest {
public void testCreateRemoveServiceTicketNoSession() throws Exception {
final ServiceTicket st = createServiceTicket(null);
assertNotNull(st);
- assertNull(st.getTicketState().getSessionId());
- assertNotNull(st.getTicketState().getPrincipalName());
+ final TicketState state = st.getTicketState();
+ assert state != null;
+ assertNull(state.getSessionId());
+ assertNotNull(state.getPrincipalName());
final ServiceTicket st2 = ticketService.removeServiceTicket(st.getId());
assertEquals(st, st2);
+ assert st2 != null;
assertEquals(st.getExpirationInstant(), st2.getExpirationInstant());
assertEquals(st.getService(), st2.getService());
assertEquals(st.getTicketState(), st2.getTicketState());
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
More information about the commits
mailing list