From dfa7489aba2d5bb90e0427f691a4dc6fc8831880 Mon Sep 17 00:00:00 2001 From: Ivan Fernandez Calvo Date: Wed, 31 May 2023 18:55:03 +0200 Subject: [PATCH] [JENKINS-71322] NPE on non existing SAML Attribute (#345) * fix: NPE processing custom attributes * Update src/main/java/org/jenkinsci/plugins/saml/SamlSecurityRealm.java --- .../org/jenkinsci/plugins/saml/SamlSecurityRealm.java | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/jenkinsci/plugins/saml/SamlSecurityRealm.java b/src/main/java/org/jenkinsci/plugins/saml/SamlSecurityRealm.java index 7b7526ed..a2b5fd41 100644 --- a/src/main/java/org/jenkinsci/plugins/saml/SamlSecurityRealm.java +++ b/src/main/java/org/jenkinsci/plugins/saml/SamlSecurityRealm.java @@ -399,9 +399,12 @@ private boolean modifyUserSamlCustomAttributes(User user, SAML2Profile profile) for (AttributeEntry attributeEntry : getSamlCustomAttributes()) { if(attributeEntry instanceof Attribute){ Attribute attr = (Attribute) attributeEntry; - SamlCustomProperty.Attribute item = new SamlCustomProperty.Attribute(attr.getName(),attr.getDisplayName()); - item.setValue(profile.getAttribute(attr.getName()).toString()); - userProperty.getAttributes().add(item); + Object attrValue = profile.getAttribute(attr.getName()); + if (attrValue != null) { + SamlCustomProperty.Attribute item = new SamlCustomProperty.Attribute(attr.getName(),attr.getDisplayName()); + item.setValue(attrValue.toString()); + userProperty.getAttributes().add(item); + } } } try {