Consistently NonNull annotation

Signed-off-by: Tran Ngoc Nhan <ngocnhan.tran1996@gmail.com>
This commit is contained in:
Tran Ngoc Nhan 2025-02-12 23:04:39 +07:00 committed by Josh Cummings
parent 31fb7feed5
commit 5d089f680e
6 changed files with 44 additions and 49 deletions

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2024 the original author or authors. * Copyright 2002-2025 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -20,10 +20,9 @@ import java.lang.reflect.Method;
import java.util.Arrays; import java.util.Arrays;
import java.util.function.Function; import java.util.function.Function;
import reactor.util.annotation.NonNull;
import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContext;
import org.springframework.expression.Expression; import org.springframework.expression.Expression;
import org.springframework.lang.NonNull;
import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.security.core.annotation.AnnotationTemplateExpressionDefaults; import org.springframework.security.core.annotation.AnnotationTemplateExpressionDefaults;
import org.springframework.security.core.annotation.SecurityAnnotationScanner; import org.springframework.security.core.annotation.SecurityAnnotationScanner;

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2024 the original author or authors. * Copyright 2002-2025 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -29,7 +29,6 @@ import java.util.Map;
import java.util.Set; import java.util.Set;
import java.util.function.Consumer; import java.util.function.Consumer;
import javax.annotation.Nonnull;
import javax.xml.namespace.QName; import javax.xml.namespace.QName;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
@ -67,6 +66,7 @@ import org.opensaml.saml.saml2.core.SubjectConfirmationData;
import org.springframework.core.convert.converter.Converter; import org.springframework.core.convert.converter.Converter;
import org.springframework.core.log.LogMessage; import org.springframework.core.log.LogMessage;
import org.springframework.lang.NonNull;
import org.springframework.security.authentication.AbstractAuthenticationToken; import org.springframework.security.authentication.AbstractAuthenticationToken;
import org.springframework.security.authentication.AuthenticationProvider; import org.springframework.security.authentication.AuthenticationProvider;
import org.springframework.security.core.Authentication; import org.springframework.security.core.Authentication;
@ -565,13 +565,13 @@ class BaseOpenSamlAuthenticationProvider implements AuthenticationProvider {
conditions.add(new AudienceRestrictionConditionValidator()); conditions.add(new AudienceRestrictionConditionValidator());
conditions.add(new DelegationRestrictionConditionValidator()); conditions.add(new DelegationRestrictionConditionValidator());
conditions.add(new ConditionValidator() { conditions.add(new ConditionValidator() {
@Nonnull @NonNull
@Override @Override
public QName getServicedCondition() { public QName getServicedCondition() {
return OneTimeUse.DEFAULT_ELEMENT_NAME; return OneTimeUse.DEFAULT_ELEMENT_NAME;
} }
@Nonnull @NonNull
@Override @Override
public ValidationResult validate(Condition condition, Assertion assertion, ValidationContext context) { public ValidationResult validate(Condition condition, Assertion assertion, ValidationContext context) {
// applications should validate their own OneTimeUse conditions // applications should validate their own OneTimeUse conditions
@ -580,16 +580,16 @@ class BaseOpenSamlAuthenticationProvider implements AuthenticationProvider {
}); });
conditions.add(new ProxyRestrictionConditionValidator()); conditions.add(new ProxyRestrictionConditionValidator());
subjects.add(new BearerSubjectConfirmationValidator() { subjects.add(new BearerSubjectConfirmationValidator() {
@Nonnull @NonNull
protected ValidationResult validateAddress(@Nonnull SubjectConfirmation confirmation, protected ValidationResult validateAddress(@NonNull SubjectConfirmation confirmation,
@Nonnull Assertion assertion, @Nonnull ValidationContext context, boolean required) @NonNull Assertion assertion, @NonNull ValidationContext context, boolean required)
throws AssertionValidationException { throws AssertionValidationException {
return ValidationResult.VALID; return ValidationResult.VALID;
} }
@Nonnull @NonNull
protected ValidationResult validateAddress(@Nonnull SubjectConfirmationData confirmationData, protected ValidationResult validateAddress(@NonNull SubjectConfirmationData confirmationData,
@Nonnull Assertion assertion, @Nonnull ValidationContext context, boolean required) @NonNull Assertion assertion, @NonNull ValidationContext context, boolean required)
throws AssertionValidationException { throws AssertionValidationException {
// applications should validate their own addresses - gh-7514 // applications should validate their own addresses - gh-7514
return ValidationResult.VALID; return ValidationResult.VALID;
@ -599,7 +599,7 @@ class BaseOpenSamlAuthenticationProvider implements AuthenticationProvider {
static final SAML20AssertionValidator attributeValidator = new SAML20AssertionValidator(conditions, subjects, static final SAML20AssertionValidator attributeValidator = new SAML20AssertionValidator(conditions, subjects,
statements, null, null, null) { statements, null, null, null) {
@Nonnull @NonNull
@Override @Override
protected ValidationResult validateSignature(Assertion token, ValidationContext context) { protected ValidationResult validateSignature(Assertion token, ValidationContext context) {
return ValidationResult.VALID; return ValidationResult.VALID;

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2024 the original author or authors. * Copyright 2002-2025 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -26,8 +26,6 @@ import java.util.Collection;
import java.util.Iterator; import java.util.Iterator;
import java.util.function.Consumer; import java.util.function.Consumer;
import javax.annotation.Nonnull;
import net.shibboleth.utilities.java.support.resolver.CriteriaSet; import net.shibboleth.utilities.java.support.resolver.CriteriaSet;
import org.opensaml.core.criterion.EntityIdCriterion; import org.opensaml.core.criterion.EntityIdCriterion;
import org.opensaml.core.xml.config.XMLObjectProviderRegistrySupport; import org.opensaml.core.xml.config.XMLObjectProviderRegistrySupport;
@ -265,7 +263,7 @@ public final class OpenSaml4AssertingPartyMetadataRepository implements Assertin
return this.resource.getFile(); return this.resource.getFile();
} }
@Nonnull @NonNull
@Override @Override
public InputStream getInputStream() throws IOException { public InputStream getInputStream() throws IOException {
return this.resource.getInputStream(); return this.resource.getInputStream();

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2022 the original author or authors. * Copyright 2002-2025 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -19,7 +19,6 @@ package org.springframework.security.saml2.provider.service.authentication;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import javax.annotation.Nonnull;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import javax.xml.namespace.QName; import javax.xml.namespace.QName;
@ -40,6 +39,7 @@ import org.opensaml.saml.common.xml.SAMLConstants;
import org.opensaml.saml.saml2.core.AttributeValue; import org.opensaml.saml.saml2.core.AttributeValue;
import org.w3c.dom.Element; import org.w3c.dom.Element;
import org.springframework.lang.NonNull;
import org.springframework.security.saml2.core.OpenSamlInitializationService; import org.springframework.security.saml2.core.OpenSamlInitializationService;
public final class TestCustomOpenSaml4Objects { public final class TestCustomOpenSaml4Objects {
@ -103,7 +103,7 @@ public final class TestCustomOpenSaml4Objects {
public static class CustomOpenSamlObjectImpl extends AbstractXMLObject implements CustomOpenSamlObject { public static class CustomOpenSamlObjectImpl extends AbstractXMLObject implements CustomOpenSamlObject {
@Nonnull @NonNull
private IndexedXMLObjectChildrenList<XMLObject> unknownXMLObjects; private IndexedXMLObjectChildrenList<XMLObject> unknownXMLObjects;
/** /**
@ -113,22 +113,22 @@ public final class TestCustomOpenSaml4Objects {
* represents * represents
* @param namespacePrefix the prefix for the given namespace * @param namespacePrefix the prefix for the given namespace
*/ */
protected CustomOpenSamlObjectImpl(@Nullable String namespaceURI, @Nonnull String elementLocalName, protected CustomOpenSamlObjectImpl(@javax.annotation.Nullable String namespaceURI,
@Nullable String namespacePrefix) { @NonNull String elementLocalName, @Nullable String namespacePrefix) {
super(namespaceURI, elementLocalName, namespacePrefix); super(namespaceURI, elementLocalName, namespacePrefix);
super.getNamespaceManager().registerNamespaceDeclaration(new Namespace(CUSTOM_NS, TYPE_CUSTOM_PREFIX)); super.getNamespaceManager().registerNamespaceDeclaration(new Namespace(CUSTOM_NS, TYPE_CUSTOM_PREFIX));
this.unknownXMLObjects = new IndexedXMLObjectChildrenList<>(this); this.unknownXMLObjects = new IndexedXMLObjectChildrenList<>(this);
} }
@Nonnull @NonNull
@Override @Override
public List<XMLObject> getUnknownXMLObjects() { public List<XMLObject> getUnknownXMLObjects() {
return this.unknownXMLObjects; return this.unknownXMLObjects;
} }
@Nonnull @NonNull
@Override @Override
public List<XMLObject> getUnknownXMLObjects(@Nonnull QName typeOrName) { public List<XMLObject> getUnknownXMLObjects(@NonNull QName typeOrName) {
return (List<XMLObject>) this.unknownXMLObjects.subList(typeOrName); return (List<XMLObject>) this.unknownXMLObjects.subList(typeOrName);
} }
@ -162,9 +162,9 @@ public final class TestCustomOpenSaml4Objects {
public static class CustomSamlObjectBuilder extends AbstractXMLObjectBuilder<CustomOpenSamlObject> { public static class CustomSamlObjectBuilder extends AbstractXMLObjectBuilder<CustomOpenSamlObject> {
@Nonnull @NonNull
@Override @Override
public CustomOpenSamlObject buildObject(@Nullable String namespaceURI, @Nonnull String localName, public CustomOpenSamlObject buildObject(@Nullable String namespaceURI, @NonNull String localName,
@Nullable String namespacePrefix) { @Nullable String namespacePrefix) {
return new CustomOpenSamlObjectImpl(namespaceURI, localName, namespacePrefix); return new CustomOpenSamlObjectImpl(namespaceURI, localName, namespacePrefix);
} }
@ -178,7 +178,7 @@ public final class TestCustomOpenSaml4Objects {
} }
@Override @Override
protected void marshallElementContent(@Nonnull XMLObject xmlObject, @Nonnull Element domElement) { protected void marshallElementContent(@NonNull XMLObject xmlObject, @NonNull Element domElement) {
final CustomOpenSamlObject customSamlObject = (CustomOpenSamlObject) xmlObject; final CustomOpenSamlObject customSamlObject = (CustomOpenSamlObject) xmlObject;
for (XMLObject object : customSamlObject.getOrderedChildren()) { for (XMLObject object : customSamlObject.getOrderedChildren()) {
@ -195,15 +195,15 @@ public final class TestCustomOpenSaml4Objects {
} }
@Override @Override
protected void processChildElement(@Nonnull XMLObject parentXMLObject, @Nonnull XMLObject childXMLObject) protected void processChildElement(@NonNull XMLObject parentXMLObject, @NonNull XMLObject childXMLObject)
throws UnmarshallingException { throws UnmarshallingException {
final CustomOpenSamlObject customSamlObject = (CustomOpenSamlObject) parentXMLObject; final CustomOpenSamlObject customSamlObject = (CustomOpenSamlObject) parentXMLObject;
customSamlObject.getUnknownXMLObjects().add(childXMLObject); customSamlObject.getUnknownXMLObjects().add(childXMLObject);
} }
@Nonnull @NonNull
@Override @Override
protected XMLObject buildXMLObject(@Nonnull Element domElement) { protected XMLObject buildXMLObject(@NonNull Element domElement) {
return new CustomOpenSamlObjectImpl(SAMLConstants.SAML20_NS, AttributeValue.DEFAULT_ELEMENT_LOCAL_NAME, return new CustomOpenSamlObjectImpl(SAMLConstants.SAML20_NS, AttributeValue.DEFAULT_ELEMENT_LOCAL_NAME,
CustomOpenSamlObject.TYPE_CUSTOM_PREFIX); CustomOpenSamlObject.TYPE_CUSTOM_PREFIX);
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2024 the original author or authors. * Copyright 2002-2025 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -26,8 +26,6 @@ import java.util.Collection;
import java.util.Iterator; import java.util.Iterator;
import java.util.function.Consumer; import java.util.function.Consumer;
import javax.annotation.Nonnull;
import net.shibboleth.shared.resolver.CriteriaSet; import net.shibboleth.shared.resolver.CriteriaSet;
import org.opensaml.core.criterion.EntityIdCriterion; import org.opensaml.core.criterion.EntityIdCriterion;
import org.opensaml.core.xml.config.XMLObjectProviderRegistrySupport; import org.opensaml.core.xml.config.XMLObjectProviderRegistrySupport;
@ -266,7 +264,7 @@ public final class OpenSaml5AssertingPartyMetadataRepository implements Assertin
return this.resource.getFile(); return this.resource.getFile();
} }
@Nonnull @NonNull
@Override @Override
public InputStream getInputStream() throws IOException { public InputStream getInputStream() throws IOException {
return this.resource.getInputStream(); return this.resource.getInputStream();

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2022 the original author or authors. * Copyright 2002-2025 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -19,7 +19,6 @@ package org.springframework.security.saml2.provider.service.authentication;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import javax.annotation.Nonnull;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import javax.xml.namespace.QName; import javax.xml.namespace.QName;
@ -40,6 +39,7 @@ import org.opensaml.saml.common.xml.SAMLConstants;
import org.opensaml.saml.saml2.core.AttributeValue; import org.opensaml.saml.saml2.core.AttributeValue;
import org.w3c.dom.Element; import org.w3c.dom.Element;
import org.springframework.lang.NonNull;
import org.springframework.security.saml2.core.OpenSamlInitializationService; import org.springframework.security.saml2.core.OpenSamlInitializationService;
public final class TestCustomOpenSaml5Objects { public final class TestCustomOpenSaml5Objects {
@ -103,7 +103,7 @@ public final class TestCustomOpenSaml5Objects {
public static class CustomOpenSamlObjectImpl extends AbstractXMLObject implements CustomOpenSamlObject { public static class CustomOpenSamlObjectImpl extends AbstractXMLObject implements CustomOpenSamlObject {
@Nonnull @NonNull
private IndexedXMLObjectChildrenList<XMLObject> unknownXMLObjects; private IndexedXMLObjectChildrenList<XMLObject> unknownXMLObjects;
/** /**
@ -113,22 +113,22 @@ public final class TestCustomOpenSaml5Objects {
* represents * represents
* @param namespacePrefix the prefix for the given namespace * @param namespacePrefix the prefix for the given namespace
*/ */
protected CustomOpenSamlObjectImpl(@Nullable String namespaceURI, @Nonnull String elementLocalName, protected CustomOpenSamlObjectImpl(@Nullable String namespaceURI, @NonNull String elementLocalName,
@Nullable String namespacePrefix) { @Nullable String namespacePrefix) {
super(namespaceURI, elementLocalName, namespacePrefix); super(namespaceURI, elementLocalName, namespacePrefix);
super.getNamespaceManager().registerNamespaceDeclaration(new Namespace(CUSTOM_NS, TYPE_CUSTOM_PREFIX)); super.getNamespaceManager().registerNamespaceDeclaration(new Namespace(CUSTOM_NS, TYPE_CUSTOM_PREFIX));
this.unknownXMLObjects = new IndexedXMLObjectChildrenList<>(this); this.unknownXMLObjects = new IndexedXMLObjectChildrenList<>(this);
} }
@Nonnull @NonNull
@Override @Override
public List<XMLObject> getUnknownXMLObjects() { public List<XMLObject> getUnknownXMLObjects() {
return this.unknownXMLObjects; return this.unknownXMLObjects;
} }
@Nonnull @NonNull
@Override @Override
public List<XMLObject> getUnknownXMLObjects(@Nonnull QName typeOrName) { public List<XMLObject> getUnknownXMLObjects(@NonNull QName typeOrName) {
return (List<XMLObject>) this.unknownXMLObjects.subList(typeOrName); return (List<XMLObject>) this.unknownXMLObjects.subList(typeOrName);
} }
@ -162,9 +162,9 @@ public final class TestCustomOpenSaml5Objects {
public static class CustomSamlObjectBuilder extends AbstractXMLObjectBuilder<CustomOpenSamlObject> { public static class CustomSamlObjectBuilder extends AbstractXMLObjectBuilder<CustomOpenSamlObject> {
@Nonnull @NonNull
@Override @Override
public CustomOpenSamlObject buildObject(@Nullable String namespaceURI, @Nonnull String localName, public CustomOpenSamlObject buildObject(@Nullable String namespaceURI, @NonNull String localName,
@Nullable String namespacePrefix) { @Nullable String namespacePrefix) {
return new CustomOpenSamlObjectImpl(namespaceURI, localName, namespacePrefix); return new CustomOpenSamlObjectImpl(namespaceURI, localName, namespacePrefix);
} }
@ -178,7 +178,7 @@ public final class TestCustomOpenSaml5Objects {
} }
@Override @Override
protected void marshallElementContent(@Nonnull XMLObject xmlObject, @Nonnull Element domElement) { protected void marshallElementContent(@NonNull XMLObject xmlObject, @NonNull Element domElement) {
final CustomOpenSamlObject customSamlObject = (CustomOpenSamlObject) xmlObject; final CustomOpenSamlObject customSamlObject = (CustomOpenSamlObject) xmlObject;
for (XMLObject object : customSamlObject.getOrderedChildren()) { for (XMLObject object : customSamlObject.getOrderedChildren()) {
@ -195,15 +195,15 @@ public final class TestCustomOpenSaml5Objects {
} }
@Override @Override
protected void processChildElement(@Nonnull XMLObject parentXMLObject, @Nonnull XMLObject childXMLObject) protected void processChildElement(@NonNull XMLObject parentXMLObject, @NonNull XMLObject childXMLObject)
throws UnmarshallingException { throws UnmarshallingException {
final CustomOpenSamlObject customSamlObject = (CustomOpenSamlObject) parentXMLObject; final CustomOpenSamlObject customSamlObject = (CustomOpenSamlObject) parentXMLObject;
customSamlObject.getUnknownXMLObjects().add(childXMLObject); customSamlObject.getUnknownXMLObjects().add(childXMLObject);
} }
@Nonnull @NonNull
@Override @Override
protected XMLObject buildXMLObject(@Nonnull Element domElement) { protected XMLObject buildXMLObject(@NonNull Element domElement) {
return new CustomOpenSamlObjectImpl(SAMLConstants.SAML20_NS, AttributeValue.DEFAULT_ELEMENT_LOCAL_NAME, return new CustomOpenSamlObjectImpl(SAMLConstants.SAML20_NS, AttributeValue.DEFAULT_ELEMENT_LOCAL_NAME,
CustomOpenSamlObject.TYPE_CUSTOM_PREFIX); CustomOpenSamlObject.TYPE_CUSTOM_PREFIX);
} }