[java-opensaml] 02/02: OSJ-334: Mitigation for bad logger implementation
Brent Putman
putmanb at georgetown.edu
Sat Feb 12 02:14:33 UTC 2022
This is an automated email from the git hooks/post-receive script.
putmanb pushed a commit to branch main
in repository java-opensaml.
View the commit online:
http://git.shibboleth.net/view/?p=java-opensaml.git;a=commit;h=23d7cb7f1949f3e04a9745d2a9721baf3519c6d0
commit 23d7cb7f1949f3e04a9745d2a9721baf3519c6d0
Author: Brent Putman <putmanb at georgetown.edu>
AuthorDate: Fri Feb 11 21:06:35 2022 -0500
OSJ-334: Mitigation for bad logger implementation
---
.../opensaml/core/config/ConfigurationService.java | 26 ++++------
.../core/config/InitializationService.java | 20 +++-----
.../opensaml/core/xml/util/XMLObjectSupport.java | 55 +++++++++-------------
.../opensaml/saml/common/SAMLObjectSupport.java | 17 ++-----
.../metadata/support/SAML2MetadataSupport.java | 24 ++++------
.../saml/saml1/profile/SAML1ActionSupport.java | 20 +++-----
.../saml/saml1/profile/SAML1ObjectSupport.java | 12 ++---
.../saml/saml2/profile/SAML2ActionSupport.java | 24 ++++------
.../org/opensaml/security/crypto/KeySupport.java | 25 ++++------
.../org/opensaml/security/crypto/SigningUtil.java | 43 +++++++----------
.../org/opensaml/security/x509/X509Support.java | 29 ++++--------
.../impl/EvaluableCredentialCriteriaRegistry.java | 42 ++++++-----------
.../xmlsec/algorithm/AlgorithmSupport.java | 17 ++-----
.../opensaml/xmlsec/keyinfo/KeyInfoSupport.java | 43 +++++++----------
.../xmlsec/signature/support/SignatureSupport.java | 24 +++-------
.../signature/support/SignatureValidator.java | 14 ++----
.../opensaml/xmlsec/signature/support/Signer.java | 16 ++-----
17 files changed, 156 insertions(+), 295 deletions(-)
diff --git a/opensaml-core/src/main/java/org/opensaml/core/config/ConfigurationService.java b/opensaml-core/src/main/java/org/opensaml/core/config/ConfigurationService.java
index 992f54ff6..c9db4a33d 100644
--- a/opensaml-core/src/main/java/org/opensaml/core/config/ConfigurationService.java
+++ b/opensaml-core/src/main/java/org/opensaml/core/config/ConfigurationService.java
@@ -64,6 +64,9 @@ public class ConfigurationService {
/** The configuration property name for the storage partition name to use. */
@Nonnull public static final String PROPERTY_PARTITION_NAME = "opensaml.config.partitionName";
+ /** Logger. */
+ @Nonnull private static final Logger LOG = LoggerFactory.getLogger(ConfigurationService.class);
+
/** The service loader used to locate registered implementations of ConfigurationPropertiesSource. */
private static ServiceLoader<ConfigurationPropertiesSource> configPropertiesLoader =
ServiceLoader.load(ConfigurationPropertiesSource.class) ;
@@ -137,26 +140,25 @@ public class ConfigurationService {
*/
@Nullable public static Properties getConfigurationProperties() {
//TODO make these immutable?
- final Logger log = getLogger();
- log.trace("Resolving configuration propreties source");
+ LOG.trace("Resolving configuration propreties source");
final Iterator<ConfigurationPropertiesSource> iter = configPropertiesLoader.iterator();
if (!iter.hasNext()) {
- log.trace("No ConfigurationPropertiesSources are configured, defaulting to system properties");
+ LOG.trace("No ConfigurationPropertiesSources are configured, defaulting to system properties");
return new SystemPropertyConfigurationPropertiesSource().getProperties();
}
while (iter.hasNext()) {
final ConfigurationPropertiesSource source = iter.next();
- log.trace("Evaluating configuration properties implementation: {}", source.getClass().getName());
+ LOG.trace("Evaluating configuration properties implementation: {}", source.getClass().getName());
final Properties props = source.getProperties();
if (props != null) {
- log.trace("Resolved non-null configuration properties using implementation: {}",
+ LOG.trace("Resolved non-null configuration properties using implementation: {}",
source.getClass().getName());
return props;
}
}
- log.trace("Unable to resolve non-null configuration properties from any ConfigurationPropertiesSource");
+ LOG.trace("Unable to resolve non-null configuration properties from any ConfigurationPropertiesSource");
return null;
}
@@ -187,7 +189,6 @@ public class ConfigurationService {
* @return the partition name
*/
@Nonnull @NotEmpty protected static String getPartitionName() {
- final Logger log = getLogger();
final Properties configProperties = getConfigurationProperties();
String partitionName = null;
if (configProperties != null) {
@@ -195,7 +196,7 @@ public class ConfigurationService {
} else {
partitionName = DEFAULT_PARTITION_NAME;
}
- log.trace("Resolved effective configuration partition name '{}'", partitionName);
+ LOG.trace("Resolved effective configuration partition name '{}'", partitionName);
return partitionName;
}
@@ -226,13 +227,4 @@ public class ConfigurationService {
return configuration;
}
- /**
- * Get a logger.
- *
- * @return an SLF4J logger instance
- */
- @Nonnull private static Logger getLogger() {
- return LoggerFactory.getLogger(ConfigurationService.class);
- }
-
}
\ No newline at end of file
diff --git a/opensaml-core/src/main/java/org/opensaml/core/config/InitializationService.java b/opensaml-core/src/main/java/org/opensaml/core/config/InitializationService.java
index a203e05ae..f623774fe 100644
--- a/opensaml-core/src/main/java/org/opensaml/core/config/InitializationService.java
+++ b/opensaml-core/src/main/java/org/opensaml/core/config/InitializationService.java
@@ -34,6 +34,9 @@ import org.slf4j.LoggerFactory;
*/
public class InitializationService {
+ /** Logger. */
+ @Nonnull private static final Logger LOG = LoggerFactory.getLogger(InitializationService.class);
+
/** Constructor.*/
protected InitializationService() { }
@@ -43,19 +46,17 @@ public class InitializationService {
* @throws InitializationException if initialization did not complete successfully
*/
public static synchronized void initialize() throws InitializationException {
- final Logger log = getLogger();
-
- log.info("Initializing OpenSAML using the Java Services API");
+ LOG.info("Initializing OpenSAML using the Java Services API");
final ServiceLoader<Initializer> serviceLoader = getServiceLoader();
final Iterator<Initializer> iter = serviceLoader.iterator();
while (iter.hasNext()) {
final Initializer initializer = iter.next();
- log.debug("Initializing module initializer implementation: {}", initializer.getClass().getName());
+ LOG.debug("Initializing module initializer implementation: {}", initializer.getClass().getName());
try {
initializer.init();
} catch (final InitializationException e) {
- log.error("Error initializing module: {}", e.getMessage());
+ LOG.error("Error initializing module: {}", e.getMessage());
throw e;
}
}
@@ -74,13 +75,4 @@ public class InitializationService {
return ServiceLoader.load(Initializer.class);
}
- /**
- * Get a logger.
- *
- * @return an SLF4J logger instance
- */
- @Nonnull private static Logger getLogger() {
- return LoggerFactory.getLogger(InitializationService.class);
- }
-
}
\ No newline at end of file
diff --git a/opensaml-core/src/main/java/org/opensaml/core/xml/util/XMLObjectSupport.java b/opensaml-core/src/main/java/org/opensaml/core/xml/util/XMLObjectSupport.java
index e8e69bcb7..a0c11ed42 100644
--- a/opensaml-core/src/main/java/org/opensaml/core/xml/util/XMLObjectSupport.java
+++ b/opensaml-core/src/main/java/org/opensaml/core/xml/util/XMLObjectSupport.java
@@ -58,6 +58,9 @@ import org.w3c.dom.Element;
*/
public final class XMLObjectSupport {
+ /** Logger. */
+ @Nonnull private static final Logger LOG = LoggerFactory.getLogger(XMLObjectSupport.class);
+
/** Options for handling output of XMLObject cloning. */
public enum CloneOutputOption {
@@ -189,22 +192,21 @@ public final class XMLObjectSupport {
*/
public static XMLObject unmarshallFromInputStream(final ParserPool parserPool, final InputStream inputStream)
throws XMLParserException, UnmarshallingException {
- final Logger log = getLogger();
- log.debug("Parsing InputStream into DOM document");
+ LOG.debug("Parsing InputStream into DOM document");
try {
final Document messageDoc = parserPool.parse(inputStream);
final Element messageElem = messageDoc.getDocumentElement();
- if (log.isTraceEnabled()) {
- log.trace("Resultant DOM message was:");
- log.trace(SerializeSupport.nodeToString(messageElem));
+ if (LOG.isTraceEnabled()) {
+ LOG.trace("Resultant DOM message was:");
+ LOG.trace(SerializeSupport.nodeToString(messageElem));
}
- log.debug("Unmarshalling DOM parsed from InputStream");
+ LOG.debug("Unmarshalling DOM parsed from InputStream");
final Unmarshaller unmarshaller = getUnmarshaller(messageElem);
if (unmarshaller == null) {
- log.error("Unable to unmarshall InputStream, no unmarshaller registered for element "
+ LOG.error("Unable to unmarshall InputStream, no unmarshaller registered for element "
+ QNameSupport.getNodeQName(messageElem));
throw new UnmarshallingException(
"Unable to unmarshall InputStream, no unmarshaller registered for element "
@@ -213,7 +215,7 @@ public final class XMLObjectSupport {
final XMLObject message = unmarshaller.unmarshall(messageElem);
- log.debug("InputStream succesfully unmarshalled");
+ LOG.debug("InputStream succesfully unmarshalled");
return message;
} catch (final RuntimeException e) {
throw new UnmarshallingException("Fatal error unmarshalling XMLObject", e);
@@ -231,23 +233,22 @@ public final class XMLObjectSupport {
*/
public static XMLObject unmarshallFromReader(final ParserPool parserPool, final Reader reader)
throws XMLParserException, UnmarshallingException {
- final Logger log = getLogger();
- log.debug("Parsing Reader into DOM document");
+ LOG.debug("Parsing Reader into DOM document");
try {
final Document messageDoc = parserPool.parse(reader);
final Element messageElem = messageDoc.getDocumentElement();
- if (log.isTraceEnabled()) {
- log.trace("Resultant DOM message was:");
- log.trace(SerializeSupport.nodeToString(messageElem));
+ if (LOG.isTraceEnabled()) {
+ LOG.trace("Resultant DOM message was:");
+ LOG.trace(SerializeSupport.nodeToString(messageElem));
}
- log.debug("Unmarshalling DOM parsed from Reader");
+ LOG.debug("Unmarshalling DOM parsed from Reader");
final Unmarshaller unmarshaller = getUnmarshaller(messageElem);
if (unmarshaller == null) {
- log.error("Unable to unmarshall Reader, no unmarshaller registered for element "
+ LOG.error("Unable to unmarshall Reader, no unmarshaller registered for element "
+ QNameSupport.getNodeQName(messageElem));
throw new UnmarshallingException(
"Unable to unmarshall Reader, no unmarshaller registered for element "
@@ -256,7 +257,7 @@ public final class XMLObjectSupport {
final XMLObject message = unmarshaller.unmarshall(messageElem);
- log.debug("Reader succesfully unmarshalled");
+ LOG.debug("Reader succesfully unmarshalled");
return message;
} catch (final RuntimeException e) {
throw new UnmarshallingException("Fatal error unmarshalling XMLObject", e);
@@ -272,17 +273,16 @@ public final class XMLObjectSupport {
* @throws MarshallingException if there is a problem marshalling the XMLObject
*/
@Nonnull public static Element marshall(@Nonnull final XMLObject xmlObject) throws MarshallingException {
- final Logger log = getLogger();
- log.debug("Marshalling XMLObject");
+ LOG.debug("Marshalling XMLObject");
if (xmlObject.getDOM() != null) {
- log.debug("XMLObject already had cached DOM, returning that element");
+ LOG.debug("XMLObject already had cached DOM, returning that element");
return xmlObject.getDOM();
}
final Marshaller marshaller = getMarshaller(xmlObject);
if (marshaller == null) {
- log.error("Unable to marshall XMLObject, no marshaller registered for object: "
+ LOG.error("Unable to marshall XMLObject, no marshaller registered for object: "
+ xmlObject.getElementQName());
throw new MarshallingException("Unable to marshall XMLObject, no marshaller registered for object: "
+ xmlObject.getElementQName());
@@ -290,9 +290,9 @@ public final class XMLObjectSupport {
final Element messageElem = marshaller.marshall(xmlObject);
- if (log.isTraceEnabled()) {
- log.trace("Marshalled XMLObject into DOM:");
- log.trace(SerializeSupport.nodeToString(messageElem));
+ if (LOG.isTraceEnabled()) {
+ LOG.trace("Marshalled XMLObject into DOM:");
+ LOG.trace(SerializeSupport.nodeToString(messageElem));
}
return messageElem;
@@ -357,15 +357,6 @@ public final class XMLObjectSupport {
return null;
}
- /**
- * Get an SLF4J Logger.
- *
- * @return a Logger instance
- */
- private static Logger getLogger() {
- return LoggerFactory.getLogger(XMLObjectSupport.class);
- }
-
/**
* Marshall an attribute name and value to a DOM Element. This is particularly useful for attributes whose names
* appear in namespace-qualified form.
diff --git a/opensaml-saml-api/src/main/java/org/opensaml/saml/common/SAMLObjectSupport.java b/opensaml-saml-api/src/main/java/org/opensaml/saml/common/SAMLObjectSupport.java
index ec26dcf76..051509f94 100644
--- a/opensaml-saml-api/src/main/java/org/opensaml/saml/common/SAMLObjectSupport.java
+++ b/opensaml-saml-api/src/main/java/org/opensaml/saml/common/SAMLObjectSupport.java
@@ -32,6 +32,9 @@ import org.slf4j.LoggerFactory;
*/
public final class SAMLObjectSupport {
+ /** Logger. */
+ @Nonnull private static final Logger LOG = LoggerFactory.getLogger(SAMLObjectSupport.class);
+
/** Constructor. */
private SAMLObjectSupport() { }
@@ -51,9 +54,8 @@ public final class SAMLObjectSupport {
* @param signableObject the signable SAML object to evaluate
*/
public static void declareNonVisibleNamespaces(@Nonnull final SignableSAMLObject signableObject) {
- final Logger log = getLogger();
if (signableObject.getDOM() == null && signableObject.getSignature() != null) {
- log.debug("Examining signed object for content references with exclusive canonicalization transform");
+ LOG.debug("Examining signed object for content references with exclusive canonicalization transform");
boolean sawExclusive = false;
for (final ContentReference cr : signableObject.getSignature().getContentReferences()) {
if (cr instanceof SAMLObjectContentReference) {
@@ -67,21 +69,12 @@ public final class SAMLObjectSupport {
}
if (sawExclusive) {
- log.debug("Saw exclusive transform, declaring non-visible namespaces on signed object");
+ LOG.debug("Saw exclusive transform, declaring non-visible namespaces on signed object");
for (final Namespace ns : signableObject.getNamespaceManager().getNonVisibleNamespaces()) {
signableObject.getNamespaceManager().registerNamespaceDeclaration(ns);
}
}
}
}
-
- /**
- * Get an SLF4J Logger.
- *
- * @return a Logger instance
- */
- @Nonnull private static Logger getLogger() {
- return LoggerFactory.getLogger(SAMLObjectSupport.class);
- }
}
\ No newline at end of file
diff --git a/opensaml-saml-api/src/main/java/org/opensaml/saml/metadata/support/SAML2MetadataSupport.java b/opensaml-saml-api/src/main/java/org/opensaml/saml/metadata/support/SAML2MetadataSupport.java
index add63f3f6..f5a994e7a 100644
--- a/opensaml-saml-api/src/main/java/org/opensaml/saml/metadata/support/SAML2MetadataSupport.java
+++ b/opensaml-saml-api/src/main/java/org/opensaml/saml/metadata/support/SAML2MetadataSupport.java
@@ -19,6 +19,8 @@ package org.opensaml.saml.metadata.support;
import java.util.List;
+import javax.annotation.Nonnull;
+
import org.opensaml.saml.saml2.metadata.IndexedEndpoint;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -28,6 +30,9 @@ import org.slf4j.LoggerFactory;
*/
public final class SAML2MetadataSupport {
+ /** Logger. */
+ @Nonnull private static final Logger LOG = LoggerFactory.getLogger(SAML2MetadataSupport.class);
+
/** Constructor. */
private SAML2MetadataSupport() { }
@@ -50,18 +55,17 @@ public final class SAML2MetadataSupport {
*
*/
public static <T extends IndexedEndpoint> T getDefaultIndexedEndpoint(final List<T> candidates) {
- final Logger log = getLogger();
- log.debug("Selecting default IndexedEndpoint");
+ LOG.debug("Selecting default IndexedEndpoint");
if (candidates == null || candidates.isEmpty()) {
- log.debug("IndexedEndpoint list was null or empty, returning null");
+ LOG.debug("IndexedEndpoint list was null or empty, returning null");
return null;
}
T firstNoDefault = null;
for (final T endpoint : candidates) {
if (endpoint.isDefault()) {
- log.debug("Selected IndexedEndpoint with explicit isDefault of true");
+ LOG.debug("Selected IndexedEndpoint with explicit isDefault of true");
return endpoint;
}
@@ -72,20 +76,12 @@ public final class SAML2MetadataSupport {
}
if (firstNoDefault != null) {
- log.debug("Selected first IndexedEndpoint with no explicit isDefault");
+ LOG.debug("Selected first IndexedEndpoint with no explicit isDefault");
return firstNoDefault;
}
- log.debug("Selected first IndexedEndpoint with explicit isDefault of false");
+ LOG.debug("Selected first IndexedEndpoint with explicit isDefault of false");
return candidates.get(0);
}
- /**
- * Get an SLF4J Logger.
- *
- * @return a Logger instance
- */
- private static Logger getLogger() {
- return LoggerFactory.getLogger(SAML2MetadataSupport.class);
- }
}
\ No newline at end of file
diff --git a/opensaml-saml-api/src/main/java/org/opensaml/saml/saml1/profile/SAML1ActionSupport.java b/opensaml-saml-api/src/main/java/org/opensaml/saml/saml1/profile/SAML1ActionSupport.java
index 69879c8b3..c0fe4abf8 100644
--- a/opensaml-saml-api/src/main/java/org/opensaml/saml/saml1/profile/SAML1ActionSupport.java
+++ b/opensaml-saml-api/src/main/java/org/opensaml/saml/saml1/profile/SAML1ActionSupport.java
@@ -36,6 +36,9 @@ import org.slf4j.LoggerFactory;
/** Helper methods for SAML 1 profile actions. */
public final class SAML1ActionSupport {
+
+ /** Logger. */
+ @Nonnull private static final Logger LOG = LoggerFactory.getLogger(SAML1ActionSupport.class);
/** Constructor. */
private SAML1ActionSupport() {
@@ -65,7 +68,7 @@ public final class SAML1ActionSupport {
assertion.setIssuer(issuer);
assertion.setVersion(SAMLVersion.VERSION_11);
- getLogger().debug("Profile Action {}: Created Assertion {}", action.getClass().getSimpleName(),
+ LOG.debug("Profile Action {}: Created Assertion {}", action.getClass().getSimpleName(),
assertion.getID());
return assertion;
@@ -89,7 +92,7 @@ public final class SAML1ActionSupport {
final Assertion assertion = buildAssertion(action, idGenerator, issuer);
assertion.setIssueInstant(response.getIssueInstant());
- getLogger().debug("Profile Action {}: Added Assertion {} to Response {}",
+ LOG.debug("Profile Action {}: Added Assertion {} to Response {}",
new Object[] {action.getClass().getSimpleName(), assertion.getID(), response.getID(),});
response.getAssertions().add(assertion);
@@ -114,23 +117,14 @@ public final class SAML1ActionSupport {
Conditions.DEFAULT_ELEMENT_NAME);
conditions = conditionsBuilder.buildObject();
assertion.setConditions(conditions);
- getLogger().debug("Profile Action {}: Assertion {} did not already contain Conditions, added",
+ LOG.debug("Profile Action {}: Assertion {} did not already contain Conditions, added",
action.getClass().getSimpleName(), assertion.getID());
} else {
- getLogger().debug("Profile Action {}: Assertion {} already contains Conditions, nothing was done",
+ LOG.debug("Profile Action {}: Assertion {} already contains Conditions, nothing was done",
action.getClass().getSimpleName(), assertion.getID());
}
return conditions;
}
-
- /**
- * Gets the logger for this class.
- *
- * @return logger for this class, never null
- */
- @Nonnull private static Logger getLogger() {
- return LoggerFactory.getLogger(SAML1ActionSupport.class);
- }
}
\ No newline at end of file
diff --git a/opensaml-saml-api/src/main/java/org/opensaml/saml/saml1/profile/SAML1ObjectSupport.java b/opensaml-saml-api/src/main/java/org/opensaml/saml/saml1/profile/SAML1ObjectSupport.java
index 16bc4698e..340f7882c 100644
--- a/opensaml-saml-api/src/main/java/org/opensaml/saml/saml1/profile/SAML1ObjectSupport.java
+++ b/opensaml-saml-api/src/main/java/org/opensaml/saml/saml1/profile/SAML1ObjectSupport.java
@@ -31,6 +31,9 @@ import org.slf4j.LoggerFactory;
*/
public final class SAML1ObjectSupport {
+ /** Logger. */
+ @Nonnull private static final Logger LOG = LoggerFactory.getLogger(SAML1ObjectSupport.class);
+
/** Constructor. */
private SAML1ObjectSupport() {
@@ -66,13 +69,4 @@ public final class SAML1ObjectSupport {
&& Objects.equals(name1.getNameQualifier(), name2.getNameQualifier());
}
- /**
- * Get an SLF4J Logger.
- *
- * @return a Logger instance
- */
- @Nonnull private static Logger getLogger() {
- return LoggerFactory.getLogger(SAML1ObjectSupport.class);
- }
-
}
\ No newline at end of file
diff --git a/opensaml-saml-api/src/main/java/org/opensaml/saml/saml2/profile/SAML2ActionSupport.java b/opensaml-saml-api/src/main/java/org/opensaml/saml/saml2/profile/SAML2ActionSupport.java
index 58ebd29ec..907cb5894 100644
--- a/opensaml-saml-api/src/main/java/org/opensaml/saml/saml2/profile/SAML2ActionSupport.java
+++ b/opensaml-saml-api/src/main/java/org/opensaml/saml/saml2/profile/SAML2ActionSupport.java
@@ -38,6 +38,9 @@ import org.slf4j.LoggerFactory;
/** Helper methods for SAML 2 IdP actions. */
public final class SAML2ActionSupport {
+
+ /** Logger. */
+ @Nonnull private static final Logger LOG = LoggerFactory.getLogger(SAML2ActionSupport.class);
/** Constructor. */
private SAML2ActionSupport() {
@@ -75,7 +78,7 @@ public final class SAML2ActionSupport {
assertion.setIssuer(issuerObject);
}
- getLogger().debug("Profile Action {}: Created Assertion {}", action.getClass().getSimpleName(),
+ LOG.debug("Profile Action {}: Created Assertion {}", action.getClass().getSimpleName(),
assertion.getID());
return assertion;
@@ -99,7 +102,7 @@ public final class SAML2ActionSupport {
final Assertion assertion = buildAssertion(action, idGenerator, issuer);
assertion.setIssueInstant(response.getIssueInstant());
- getLogger().debug("Profile Action {}: Added Assertion {} to Response {}",
+ LOG.debug("Profile Action {}: Added Assertion {} to Response {}",
new Object[] {action.getClass().getSimpleName(), assertion.getID(), response.getID(),});
response.getAssertions().add(assertion);
@@ -124,10 +127,10 @@ public final class SAML2ActionSupport {
Conditions.DEFAULT_ELEMENT_NAME);
conditions = conditionsBuilder.buildObject();
assertion.setConditions(conditions);
- getLogger().debug("Profile Action {}: Assertion {} did not already contain Conditions, one was added",
+ LOG.debug("Profile Action {}: Assertion {} did not already contain Conditions, one was added",
action.getClass().getSimpleName(), assertion.getID());
} else {
- getLogger().debug("Profile Action {}: Assertion {} already contained Conditions, nothing was done",
+ LOG.debug("Profile Action {}: Assertion {} already contained Conditions, nothing was done",
action.getClass().getSimpleName(), assertion.getID());
}
@@ -152,23 +155,14 @@ public final class SAML2ActionSupport {
Advice.DEFAULT_ELEMENT_NAME);
advice = adviceBuilder.buildObject();
assertion.setAdvice(advice);
- getLogger().debug("Profile Action {}: Assertion {} did not already contain Advice, one was added",
+ LOG.debug("Profile Action {}: Assertion {} did not already contain Advice, one was added",
action.getClass().getSimpleName(), assertion.getID());
} else {
- getLogger().debug("Profile Action {}: Assertion {} already contained Advice, nothing was done",
+ LOG.debug("Profile Action {}: Assertion {} already contained Advice, nothing was done",
action.getClass().getSimpleName(), assertion.getID());
}
return advice;
}
-
- /**
- * Gets the logger for this class.
- *
- * @return logger for this class, never null
- */
- @Nonnull private static Logger getLogger() {
- return LoggerFactory.getLogger(SAML2ActionSupport.class);
- }
}
\ No newline at end of file
diff --git a/opensaml-security-api/src/main/java/org/opensaml/security/crypto/KeySupport.java b/opensaml-security-api/src/main/java/org/opensaml/security/crypto/KeySupport.java
index 8b50f5b9a..6b70e5321 100644
--- a/opensaml-security-api/src/main/java/org/opensaml/security/crypto/KeySupport.java
+++ b/opensaml-security-api/src/main/java/org/opensaml/security/crypto/KeySupport.java
@@ -79,6 +79,9 @@ import com.google.common.io.Files;
* Helper methods for cryptographic keys and key pairs.
*/
public final class KeySupport {
+
+ /** Logger. */
+ @Nonnull private static final Logger LOG = LoggerFactory.getLogger(KeySupport.class);
/** Maps key algorithms to the signing algorithm used in the key matching function. */
private static Map<String, String> keyMatchAlgorithms;
@@ -94,8 +97,7 @@ public final class KeySupport {
* @return length of the key in bits, or null if the length cannot be determined
*/
@Nullable public static Integer getKeyLength(@Nonnull final Key key) {
- final Logger log = getLogger();
- log.debug("Attempting to determine length of Key with algorithm '{}' and encoding format '{}'",
+ LOG.debug("Attempting to determine length of Key with algorithm '{}' and encoding format '{}'",
key.getAlgorithm(), key.getFormat());
// TODO investigate if exists, and can/how to support, non-RAW format symmetric keys
if (key instanceof SecretKey && JCAConstants.KEY_FORMAT_RAW.equals(key.getFormat())) {
@@ -107,7 +109,7 @@ public final class KeySupport {
} else if (key instanceof ECKey) {
return ((ECKey) key).getParams().getCurve().getField().getFieldSize();
}
- log.debug("Unable to determine length in bits of specified Key instance");
+ LOG.debug("Unable to determine length in bits of specified Key instance");
return null;
}
@@ -123,7 +125,6 @@ public final class KeySupport {
*/
@Nonnull public static SecretKey decodeSecretKey(@Nonnull final byte[] key, @Nonnull final String algorithm)
throws KeyException {
- final Logger log = getLogger();
Constraint.isNotNull(key, "Secret key bytes can not be null");
Constraint.isNotNull(algorithm, "Secret key algorithm can not be null");
Constraint.isGreaterThanOrEqual(1, key.length, "Secret key bytes can not be empty");
@@ -150,7 +151,7 @@ public final class KeySupport {
}
break;
default:
- log.debug("No length and sanity checking done for key with algorithm: {}", algorithm);
+ LOG.debug("No length and sanity checking done for key with algorithm: {}", algorithm);
}
return new SecretKeySpec(key, algorithm);
@@ -601,9 +602,8 @@ public final class KeySupport {
+ privKey.getAlgorithm());
}
- final Logger log = getLogger();
- if (log.isDebugEnabled()) {
- log.debug("Attempting to match key pair containing key algorithms public '{}' private '{}', "
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("Attempting to match key pair containing key algorithms public '{}' private '{}', "
+ "using JCA signature algorithm '{}'", new Object[] {pubKey.getAlgorithm(),
privKey.getAlgorithm(), jcaAlgoID,});
}
@@ -613,15 +613,6 @@ public final class KeySupport {
return SigningUtil.verify(pubKey, jcaAlgoID, signature, data);
}
- /**
- * Get an SLF4J Logger.
- *
- * @return a Logger instance
- */
- @Nonnull private static Logger getLogger() {
- return LoggerFactory.getLogger(KeySupport.class);
- }
-
static {
keyMatchAlgorithms = new LazyMap<>();
keyMatchAlgorithms.put(JCAConstants.KEY_ALGO_RSA, JCAConstants.SIGNATURE_RSA_SHA1);
diff --git a/opensaml-security-api/src/main/java/org/opensaml/security/crypto/SigningUtil.java b/opensaml-security-api/src/main/java/org/opensaml/security/crypto/SigningUtil.java
index aacf6c786..ac65e6fe4 100644
--- a/opensaml-security-api/src/main/java/org/opensaml/security/crypto/SigningUtil.java
+++ b/opensaml-security-api/src/main/java/org/opensaml/security/crypto/SigningUtil.java
@@ -40,6 +40,9 @@ import org.slf4j.LoggerFactory;
* A utility class for computing and verifying raw signatures and MAC values.
*/
public final class SigningUtil {
+
+ /** Logger. */
+ @Nonnull private static final Logger LOG = LoggerFactory.getLogger(SigningUtil.class);
/** Constructor. */
private SigningUtil() {
@@ -62,11 +65,10 @@ public final class SigningUtil {
@Nonnull public static byte[] sign(@Nonnull final Credential signingCredential,
@Nonnull final String jcaAlgorithmID, final boolean isMAC, @Nonnull final byte[] input)
throws SecurityException {
- final Logger log = getLogger();
final Key signingKey = CredentialSupport.extractSigningKey(signingCredential);
if (signingKey == null) {
- log.error("No signing key supplied in signing credential for signature computation");
+ LOG.error("No signing key supplied in signing credential for signature computation");
throw new SecurityException("No signing key supplied in signing credential");
}
@@ -75,7 +77,7 @@ public final class SigningUtil {
} else if (signingKey instanceof PrivateKey) {
return sign((PrivateKey) signingKey, jcaAlgorithmID, input);
} else {
- log.error("No PrivateKey present in signing credential for signature computation");
+ LOG.error("No PrivateKey present in signing credential for signature computation");
throw new SecurityException("No PrivateKey supplied for signing");
}
}
@@ -98,8 +100,7 @@ public final class SigningUtil {
Constraint.isNotNull(jcaAlgorithmID, "JCA algorithm ID cannot be null");
Constraint.isNotNull(input, "Input data to sign cannot be null");
- final Logger log = getLogger();
- log.debug("Computing signature over input using private key of type {} and JCA algorithm ID {}", signingKey
+ LOG.debug("Computing signature over input using private key of type {} and JCA algorithm ID {}", signingKey
.getAlgorithm(), jcaAlgorithmID);
try {
@@ -107,10 +108,10 @@ public final class SigningUtil {
signature.initSign(signingKey);
signature.update(input);
final byte[] rawSignature = signature.sign();
- log.debug("Computed signature: {}", Hex.encodeHex(rawSignature));
+ LOG.debug("Computed signature: {}", Hex.encodeHex(rawSignature));
return rawSignature;
} catch (final GeneralSecurityException e) {
- log.error("Error during signature generation: {}", e.getMessage());
+ LOG.error("Error during signature generation: {}", e.getMessage());
throw new SecurityException("Error during signature generation", e);
}
}
@@ -133,8 +134,7 @@ public final class SigningUtil {
Constraint.isNotNull(jcaAlgorithmID, "JCA algorithm ID cannot be null");
Constraint.isNotNull(input, "Input data to sign cannot be null");
- final Logger log = getLogger();
- log.debug("Computing MAC over input using key of type {} and JCA algorithm ID {}", signingKey.getAlgorithm(),
+ LOG.debug("Computing MAC over input using key of type {} and JCA algorithm ID {}", signingKey.getAlgorithm(),
jcaAlgorithmID);
try {
@@ -142,10 +142,10 @@ public final class SigningUtil {
mac.init(signingKey);
mac.update(input);
final byte[] rawMAC = mac.doFinal();
- log.debug("Computed MAC: {}", Hex.encodeHexString(rawMAC));
+ LOG.debug("Computed MAC: {}", Hex.encodeHexString(rawMAC));
return rawMAC;
} catch (final GeneralSecurityException e) {
- log.error("Error during MAC generation: {}", e.getMessage());
+ LOG.error("Error during MAC generation: {}", e.getMessage());
throw new SecurityException("Error during MAC generation", e);
}
}
@@ -168,11 +168,10 @@ public final class SigningUtil {
public static boolean verify(@Nonnull final Credential verificationCredential,
@Nonnull final String jcaAlgorithmID, final boolean isMAC, @Nonnull final byte[] signature,
@Nonnull final byte[] input) throws SecurityException {
- final Logger log = getLogger();
final Key verificationKey = CredentialSupport.extractVerificationKey(verificationCredential);
if (verificationKey == null) {
- log.error("No verification key supplied in verification credential for signature verification");
+ LOG.error("No verification key supplied in verification credential for signature verification");
throw new SecurityException("No verification key supplied in verification credential");
}
@@ -181,7 +180,7 @@ public final class SigningUtil {
} else if (verificationKey instanceof PublicKey) {
return verify((PublicKey) verificationKey, jcaAlgorithmID, signature, input);
} else {
- log.error("No PublicKey present in verification credential for signature verification");
+ LOG.error("No PublicKey present in verification credential for signature verification");
throw new SecurityException("No PublicKey supplied for signature verification");
}
}
@@ -207,8 +206,7 @@ public final class SigningUtil {
Constraint.isNotNull(signature, "Signature data to verify cannot be null");
Constraint.isNotNull(input, "Input data to verify cannot be null");
- final Logger log = getLogger();
- log.debug("Verifying signature over input using public key of type {} and JCA algorithm ID {}", verificationKey
+ LOG.debug("Verifying signature over input using public key of type {} and JCA algorithm ID {}", verificationKey
.getAlgorithm(), jcaAlgorithmID);
try {
@@ -217,7 +215,7 @@ public final class SigningUtil {
sig.update(input);
return sig.verify(signature);
} catch (final GeneralSecurityException e) {
- log.error("Error during signature verification: {}", e.getMessage());
+ LOG.error("Error during signature verification: {}", e.getMessage());
throw new SecurityException("Error during signature verification", e);
}
}
@@ -244,8 +242,7 @@ public final class SigningUtil {
Constraint.isNotNull(signature, "Signature data to verify cannot be null");
Constraint.isNotNull(input, "Input data to verify cannot be null");
- final Logger log = getLogger();
- log.debug("Verifying MAC over input using key of type {} and JCA algorithm ID {}", verificationKey
+ LOG.debug("Verifying MAC over input using key of type {} and JCA algorithm ID {}", verificationKey
.getAlgorithm(), jcaAlgorithmID);
// Java JCA/JCE Mac interface doesn't have a verification op,
@@ -255,12 +252,4 @@ public final class SigningUtil {
return Arrays.equals(computed, signature);
}
- /**
- * Get an SLF4J Logger.
- *
- * @return a Logger instance
- */
- @Nonnull private static Logger getLogger() {
- return LoggerFactory.getLogger(SigningUtil.class);
- }
}
\ No newline at end of file
diff --git a/opensaml-security-api/src/main/java/org/opensaml/security/x509/X509Support.java b/opensaml-security-api/src/main/java/org/opensaml/security/x509/X509Support.java
index 4512f5e56..9ee953194 100644
--- a/opensaml-security-api/src/main/java/org/opensaml/security/x509/X509Support.java
+++ b/opensaml-security-api/src/main/java/org/opensaml/security/x509/X509Support.java
@@ -108,6 +108,9 @@ public class X509Support {
/** RFC 2459 Registered ID Subject Alt Name type. */
public static final Integer REGISTERED_ID_ALT_NAME = 8;
+
+ /** Logger. */
+ @Nonnull private static final Logger LOG = LoggerFactory.getLogger(X509Support.class);
/** Constructed. */
protected X509Support() {
@@ -166,8 +169,7 @@ public class X509Support {
return null;
}
- final Logger log = getLogger();
- log.debug("Extracting CNs from the following DN: {}", dn.toString());
+ LOG.debug("Extracting CNs from the following DN: {}", dn.toString());
final RDNSequence attrs = NameReader.readX500Principal(dn);
// Have to copy because list returned from Attributes is unmodifiable, so can't reverse it.
final List<String> values = new ArrayList<>(attrs.getValues(StandardAttributeType.CommonName));
@@ -208,8 +210,7 @@ public class X509Support {
}
return altNames;
} catch (final EncodingException e) {
- final Logger log = getLogger();
- log.warn("Could not extract alt names from certificate: {}", e.getMessage());
+ LOG.warn("Could not extract alt names from certificate: {}", e.getMessage());
throw e;
}
}
@@ -258,7 +259,7 @@ public class X509Support {
final ASN1Primitive ski = JcaX509ExtensionUtils.parseExtensionValue(derValue);
return ((DEROctetString) ski).getOctets();
} catch (final IOException e) {
- getLogger().error("Unable to extract subject key identifier from certificate: ASN.1 parsing failed: " + e);
+ LOG.error("Unable to extract subject key identifier from certificate: ASN.1 parsing failed: " + e);
return null;
}
}
@@ -277,10 +278,10 @@ public class X509Support {
final MessageDigest hasher = MessageDigest.getInstance(jcaAlgorithm);
return hasher.digest(certificate.getEncoded());
} catch (final CertificateEncodingException e) {
- getLogger().error("Unable to encode certificate for digest operation", e);
+ LOG.error("Unable to encode certificate for digest operation", e);
throw new SecurityException("Unable to encode certificate for digest operation", e);
} catch (final NoSuchAlgorithmException e) {
- getLogger().error("Algorithm {} is unsupported", jcaAlgorithm);
+ LOG.error("Algorithm {} is unsupported", jcaAlgorithm);
throw new SecurityException("Algorithm " + jcaAlgorithm + " is unsupported", e);
}
}
@@ -552,7 +553,6 @@ public class X509Support {
*/
@Nullable private static Object convertAltNameType(@Nonnull final Integer nameType,
@Nonnull final ASN1Primitive nameValue) {
- final Logger log = getLogger();
if (DIRECTORY_ALT_NAME.equals(nameType) || DNS_ALT_NAME.equals(nameType) || RFC822_ALT_NAME.equals(nameType)
|| URI_ALT_NAME.equals(nameType) || REGISTERED_ID_ALT_NAME.equals(nameType)) {
@@ -565,7 +565,7 @@ public class X509Support {
try {
return InetAddresses.toAddrString(InetAddress.getByAddress(nameValueBytes));
} catch (final UnknownHostException e) {
- log.warn("Was unable to convert IP address alt name byte[] to string: " +
+ LOG.warn("Was unable to convert IP address alt name byte[] to string: " +
CodecUtil.hex(nameValueBytes, true), e);
return null;
}
@@ -575,19 +575,10 @@ public class X509Support {
// these have no defined representation, just return a DER-encoded byte[]
return nameValue;
} else {
- log.warn("Encountered unknown alt name type '{}', adding as-is", nameType);
+ LOG.warn("Encountered unknown alt name type '{}', adding as-is", nameType);
return nameValue;
}
}
// Checkstyle: CyclomaticComplexity ON
- /**
- * Get an SLF4J Logger.
- *
- * @return a Logger instance
- */
- @Nonnull private static Logger getLogger() {
- return LoggerFactory.getLogger(X509Support.class);
- }
-
}
\ No newline at end of file
diff --git a/opensaml-security-impl/src/main/java/org/opensaml/security/credential/criteria/impl/EvaluableCredentialCriteriaRegistry.java b/opensaml-security-impl/src/main/java/org/opensaml/security/credential/criteria/impl/EvaluableCredentialCriteriaRegistry.java
index ed08cd8c2..d58b59605 100644
--- a/opensaml-security-impl/src/main/java/org/opensaml/security/credential/criteria/impl/EvaluableCredentialCriteriaRegistry.java
+++ b/opensaml-security-impl/src/main/java/org/opensaml/security/credential/criteria/impl/EvaluableCredentialCriteriaRegistry.java
@@ -56,6 +56,9 @@ public final class EvaluableCredentialCriteriaRegistry {
/** Flag to track whether registry is initialized. */
private static boolean initialized;
+
+ /** Logger. */
+ @Nonnull private static final Logger LOG = LoggerFactory.getLogger(EvaluableCredentialCriteriaRegistry.class);
/** Constructor. */
private EvaluableCredentialCriteriaRegistry() {
@@ -74,11 +77,10 @@ public final class EvaluableCredentialCriteriaRegistry {
throws SecurityException {
Constraint.isNotNull(criteria, "Criteria to map cannot be null");
- final Logger log = getLogger();
final Class<? extends EvaluableCredentialCriterion> clazz = lookup(criteria.getClass());
if (clazz != null) {
- log.debug("Registry located evaluable criteria class {} for criteria class {}", clazz.getName(), criteria
+ LOG.debug("Registry located evaluable criteria class {} for criteria class {}", clazz.getName(), criteria
.getClass().getName());
try {
@@ -89,11 +91,11 @@ public final class EvaluableCredentialCriteriaRegistry {
} catch (final java.lang.SecurityException | InstantiationException | IllegalAccessException
| IllegalArgumentException | InvocationTargetException | NoSuchMethodException e) {
- log.error("Error instantiating new EvaluableCredentialCriterion instance: {}", e.getMessage());
+ LOG.error("Error instantiating new EvaluableCredentialCriterion instance: {}", e.getMessage());
throw new SecurityException("Could not create new EvaluableCredentialCriterion", e);
}
}
- log.debug("Registry could not locate evaluable criteria for criteria class {}", criteria.getClass().getName());
+ LOG.debug("Registry could not locate evaluable criteria for criteria class {}", criteria.getClass().getName());
return null;
}
@@ -120,8 +122,7 @@ public final class EvaluableCredentialCriteriaRegistry {
Constraint.isNotNull(criteriaClass, "Criterion class to register cannot be null");
Constraint.isNotNull(evaluableClass, "Evaluable class to register cannot be null");
- final Logger log = getLogger();
- log.debug("Registering class {} as evaluator for class {}", evaluableClass.getName(), criteriaClass.getName());
+ LOG.debug("Registering class {} as evaluator for class {}", evaluableClass.getName(), criteriaClass.getName());
registry.put(criteriaClass, evaluableClass);
}
@@ -134,8 +135,7 @@ public final class EvaluableCredentialCriteriaRegistry {
public static synchronized void deregister(@Nonnull final Class<? extends Criterion> criteriaClass) {
Constraint.isNotNull(criteriaClass, "Criterion class to unregister cannot be null");
- final Logger log = getLogger();
- log.debug("Deregistering evaluator for class {}", criteriaClass.getName());
+ LOG.debug("Deregistering evaluator for class {}", criteriaClass.getName());
registry.remove(criteriaClass);
}
@@ -143,8 +143,7 @@ public final class EvaluableCredentialCriteriaRegistry {
* Clear all mappings from the registry.
*/
public static synchronized void clearRegistry() {
- final Logger log = getLogger();
- log.debug("Clearing evaluable criteria registry");
+ LOG.debug("Clearing evaluable criteria registry");
registry.clear();
}
@@ -177,13 +176,12 @@ public final class EvaluableCredentialCriteriaRegistry {
* Load the default set of criteria-evaluator mappings from the default mappings properties file.
*/
public static synchronized void loadDefaultMappings() {
- final Logger log = getLogger();
- log.debug("Loading default evaluable credential criteria mappings");
+ LOG.debug("Loading default evaluable credential criteria mappings");
try (final InputStream inStream =
EvaluableCredentialCriteriaRegistry.class.getResourceAsStream(DEFAULT_MAPPINGS_FILE) ) {
if (inStream == null) {
- log.error("Could not open resource stream from default mappings file '{}'", DEFAULT_MAPPINGS_FILE);
+ LOG.error("Could not open resource stream from default mappings file '{}'", DEFAULT_MAPPINGS_FILE);
return;
}
@@ -193,7 +191,7 @@ public final class EvaluableCredentialCriteriaRegistry {
loadMappings(defaultMappings);
} catch (final IOException e) {
- log.error("Error loading properties file from resource stream", e);
+ LOG.error("Error loading properties file from resource stream", e);
return;
}
@@ -207,10 +205,9 @@ public final class EvaluableCredentialCriteriaRegistry {
public static synchronized void loadMappings(@Nonnull final Properties mappings) {
Constraint.isNotNull(mappings, "Mappings to load cannot be null");
- final Logger log = getLogger();
for (final Object key : mappings.keySet()) {
if (!(key instanceof String)) {
- log.error("Properties key was not an instance of String, was '{}', skipping...",
+ LOG.error("Properties key was not an instance of String, was '{}', skipping...",
key.getClass().getName());
continue;
}
@@ -222,7 +219,7 @@ public final class EvaluableCredentialCriteriaRegistry {
try {
criteriaClass = (Class<? extends Criterion>) classLoader.loadClass(criteriaName);
} catch (final ClassNotFoundException e) {
- log.error("Could not find criteria class '{}', skipping registration", criteriaName);
+ LOG.error("Could not find criteria class '{}', skipping registration", criteriaName);
continue;
}
@@ -230,7 +227,7 @@ public final class EvaluableCredentialCriteriaRegistry {
try {
evaluableClass = (Class<? extends EvaluableCredentialCriterion>) classLoader.loadClass(evaluatorName);
} catch (final ClassNotFoundException e) {
- log.error("Could not find evaluator class '{}', skipping registration", criteriaName);
+ LOG.error("Could not find evaluator class '{}', skipping registration", criteriaName);
continue;
}
@@ -238,15 +235,6 @@ public final class EvaluableCredentialCriteriaRegistry {
}
}
-
- /**
- * Get an SLF4J Logger.
- *
- * @return a Logger instance
- */
- @Nonnull private static Logger getLogger() {
- return LoggerFactory.getLogger(EvaluableCredentialCriteriaRegistry.class);
- }
static {
init();
diff --git a/opensaml-xmlsec-api/src/main/java/org/opensaml/xmlsec/algorithm/AlgorithmSupport.java b/opensaml-xmlsec-api/src/main/java/org/opensaml/xmlsec/algorithm/AlgorithmSupport.java
index 6fe8d474a..69b1e469e 100644
--- a/opensaml-xmlsec-api/src/main/java/org/opensaml/xmlsec/algorithm/AlgorithmSupport.java
+++ b/opensaml-xmlsec-api/src/main/java/org/opensaml/xmlsec/algorithm/AlgorithmSupport.java
@@ -325,7 +325,6 @@ public final class AlgorithmSupport {
* indeterminable from the URI
*/
@Nullable public static Integer getKeyLength(@Nonnull final String algorithmURI) {
- final Logger log = getLogger();
final AlgorithmRegistry registry = getGlobalAlgorithmRegistry();
if (registry != null){
final AlgorithmDescriptor descriptor = registry.get(algorithmURI);
@@ -334,7 +333,7 @@ public final class AlgorithmSupport {
}
}
- log.info("Mapping from algorithm URI {} to key length not available", algorithmURI);
+ LOG.info("Mapping from algorithm URI {} to key length not available", algorithmURI);
return null;
}
@@ -348,10 +347,9 @@ public final class AlgorithmSupport {
*/
@Nonnull public static SecretKey generateSymmetricKey(@Nonnull final String algoURI)
throws NoSuchAlgorithmException, KeyException {
- final Logger log = getLogger();
final String jceAlgorithmName = getKeyAlgorithm(algoURI);
if (Strings.isNullOrEmpty(jceAlgorithmName)) {
- log.error("Mapping from algorithm URI '" + algoURI
+ LOG.error("Mapping from algorithm URI '" + algoURI
+ "' to key algorithm not available, key generation failed");
throw new NoSuchAlgorithmException("Algorithm URI'" + algoURI + "' is invalid for key generation");
}
@@ -370,7 +368,7 @@ public final class AlgorithmSupport {
}
if (keyLength == null) {
- log.error("Key length could not be determined from algorithm URI, can't generate key");
+ LOG.error("Key length could not be determined from algorithm URI, can't generate key");
throw new KeyException("Key length not determinable from algorithm URI, could not generate new key");
}
final KeyGenerator keyGenerator = KeyGenerator.getInstance(jceAlgorithmName);
@@ -509,14 +507,5 @@ public final class AlgorithmSupport {
return true;
}
-
- /**
- * Get an SLF4J Logger.
- *
- * @return a Logger instance
- */
- @Nonnull private static Logger getLogger() {
- return LoggerFactory.getLogger(AlgorithmSupport.class);
- }
}
\ No newline at end of file
diff --git a/opensaml-xmlsec-api/src/main/java/org/opensaml/xmlsec/keyinfo/KeyInfoSupport.java b/opensaml-xmlsec-api/src/main/java/org/opensaml/xmlsec/keyinfo/KeyInfoSupport.java
index d07f232d4..83f0104e5 100644
--- a/opensaml-xmlsec-api/src/main/java/org/opensaml/xmlsec/keyinfo/KeyInfoSupport.java
+++ b/opensaml-xmlsec-api/src/main/java/org/opensaml/xmlsec/keyinfo/KeyInfoSupport.java
@@ -104,6 +104,9 @@ import net.shibboleth.utilities.java.support.logic.Constraint;
* types, and for storing these Java native types inside a KeyInfo.
*/
public class KeyInfoSupport {
+
+ /** Logger. */
+ @Nonnull private static final Logger LOG = LoggerFactory.getLogger(KeyInfoSupport.class);
/**
* Factory for {@link java.security.cert.X509Certificate} and {@link java.security.cert.X509CRL} creation.
@@ -469,8 +472,6 @@ public class KeyInfoSupport {
@Nullable public static X509SKI buildX509SKI(@Nonnull final X509Certificate javaCert) throws SecurityException {
final byte[] skiPlainValue = X509Support.getSubjectKeyIdentifier(javaCert);
- final Logger log = getLogger();
-
if (skiPlainValue == null || skiPlainValue.length == 0) {
return null;
}
@@ -484,7 +485,7 @@ public class KeyInfoSupport {
xmlSKI.setValue(Base64Support.encode(skiPlainValue, Base64Support.CHUNKED));
return xmlSKI;
} catch (final EncodingException e) {
- log.warn("X.509 subject key identifier could not be base64 encoded",e);
+ LOG.warn("X.509 subject key identifier could not be base64 encoded",e);
throw new SecurityException("X.509 subject key identifier could not be base64 encoded",e);
}
}
@@ -1038,16 +1039,15 @@ public class KeyInfoSupport {
*/
@Nonnull protected static PublicKey buildKey(@Nonnull final KeySpec keySpec, @Nonnull final String keyAlgorithm)
throws KeyException {
- final Logger log = getLogger();
try {
final KeyFactory keyFactory = KeyFactory.getInstance(keyAlgorithm);
return keyFactory.generatePublic(keySpec);
} catch (final NoSuchAlgorithmException e) {
final String msg = keyAlgorithm + " algorithm is not supported by this JCE";
- log.error(msg + ": {}", e.getMessage());
+ LOG.error(msg + ": {}", e.getMessage());
throw new KeyException(msg, e);
} catch (final InvalidKeySpecException e) {
- log.error("Invalid key information: {}", e.getMessage());
+ LOG.error("Invalid key information: {}", e.getMessage());
throw new KeyException("Invalid key information", e);
}
}
@@ -1089,17 +1089,17 @@ public class KeyInfoSupport {
final String[] keyTypes = parsedKeyType != null ? new String[]{parsedKeyType} : supportedKeyTypes;
for (final String keyType : keyTypes) {
- getLogger().trace("Attempting to decode DER key as type: {}", keyType);
+ LOG.trace("Attempting to decode DER key as type: {}", keyType);
try {
final KeyFactory keyFactory = KeyFactory.getInstance(keyType);
final X509EncodedKeySpec keySpec = new X509EncodedKeySpec(encodedKey);
final PublicKey publicKey = keyFactory.generatePublic(keySpec);
if (publicKey != null) {
- getLogger().trace("DER key decoded successfully as type: {}", keyType);
+ LOG.trace("DER key decoded successfully as type: {}", keyType);
return publicKey;
}
} catch (final NoSuchAlgorithmException | InvalidKeySpecException e) {
- getLogger().trace("DER key failed decoding as: {}", keyType);
+ LOG.trace("DER key failed decoding as: {}", keyType);
}
}
throw new KeyException("DEREncodedKeyValue did not contain a supported key type");
@@ -1122,7 +1122,7 @@ public class KeyInfoSupport {
try (final ASN1InputStream input = new ASN1InputStream(encodedKey)) {
final SubjectPublicKeyInfo spki = SubjectPublicKeyInfo.getInstance(input.readObject());
final String keyTypeOID = spki.getAlgorithm().getAlgorithm().getId();
- getLogger().debug("Parsed key type OID: {}", keyTypeOID);
+ LOG.debug("Parsed key type OID: {}", keyTypeOID);
String parsedKeyType = null;
switch(keyTypeOID) {
@@ -1147,10 +1147,10 @@ public class KeyInfoSupport {
parsedKeyType = null;
}
- getLogger().debug("Parsed key type: {}", parsedKeyType);
+ LOG.debug("Parsed key type: {}", parsedKeyType);
return parsedKeyType;
} catch (final Exception e) {
- getLogger().warn("Error parsing encoded key, can not determine key type", e);
+ LOG.warn("Error parsing encoded key, can not determine key type", e);
return null;
}
}
@@ -1191,33 +1191,22 @@ public class KeyInfoSupport {
Constraint.isNotNull(credential, "Credential may not be null");
Constraint.isNotNull(manager, "NamedKeyInfoGeneratorManager may not be null");
- final Logger log = getLogger();
-
KeyInfoGeneratorFactory factory = null;
if (keyInfoProfileName != null) {
- log.trace("Resolving KeyInfoGeneratorFactory using profile name: {}", keyInfoProfileName);
+ LOG.trace("Resolving KeyInfoGeneratorFactory using profile name: {}", keyInfoProfileName);
factory = manager.getFactory(keyInfoProfileName, credential);
} else {
- log.trace("Resolving KeyInfoGeneratorFactory using default manager: {}", keyInfoProfileName);
+ LOG.trace("Resolving KeyInfoGeneratorFactory using default manager: {}", keyInfoProfileName);
factory = manager.getDefaultManager().getFactory(credential);
}
if (factory != null) {
- log.trace("Found KeyInfoGeneratorFactory: {}", factory.getClass().getName());
+ LOG.trace("Found KeyInfoGeneratorFactory: {}", factory.getClass().getName());
return factory.newInstance();
}
- log.trace("Unable to resolve KeyInfoGeneratorFactory for credential");
+ LOG.trace("Unable to resolve KeyInfoGeneratorFactory for credential");
return null;
}
-
- /**
- * Get an SLF4J Logger.
- *
- * @return a Logger instance
- */
- @Nonnull private static Logger getLogger() {
- return LoggerFactory.getLogger(KeyInfoSupport.class);
- }
}
\ No newline at end of file
diff --git a/opensaml-xmlsec-api/src/main/java/org/opensaml/xmlsec/signature/support/SignatureSupport.java b/opensaml-xmlsec-api/src/main/java/org/opensaml/xmlsec/signature/support/SignatureSupport.java
index b1b9f5106..da84b3019 100644
--- a/opensaml-xmlsec-api/src/main/java/org/opensaml/xmlsec/signature/support/SignatureSupport.java
+++ b/opensaml-xmlsec-api/src/main/java/org/opensaml/xmlsec/signature/support/SignatureSupport.java
@@ -46,6 +46,9 @@ import net.shibboleth.utilities.java.support.primitive.StringSupport;
*/
public final class SignatureSupport {
+ /** Logger. */
+ @Nonnull private static final Logger LOG = LoggerFactory.getLogger(SignatureSupport.class);
+
/** Set of known canonicalization algorithm URIs. */
@Nonnull @NonnullElements private static final Set<String> C14N_ALGORITHMS = Set.of(
SignatureConstants.ALGO_ID_C14N11_OMIT_COMMENTS,
@@ -61,15 +64,6 @@ public final class SignatureSupport {
}
- /**
- * Get an SLF4J Logger.
- *
- * @return a Logger instance
- */
- @Nonnull private static Logger getLogger() {
- return LoggerFactory.getLogger(SignatureSupport.class);
- }
-
/**
* Prepare a {@link Signature} with necessary additional information prior to signing.
*
@@ -160,8 +154,6 @@ public final class SignatureSupport {
private static void processKeyInfo(final Signature signature,
final SignatureSigningParameters parameters) throws SecurityException {
- final Logger log = getLogger();
-
if (signature.getKeyInfo() == null) {
final KeyInfoGenerator kiGenerator = parameters.getKeyInfoGenerator();
if (kiGenerator != null) {
@@ -169,11 +161,11 @@ public final class SignatureSupport {
final KeyInfo keyInfo = kiGenerator.generate(signature.getSigningCredential());
signature.setKeyInfo(keyInfo);
} catch (final SecurityException e) {
- log.error("Error generating KeyInfo from credential: {}", e.getMessage());
+ LOG.error("Error generating KeyInfo from credential: {}", e.getMessage());
throw e;
}
} else {
- log.info("No KeyInfoGenerator was supplied in parameters or resolveable "
+ LOG.info("No KeyInfoGenerator was supplied in parameters or resolveable "
+ "for credential type {}, No KeyInfo will be generated for Signature",
signature.getSigningCredential().getCredentialType().getName());
}
@@ -227,9 +219,7 @@ public final class SignatureSupport {
return;
}
- final Logger log = getLogger();
-
- log.trace("Adding or replacing content reference transform: {}", uri);
+ LOG.trace("Adding or replacing content reference transform: {}", uri);
if (cr instanceof TransformsConfigurableContentReference) {
final List<String> transforms = ((TransformsConfigurableContentReference)cr).getTransforms();
@@ -246,7 +236,7 @@ public final class SignatureSupport {
// Didn't see an existing one, so add it
transforms.add(uri);
} else {
- log.warn("A non-null signature reference c14n transform was specified, "
+ LOG.warn("A non-null signature reference c14n transform was specified, "
+ "but ContentReference was not configurable for transforms: {}",
cr.getClass().getName());
}
diff --git a/opensaml-xmlsec-api/src/main/java/org/opensaml/xmlsec/signature/support/SignatureValidator.java b/opensaml-xmlsec-api/src/main/java/org/opensaml/xmlsec/signature/support/SignatureValidator.java
index 8994bd266..2cec66523 100644
--- a/opensaml-xmlsec-api/src/main/java/org/opensaml/xmlsec/signature/support/SignatureValidator.java
+++ b/opensaml-xmlsec-api/src/main/java/org/opensaml/xmlsec/signature/support/SignatureValidator.java
@@ -33,6 +33,9 @@ import org.slf4j.LoggerFactory;
*/
public final class SignatureValidator {
+ /** Logger. */
+ @Nonnull private static final Logger LOG = LoggerFactory.getLogger(SignatureValidationProvider.class);
+
/** The cached signature validation provider instance to use. */
private static SignatureValidationProvider validatorInstance;
@@ -50,7 +53,7 @@ public final class SignatureValidator {
public static void validate(@Nonnull final Signature signature, @Nonnull final Credential validationCredential)
throws SignatureException {
final SignatureValidationProvider validator = getSignatureValidationProvider();
- getLogger().debug("Using a validation provider of implementation: {}", validator.getClass().getName());
+ LOG.debug("Using a validation provider of implementation: {}", validator.getClass().getName());
validator.validate(signature, validationCredential);
}
@@ -76,14 +79,5 @@ public final class SignatureValidator {
}
return validatorInstance;
}
-
- /**
- * Get an SLF4J Logger.
- *
- * @return a Logger instance
- */
- @Nonnull private static Logger getLogger() {
- return LoggerFactory.getLogger(SignatureValidationProvider.class);
- }
}
\ No newline at end of file
diff --git a/opensaml-xmlsec-api/src/main/java/org/opensaml/xmlsec/signature/support/Signer.java b/opensaml-xmlsec-api/src/main/java/org/opensaml/xmlsec/signature/support/Signer.java
index e09ef8182..30cda543c 100644
--- a/opensaml-xmlsec-api/src/main/java/org/opensaml/xmlsec/signature/support/Signer.java
+++ b/opensaml-xmlsec-api/src/main/java/org/opensaml/xmlsec/signature/support/Signer.java
@@ -41,6 +41,9 @@ import org.slf4j.LoggerFactory;
*/
public final class Signer {
+ /** Logger. */
+ @Nonnull private static final Logger LOG = LoggerFactory.getLogger(Signer.class);
+
/** The cached signer provider instance to use. */
private static SignerProvider signerInstance;
@@ -55,7 +58,7 @@ public final class Signer {
*/
public static void signObjects(@Nonnull final List<Signature> signatures) throws SignatureException {
final SignerProvider signer = getSignerProvider();
- getLogger().debug("Using a signer of implementation: {}", signer.getClass().getName());
+ LOG.debug("Using a signer of implementation: {}", signer.getClass().getName());
for (final Signature signature : signatures) {
signer.signObject(signature);
}
@@ -69,7 +72,7 @@ public final class Signer {
*/
public static void signObject(@Nonnull final Signature signature) throws SignatureException {
final SignerProvider signer = getSignerProvider();
- getLogger().debug("Using a signer of implemenation: {}", signer.getClass().getName());
+ LOG.debug("Using a signer of implemenation: {}", signer.getClass().getName());
signer.signObject(signature);
}
@@ -91,14 +94,5 @@ public final class Signer {
}
return signerInstance;
}
-
- /**
- * Get an SLF4J Logger.
- *
- * @return a Logger instance
- */
- @Nonnull private static Logger getLogger() {
- return LoggerFactory.getLogger(Signer.class);
- }
}
\ No newline at end of file
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
More information about the commits
mailing list