[java-identity-provider] branch main updated: IDP-2240 Improve adding attributes to views
Rod Widdowson
rdw at steadingsoftware.com
Mon Feb 12 11:44:01 UTC 2024
This is an automated email from the git hooks/post-receive script.
rdw pushed a commit to branch main
in repository java-identity-provider.
View the commit online:
http://git.shibboleth.net/view/?p=java-identity-provider.git;a=commit;h=184b0b117cc35fb15d69e4d927151cc148f44ab7
The following commit(s) were added to refs/heads/main by this push:
new 184b0b117 IDP-2240 Improve adding attributes to views
184b0b117 is described below
commit 184b0b117cc35fb15d69e4d927151cc148f44ab7
Author: Rod Widdowson <rdw at steadingsoftware.com>
AuthorDate: Mon Feb 12 11:32:40 2024 +0000
IDP-2240 Improve adding attributes to views
https://shibboleth.atlassian.net/browse/IDP-2240
The String helpers are now called GetFirstXXXAttributeDisplayValue (and return @Nonnull)
We also have GetFirstXXXAttributeValue() return an IdPAttributeValue and are @Nullable)
---
.../shibboleth/idp/ui/helper/AttributeHelper.java | 130 +++++++++++++--------
.../net/shibboleth/idp/ui/AttributeHelperTest.java | 12 +-
2 files changed, 86 insertions(+), 56 deletions(-)
diff --git a/idp-ui/src/main/java/net/shibboleth/idp/ui/helper/AttributeHelper.java b/idp-ui/src/main/java/net/shibboleth/idp/ui/helper/AttributeHelper.java
index 581794365..b72c290e5 100644
--- a/idp-ui/src/main/java/net/shibboleth/idp/ui/helper/AttributeHelper.java
+++ b/idp-ui/src/main/java/net/shibboleth/idp/ui/helper/AttributeHelper.java
@@ -37,7 +37,7 @@ public final class AttributeHelper extends AbstractIdentifiableInitializableComp
/** How to get the AttributeContext we are looking at. */
@SuppressWarnings("null")
- @Nonnull private Function<ProfileRequestContext,AttributeContext> attributeContextStrategy =
+ @Nonnull private Function<ProfileRequestContext,AttributeContext> attributeContextStrategy =
new ChildContextLookup<>(AttributeContext.class).compose(new ChildContextLookup<>(RelyingPartyContext.class));
/** Logger. */
@@ -51,89 +51,119 @@ public final class AttributeHelper extends AbstractIdentifiableInitializableComp
attributeContextStrategy = Constraint.isNotNull(strategy, "Injected strategy must not be null");
}
- /** Return the first (filtered) attribute Value from the attribute of that name.
- * @param prc the ProfileRequestContext
- * @param attributeName the attribute name to look up
- * @param defaultValue what to return if nothing found.
- * @return the default value or the attribute value
+ /** Return the first (filtered) attribute Value from the attribute of that name as an {@link IdPAttributeValue}.
+ * @param prc The ProfileRequestContext
+ * @param attributeName The attribute name to look up
+ * @return The attribute value or null
*/
- @Nonnull public String getFirstAttributeValue(final ProfileRequestContext prc,
- final @Nonnull @NotEmpty String attributeName,
- final @Nonnull String defaultValue) {
+ @Nullable public IdPAttributeValue getFirstAttributeValue(final ProfileRequestContext prc,
+ final @Nonnull @NotEmpty String attributeName) {
if (prc == null) {
- log.error("Provided ProfileRequestContext was null, returning {}", defaultValue);
- return defaultValue;
+ log.error("Provided ProfileRequestContext was null");
+ return null;
}
- Constraint.isNotNull(defaultValue, "Default value must be non-null");
Constraint.isNotNull(attributeName, "Attribute Name must be non-niull");
final AttributeContext context = attributeContextStrategy.apply(prc);
if (context == null) {
- log.error("Attribute Context could not be located, returning {}", defaultValue);
- return defaultValue;
+ log.error("Attribute Context could not be located");
+ return null;
+ }
+ return getFirstValue(context.getIdPAttributes().get(attributeName));
+ }
+
+ /** Return the first (filtered) attribute Value from the attribute of that name as a Display String.
+ * @param prc The ProfileRequestContext
+ * @param attributeName The attribute name to look up
+ * @param defaultValue What to return if nothing found.
+ * @return The default value or the attribute value
+ */
+ @Nonnull public String getFirstAttributeDisplayValue(final ProfileRequestContext prc,
+ final @Nonnull @NotEmpty String attributeName,
+ final @Nonnull String defaultValue) {
+ Constraint.isNotNull(defaultValue, "Default value must be non-null");
+ final IdPAttributeValue value = getFirstAttributeValue(prc, attributeName);
+ if (value == null) {
+ log.error("No Attribute Value found, returning {}", defaultValue);
+ return defaultValue;
}
- return getFirstValue(context.getIdPAttributes().get(attributeName), defaultValue);
+ return value.getDisplayValue();
}
- /** Return the first (filtered) attribute Value from the attribute of that name.
- * @param prc the ProfileRequestContext
- * @param attributeName the attribute name to look up
- * @return the attribute value or ""
+ /** Return the first (filtered) attribute Value from the attribute of that name as a Display String.
+ * @param prc The ProfileRequestContext
+ * @param attributeName The attribute name to look up
+ * @return The attribute value or ""
*/
- @Nonnull public String getFirstAttributeValue(final ProfileRequestContext prc,
- final @Nonnull @NotEmpty String attributeName) {
- return getFirstAttributeValue(prc, attributeName, "");
+ @Nonnull public String getFirstAttributeDisplayValue(final ProfileRequestContext prc,
+ final @Nonnull @NotEmpty String attributeName) {
+ return getFirstAttributeDisplayValue(prc, attributeName, "");
}
- /** Return the first (unfiltered) attribute Value from the attribute of that name.
- * @param prc the ProfileRequestContext
- * @param attributeName the attribute name to look up
- * @param defaultValue what to return if nothing found.
- * @return the default value or the attribute value
+ /** Return the first (unfiltered) attribute Value from the attribute of that name as an {@link IdPAttributeValue}.
+ * @param prc The ProfileRequestContext
+ * @param attributeName The attribute name to look up
+ * @return The attribute value or null
*/
- @Nonnull public String getFirstUnfilteredAttributeValue(final ProfileRequestContext prc,
- final @Nonnull @NotEmpty String attributeName,
- final @Nonnull String defaultValue) {
+ @Nullable public IdPAttributeValue getFirstUnfilteredAttributeValue(final ProfileRequestContext prc,
+ final @Nonnull @NotEmpty String attributeName) {
if (prc == null) {
- log.error("Provided ProfileRequestContext was null, returning {}", defaultValue);
- return defaultValue;
+ log.error("Provided ProfileRequestContext was null");
+ return null;
}
- Constraint.isNotNull(defaultValue, "Default value must be non-null");
Constraint.isNotNull(attributeName, "Attribute Name must be non-niull");
final AttributeContext context = attributeContextStrategy.apply(prc);
if (context == null) {
- log.error("Attribute Context could not be located, returning {}", defaultValue);
+ log.error("Attribute Context could not be located");
+ return null;
+ }
+ return getFirstValue(context.getUnfilteredIdPAttributes().get(attributeName));
+ }
+
+
+ /** Return the first (unfiltered) attribute Value from the attribute of that name as a Display String
+ * @param prc The ProfileRequestContext
+ * @param attributeName The attribute name to look up
+ * @param defaultValue What to return if nothing found.
+ * @return The default value or the attribute value
+ */
+ @Nonnull public String getFirstUnfilteredAttributeDisplayValue(final ProfileRequestContext prc,
+ final @Nonnull @NotEmpty String attributeName,
+ final @Nonnull String defaultValue) {
+
+ Constraint.isNotNull(defaultValue, "Default value must be non-null");
+ final IdPAttributeValue value = getFirstUnfilteredAttributeValue(prc, attributeName);
+ if (value == null) {
+ log.error("No Attribute Value found, returning {}", defaultValue);
return defaultValue;
}
- return getFirstValue(context.getUnfilteredIdPAttributes().get(attributeName), defaultValue);
+ return value.getDisplayValue();
}
- /** Return the first (unfiltered) attribute Value from the attribute of that name.
- * @param prc the ProfileRequestContext
- * @param attributeName the attribute name to look up
- * @param defaultValue what to return if nothing found.
- * @return the attribute value or ""
+ /** Return the first (unfiltered) attribute Value from the attribute of that name as a Display String.
+ * @param prc The ProfileRequestContext
+ * @param attributeName The attribute name to look up
+ * @return The attribute value or ""
*/
- @Nonnull public String getFirstUnfilteredAttributeValue(final ProfileRequestContext prc,
+ @Nonnull public String getFirstUnfilteredAttributeDisplayValue(final ProfileRequestContext prc,
@Nonnull @NotEmpty final String attributeName) {
- return getFirstUnfilteredAttributeValue(prc, attributeName, "");
+ return getFirstUnfilteredAttributeDisplayValue(prc, attributeName, "");
}
/** Helper method to get the first attribute name from the attribute.
* @param Attribute the Attribute or null if there wasn't one
- * @param defaultValue the value to return if no values are found
- * @return defaultValue or the display string of the first attribute
+ * @return the first attribute valkue or null
*/
- @Nonnull private String getFirstValue(final @Nullable IdPAttribute attribute, @Nonnull String defaultValue) {
+ @Nullable private IdPAttributeValue getFirstValue(final @Nullable IdPAttribute attribute) {
if (attribute == null) {
- log.info("No attribute found, returning {}", defaultValue);
- return defaultValue;
+ log.debug("No attribute found");
+ return null;
}
List<IdPAttributeValue> values = attribute.getValues();
if (values == null|| values.size() < 1) {
- log.info("No attribute values associated with {}, returning {}", attribute.getId(), defaultValue);
- return defaultValue;
+ log.info("No attribute values associated with {}", attribute.getId());
+ return null;
}
- return values.get(0).getDisplayValue();
+ return values.get(0);
}
}
diff --git a/idp-ui/src/test/java/net/shibboleth/idp/ui/AttributeHelperTest.java b/idp-ui/src/test/java/net/shibboleth/idp/ui/AttributeHelperTest.java
index 377b2c63b..b03d1c311 100644
--- a/idp-ui/src/test/java/net/shibboleth/idp/ui/AttributeHelperTest.java
+++ b/idp-ui/src/test/java/net/shibboleth/idp/ui/AttributeHelperTest.java
@@ -27,13 +27,13 @@ public class AttributeHelperTest {
ac.setUnfilteredIdPAttributes(CollectionSupport.arrayAsList(a1, a2));
ac.setIdPAttributes(CollectionSupport.singleton(a1));
- assertEquals(ah.getFirstAttributeValue(prc, "A1"), "A1Value1");
- assertEquals(ah.getFirstAttributeValue(prc, "A2"), "");
- assertEquals(ah.getFirstAttributeValue(prc, "A3", "Nothing"), "Nothing");
+ assertEquals(ah.getFirstAttributeDisplayValue(prc, "A1"), "A1Value1");
+ assertEquals(ah.getFirstAttributeDisplayValue(prc, "A2"), "");
+ assertEquals(ah.getFirstAttributeDisplayValue(prc, "A3", "Nothing"), "Nothing");
- assertEquals(ah.getFirstUnfilteredAttributeValue(prc, "A1"), "A1Value1");
- assertEquals(ah.getFirstUnfilteredAttributeValue(prc, "A2"), "A2Value1");
- assertEquals(ah.getFirstAttributeValue(prc, "A3"), "");
+ assertEquals(ah.getFirstUnfilteredAttributeDisplayValue(prc, "A1"), "A1Value1");
+ assertEquals(ah.getFirstUnfilteredAttributeDisplayValue(prc, "A2"), "A2Value1");
+ assertEquals(ah.getFirstAttributeDisplayValue(prc, "A3"), "");
}
}
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
More information about the commits
mailing list