[Lada-commits] [PATCH 10 of 13] Added stubs for authentication/authorization

Wald Commits scm-commit at wald.intevation.org
Fri Feb 6 17:57:44 CET 2015


# HG changeset patch
# User Raimund Renkert <raimund.renkert at intevation.de>
# Date 1423241798 -3600
# Node ID bcd43f47ac5df0778eccb060e9e9f722ae4d6b09
# Parent  f0ad10e0e1b1fe3b92e3c554ab49f25ae19179df
Added stubs for authentication/authorization.

diff -r f0ad10e0e1b1 -r bcd43f47ac5d src/main/java/de/intevation/lada/util/annotation/AuthenticationConfig.java
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/main/java/de/intevation/lada/util/annotation/AuthenticationConfig.java	Fri Feb 06 17:56:38 2015 +0100
@@ -0,0 +1,11 @@
+package de.intevation.lada.util.annotation;
+
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+
+import de.intevation.lada.util.auth.AuthenticationType;
+
+ at Retention(RetentionPolicy.RUNTIME)
+public @interface AuthenticationConfig {
+    AuthenticationType type() default AuthenticationType.NONE;
+}
diff -r f0ad10e0e1b1 -r bcd43f47ac5d src/main/java/de/intevation/lada/util/annotation/AuthorizationConfig.java
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/main/java/de/intevation/lada/util/annotation/AuthorizationConfig.java	Fri Feb 06 17:56:38 2015 +0100
@@ -0,0 +1,11 @@
+package de.intevation.lada.util.annotation;
+
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+
+import de.intevation.lada.util.auth.AuthorizationType;
+
+ at Retention(RetentionPolicy.RUNTIME)
+public @interface AuthorizationConfig {
+    AuthorizationType type() default AuthorizationType.NONE;
+}
diff -r f0ad10e0e1b1 -r bcd43f47ac5d src/main/java/de/intevation/lada/util/auth/Authentication.java
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/main/java/de/intevation/lada/util/auth/Authentication.java	Fri Feb 06 17:56:38 2015 +0100
@@ -0,0 +1,8 @@
+package de.intevation.lada.util.auth;
+
+import javax.ws.rs.core.HttpHeaders;
+
+public interface Authentication {
+
+    public boolean isAuthenticated(HttpHeaders headers);
+}
diff -r f0ad10e0e1b1 -r bcd43f47ac5d src/main/java/de/intevation/lada/util/auth/AuthenticationType.java
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/main/java/de/intevation/lada/util/auth/AuthenticationType.java	Fri Feb 06 17:56:38 2015 +0100
@@ -0,0 +1,6 @@
+package de.intevation.lada.util.auth;
+
+public enum AuthenticationType {
+    NONE, //DEVELOPMENT ONLY!
+    OPENID, // ... and others...
+}
diff -r f0ad10e0e1b1 -r bcd43f47ac5d src/main/java/de/intevation/lada/util/auth/Authorization.java
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/main/java/de/intevation/lada/util/auth/Authorization.java	Fri Feb 06 17:56:38 2015 +0100
@@ -0,0 +1,9 @@
+package de.intevation.lada.util.auth;
+
+import java.util.Map;
+
+import javax.ws.rs.core.HttpHeaders;
+
+public interface Authorization {
+    public Map<String, Object> getInfo(HttpHeaders headers);
+}
diff -r f0ad10e0e1b1 -r bcd43f47ac5d src/main/java/de/intevation/lada/util/auth/AuthorizationType.java
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/main/java/de/intevation/lada/util/auth/AuthorizationType.java	Fri Feb 06 17:56:38 2015 +0100
@@ -0,0 +1,6 @@
+package de.intevation.lada.util.auth;
+
+public enum AuthorizationType {
+    NONE, // DEVELOPMENT ONLY!
+    LDAP, // ... and others...
+}
diff -r f0ad10e0e1b1 -r bcd43f47ac5d src/main/java/de/intevation/lada/util/auth/DefaultAuthentication.java
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/main/java/de/intevation/lada/util/auth/DefaultAuthentication.java	Fri Feb 06 17:56:38 2015 +0100
@@ -0,0 +1,12 @@
+package de.intevation.lada.util.auth;
+
+import javax.ws.rs.core.HttpHeaders;
+
+public class DefaultAuthentication implements Authentication {
+
+    @Override
+    public boolean isAuthenticated(HttpHeaders headers) {
+        return true;
+    }
+
+}
diff -r f0ad10e0e1b1 -r bcd43f47ac5d src/main/java/de/intevation/lada/util/auth/DefaultAuthorization.java
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/main/java/de/intevation/lada/util/auth/DefaultAuthorization.java	Fri Feb 06 17:56:38 2015 +0100
@@ -0,0 +1,14 @@
+package de.intevation.lada.util.auth;
+
+import java.util.Map;
+
+import javax.ws.rs.core.HttpHeaders;
+
+public class DefaultAuthorization implements Authorization {
+
+    @Override
+    public Map<String, Object> getInfo(HttpHeaders headers) {
+        return null;
+    }
+
+}
diff -r f0ad10e0e1b1 -r bcd43f47ac5d src/main/java/de/intevation/lada/util/factory/AuthenticationFactory.java
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/main/java/de/intevation/lada/util/factory/AuthenticationFactory.java	Fri Feb 06 17:56:38 2015 +0100
@@ -0,0 +1,33 @@
+package de.intevation.lada.util.factory;
+
+import javax.enterprise.context.ApplicationScoped;
+import javax.enterprise.inject.Produces;
+import javax.enterprise.inject.spi.Annotated;
+import javax.enterprise.inject.spi.InjectionPoint;
+
+import de.intevation.lada.util.annotation.AuthenticationConfig;
+import de.intevation.lada.util.auth.Authentication;
+import de.intevation.lada.util.auth.AuthenticationType;
+import de.intevation.lada.util.auth.DefaultAuthentication;
+
+
+ at ApplicationScoped
+public class AuthenticationFactory {
+
+    @Produces
+    Authentication createAuthentication(InjectionPoint injectionPoint) {
+        Annotated annotated = injectionPoint.getAnnotated();
+        AuthenticationConfig config =
+            annotated.getAnnotation(AuthenticationConfig.class);
+        if (config == null) {
+            return new DefaultAuthentication();
+        }
+        Authentication auth = new DefaultAuthentication();
+        if (config.type() == AuthenticationType.NONE) {
+            auth = new DefaultAuthentication();
+        }
+        // TODO Add more Authentication methods.
+        return auth;
+    }
+
+}
diff -r f0ad10e0e1b1 -r bcd43f47ac5d src/main/java/de/intevation/lada/util/factory/AuthorizationFactory.java
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/main/java/de/intevation/lada/util/factory/AuthorizationFactory.java	Fri Feb 06 17:56:38 2015 +0100
@@ -0,0 +1,31 @@
+package de.intevation.lada.util.factory;
+
+import javax.enterprise.context.ApplicationScoped;
+import javax.enterprise.inject.Produces;
+import javax.enterprise.inject.spi.Annotated;
+import javax.enterprise.inject.spi.InjectionPoint;
+
+import de.intevation.lada.util.annotation.AuthorizationConfig;
+import de.intevation.lada.util.auth.Authorization;
+import de.intevation.lada.util.auth.AuthorizationType;
+import de.intevation.lada.util.auth.DefaultAuthorization;
+
+ at ApplicationScoped
+public class AuthorizationFactory {
+
+    @Produces
+    Authorization createAuthorization(InjectionPoint injectionPoint) {
+        Annotated annotated = injectionPoint.getAnnotated();
+        AuthorizationConfig config =
+            annotated.getAnnotation(AuthorizationConfig.class);
+        if (config == null) {
+            return new DefaultAuthorization();
+        }
+        Authorization auth = new DefaultAuthorization();
+        if (config.type() == AuthorizationType.NONE) {
+            auth = new DefaultAuthorization();
+        }
+
+        return auth;
+    }
+}


More information about the Lada-commits mailing list