Skip to content

Commit

Permalink
SHIBUI-1788
Browse files Browse the repository at this point in the history
Fixes for lists in custom attribute definitions showing up on the
relying party override config in metadata
  • Loading branch information
chasegawa committed Jun 15, 2021
1 parent efcf415 commit 222a3db
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class JsonSchemaBuilderService {
[title : it['displayName'],
description: it['helpText'],
type : it['displayType'],
examples : it['defaultValues']]
examples : it['examples']]
}
properties[(String) it['name']] = property
}
Expand All @@ -59,7 +59,7 @@ class JsonSchemaBuilderService {
def items = [type : 'string',
minLength: 1, // TODO: should this be configurable?
maxLength: 255] //TODO: or this?
items.examples = it['defaultValues']
items.examples = it['examples']

definition['items'] = items
json[(String) it['name']] = definition
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,24 @@
@ConfigurationProperties(prefix = "custom")
public class CustomPropertiesConfiguration implements ApplicationListener<CustomEntityAttributeDefinitionChangeEvent> {
private List<? extends Map<String, String>> attributes = new ArrayList<>();

private CustomEntityAttributesDefinitionService ceadService;

private HashMap<String, IRelyingPartyOverrideProperty> overrides = new HashMap<>();

private List<RelyingPartyOverrideProperty> overridesFromConfigFile = new ArrayList<>();

private void buildRelyingPartyOverrides() {
// Start over with a clean map and get the CustomEntityAttributesDefinitions from the DB
overrides = new HashMap<>();
ceadService.getAllDefinitions().forEach(def -> overrides.put(def.getName(), def));

// We only want to add to an override from the config file if the incoming override (by name) isn't already in
ceadService.getAllDefinitions().forEach(def -> {
def.updateExamplesList(); // totally non-ooo, but @PostLoad wasn't working and JPA/Hibernate is doing some reflection crap
overrides.put(def.getName(), def);
});

// We only want to add to an override from the config file if the incoming override (by name) isn't already in
// the list of overrides (ie DB > file config)
for(RelyingPartyOverrideProperty rpop : this.overridesFromConfigFile) {
for (RelyingPartyOverrideProperty rpop : this.overridesFromConfigFile) {
if (!this.overrides.containsKey(rpop.getName())) {
this.overrides.put(rpop.getName(), rpop);
}
Expand All @@ -44,10 +47,10 @@ private void buildRelyingPartyOverrides() {

public List<? extends Map<String, String>> getAttributes() {
return attributes;
}
}

public List<IRelyingPartyOverrideProperty> getOverrides() {
return new ArrayList<>(overrides.values());
return new ArrayList<>(overrides.values());
}

/**
Expand All @@ -56,9 +59,9 @@ public List<IRelyingPartyOverrideProperty> getOverrides() {
*/
@Override
public void onApplicationEvent(CustomEntityAttributeDefinitionChangeEvent arg0) {
buildRelyingPartyOverrides();
buildRelyingPartyOverrides();
}

@PostConstruct
public void postConstruct() {
// Make sure we have the right data
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,11 @@
import javax.persistence.Column;
import javax.persistence.ElementCollection;
import javax.persistence.Entity;
import javax.persistence.EntityListeners;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.PostLoad;
import javax.persistence.Transient;

import org.hibernate.annotations.Fetch;
import org.hibernate.annotations.FetchMode;
Expand Down Expand Up @@ -41,6 +44,9 @@ public class CustomEntityAttributeDefinition implements IRelyingPartyOverridePro
@Column(name = "display_name", nullable = true)
String displayName;

@Transient
Set<String> examples;

@Column(name = "help_text", nullable = true)
String helpText;

Expand Down Expand Up @@ -78,12 +84,12 @@ public String getDisplayName() {
public String getDisplayType() {
return attributeType.name().toLowerCase();
}

@Override
public Boolean getFromConfigFile() {
return Boolean.FALSE;
}

@Override
public void setDefaultValues(Set<String> defaultValues) {
// This is here to comply with the interface only and should not be used to change the set of values in this implementation
Expand All @@ -92,5 +98,9 @@ public void setDefaultValues(Set<String> defaultValues) {
@Override
public void setDisplayType(String displayType) {
// This is here to comply with the interface only and should not be used to change the value in this implementation
}
}

public void updateExamplesList() {
examples = customAttrListDefinitions;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,13 @@ public class RelyingPartyOverrideProperty implements IRelyingPartyOverrideProper
private Set<String> defaultValues;
private String displayName;
private String displayType;
private Set<String> examples;
private String helpText;
private String invert;
private String name;
private String persistType;
private String persistValue;

@Override
public Boolean getFromConfigFile() {
return Boolean.TRUE;
Expand All @@ -39,6 +40,10 @@ public CustomAttributeType getAttributeType() {
default:
return CustomAttributeType.valueOf(displayType.toUpperCase());
}

}

public void setDefaultValues(Set<String> defaults) {
defaultValues = defaults;
examples = defaults;
}
}
4 changes: 2 additions & 2 deletions backend/src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ custom:
displayName: label.nameid-format-to-send
displayType: set
helpText: tooltip.nameid-format
examples:
defaultValues:
- urn:oasis:names:tc:SAML:1.1:nameid-format:unspecified
- urn:oasis:names:tc:SAML:1.1:nameid-format:emailAddress
- urn:oasis:names:tc:SAML:2.0:nameid-format:persistent
Expand All @@ -129,7 +129,7 @@ custom:
displayName: label.authentication-methods-to-use
displayType: set
helpText: tooltip.authentication-methods-to-use
examples:
defaultValues:
- https://refeds.org/profile/mfa
- urn:oasis:names:tc:SAML:2.0:ac:classes:TimeSyncToken
- urn:oasis:names:tc:SAML:2.0:ac:classes:PasswordProtectedTransport
Expand Down

0 comments on commit 222a3db

Please sign in to comment.