aboutsummaryrefslogtreecommitdiff
path: root/id
diff options
context:
space:
mode:
authorGerwin Gsenger <g.gsenger@datentechnik-innovation.at>2015-01-28 10:31:33 +0100
committerGerwin Gsenger <g.gsenger@datentechnik-innovation.at>2015-01-28 10:31:33 +0100
commitb187c1470167335ad6142b9b8b730e106348a8f8 (patch)
treee9a39b378596f796c9559d105318d82bd39cee64 /id
parent92a879913faceb6f8392048768953846cf7a4e86 (diff)
downloadmoa-id-spss-b187c1470167335ad6142b9b8b730e106348a8f8.tar.gz
moa-id-spss-b187c1470167335ad6142b9b8b730e106348a8f8.tar.bz2
moa-id-spss-b187c1470167335ad6142b9b8b730e106348a8f8.zip
implement ModuleRegistry, implement standard moaid process, start ModuleRegistry at moa-id startup, fix typo in package name
Diffstat (limited to 'id')
-rw-r--r--id/server/auth/src/main/webapp/WEB-INF/applicationContext.xml2
-rw-r--r--id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/moduls/moduleregistration/AuthModule.java (renamed from id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/moduls/modulregistration/AuthModule.java)4
-rw-r--r--id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/moduls/moduleregistration/AuthModuleImpl.java23
-rw-r--r--id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/moduls/moduleregistration/ModuleRegistration.java140
-rw-r--r--id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/moduls/modulregistration/ModuleRegistration.java29
-rw-r--r--id/server/idserverlib/src/main/resources/META-INF/services/at.gv.egovernment.moa.id.moduls.modulregistration.AuthModule2
6 files changed, 168 insertions, 32 deletions
diff --git a/id/server/auth/src/main/webapp/WEB-INF/applicationContext.xml b/id/server/auth/src/main/webapp/WEB-INF/applicationContext.xml
index 0f9f05baa..a4a06d24a 100644
--- a/id/server/auth/src/main/webapp/WEB-INF/applicationContext.xml
+++ b/id/server/auth/src/main/webapp/WEB-INF/applicationContext.xml
@@ -27,5 +27,5 @@
</task:scheduled-tasks>
<bean id="authenticationManager" class="at.gv.egovernment.moa.id.moduls.AuthenticationManager" factory-method="getInstance" />
-
+ <bean id="moduleRegistration" class="at.gv.egovernment.moa.id.moduls.modulregistration.ModuleRegistration" factory-method="getInstance" />
</beans>
diff --git a/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/moduls/modulregistration/AuthModule.java b/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/moduls/moduleregistration/AuthModule.java
index 6ee18c0ab..35273cd2b 100644
--- a/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/moduls/modulregistration/AuthModule.java
+++ b/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/moduls/moduleregistration/AuthModule.java
@@ -1,4 +1,4 @@
-package at.gv.egovernment.moa.id.moduls.modulregistration;
+package at.gv.egovernment.moa.id.moduls.moduleregistration;
import com.datentechnik.process_engine.api.ExecutionContext;
import com.datentechnik.process_engine.model.ProcessDefinition;
@@ -18,7 +18,7 @@ public interface AuthModule {
int getPriority();
/**
- * Checks if the module has a process, which is able to do an authentication
+ * Checks if the module has a process, which is able to perform an authentication
* with the given {@link ExecutionContext}.
*
* @param context
diff --git a/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/moduls/moduleregistration/AuthModuleImpl.java b/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/moduls/moduleregistration/AuthModuleImpl.java
new file mode 100644
index 000000000..cbe5c5932
--- /dev/null
+++ b/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/moduls/moduleregistration/AuthModuleImpl.java
@@ -0,0 +1,23 @@
+package at.gv.egovernment.moa.id.moduls.moduleregistration;
+
+import com.datentechnik.process_engine.api.ExecutionContext;
+
+public class AuthModuleImpl implements AuthModule {
+
+ @Override
+ public int getPriority() {
+ // neutral priority between Integer.MIN_VALUE and Integer.MAX_VALUE
+ return 0;
+ }
+
+ @Override
+ public String selectProcess(ExecutionContext context) {
+ return context.get("ccc") == null ? "DefaultAuthentication" : null;
+ }
+
+ @Override
+ public String[] getProcessDefinitions() {
+ return new String[] { "DefaultAuthentication" };
+ }
+
+}
diff --git a/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/moduls/moduleregistration/ModuleRegistration.java b/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/moduls/moduleregistration/ModuleRegistration.java
new file mode 100644
index 000000000..522e5c7eb
--- /dev/null
+++ b/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/moduls/moduleregistration/ModuleRegistration.java
@@ -0,0 +1,140 @@
+package at.gv.egovernment.moa.id.moduls.moduleregistration;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.ServiceLoader;
+
+import javax.annotation.PostConstruct;
+
+import org.apache.commons.lang3.StringUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.context.ApplicationContext;
+import org.springframework.core.io.Resource;
+
+import com.datentechnik.process_engine.ProcessEngine;
+import com.datentechnik.process_engine.api.ExecutionContext;
+
+/**
+ * This class handles registering modules. The modules are detected either with
+ * the ServiceLoader mechanism or via Spring. All detected modules are ranked
+ * according to their priority.
+ */
+public class ModuleRegistration {
+
+ private static ModuleRegistration instance = new ModuleRegistration();
+
+ private List<AuthModule> orderedModules = new ArrayList<>();
+
+ @Autowired
+ private ApplicationContext ctx;
+
+ @Autowired
+ ProcessEngine processEngine;
+
+ private Logger log = LoggerFactory.getLogger(getClass());
+
+ public static ModuleRegistration getInstance() {
+ return instance;
+ }
+
+ private ModuleRegistration() {
+ }
+
+ @PostConstruct
+ private void init() {
+ // load modules via the ServiceLoader
+ initServiceLoaderModules();
+
+ // load modules via Spring
+ initSpringModules();
+
+ // order modules according to their priority
+ orderModules();
+ }
+
+ /**
+ * Discovers modules which use the ServiceLoader mechanism.
+ */
+ private void initServiceLoaderModules() {
+ log.debug("Discovering modules which use the ServiceLoader mechanism.");
+ ServiceLoader<AuthModule> loader = ServiceLoader.load(AuthModule.class);
+ Iterator<AuthModule> modules = loader.iterator();
+ while (modules.hasNext()) {
+ AuthModule module = modules.next();
+ registerResourceUris(module);
+ orderedModules.add(module);
+ }
+ }
+
+ /**
+ * Discovers modules which use Spring.
+ */
+ private void initSpringModules() {
+ log.debug("Discovering Spring modules.");
+ Map<String, AuthModule> modules = ctx.getBeansOfType(AuthModule.class);
+ for (AuthModule module : modules.values()) {
+ registerResourceUris(module);
+ orderedModules.add(module);
+ }
+ }
+
+ /**
+ * Registers the resource uris for the module.
+ *
+ * @param module
+ * the module.
+ */
+ private void registerResourceUris(AuthModule module) {
+ for (String uri : module.getProcessDefinitions()) {
+ Resource resource = ctx.getResource(uri);
+ if (resource.exists()) {
+ log.debug("Registering process definition resource url: '{}'.", resource);
+ // TODO: register resource with the process engine
+ // processEngine.registerResourceUri(resource);
+ } else {
+ log.info("Resource url: '{}' does NOT exist.", resource);
+ }
+ }
+ }
+
+ /**
+ * Order the modules in descending order according to their priority.
+ */
+ private void orderModules() {
+ Collections.sort(orderedModules, new Comparator<AuthModule>() {
+ @Override
+ public int compare(AuthModule thisAuthModule, AuthModule otherAuthModule) {
+ int thisOrder = thisAuthModule.getPriority();
+ int otherOrder = otherAuthModule.getPriority();
+ return (thisOrder < otherOrder ? -1 : (thisOrder == otherOrder ? 0 : 1));
+ }
+ });
+ log.debug("Modules are ordered in descending order, according to their priority.");
+ }
+
+ /**
+ * Returns the process id of the first process, in the highest ranked
+ * module, which is able to work with the given execution context.
+ *
+ * @param context
+ * the {@link ExecutionContext}.
+ * @return the process id or {@code null}
+ */
+ public String selectProcess(ExecutionContext context) {
+ for (AuthModule module : orderedModules) {
+ String id = module.selectProcess(context);
+ if (StringUtils.isNotEmpty(id)) {
+ log.debug("Process with id '{}' selected, for context '{}'.", id, context);
+ return id;
+ }
+ }
+ log.info("No process is able to handle context '{}'.", context);
+ return null;
+ }
+}
diff --git a/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/moduls/modulregistration/ModuleRegistration.java b/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/moduls/modulregistration/ModuleRegistration.java
deleted file mode 100644
index fc352742d..000000000
--- a/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/moduls/modulregistration/ModuleRegistration.java
+++ /dev/null
@@ -1,29 +0,0 @@
-package at.gv.egovernment.moa.id.moduls.modulregistration;
-
-import com.datentechnik.process_engine.api.ExecutionContext;
-
-public class ModuleRegistration {
-
- private static ModuleRegistration instance;
-
- public static ModuleRegistration getInstance() {
- if (instance == null) {
- instance = new ModuleRegistration();
- }
- return instance;
- }
-
- private ModuleRegistration() {
- initRegistry();
- }
-
- private void initRegistry() {
- // TODO: use ServiceLoader and Spring to find all modules
- }
-
- public String selectProcess(ExecutionContext context) {
- // TODO: implement
- return null;
- }
-
-}
diff --git a/id/server/idserverlib/src/main/resources/META-INF/services/at.gv.egovernment.moa.id.moduls.modulregistration.AuthModule b/id/server/idserverlib/src/main/resources/META-INF/services/at.gv.egovernment.moa.id.moduls.modulregistration.AuthModule
new file mode 100644
index 000000000..0d7e98006
--- /dev/null
+++ b/id/server/idserverlib/src/main/resources/META-INF/services/at.gv.egovernment.moa.id.moduls.modulregistration.AuthModule
@@ -0,0 +1,2 @@
+# The default moaid process
+at.gv.egovernment.moa.id.moduls.modulregistration.AuthModuleImpl \ No newline at end of file