[java-identity-provider] branch master updated: JSPT-93 - Clean up API for BaseXXSupport decoders (ENCODE)
Phil Smart
philip.smart at jisc.ac.uk
Fri Feb 7 12:12:21 EST 2020
This is an automated email from the git hooks/post-receive script.
philsmart pushed a commit to branch master
in repository java-identity-provider.
View the commit online:
http://git.shibboleth.net/view/?p=java-identity-provider.git;a=commit;h=6bf8449f1c881e221fd13c725052d49fc889c5bb
The following commit(s) were added to refs/heads/master by this push:
new 6bf8449 JSPT-93 - Clean up API for BaseXXSupport decoders (ENCODE)
6bf8449 is described below
commit 6bf8449f1c881e221fd13c725052d49fc889c5bb
Author: Phil Smart <philip.smart at jisc.ac.uk>
AuthorDate: Fri Feb 7 17:02:58 2020 +0000
JSPT-93 - Clean up API for BaseXXSupport decoders (ENCODE)
- Add appropriate error handling for the new EncodingException thrown by the
Base64Support and Base32Support encode methods.
https://issues.shibboleth.net/jira/browse/JSPT-93
---
.../net/shibboleth/idp/attribute/ByteAttributeValue.java | 4 +++-
.../shibboleth/idp/attribute/ByteAttributeValueTest.java | 3 ++-
.../idp/attribute/impl/ComputedPairwiseIdStore.java | 4 ++++
.../idp/attribute/impl/ComputedPairwiseIdStoreTest.java | 3 ++-
.../idp/authn/spnego/impl/SPNEGOAuthnControllerTest.java | 15 ++++++++++++---
.../idp/test/flows/saml2/SAML2POSTSSOFlowTest.java | 4 +++-
.../test/flows/saml2/SAML2POSTSimpleSignSSOFlowTest.java | 4 +++-
.../idp/test/flows/saml2/SAML2RedirectSSOFlowTest.java | 4 +++-
.../saml/attribute/transcoding/SAMLEncoderSupport.java | 5 ++++-
.../attribute/transcoding/SAMLEncoderSupportTest.java | 3 ++-
.../transcoding/impl/SAML1ByteAttributeTranscoder.java | 9 +++++++--
.../transcoding/impl/SAML2ByteAttributeTranscoder.java | 9 +++++++--
12 files changed, 52 insertions(+), 15 deletions(-)
diff --git a/idp-attribute-api/src/main/java/net/shibboleth/idp/attribute/ByteAttributeValue.java b/idp-attribute-api/src/main/java/net/shibboleth/idp/attribute/ByteAttributeValue.java
index 6003aec..0dab152 100644
--- a/idp-attribute-api/src/main/java/net/shibboleth/idp/attribute/ByteAttributeValue.java
+++ b/idp-attribute-api/src/main/java/net/shibboleth/idp/attribute/ByteAttributeValue.java
@@ -25,6 +25,7 @@ import javax.annotation.Nullable;
import net.shibboleth.utilities.java.support.annotation.ParameterName;
import net.shibboleth.utilities.java.support.annotation.constraint.NotEmpty;
import net.shibboleth.utilities.java.support.codec.Base64Support;
+import net.shibboleth.utilities.java.support.codec.EncodingException;
import net.shibboleth.utilities.java.support.logic.Constraint;
import org.apache.commons.codec.binary.Hex;
@@ -77,8 +78,9 @@ public final class ByteAttributeValue implements IdPAttributeValue {
* Gets this value as a Base64-encoded string.
*
* @return a Base64-encoded string
+ * @throws EncodingException on failure to base64 encode byte value
*/
- @Nonnull public String toBase64() {
+ @Nonnull public String toBase64() throws EncodingException {
return Base64Support.encode(value, Base64Support.UNCHUNKED);
}
diff --git a/idp-attribute-api/src/test/java/net/shibboleth/idp/attribute/ByteAttributeValueTest.java b/idp-attribute-api/src/test/java/net/shibboleth/idp/attribute/ByteAttributeValueTest.java
index 3e00010..45fe41d 100644
--- a/idp-attribute-api/src/test/java/net/shibboleth/idp/attribute/ByteAttributeValueTest.java
+++ b/idp-attribute-api/src/test/java/net/shibboleth/idp/attribute/ByteAttributeValueTest.java
@@ -21,6 +21,7 @@ import java.util.Arrays;
import net.shibboleth.utilities.java.support.codec.Base64Support;
import net.shibboleth.utilities.java.support.codec.DecodingException;
+import net.shibboleth.utilities.java.support.codec.EncodingException;
import net.shibboleth.utilities.java.support.logic.ConstraintViolationException;
import org.testng.Assert;
@@ -69,7 +70,7 @@ public class ByteAttributeValueTest {
Assert.assertFalse(value3.equals(value2));
}
- @Test public void toHexStringBase64() throws DecodingException {
+ @Test public void toHexStringBase64() throws DecodingException, EncodingException {
ByteAttributeValue value = new ByteAttributeValue(DATA1);
value.toString();
diff --git a/idp-attribute-impl/src/main/java/net/shibboleth/idp/attribute/impl/ComputedPairwiseIdStore.java b/idp-attribute-impl/src/main/java/net/shibboleth/idp/attribute/impl/ComputedPairwiseIdStore.java
index c0c2f54..7368c04 100644
--- a/idp-attribute-impl/src/main/java/net/shibboleth/idp/attribute/impl/ComputedPairwiseIdStore.java
+++ b/idp-attribute-impl/src/main/java/net/shibboleth/idp/attribute/impl/ComputedPairwiseIdStore.java
@@ -34,6 +34,7 @@ import net.shibboleth.utilities.java.support.annotation.constraint.NotEmpty;
import net.shibboleth.utilities.java.support.codec.Base32Support;
import net.shibboleth.utilities.java.support.codec.Base64Support;
import net.shibboleth.utilities.java.support.codec.DecodingException;
+import net.shibboleth.utilities.java.support.codec.EncodingException;
import net.shibboleth.utilities.java.support.component.AbstractInitializableComponent;
import net.shibboleth.utilities.java.support.component.ComponentInitializationException;
import net.shibboleth.utilities.java.support.component.ComponentSupport;
@@ -268,6 +269,9 @@ public class ComputedPairwiseIdStore extends AbstractInitializableComponent impl
} catch (final NoSuchAlgorithmException e) {
log.error("Digest algorithm {} is not supported", algorithm);
throw new IOException("Digest algorithm was not supported, unable to compute ID", e);
+ } catch (final EncodingException e) {
+ log.error("Unable to {} encode digest",encoding);
+ throw new IOException("Unable to either base64 or base32 encode digest, unable to compute ID", e);
}
return pid;
diff --git a/idp-attribute-impl/src/test/java/net/shibboleth/idp/attribute/impl/ComputedPairwiseIdStoreTest.java b/idp-attribute-impl/src/test/java/net/shibboleth/idp/attribute/impl/ComputedPairwiseIdStoreTest.java
index ce4805d..6f5a9f0 100644
--- a/idp-attribute-impl/src/test/java/net/shibboleth/idp/attribute/impl/ComputedPairwiseIdStoreTest.java
+++ b/idp-attribute-impl/src/test/java/net/shibboleth/idp/attribute/impl/ComputedPairwiseIdStoreTest.java
@@ -24,6 +24,7 @@ import net.shibboleth.idp.attribute.PairwiseId;
import net.shibboleth.idp.attribute.impl.ComputedPairwiseIdStore.Encoding;
import net.shibboleth.idp.testing.DatabaseTestingSupport;
import net.shibboleth.utilities.java.support.codec.Base64Support;
+import net.shibboleth.utilities.java.support.codec.EncodingException;
import net.shibboleth.utilities.java.support.component.ComponentInitializationException;
import org.testng.Assert;
@@ -57,7 +58,7 @@ public class ComputedPairwiseIdStoreTest {
}
@Test
- public void testSaltSetters() throws ComponentInitializationException {
+ public void testSaltSetters() throws ComponentInitializationException, EncodingException {
final ComputedPairwiseIdStore store = new ComputedPairwiseIdStore();
store.setSalt(salt);
Assert.assertEquals(salt, store.getSalt());
diff --git a/idp-authn-impl/src/test/java/net/shibboleth/idp/authn/spnego/impl/SPNEGOAuthnControllerTest.java b/idp-authn-impl/src/test/java/net/shibboleth/idp/authn/spnego/impl/SPNEGOAuthnControllerTest.java
index d557d12..bde7a77 100644
--- a/idp-authn-impl/src/test/java/net/shibboleth/idp/authn/spnego/impl/SPNEGOAuthnControllerTest.java
+++ b/idp-authn-impl/src/test/java/net/shibboleth/idp/authn/spnego/impl/SPNEGOAuthnControllerTest.java
@@ -42,6 +42,7 @@ import net.shibboleth.idp.authn.impl.ExternalAuthenticationImpl;
import net.shibboleth.idp.authn.principal.UsernamePrincipal;
import net.shibboleth.idp.profile.RequestContextBuilder;
import net.shibboleth.utilities.java.support.codec.Base64Support;
+import net.shibboleth.utilities.java.support.codec.EncodingException;
import net.shibboleth.utilities.java.support.component.ComponentInitializationException;
import org.ietf.jgss.GSSContext;
@@ -57,6 +58,7 @@ import org.springframework.mock.web.MockServletContext;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.webflow.execution.RequestContext;
import org.testng.Assert;
+import org.testng.annotations.BeforeClass;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
@@ -64,14 +66,21 @@ public class SPNEGOAuthnControllerTest {
private static final String TEST_CONVERSATION_KEY = "e1s1";
- private static final String NTLMSSP_HEADER_DATA = Base64Support.encode(new byte[] {(byte) 0x4E, (byte) 0x54,
- (byte) 0x4C, (byte) 0x4D, (byte) 0x53, (byte) 0x53, (byte) 0x50}, false);
+ private static String NTLMSSP_HEADER_DATA;
- private static final String NEGOTIATE_HEADER_DATA = Base64Support.encode("testdata".getBytes(), false);
+ private static String NEGOTIATE_HEADER_DATA;
private SPNEGOAuthnController controller = new SPNEGOAuthnController();
private GSSContextAcceptor mockGSSContextAcceptor;
+
+
+ @BeforeClass
+ public void init() throws EncodingException {
+ NTLMSSP_HEADER_DATA = Base64Support.encode(new byte[] {(byte) 0x4E, (byte) 0x54,
+ (byte) 0x4C, (byte) 0x4D, (byte) 0x53, (byte) 0x53, (byte) 0x50}, false);
+ NEGOTIATE_HEADER_DATA = Base64Support.encode("testdata".getBytes(), false);
+ }
private SPNEGOAuthnController mockedGSSController = new SPNEGOAuthnController() {
@Override
diff --git a/idp-conf/src/test/java/net/shibboleth/idp/test/flows/saml2/SAML2POSTSSOFlowTest.java b/idp-conf/src/test/java/net/shibboleth/idp/test/flows/saml2/SAML2POSTSSOFlowTest.java
index 989eb28..9315631 100644
--- a/idp-conf/src/test/java/net/shibboleth/idp/test/flows/saml2/SAML2POSTSSOFlowTest.java
+++ b/idp-conf/src/test/java/net/shibboleth/idp/test/flows/saml2/SAML2POSTSSOFlowTest.java
@@ -22,6 +22,7 @@ import java.io.UnsupportedEncodingException;
import javax.annotation.Nonnull;
import net.shibboleth.utilities.java.support.codec.Base64Support;
+import net.shibboleth.utilities.java.support.codec.EncodingException;
import net.shibboleth.utilities.java.support.xml.SerializeSupport;
import org.opensaml.core.xml.io.MarshallingException;
@@ -86,9 +87,10 @@ public class SAML2POSTSSOFlowTest extends AbstractSAML2SSOFlowTest {
* @return Base64 encoded message
* @throws MarshallingException if there is a problem marshalling the XMLObject
* @throws UnsupportedEncodingException If the named charset is not supported
+ * @throws EncodingException if the message can not be base64 encoded
*/
@Nonnull public String encodeMessage(@Nonnull final SAMLObject message) throws MarshallingException,
- UnsupportedEncodingException {
+ UnsupportedEncodingException, EncodingException {
final Element domMessage = XMLObjectSupport.marshall(message);
final String messageXML = SerializeSupport.nodeToString(domMessage);
diff --git a/idp-conf/src/test/java/net/shibboleth/idp/test/flows/saml2/SAML2POSTSimpleSignSSOFlowTest.java b/idp-conf/src/test/java/net/shibboleth/idp/test/flows/saml2/SAML2POSTSimpleSignSSOFlowTest.java
index bf7f2ac..b6224ba 100644
--- a/idp-conf/src/test/java/net/shibboleth/idp/test/flows/saml2/SAML2POSTSimpleSignSSOFlowTest.java
+++ b/idp-conf/src/test/java/net/shibboleth/idp/test/flows/saml2/SAML2POSTSimpleSignSSOFlowTest.java
@@ -22,6 +22,7 @@ import java.io.UnsupportedEncodingException;
import javax.annotation.Nonnull;
import net.shibboleth.utilities.java.support.codec.Base64Support;
+import net.shibboleth.utilities.java.support.codec.EncodingException;
import net.shibboleth.utilities.java.support.xml.SerializeSupport;
import org.opensaml.core.xml.io.MarshallingException;
@@ -86,9 +87,10 @@ public class SAML2POSTSimpleSignSSOFlowTest extends AbstractSAML2SSOFlowTest {
* @return Base64 encoded message
* @throws MarshallingException if there is a problem marshalling the XMLObject
* @throws UnsupportedEncodingException If the named charset is not supported
+ * @throws EncodingException if the message can not be base64 encoded
*/
@Nonnull public String encodeMessage(@Nonnull final SAMLObject message) throws MarshallingException,
- UnsupportedEncodingException {
+ UnsupportedEncodingException, EncodingException {
final Element domMessage = XMLObjectSupport.marshall(message);
final String messageXML = SerializeSupport.nodeToString(domMessage);
diff --git a/idp-conf/src/test/java/net/shibboleth/idp/test/flows/saml2/SAML2RedirectSSOFlowTest.java b/idp-conf/src/test/java/net/shibboleth/idp/test/flows/saml2/SAML2RedirectSSOFlowTest.java
index f5a0d6b..aef895d 100644
--- a/idp-conf/src/test/java/net/shibboleth/idp/test/flows/saml2/SAML2RedirectSSOFlowTest.java
+++ b/idp-conf/src/test/java/net/shibboleth/idp/test/flows/saml2/SAML2RedirectSSOFlowTest.java
@@ -25,6 +25,7 @@ import java.util.zip.DeflaterOutputStream;
import javax.annotation.Nonnull;
import net.shibboleth.utilities.java.support.codec.Base64Support;
+import net.shibboleth.utilities.java.support.codec.EncodingException;
import net.shibboleth.utilities.java.support.xml.SerializeSupport;
import org.opensaml.core.xml.io.MarshallingException;
@@ -89,8 +90,9 @@ public class SAML2RedirectSSOFlowTest extends AbstractSAML2SSOFlowTest {
* @return DEFLATE compressed message
* @throws MarshallingException if there is a problem marshalling the XMLObject
* @throws IOException if an I/O error has occurred
+ * @throws EncodingException if the message can not be base64 encoded
*/
- @Nonnull public String encodeMessage(@Nonnull final SAMLObject message) throws MarshallingException, IOException {
+ @Nonnull public String encodeMessage(@Nonnull final SAMLObject message) throws MarshallingException, IOException, EncodingException {
final Element domMessage = XMLObjectSupport.marshall(message);
final String messageXML = SerializeSupport.nodeToString(domMessage);
diff --git a/idp-saml-api/src/main/java/net/shibboleth/idp/saml/attribute/transcoding/SAMLEncoderSupport.java b/idp-saml-api/src/main/java/net/shibboleth/idp/saml/attribute/transcoding/SAMLEncoderSupport.java
index 2176a58..eb7ab99 100644
--- a/idp-saml-api/src/main/java/net/shibboleth/idp/saml/attribute/transcoding/SAMLEncoderSupport.java
+++ b/idp-saml-api/src/main/java/net/shibboleth/idp/saml/attribute/transcoding/SAMLEncoderSupport.java
@@ -26,6 +26,7 @@ import net.shibboleth.idp.attribute.ScopedStringAttributeValue;
import net.shibboleth.idp.saml.xmlobject.ScopedValue;
import net.shibboleth.utilities.java.support.annotation.constraint.NotEmpty;
import net.shibboleth.utilities.java.support.codec.Base64Support;
+import net.shibboleth.utilities.java.support.codec.EncodingException;
import net.shibboleth.utilities.java.support.logic.Constraint;
import org.opensaml.core.xml.XMLObject;
@@ -98,9 +99,11 @@ public final class SAMLEncoderSupport {
* @param withType whether to include xsi:type
*
* @return the attribute value element or null if the given value was null or empty
+ * @throws EncodingException if the byte array can not be base64 encoded.
*/
@Nullable public static XMLObject encodeByteArrayValue(@Nonnull final IdPAttribute attribute,
- @Nonnull final QName attributeValueElementName, @Nullable final byte[] value, final boolean withType) {
+ @Nonnull final QName attributeValueElementName, @Nullable final byte[] value, final boolean withType)
+ throws EncodingException {
Constraint.isNotNull(attribute, "Attribute cannot be null");
Constraint.isNotNull(attributeValueElementName, "Attribute Element Name cannot be null");
diff --git a/idp-saml-api/src/test/java/net/shibboleth/idp/saml/attribute/transcoding/SAMLEncoderSupportTest.java b/idp-saml-api/src/test/java/net/shibboleth/idp/saml/attribute/transcoding/SAMLEncoderSupportTest.java
index e341421..f6904ea 100644
--- a/idp-saml-api/src/test/java/net/shibboleth/idp/saml/attribute/transcoding/SAMLEncoderSupportTest.java
+++ b/idp-saml-api/src/test/java/net/shibboleth/idp/saml/attribute/transcoding/SAMLEncoderSupportTest.java
@@ -26,6 +26,7 @@ import net.shibboleth.idp.attribute.ScopedStringAttributeValue;
import net.shibboleth.idp.saml.xmlobject.ScopedValue;
import net.shibboleth.utilities.java.support.codec.Base64Support;
import net.shibboleth.utilities.java.support.codec.DecodingException;
+import net.shibboleth.utilities.java.support.codec.EncodingException;
import net.shibboleth.utilities.java.support.logic.ConstraintViolationException;
import net.shibboleth.utilities.java.support.xml.ElementSupport;
@@ -93,7 +94,7 @@ public class SAMLEncoderSupportTest extends OpenSAMLInitBaseTestCase {
Assert.assertEquals(str.getValue(), STRING_VALUE);
}
- @Test public void encodeByteArrayValue() throws DecodingException {
+ @Test public void encodeByteArrayValue() throws DecodingException, EncodingException {
try {
SAMLEncoderSupport.encodeByteArrayValue(null, QNAME, BYTE_ARRAY_VALUE, true);
diff --git a/idp-saml-impl/src/main/java/net/shibboleth/idp/saml/attribute/transcoding/impl/SAML1ByteAttributeTranscoder.java b/idp-saml-impl/src/main/java/net/shibboleth/idp/saml/attribute/transcoding/impl/SAML1ByteAttributeTranscoder.java
index ce17f82..4f257ae 100644
--- a/idp-saml-impl/src/main/java/net/shibboleth/idp/saml/attribute/transcoding/impl/SAML1ByteAttributeTranscoder.java
+++ b/idp-saml-impl/src/main/java/net/shibboleth/idp/saml/attribute/transcoding/impl/SAML1ByteAttributeTranscoder.java
@@ -29,6 +29,7 @@ import net.shibboleth.idp.saml.attribute.transcoding.SAMLEncoderSupport;
import net.shibboleth.idp.saml.attribute.transcoding.AbstractSAML1AttributeTranscoder;
import net.shibboleth.utilities.java.support.codec.Base64Support;
import net.shibboleth.utilities.java.support.codec.DecodingException;
+import net.shibboleth.utilities.java.support.codec.EncodingException;
import org.opensaml.core.xml.XMLObject;
import org.opensaml.profile.context.ProfileRequestContext;
@@ -59,8 +60,12 @@ public class SAML1ByteAttributeTranscoder extends AbstractSAML1AttributeTranscod
final Boolean encodeType = rule.getOrDefault(PROP_ENCODE_TYPE, Boolean.class, Boolean.TRUE);
- return SAMLEncoderSupport.encodeByteArrayValue(attribute, AttributeValue.DEFAULT_ELEMENT_NAME, value.getValue(),
- encodeType);
+ try {
+ return SAMLEncoderSupport.encodeByteArrayValue(attribute, AttributeValue.DEFAULT_ELEMENT_NAME,
+ value.getValue(), encodeType);
+ } catch (final EncodingException e) {
+ throw new AttributeEncodingException("Attribtue value could not be encoded",e);
+ }
}
/** {@inheritDoc} */
diff --git a/idp-saml-impl/src/main/java/net/shibboleth/idp/saml/attribute/transcoding/impl/SAML2ByteAttributeTranscoder.java b/idp-saml-impl/src/main/java/net/shibboleth/idp/saml/attribute/transcoding/impl/SAML2ByteAttributeTranscoder.java
index 88b92cf..3bea037 100644
--- a/idp-saml-impl/src/main/java/net/shibboleth/idp/saml/attribute/transcoding/impl/SAML2ByteAttributeTranscoder.java
+++ b/idp-saml-impl/src/main/java/net/shibboleth/idp/saml/attribute/transcoding/impl/SAML2ByteAttributeTranscoder.java
@@ -29,6 +29,7 @@ import net.shibboleth.idp.saml.attribute.transcoding.AbstractSAML2AttributeTrans
import net.shibboleth.idp.saml.attribute.transcoding.SAMLEncoderSupport;
import net.shibboleth.utilities.java.support.codec.Base64Support;
import net.shibboleth.utilities.java.support.codec.DecodingException;
+import net.shibboleth.utilities.java.support.codec.EncodingException;
import org.opensaml.core.xml.XMLObject;
import org.opensaml.profile.context.ProfileRequestContext;
@@ -59,8 +60,12 @@ public class SAML2ByteAttributeTranscoder extends AbstractSAML2AttributeTranscod
final Boolean encodeType = rule.getOrDefault(PROP_ENCODE_TYPE, Boolean.class, Boolean.TRUE);
- return SAMLEncoderSupport.encodeByteArrayValue(attribute, AttributeValue.DEFAULT_ELEMENT_NAME, value.getValue(),
- encodeType);
+ try {
+ return SAMLEncoderSupport.encodeByteArrayValue(attribute, AttributeValue.DEFAULT_ELEMENT_NAME,
+ value.getValue(), encodeType);
+ } catch (final EncodingException e) {
+ throw new AttributeEncodingException("Attribtue value could not be encoded",e);
+ }
}
/** {@inheritDoc} */
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
More information about the commits
mailing list