summaryrefslogtreecommitdiff
path: root/eaaf_modules
diff options
context:
space:
mode:
authorThomas Lenz <thomas.lenz@egiz.gv.at>2020-06-10 13:39:57 +0200
committerThomas Lenz <thomas.lenz@egiz.gv.at>2020-06-10 13:39:57 +0200
commitc2d6fbd70a2a79396286eb3c3fc7101ff9bfd040 (patch)
tree07271299aa263aee6a60bed4336160bdf0572620 /eaaf_modules
parent4e4002c7e982218649f10349e634c17770d603d4 (diff)
downloadEAAF-Components-c2d6fbd70a2a79396286eb3c3fc7101ff9bfd040.tar.gz
EAAF-Components-c2d6fbd70a2a79396286eb3c3fc7101ff9bfd040.tar.bz2
EAAF-Components-c2d6fbd70a2a79396286eb3c3fc7101ff9bfd040.zip
Add new AttributeBuilder registration
Diffstat (limited to 'eaaf_modules')
-rw-r--r--eaaf_modules/eaaf_module_pvp2_core/src/main/java/at/gv/egiz/eaaf/modules/pvp2/impl/builder/PvpAttributeBuilder.java73
1 files changed, 14 insertions, 59 deletions
diff --git a/eaaf_modules/eaaf_module_pvp2_core/src/main/java/at/gv/egiz/eaaf/modules/pvp2/impl/builder/PvpAttributeBuilder.java b/eaaf_modules/eaaf_module_pvp2_core/src/main/java/at/gv/egiz/eaaf/modules/pvp2/impl/builder/PvpAttributeBuilder.java
index 92e75e17..e8c06dd6 100644
--- a/eaaf_modules/eaaf_module_pvp2_core/src/main/java/at/gv/egiz/eaaf/modules/pvp2/impl/builder/PvpAttributeBuilder.java
+++ b/eaaf_modules/eaaf_module_pvp2_core/src/main/java/at/gv/egiz/eaaf/modules/pvp2/impl/builder/PvpAttributeBuilder.java
@@ -21,10 +21,11 @@ package at.gv.egiz.eaaf.modules.pvp2.impl.builder;
import java.util.ArrayList;
import java.util.Collection;
-import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
-import java.util.ServiceLoader;
+
+import org.opensaml.saml.saml2.core.Attribute;
+import org.opensaml.saml.saml2.metadata.RequestedAttribute;
import at.gv.egiz.eaaf.core.api.idp.IAttributeBuilder;
import at.gv.egiz.eaaf.core.api.idp.IAttributeGenerator;
@@ -33,64 +34,17 @@ import at.gv.egiz.eaaf.core.api.idp.ISpConfiguration;
import at.gv.egiz.eaaf.core.exceptions.AttributeBuilderException;
import at.gv.egiz.eaaf.core.exceptions.InvalidDateFormatAttributeException;
import at.gv.egiz.eaaf.core.exceptions.UnavailableAttributeException;
+import at.gv.egiz.eaaf.core.impl.idp.builder.AttributeBuilderRegistration;
import at.gv.egiz.eaaf.core.impl.idp.builder.attributes.PvpMetadata;
import at.gv.egiz.eaaf.modules.pvp2.exception.InvalidDateFormatException;
import at.gv.egiz.eaaf.modules.pvp2.exception.Pvp2Exception;
import at.gv.egiz.eaaf.modules.pvp2.impl.utils.Saml2Utils;
+import lombok.extern.slf4j.Slf4j;
-import org.opensaml.saml.saml2.core.Attribute;
-import org.opensaml.saml.saml2.metadata.RequestedAttribute;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
+@Slf4j
public class PvpAttributeBuilder {
- private static final Logger log = LoggerFactory.getLogger(PvpAttributeBuilder.class);
-
private static IAttributeGenerator<Attribute> generator = new SamlAttributeGenerator();
- private static HashMap<String, IAttributeBuilder> builders;
-
- private static ServiceLoader<IAttributeBuilder> attributBuilderLoader =
- ServiceLoader.load(IAttributeBuilder.class);
-
- private static void addBuilder(final IAttributeBuilder builder) {
- builders.put(builder.getName(), builder);
- }
-
- static {
- builders = new HashMap<>();
-
- log.info("Loading protocol attribut-builder modules:");
- if (attributBuilderLoader != null) {
- final Iterator<IAttributeBuilder> moduleLoaderInterator = attributBuilderLoader.iterator();
- while (moduleLoaderInterator.hasNext()) {
- try {
- final IAttributeBuilder modul = moduleLoaderInterator.next();
- log.info("Loading attribut-builder Modul Information: " + modul.getName());
- addBuilder(modul);
-
- } catch (final Throwable e) {
- log.error("Check configuration! " + "Some attribute-builder modul"
- + " is not a valid IAttributeBuilder", e);
- }
- }
- }
-
- log.info("Loading attribute-builder modules done");
-
- }
-
- /**
- * Get a specific attribute builder.
- *
- * @param name Attribute-builder friendly name
- *
- * @return Attribute-builder with this name or null if builder does not exists
- */
- public static IAttributeBuilder getAttributeBuilder(final String name) {
- return builders.get(name);
-
- }
/**
* Build an SAML2 attribute.
@@ -102,8 +56,9 @@ public class PvpAttributeBuilder {
public static Attribute buildAttribute(final String name, final String value) {
log.warn("Attribute value: {} is NOT injected", value);
- if (builders.containsKey(name)) {
- return builders.get(name).buildEmpty(generator);
+ if (AttributeBuilderRegistration.containsBuilder(name)) {
+ return AttributeBuilderRegistration.getAttributeBuilder(name).buildEmpty(generator);
+
}
return null;
}
@@ -120,9 +75,9 @@ public class PvpAttributeBuilder {
*/
public static Attribute buildAttribute(final String name, final ISpConfiguration oaParam,
final IAuthData authData) throws Pvp2Exception, AttributeBuilderException {
- if (builders.containsKey(name)) {
+ if (AttributeBuilderRegistration.containsBuilder(name)) {
try {
- return builders.get(name).build(oaParam, authData, generator);
+ return AttributeBuilderRegistration.getAttributeBuilder(name).build(oaParam, authData, generator);
} catch (final AttributeBuilderException e) {
if (e instanceof UnavailableAttributeException) {
throw e;
@@ -146,8 +101,8 @@ public class PvpAttributeBuilder {
* @return SAML2 attribute
*/
public static Attribute buildEmptyAttribute(final String name) {
- if (builders.containsKey(name)) {
- return builders.get(name).buildEmpty(generator);
+ if (AttributeBuilderRegistration.containsBuilder(name)) {
+ return AttributeBuilderRegistration.getAttributeBuilder(name).buildEmpty(generator);
}
return null;
}
@@ -159,7 +114,7 @@ public class PvpAttributeBuilder {
*/
public static List<Attribute> buildSupportedEmptyAttributes() {
final List<Attribute> attributes = new ArrayList<>();
- final Iterator<IAttributeBuilder> builderIt = builders.values().iterator();
+ final Iterator<IAttributeBuilder> builderIt = AttributeBuilderRegistration.getAllRegistratedBuilder();
while (builderIt.hasNext()) {
final IAttributeBuilder builder = builderIt.next();
if (builder.getClass().isAnnotationPresent(PvpMetadata.class)) {