Mercurial > lada > lada-server
changeset 439:bcd43f47ac5d
Added stubs for authentication/authorization.
author | Raimund Renkert <raimund.renkert@intevation.de> |
---|---|
date | Fri, 06 Feb 2015 17:56:38 +0100 |
parents | f0ad10e0e1b1 |
children | 7cb0732de39d |
files | src/main/java/de/intevation/lada/util/annotation/AuthenticationConfig.java src/main/java/de/intevation/lada/util/annotation/AuthorizationConfig.java src/main/java/de/intevation/lada/util/auth/Authentication.java src/main/java/de/intevation/lada/util/auth/AuthenticationType.java src/main/java/de/intevation/lada/util/auth/Authorization.java src/main/java/de/intevation/lada/util/auth/AuthorizationType.java src/main/java/de/intevation/lada/util/auth/DefaultAuthentication.java src/main/java/de/intevation/lada/util/auth/DefaultAuthorization.java src/main/java/de/intevation/lada/util/factory/AuthenticationFactory.java src/main/java/de/intevation/lada/util/factory/AuthorizationFactory.java |
diffstat | 10 files changed, 141 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- /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; + +@Retention(RetentionPolicy.RUNTIME) +public @interface AuthenticationConfig { + AuthenticationType type() default AuthenticationType.NONE; +}
--- /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; + +@Retention(RetentionPolicy.RUNTIME) +public @interface AuthorizationConfig { + AuthorizationType type() default AuthorizationType.NONE; +}
--- /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); +}
--- /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... +}
--- /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); +}
--- /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... +}
--- /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; + } + +}
--- /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; + } + +}
--- /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; + + +@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; + } + +}
--- /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; + +@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; + } +}