[java-opensaml] branch master updated: Convert "pseudo-enums" into full enums.
Scott Cantor
cantor.2 at osu.edu
Mon Sep 16 20:13:11 EDT 2019
This is an automated email from the git hooks/post-receive script.
scantor pushed a commit to branch master
in repository java-opensaml.
View the commit online:
http://git.shibboleth.net/view/?p=java-opensaml.git;a=commit;h=6d2c855f4ca45814be3b8ffb3bb20ab77795c9b3
The following commit(s) were added to refs/heads/master by this push:
new 6d2c855 Convert "pseudo-enums" into full enums.
6d2c855 is described below
commit 6d2c855f4ca45814be3b8ffb3bb20ab77795c9b3
Author: Scott Cantor <cantor.2 at osu.edu>
AuthorDate: Mon Sep 16 20:10:30 2019 -0400
Convert "pseudo-enums" into full enums.
---
.../AuthnContextComparisonTypeEnumeration.java | 30 ++++++++++++----------
.../metadata/ContactPersonTypeEnumeration.java | 30 +++++++++++-----------
.../impl/RequestedAuthnContextUnmarshaller.java | 18 ++++++-------
.../metadata/impl/ContactPersonUnmarshaller.java | 21 +++++++--------
4 files changed, 49 insertions(+), 50 deletions(-)
diff --git a/opensaml-saml-api/src/main/java/org/opensaml/saml/saml2/core/AuthnContextComparisonTypeEnumeration.java b/opensaml-saml-api/src/main/java/org/opensaml/saml/saml2/core/AuthnContextComparisonTypeEnumeration.java
index 9ef735f..42f85fe 100644
--- a/opensaml-saml-api/src/main/java/org/opensaml/saml/saml2/core/AuthnContextComparisonTypeEnumeration.java
+++ b/opensaml-saml-api/src/main/java/org/opensaml/saml/saml2/core/AuthnContextComparisonTypeEnumeration.java
@@ -17,41 +17,43 @@
package org.opensaml.saml.saml2.core;
+import javax.annotation.Nonnull;
+
+import net.shibboleth.utilities.java.support.annotation.constraint.NotEmpty;
+
/**
- * A type safe enumeration of {@link org.opensaml.saml.saml2.core.RequestedAuthnContext} comparison types.
+ * Enumeration of {@link org.opensaml.saml.saml2.core.RequestedAuthnContext} comparison types.
*/
-public final class AuthnContextComparisonTypeEnumeration {
+public enum AuthnContextComparisonTypeEnumeration {
/** "exact" comparison type. */
- public static final AuthnContextComparisonTypeEnumeration EXACT =
- new AuthnContextComparisonTypeEnumeration("exact");
+ EXACT("exact"),
/** "minimum" comparison type. */
- public static final AuthnContextComparisonTypeEnumeration MINIMUM =
- new AuthnContextComparisonTypeEnumeration("minimum");
+ MINIMUM("minimum"),
/** "maximum" comparison type. */
- public static final AuthnContextComparisonTypeEnumeration MAXIMUM =
- new AuthnContextComparisonTypeEnumeration("maximum");
+ MAXIMUM("maximum"),
/** "better" comparison type. */
- public static final AuthnContextComparisonTypeEnumeration BETTER =
- new AuthnContextComparisonTypeEnumeration("better");
+ BETTER("better");
/** The comparison type string. */
- private String comparisonType;
+ @Nonnull @NotEmpty private String comparisonType;
/**
* Constructor.
*
* @param newComparisonType the comparison type string
*/
- protected AuthnContextComparisonTypeEnumeration(final String newComparisonType) {
- this.comparisonType= newComparisonType;
+ private AuthnContextComparisonTypeEnumeration(@Nonnull @NotEmpty final String newComparisonType) {
+ comparisonType = newComparisonType;
}
/** {@inheritDoc} */
+ @Override
public String toString() {
return comparisonType;
}
-}
+
+}
\ No newline at end of file
diff --git a/opensaml-saml-api/src/main/java/org/opensaml/saml/saml2/metadata/ContactPersonTypeEnumeration.java b/opensaml-saml-api/src/main/java/org/opensaml/saml/saml2/metadata/ContactPersonTypeEnumeration.java
index 385478a..a151aad 100644
--- a/opensaml-saml-api/src/main/java/org/opensaml/saml/saml2/metadata/ContactPersonTypeEnumeration.java
+++ b/opensaml-saml-api/src/main/java/org/opensaml/saml/saml2/metadata/ContactPersonTypeEnumeration.java
@@ -17,45 +17,45 @@
package org.opensaml.saml.saml2.metadata;
+import javax.annotation.Nonnull;
+
+import net.shibboleth.utilities.java.support.annotation.constraint.NotEmpty;
+
/**
* A type safe enumeration of contact types used by {@link org.opensaml.saml.saml2.metadata.ContactPerson}.
*/
-public final class ContactPersonTypeEnumeration {
+public enum ContactPersonTypeEnumeration {
/** "technical" contact type. */
- public static final ContactPersonTypeEnumeration TECHNICAL = new ContactPersonTypeEnumeration("technical");
+ TECHNICAL("technical"),
/** "support" contact type. */
- public static final ContactPersonTypeEnumeration SUPPORT = new ContactPersonTypeEnumeration("support");
+ SUPPORT("support"),
/** "administrative" contact type. */
- public static final ContactPersonTypeEnumeration ADMINISTRATIVE =
- new ContactPersonTypeEnumeration("administrative");
+ ADMINISTRATIVE("administrative"),
/** "billing" contact type. */
- public static final ContactPersonTypeEnumeration BILLING = new ContactPersonTypeEnumeration("billing");
+ BILLING("billing"),
/** "other" contact type. */
- public static final ContactPersonTypeEnumeration OTHER = new ContactPersonTypeEnumeration("other");
+ OTHER("other");
- /** the contact type. */
- private String type;
+ /** The contact type. */
+ @Nonnull @NotEmpty private String type;
/**
* Constructor.
*
* @param providedType the contact type
*/
- protected ContactPersonTypeEnumeration(final String providedType) {
+ private ContactPersonTypeEnumeration(@Nonnull @NotEmpty final String providedType) {
type = providedType;
}
- /**
- * Gets the contact type as a string.
- *
- * @return the contact type
- */
+ /** {@inheritDoc} */
public String toString() {
return type;
}
+
}
\ No newline at end of file
diff --git a/opensaml-saml-impl/src/main/java/org/opensaml/saml/saml2/core/impl/RequestedAuthnContextUnmarshaller.java b/opensaml-saml-impl/src/main/java/org/opensaml/saml/saml2/core/impl/RequestedAuthnContextUnmarshaller.java
index e08c504..038746c 100644
--- a/opensaml-saml-impl/src/main/java/org/opensaml/saml/saml2/core/impl/RequestedAuthnContextUnmarshaller.java
+++ b/opensaml-saml-impl/src/main/java/org/opensaml/saml/saml2/core/impl/RequestedAuthnContextUnmarshaller.java
@@ -55,15 +55,14 @@ public class RequestedAuthnContextUnmarshaller extends AbstractSAMLObjectUnmarsh
if (attribute.getLocalName().equals(RequestedAuthnContext.COMPARISON_ATTRIB_NAME)
&& attribute.getNamespaceURI() == null) {
- if ("exact".equals(attribute.getValue())) {
- rac.setComparison(AuthnContextComparisonTypeEnumeration.EXACT);
- } else if ("minimum".equals(attribute.getValue())) {
- rac.setComparison(AuthnContextComparisonTypeEnumeration.MINIMUM);
- } else if ("maximum".equals(attribute.getValue())) {
- rac.setComparison(AuthnContextComparisonTypeEnumeration.MAXIMUM);
- } else if ("better".equals(attribute.getValue())) {
- rac.setComparison(AuthnContextComparisonTypeEnumeration.BETTER);
- } else {
+ try {
+ if (attribute.getValue() != null) {
+ rac.setComparison(
+ AuthnContextComparisonTypeEnumeration.valueOf(attribute.getValue().toUpperCase()));
+ } else {
+ throw new UnmarshallingException("Saw an empty value for Comparison attribute");
+ }
+ } catch (final IllegalArgumentException e) {
throw new UnmarshallingException("Saw an invalid value for Comparison attribute: "
+ attribute.getValue());
}
@@ -71,4 +70,5 @@ public class RequestedAuthnContextUnmarshaller extends AbstractSAMLObjectUnmarsh
super.processAttribute(samlObject, attribute);
}
}
+
}
\ No newline at end of file
diff --git a/opensaml-saml-impl/src/main/java/org/opensaml/saml/saml2/metadata/impl/ContactPersonUnmarshaller.java b/opensaml-saml-impl/src/main/java/org/opensaml/saml/saml2/metadata/impl/ContactPersonUnmarshaller.java
index 33d705f..4a93b1b 100644
--- a/opensaml-saml-impl/src/main/java/org/opensaml/saml/saml2/metadata/impl/ContactPersonUnmarshaller.java
+++ b/opensaml-saml-impl/src/main/java/org/opensaml/saml/saml2/metadata/impl/ContactPersonUnmarshaller.java
@@ -67,18 +67,15 @@ public class ContactPersonUnmarshaller extends AbstractSAMLObjectUnmarshaller {
if (attribute.getNamespaceURI() == null) {
if (attribute.getLocalName().equals(ContactPerson.CONTACT_TYPE_ATTRIB_NAME)) {
- if (ContactPersonTypeEnumeration.TECHNICAL.toString().equals(attribute.getValue())) {
- person.setType(ContactPersonTypeEnumeration.TECHNICAL);
- } else if (ContactPersonTypeEnumeration.SUPPORT.toString().equals(attribute.getValue())) {
- person.setType(ContactPersonTypeEnumeration.SUPPORT);
- } else if (ContactPersonTypeEnumeration.ADMINISTRATIVE.toString().equals(attribute.getValue())) {
- person.setType(ContactPersonTypeEnumeration.ADMINISTRATIVE);
- } else if (ContactPersonTypeEnumeration.BILLING.toString().equals(attribute.getValue())) {
- person.setType(ContactPersonTypeEnumeration.BILLING);
- } else if (ContactPersonTypeEnumeration.OTHER.toString().equals(attribute.getValue())) {
- person.setType(ContactPersonTypeEnumeration.OTHER);
- } else {
- super.processAttribute(samlObject, attribute);
+ try {
+ if (attribute.getValue() != null) {
+ person.setType(ContactPersonTypeEnumeration.valueOf(attribute.getValue().toUpperCase()));
+ } else {
+ throw new UnmarshallingException("Saw an empty value for contactType attribute");
+ }
+ } catch (final IllegalArgumentException e) {
+ throw new UnmarshallingException("Saw an invalid value for contactType attribute: "
+ + attribute.getValue());
}
} else {
super.processAttribute(samlObject, attribute);
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
More information about the commits
mailing list