Mercurial > lada > lada-server
changeset 458:2f42128de67b
Refactored auth module.
author | Raimund Renkert <raimund.renkert@intevation.de> |
---|---|
date | Mon, 16 Feb 2015 15:15:27 +0100 (2015-02-16) |
parents | 51784d74a85b |
children | 66414517e25e |
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/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 | 6 files changed, 30 insertions(+), 64 deletions(-) [+] |
line wrap: on
line diff
--- a/src/main/java/de/intevation/lada/util/annotation/AuthenticationConfig.java Mon Feb 16 15:14:48 2015 +0100 +++ b/src/main/java/de/intevation/lada/util/annotation/AuthenticationConfig.java Mon Feb 16 15:15:27 2015 +0100 @@ -1,11 +1,21 @@ package de.intevation.lada.util.annotation; +import java.lang.annotation.ElementType; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import javax.inject.Qualifier; import de.intevation.lada.util.auth.AuthenticationType; +@Qualifier @Retention(RetentionPolicy.RUNTIME) +@Target({ + ElementType.TYPE, + ElementType.FIELD, + ElementType.METHOD, + ElementType.PARAMETER}) public @interface AuthenticationConfig { AuthenticationType type() default AuthenticationType.NONE; }
--- a/src/main/java/de/intevation/lada/util/annotation/AuthorizationConfig.java Mon Feb 16 15:14:48 2015 +0100 +++ b/src/main/java/de/intevation/lada/util/annotation/AuthorizationConfig.java Mon Feb 16 15:15:27 2015 +0100 @@ -1,11 +1,21 @@ package de.intevation.lada.util.annotation; +import java.lang.annotation.ElementType; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import javax.inject.Qualifier; import de.intevation.lada.util.auth.AuthorizationType; +@Qualifier @Retention(RetentionPolicy.RUNTIME) +@Target({ + ElementType.TYPE, + ElementType.FIELD, + ElementType.METHOD, + ElementType.PARAMETER}) public @interface AuthorizationConfig { AuthorizationType type() default AuthorizationType.NONE; }
--- a/src/main/java/de/intevation/lada/util/auth/DefaultAuthentication.java Mon Feb 16 15:14:48 2015 +0100 +++ b/src/main/java/de/intevation/lada/util/auth/DefaultAuthentication.java Mon Feb 16 15:15:27 2015 +0100 @@ -1,7 +1,12 @@ package de.intevation.lada.util.auth; +import javax.ejb.Stateless; import javax.ws.rs.core.HttpHeaders; +import de.intevation.lada.util.annotation.AuthenticationConfig; + +@Stateless +@AuthenticationConfig(type=AuthenticationType.NONE) public class DefaultAuthentication implements Authentication { @Override
--- a/src/main/java/de/intevation/lada/util/auth/DefaultAuthorization.java Mon Feb 16 15:14:48 2015 +0100 +++ b/src/main/java/de/intevation/lada/util/auth/DefaultAuthorization.java Mon Feb 16 15:15:27 2015 +0100 @@ -2,8 +2,13 @@ import java.util.Map; +import javax.ejb.Stateless; import javax.ws.rs.core.HttpHeaders; +import de.intevation.lada.util.annotation.AuthorizationConfig; + +@Stateless +@AuthorizationConfig(type=AuthorizationType.NONE) public class DefaultAuthorization implements Authorization { @Override
--- a/src/main/java/de/intevation/lada/util/factory/AuthenticationFactory.java Mon Feb 16 15:14:48 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,33 +0,0 @@ -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; - } - -}
--- a/src/main/java/de/intevation/lada/util/factory/AuthorizationFactory.java Mon Feb 16 15:14:48 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,31 +0,0 @@ -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; - } -}