Skip to content
Draft
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -78,16 +78,26 @@ public static class AuthenticatorConfig {

private Map<String, String> parameters = new Hashtable<String, String>();

private final Map<String, Map<String, String>> parameterMap;

private List<String> authenticationSkippingUrls = new ArrayList<String>();

private List<String> sessionValidationSkippingUrls = new ArrayList<String>();

private AuthenticatorConfig(String name, int priority, boolean disabled, Map<String,
String> params) {
String> params, Map<String, Map<String, String>> paramMap) {
Comment thread
sahandilshan marked this conversation as resolved.
this.name = name;
this.priority = priority;
this.disabled = disabled;
this.parameters = params;

// Make sure that outer map and inner maps are unmodifiable.
Map<String, Map<String, String>> unmodifiableParamMap = new HashMap<>();
for (Map.Entry<String, Map<String, String>> entry : paramMap.entrySet()) {
unmodifiableParamMap.put(entry.getKey(),
Collections.unmodifiableMap(new HashMap<>(entry.getValue())));
}
this.parameterMap = Collections.unmodifiableMap(unmodifiableParamMap);
Comment thread
sahandilshan marked this conversation as resolved.
}

public String getName() {
Expand All @@ -106,6 +116,14 @@ public Map<String, String> getParameters() {
return parameters;
}

public Map<String, Map<String, String>> getParameterMap() {
return parameterMap;
}

public Map<String, String> getConfigFromParameterMap(String configName) {
return parameterMap.get(configName);
}

public void addAuthenticationSkippingUrl(String url) {
this.authenticationSkippingUrls.add(url);
}
Expand Down Expand Up @@ -208,10 +226,36 @@ private AuthenticatorConfig processAuthenticatorElement(OMElement authenticatorE
}

// read the config parameters
Map<String, String> parameterMap = new Hashtable<String, String>();
Map<String, String> parameterMap = new Hashtable<>();
Map<String, Map<String, String>> nestedParameterMap = new HashMap<>();

for(Iterator configElemItr = authenticatorElem.getChildrenWithLocalName(ELEM_CONFIG);
configElemItr.hasNext();){
OMElement configElement = (OMElement)configElemItr.next();

// Only process configs that have an explicit name attribute.
OMAttribute configNameAttr = configElement.getAttribute(new QName(ATTR_NAME));
if(configNameAttr == null){

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Formatting issue

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It unclear what are we trying to achieve here.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently we can have define as below

<Config>
        <Parameter name="name01">value01</Parameter>
        <Parameter name="name02">value02</Parameter>
</Config>

With this new config we are providing the support to define named config along with the previous support. so now we can have something like this

<Config>
        <Parameter name="name01">value01</Parameter>
        <Parameter name="name02">value02</Parameter>
</Config>

<Config name="configName">
        <Parameter name="name01">value01</Parameter>
        <Parameter name="name02">value02</Parameter>
</Config>

// Skip configs without name attribute - process parameters for flat map only.
for(Iterator paramIterator = configElement.getChildrenWithLocalName(ELEM_PARAMETER);
Comment thread
sahandilshan marked this conversation as resolved.
Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we avoid iterating the elements twice?

paramIterator.hasNext();){
OMElement paramElem = (OMElement)paramIterator.next();
OMAttribute paramNameAttr = paramElem.getAttribute(new QName(ATTR_NAME));
if(paramNameAttr == null){
Comment thread
sahandilshan marked this conversation as resolved.
Outdated
log.warn("An Authenticator Parameter should have a name attribute. Skipping the parameter.");
continue;
}
// Add to flat map for backward compatibility.
parameterMap.put(paramNameAttr.getAttributeValue(), paramElem.getText());
}
continue;
}

String configName = configNameAttr.getAttributeValue();

// Create a map for this config's parameters.
Map<String, String> configParametersMap = new HashMap<>();

for(Iterator paramIterator = configElement.getChildrenWithLocalName(ELEM_PARAMETER);
paramIterator.hasNext();){
OMElement paramElem = (OMElement)paramIterator.next();
Expand All @@ -220,12 +264,22 @@ private AuthenticatorConfig processAuthenticatorElement(OMElement authenticatorE
log.warn("An Authenticator Parameter should have a name attribute. Skipping the parameter.");
continue;
}
parameterMap.put(paramNameAttr.getAttributeValue(), paramElem.getText());
String paramName = paramNameAttr.getAttributeValue();
String paramValue = paramElem.getText();

// Add to both the flat map (for backward compatibility) and the nested map.
parameterMap.put(paramName, paramValue);
Comment thread
sahandilshan marked this conversation as resolved.
configParametersMap.put(paramName, paramValue);
}

// Add the config parameters to the nested parameterMap if it has any parameters.
if(!configParametersMap.isEmpty()){
Comment thread
sahandilshan marked this conversation as resolved.
Outdated
nestedParameterMap.put(configName, configParametersMap);
}
}

AuthenticatorConfig authenticatorConfig = new AuthenticatorConfig(authenticatorName,
priority, disabled, parameterMap);
priority, disabled, parameterMap, nestedParameterMap);

// read authentication skipping urls
for(Iterator configElemItr = authenticatorElem.getChildrenWithLocalName(ELEM_SKIP_AUTHENTICATION);
Expand Down