# HG changeset patch # User Raimund Renkert # Date 1424096127 -3600 # Node ID 2f42128de67b32d1b129f8c642768ba558af4aee # Parent 51784d74a85ba60973255b0d5fd77baaeecc4c2d Refactored auth module. diff -r 51784d74a85b -r 2f42128de67b src/main/java/de/intevation/lada/util/annotation/AuthenticationConfig.java --- 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; } diff -r 51784d74a85b -r 2f42128de67b src/main/java/de/intevation/lada/util/annotation/AuthorizationConfig.java --- 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; } diff -r 51784d74a85b -r 2f42128de67b src/main/java/de/intevation/lada/util/auth/DefaultAuthentication.java --- 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 diff -r 51784d74a85b -r 2f42128de67b src/main/java/de/intevation/lada/util/auth/DefaultAuthorization.java --- 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 diff -r 51784d74a85b -r 2f42128de67b src/main/java/de/intevation/lada/util/factory/AuthenticationFactory.java --- 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; - } - -} diff -r 51784d74a85b -r 2f42128de67b src/main/java/de/intevation/lada/util/factory/AuthorizationFactory.java --- 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; - } -}