Skip to content

Commit

Permalink
[JENKINS-71322] NPE on non existing SAML Attribute (#345)
Browse files Browse the repository at this point in the history
* fix: NPE processing custom attributes

* Update src/main/java/org/jenkinsci/plugins/saml/SamlSecurityRealm.java
  • Loading branch information
kuisathaverat committed May 31, 2023
1 parent 51bd50a commit dfa7489
Showing 1 changed file with 6 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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());

Check warning on line 402 in src/main/java/org/jenkinsci/plugins/saml/SamlSecurityRealm.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered line

Line 402 is not covered by tests
if (attrValue != null) {

Check warning on line 403 in src/main/java/org/jenkinsci/plugins/saml/SamlSecurityRealm.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Partially covered line

Line 403 is only partially covered, 2 branches are missing
SamlCustomProperty.Attribute item = new SamlCustomProperty.Attribute(attr.getName(),attr.getDisplayName());
item.setValue(attrValue.toString());

Check warning on line 405 in src/main/java/org/jenkinsci/plugins/saml/SamlSecurityRealm.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered line

Line 405 is not covered by tests
userProperty.getAttributes().add(item);
}
}
}

Check warning on line 409 in src/main/java/org/jenkinsci/plugins/saml/SamlSecurityRealm.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered line

Line 409 is not covered by tests
try {
Expand Down

0 comments on commit dfa7489

Please sign in to comment.