Commit 4a702641e3edd7f9015b2748756cc719e03d3acb
1 parent
8d68a1f4
Segurança e ajustes nos pacotes
Showing
64 changed files
with
1417 additions
and
1661 deletions
Show diff stats
demoiselle-core/src/main/java/org/demoiselle/jee/core/annotation/Strategy.java
| ... | ... | @@ -1,53 +0,0 @@ |
| 1 | -/* | |
| 2 | - * Demoiselle Framework | |
| 3 | - * | |
| 4 | - * License: GNU Lesser General Public License (LGPL), version 3 or later. | |
| 5 | - * See the lgpl.txt file in the root directory or <https://www.gnu.org/licenses/lgpl.html>. | |
| 6 | - */ | |
| 7 | -package org.demoiselle.jee.core.annotation; | |
| 8 | -import static java.lang.annotation.ElementType.FIELD; | |
| 9 | -import static java.lang.annotation.ElementType.METHOD; | |
| 10 | -import static java.lang.annotation.ElementType.PARAMETER; | |
| 11 | -import static java.lang.annotation.ElementType.TYPE; | |
| 12 | -import static java.lang.annotation.RetentionPolicy.RUNTIME; | |
| 13 | - | |
| 14 | -import java.lang.annotation.Inherited; | |
| 15 | -import java.lang.annotation.Retention; | |
| 16 | -import java.lang.annotation.Target; | |
| 17 | - | |
| 18 | -import javax.inject.Qualifier; | |
| 19 | - | |
| 20 | -/** | |
| 21 | - * | |
| 22 | - * <p> | |
| 23 | - * This literal marks a bean to be selected at runtime based on a priority system. | |
| 24 | - * The user qualifies the injection point with this literal and then at runtime | |
| 25 | - * the CDI engine will circle through all candidate subtypes to be injected | |
| 26 | - * that are annotated with {@link Priority}. If there is only one subtype with the | |
| 27 | - * highest priority then this one will be selected to be injected. | |
| 28 | - * </p> | |
| 29 | - * | |
| 30 | - * <p> | |
| 31 | - * This allows users to plug in libraries with new candidates and have them be selected | |
| 32 | - * if their priority values are higher than the default values already present. One example | |
| 33 | - * is the {@link org.demoiselle.security.Authorizer} type, the framework has a {@link org.demoiselle.internal.implementation.DefaultAuthorizer} | |
| 34 | - * with {@link Priority#L1_PRIORITY the lowest priority} but the user can add libraries with new | |
| 35 | - * implementations of {@link org.demoiselle.security.Authorizer} annotated with higher priorities, the code will | |
| 36 | - * then automatically select these new implementations with no extra configuration. | |
| 37 | - * </p> | |
| 38 | - * | |
| 39 | - * <p> | |
| 40 | - * This annotation must be used with supported types. Usually this involves creating {@link javax.enterprise.inject.Produces} CDI | |
| 41 | - * producer methods that will select the correct strategy. To create your own producer | |
| 42 | - * methods that support strategy selection, use the utility {@linkplain org.demoiselle.internal.producer.StrategySelector}. | |
| 43 | - * </p> | |
| 44 | - * | |
| 45 | - * @author SERPRO | |
| 46 | - */ | |
| 47 | -@Qualifier | |
| 48 | -@Inherited | |
| 49 | -@Retention(RUNTIME) | |
| 50 | -@Target({ TYPE, FIELD, METHOD, PARAMETER }) | |
| 51 | -public @interface Strategy { | |
| 52 | - | |
| 53 | -} |
demoiselle-core/src/main/java/org/demoiselle/jee/core/annotation/Type.java
| ... | ... | @@ -1,60 +0,0 @@ |
| 1 | -/* | |
| 2 | - * Demoiselle Framework | |
| 3 | - * | |
| 4 | - * License: GNU Lesser General Public License (LGPL), version 3 or later. | |
| 5 | - * See the lgpl.txt file in the root directory or <https://www.gnu.org/licenses/lgpl.html>. | |
| 6 | - */ | |
| 7 | -package org.demoiselle.jee.core.annotation; | |
| 8 | - | |
| 9 | -import static java.lang.annotation.ElementType.FIELD; | |
| 10 | -import static java.lang.annotation.ElementType.METHOD; | |
| 11 | -import static java.lang.annotation.ElementType.PARAMETER; | |
| 12 | -import static java.lang.annotation.ElementType.TYPE; | |
| 13 | -import static java.lang.annotation.RetentionPolicy.RUNTIME; | |
| 14 | - | |
| 15 | -import java.lang.annotation.Inherited; | |
| 16 | -import java.lang.annotation.Retention; | |
| 17 | -import java.lang.annotation.Target; | |
| 18 | - | |
| 19 | -import javax.enterprise.util.Nonbinding; | |
| 20 | -import javax.inject.Qualifier; | |
| 21 | - | |
| 22 | -/** | |
| 23 | - * <p> | |
| 24 | - * Type based non-binding qualifier. | |
| 25 | - * </p> | |
| 26 | - * | |
| 27 | - * <p> | |
| 28 | - * This annotation is used to qualify beans using a class type. | |
| 29 | - * {@link javax.enterprise.inject.Produces} methods can then read this type and | |
| 30 | - * use it to customize the bean creation process. | |
| 31 | - * </p> | |
| 32 | - * | |
| 33 | - * <p> | |
| 34 | - * The {@link #value()} attribute is non-binding, meaning multiple classes | |
| 35 | - * qualified with this annotation, even with different values, will be | |
| 36 | - * considered the same candidate for injection points. To avoid ambiguous | |
| 37 | - * resolutions and select which candidate to choose usually you'll need a | |
| 38 | - * producer method to read the type and select the best fitted candidate. | |
| 39 | - * </p> | |
| 40 | - * | |
| 41 | - * <p> | |
| 42 | - * The framework classes qualified with this annotation already have such | |
| 43 | - * producers and the accepted values for this annotation will be detailed in | |
| 44 | - * their respective documentations. | |
| 45 | - * </p> | |
| 46 | - * | |
| 47 | - * | |
| 48 | - * @author SERPRO | |
| 49 | - * | |
| 50 | - */ | |
| 51 | -@Qualifier | |
| 52 | -@Inherited | |
| 53 | -@Retention(RUNTIME) | |
| 54 | -@Target({ TYPE, FIELD, METHOD, PARAMETER }) | |
| 55 | -public @interface Type { | |
| 56 | - | |
| 57 | - @Nonbinding | |
| 58 | - Class<?> value() default Object.class; | |
| 59 | - | |
| 60 | -} |
demoiselle-core/src/main/java/org/demoiselle/jee/core/annotation/literal/StrategyQualifier.java
| ... | ... | @@ -1,23 +0,0 @@ |
| 1 | -/* | |
| 2 | - * Demoiselle Framework | |
| 3 | - * | |
| 4 | - * License: GNU Lesser General Public License (LGPL), version 3 or later. | |
| 5 | - * See the lgpl.txt file in the root directory or <https://www.gnu.org/licenses/lgpl.html>. | |
| 6 | - */ | |
| 7 | -package org.demoiselle.jee.core.annotation.literal; | |
| 8 | - | |
| 9 | -import org.demoiselle.jee.core.annotation.Strategy; | |
| 10 | - | |
| 11 | -import javax.enterprise.util.AnnotationLiteral; | |
| 12 | - | |
| 13 | -/** | |
| 14 | - * Annotation litteral that allows to create instances of the {@link Strategy} literal. The created instance can then be | |
| 15 | - * used to call {@link javax.enterprise.inject.spi.CDI#select(Class subtype, java.lang.annotation.Annotation... qualifiers)}. | |
| 16 | - * | |
| 17 | - * @see javax.enterprise.inject.spi.CDI | |
| 18 | - * @author SERPRO | |
| 19 | - */ | |
| 20 | -@SuppressWarnings("all") | |
| 21 | -public class StrategyQualifier extends AnnotationLiteral<Strategy> implements Strategy { | |
| 22 | - | |
| 23 | -} |
demoiselle-core/src/main/java/org/demoiselle/jee/core/annotation/literal/TypeQualifier.java
| ... | ... | @@ -1,41 +0,0 @@ |
| 1 | -/* | |
| 2 | - * Demoiselle Framework | |
| 3 | - * | |
| 4 | - * License: GNU Lesser General Public License (LGPL), version 3 or later. | |
| 5 | - * See the lgpl.txt file in the root directory or <https://www.gnu.org/licenses/lgpl.html>. | |
| 6 | - */ | |
| 7 | -package org.demoiselle.jee.core.annotation.literal; | |
| 8 | - | |
| 9 | -import org.demoiselle.jee.core.annotation.Type; | |
| 10 | - | |
| 11 | -import javax.enterprise.util.AnnotationLiteral; | |
| 12 | - | |
| 13 | -/** | |
| 14 | - * Annotation litteral that allows to create instances of the {@link Type} | |
| 15 | - * literal. The created instance can then be used to call | |
| 16 | - * {@link javax.enterprise.inject.spi.CDI#select(Class subtype, java.lang.annotation.Annotation... qualifiers)}. | |
| 17 | - * | |
| 18 | - * @see javax.enterprise.inject.spi.CDI | |
| 19 | - * @author SERPRO | |
| 20 | - */ | |
| 21 | -@SuppressWarnings("all") | |
| 22 | -public class TypeQualifier extends AnnotationLiteral<Type> implements Type { | |
| 23 | - | |
| 24 | - private static final long serialVersionUID = 1L; | |
| 25 | - | |
| 26 | - private final Class<?> value; | |
| 27 | - | |
| 28 | - /** | |
| 29 | - * Constructor with string value of name literal. | |
| 30 | - * | |
| 31 | - * @param value value of name literal. | |
| 32 | - */ | |
| 33 | - public TypeQualifier(Class<?> value) { | |
| 34 | - this.value = value; | |
| 35 | - } | |
| 36 | - | |
| 37 | - @Override | |
| 38 | - public Class<?> value() { | |
| 39 | - return this.value; | |
| 40 | - } | |
| 41 | -} |
demoiselle-core/src/main/java/org/demoiselle/jee/core/crud/package-info.java
| ... | ... | @@ -1,11 +0,0 @@ |
| 1 | -/* | |
| 2 | - * Demoiselle Framework | |
| 3 | - * | |
| 4 | - * License: GNU Lesser General Public License (LGPL), version 3 or later. | |
| 5 | - * See the lgpl.txt file in the root directory or <https://www.gnu.org/licenses/lgpl.html>. | |
| 6 | - */ | |
| 7 | -/** | |
| 8 | - * Esta pacote tem o objetivo de conter as classes relacionadas aos | |
| 9 | - * facilitadores de CRUD do framework Demoiselle. | |
| 10 | - */ | |
| 11 | -package org.demoiselle.jee.core.crud; | |
| 12 | 0 | \ No newline at end of file |
demoiselle-core/src/main/java/org/demoiselle/jee/core/interfaces/crud/package-info.java
0 → 100644
| ... | ... | @@ -0,0 +1,11 @@ |
| 1 | +/* | |
| 2 | + * Demoiselle Framework | |
| 3 | + * | |
| 4 | + * License: GNU Lesser General Public License (LGPL), version 3 or later. | |
| 5 | + * See the lgpl.txt file in the root directory or <https://www.gnu.org/licenses/lgpl.html>. | |
| 6 | + */ | |
| 7 | +/** | |
| 8 | + * Esta pacote tem o objetivo de conter as classes relacionadas aos | |
| 9 | + * facilitadores de CRUD do framework Demoiselle. | |
| 10 | + */ | |
| 11 | +package org.demoiselle.jee.core.interfaces.crud; | |
| 0 | 12 | \ No newline at end of file | ... | ... |
demoiselle-core/src/main/java/org/demoiselle/jee/core/interfaces/persistence/package-info.java
0 → 100644
| ... | ... | @@ -0,0 +1,11 @@ |
| 1 | +/* | |
| 2 | + * Demoiselle Framework | |
| 3 | + * | |
| 4 | + * License: GNU Lesser General Public License (LGPL), version 3 or later. | |
| 5 | + * See the lgpl.txt file in the root directory or <https://www.gnu.org/licenses/lgpl.html>. | |
| 6 | + */ | |
| 7 | +/** | |
| 8 | + * Esta pacote tem o objetivo de conter as classes relacionadas aos | |
| 9 | + * facilitadores de CRUD do framework Demoiselle. | |
| 10 | + */ | |
| 11 | +package org.demoiselle.jee.core.interfaces.persistence; | |
| 0 | 12 | \ No newline at end of file | ... | ... |
demoiselle-core/src/main/java/org/demoiselle/jee/core/interfaces/security/DemoisellePrincipal.java
0 → 100644
| ... | ... | @@ -0,0 +1,29 @@ |
| 1 | +/* | |
| 2 | + * To change this license header, choose License Headers in Project Properties. | |
| 3 | + * To change this template file, choose Tools | Templates | |
| 4 | + * and open the template in the editor. | |
| 5 | + */ | |
| 6 | +package org.demoiselle.jee.core.interfaces.security; | |
| 7 | + | |
| 8 | +import java.security.Principal; | |
| 9 | +import java.util.List; | |
| 10 | +import java.util.Map; | |
| 11 | + | |
| 12 | +/** | |
| 13 | + * | |
| 14 | + * @author 70744416353 | |
| 15 | + */ | |
| 16 | +public interface DemoisellePrincipal extends Principal { | |
| 17 | + | |
| 18 | + public String getId(); | |
| 19 | + | |
| 20 | + public void setId(String id); | |
| 21 | + | |
| 22 | + public void setName(String name); | |
| 23 | + | |
| 24 | + public void setRoles(List<String> roles); | |
| 25 | + | |
| 26 | + public List<String> getRoles(); | |
| 27 | + | |
| 28 | + public Map<String, String> getPermissions(); | |
| 29 | +} | ... | ... |
demoiselle-core/src/main/java/org/demoiselle/jee/core/interfaces/security/SecurityContext.java
0 → 100644
| ... | ... | @@ -0,0 +1,73 @@ |
| 1 | +/* | |
| 2 | + * Demoiselle Framework | |
| 3 | + * | |
| 4 | + * License: GNU Lesser General Public License (LGPL), version 3 or later. | |
| 5 | + * See the lgpl.txt file in the root directory or <https://www.gnu.org/licenses/lgpl.html>. | |
| 6 | + */ | |
| 7 | +package org.demoiselle.jee.core.interfaces.security; | |
| 8 | + | |
| 9 | +import java.io.Serializable; | |
| 10 | +import java.security.Principal; | |
| 11 | +import java.util.List; | |
| 12 | +import java.util.Map; | |
| 13 | + | |
| 14 | +/** | |
| 15 | + * <p> | |
| 16 | + * Structure used to handle both authentication and authorizations mechanisms. | |
| 17 | + * </p> | |
| 18 | + * | |
| 19 | + * @author SERPRO | |
| 20 | + */ | |
| 21 | +public interface SecurityContext extends Serializable { | |
| 22 | + | |
| 23 | + /** | |
| 24 | + * Checks if a specific user is logged in. | |
| 25 | + * | |
| 26 | + * @return {@code true} if the user is logged in | |
| 27 | + */ | |
| 28 | + boolean isLoggedIn(); | |
| 29 | + | |
| 30 | + /** | |
| 31 | + * @throws NotLoggedInException if there is no user logged in a specific | |
| 32 | + * session | |
| 33 | + */ | |
| 34 | + void checkLoggedIn(); | |
| 35 | + | |
| 36 | + /** | |
| 37 | + * Checks if the logged user has permission to execute an specific operation | |
| 38 | + * on a specific resource. | |
| 39 | + * | |
| 40 | + * @param resource resource to be checked | |
| 41 | + * @param operation operation to be checked | |
| 42 | + * @return {@code true} if the user has the permission | |
| 43 | + * @throws AuthorizationException When the permission checking fails, this | |
| 44 | + * exception is thrown. | |
| 45 | + * @throws NotLoggedInException if there is no user logged in a specific | |
| 46 | + * session. | |
| 47 | + */ | |
| 48 | + boolean hasPermission(String resource, String operation); | |
| 49 | + | |
| 50 | + /** | |
| 51 | + * Checks if the logged user has an specific role | |
| 52 | + * | |
| 53 | + * @param role role to be checked | |
| 54 | + * @return {@code true} if the user has the role | |
| 55 | + * @throws AuthorizationException When the permission checking fails, this | |
| 56 | + * exception is thrown. | |
| 57 | + * @throws NotLoggedInException if there is no user logged in a specific | |
| 58 | + * session. | |
| 59 | + */ | |
| 60 | + boolean hasRole(String role); | |
| 61 | + | |
| 62 | + /** | |
| 63 | + * Return the user logged in the session. | |
| 64 | + * | |
| 65 | + * @param token | |
| 66 | + * @return the user logged in a specific authenticated session. If there is | |
| 67 | + * no active session {@code null} is returned. | |
| 68 | + */ | |
| 69 | + Principal getUser(); | |
| 70 | + | |
| 71 | + void setUser(Principal loggedUser); | |
| 72 | + | |
| 73 | +} | ... | ... |
demoiselle-core/src/main/java/org/demoiselle/jee/core/interfaces/security/Token.java
0 → 100644
| ... | ... | @@ -0,0 +1,21 @@ |
| 1 | +/* | |
| 2 | + * To change this license header, choose License Headers in Project Properties. | |
| 3 | + * To change this template file, choose Tools | Templates | |
| 4 | + * and open the template in the editor. | |
| 5 | + */ | |
| 6 | +package org.demoiselle.jee.core.interfaces.security; | |
| 7 | + | |
| 8 | +/** | |
| 9 | + * | |
| 10 | + * @author 70744416353 | |
| 11 | + */ | |
| 12 | +public interface Token { | |
| 13 | + | |
| 14 | + public String getKey(); | |
| 15 | + | |
| 16 | + public void setKey(String key); | |
| 17 | + | |
| 18 | + public String getType(); | |
| 19 | + | |
| 20 | + public void setType(String type); | |
| 21 | +} | ... | ... |
demoiselle-core/src/main/java/org/demoiselle/jee/core/interfaces/security/TokensManager.java
0 → 100644
| ... | ... | @@ -0,0 +1,29 @@ |
| 1 | +/* | |
| 2 | + * Demoiselle Framework | |
| 3 | + * | |
| 4 | + * License: GNU Lesser General Public License (LGPL), version 3 or later. | |
| 5 | + * See the lgpl.txt file in the root directory or <https://www.gnu.org/licenses/lgpl.html>. | |
| 6 | + */ | |
| 7 | +package org.demoiselle.jee.core.interfaces.security; | |
| 8 | + | |
| 9 | +import java.io.Serializable; | |
| 10 | +import java.security.Principal; | |
| 11 | +import java.util.List; | |
| 12 | +import java.util.Map; | |
| 13 | + | |
| 14 | +/** | |
| 15 | + * <p> | |
| 16 | + * Structure used to handle both authentication and authorizations mechanisms. | |
| 17 | + * </p> | |
| 18 | + * | |
| 19 | + * @author SERPRO | |
| 20 | + */ | |
| 21 | +public interface TokensManager extends Serializable { | |
| 22 | + | |
| 23 | + public Principal getUser(); | |
| 24 | + | |
| 25 | + public void setUser(Principal user); | |
| 26 | + | |
| 27 | + public boolean validate(); | |
| 28 | + | |
| 29 | +} | ... | ... |
demoiselle-core/src/main/java/org/demoiselle/jee/core/interfaces/ws/package-info.java
0 → 100644
| ... | ... | @@ -0,0 +1,11 @@ |
| 1 | +/* | |
| 2 | + * Demoiselle Framework | |
| 3 | + * | |
| 4 | + * License: GNU Lesser General Public License (LGPL), version 3 or later. | |
| 5 | + * See the lgpl.txt file in the root directory or <https://www.gnu.org/licenses/lgpl.html>. | |
| 6 | + */ | |
| 7 | +/** | |
| 8 | + * Esta pacote tem o objetivo de conter as classes relacionadas aos | |
| 9 | + * facilitadores de CRUD do framework Demoiselle. | |
| 10 | + */ | |
| 11 | +package org.demoiselle.jee.core.interfaces.ws; | |
| 0 | 12 | \ No newline at end of file | ... | ... |
demoiselle-core/src/main/java/org/demoiselle/jee/core/message/DemoiselleMessages.java
0 → 100644
| ... | ... | @@ -0,0 +1,57 @@ |
| 1 | +/* | |
| 2 | + * Demoiselle Framework | |
| 3 | + * | |
| 4 | + * License: GNU Lesser General Public License (LGPL), version 3 or later. | |
| 5 | + * See the lgpl.txt file in the root directory or <https://www.gnu.org/licenses/lgpl.html>. | |
| 6 | + */ | |
| 7 | +package org.demoiselle.jee.core.message; | |
| 8 | + | |
| 9 | +import org.apache.deltaspike.core.api.message.MessageBundle; | |
| 10 | +import org.apache.deltaspike.core.api.message.MessageTemplate; | |
| 11 | + | |
| 12 | +@MessageBundle | |
| 13 | +public interface DemoiselleMessages { | |
| 14 | + | |
| 15 | + @MessageTemplate("{version}") | |
| 16 | + String version(); | |
| 17 | + | |
| 18 | + @MessageTemplate("{engine-on}") | |
| 19 | + String engineOn(); | |
| 20 | + | |
| 21 | + @MessageTemplate("{resource-not-found}") | |
| 22 | + String resourceNotFound(); | |
| 23 | + | |
| 24 | + @MessageTemplate("{key-not-found}") | |
| 25 | + String keyNotFound(String key); | |
| 26 | + | |
| 27 | + @MessageTemplate("{ambiguous-strategy-resolution}") | |
| 28 | + String ambiguousStrategyResolution(String interfaceString, String implementations); | |
| 29 | + | |
| 30 | + @MessageTemplate("{ambiguous-bean-resolution}") | |
| 31 | + String ambiguousBeanResolution(String implementation); | |
| 32 | + | |
| 33 | + @MessageTemplate("{bean-not-found}") | |
| 34 | + String beanNotFound(String bean); | |
| 35 | + | |
| 36 | + @MessageTemplate("{store-not-found}") | |
| 37 | + String storeNotFound(String object, String scope); | |
| 38 | + | |
| 39 | + @MessageTemplate("{more-than-one-exceptionhandler-defined-for-same-class}") | |
| 40 | + String moreThanOneExceptionhandlerDefinedForSameClass(String clazz, String ex); | |
| 41 | + | |
| 42 | + @MessageTemplate("{handling-exception}") | |
| 43 | + String handlingException(String ex); | |
| 44 | + | |
| 45 | + @MessageTemplate("{taking-off}") | |
| 46 | + String takingOff(); | |
| 47 | + | |
| 48 | + @MessageTemplate("{engine-off}") | |
| 49 | + String engineOff(String ex); | |
| 50 | + | |
| 51 | + @MessageTemplate("{setting-up-bean-manager}") | |
| 52 | + String settingUpBeanManagerException(String util); | |
| 53 | + | |
| 54 | + @MessageTemplate("{processing-fail}") | |
| 55 | + String processingFail(); | |
| 56 | + | |
| 57 | +} | |
| 0 | 58 | \ No newline at end of file | ... | ... |
demoiselle-core/src/main/java/org/demoiselle/jee/core/messages/DemoiselleMessages.java
| ... | ... | @@ -1,57 +0,0 @@ |
| 1 | -/* | |
| 2 | - * Demoiselle Framework | |
| 3 | - * | |
| 4 | - * License: GNU Lesser General Public License (LGPL), version 3 or later. | |
| 5 | - * See the lgpl.txt file in the root directory or <https://www.gnu.org/licenses/lgpl.html>. | |
| 6 | - */ | |
| 7 | -package org.demoiselle.jee.core.messages; | |
| 8 | - | |
| 9 | -import org.apache.deltaspike.core.api.message.MessageBundle; | |
| 10 | -import org.apache.deltaspike.core.api.message.MessageTemplate; | |
| 11 | - | |
| 12 | -@MessageBundle | |
| 13 | -public interface DemoiselleMessages { | |
| 14 | - | |
| 15 | - @MessageTemplate("{version}") | |
| 16 | - String version(); | |
| 17 | - | |
| 18 | - @MessageTemplate("{engine-on}") | |
| 19 | - String engineOn(); | |
| 20 | - | |
| 21 | - @MessageTemplate("{resource-not-found}") | |
| 22 | - String resourceNotFound(); | |
| 23 | - | |
| 24 | - @MessageTemplate("{key-not-found}") | |
| 25 | - String keyNotFound(String key); | |
| 26 | - | |
| 27 | - @MessageTemplate("{ambiguous-strategy-resolution}") | |
| 28 | - String ambiguousStrategyResolution(String interfaceString, String implementations); | |
| 29 | - | |
| 30 | - @MessageTemplate("{ambiguous-bean-resolution}") | |
| 31 | - String ambiguousBeanResolution(String implementation); | |
| 32 | - | |
| 33 | - @MessageTemplate("{bean-not-found}") | |
| 34 | - String beanNotFound(String bean); | |
| 35 | - | |
| 36 | - @MessageTemplate("{store-not-found}") | |
| 37 | - String storeNotFound(String object, String scope); | |
| 38 | - | |
| 39 | - @MessageTemplate("{more-than-one-exceptionhandler-defined-for-same-class}") | |
| 40 | - String moreThanOneExceptionhandlerDefinedForSameClass(String clazz, String ex); | |
| 41 | - | |
| 42 | - @MessageTemplate("{handling-exception}") | |
| 43 | - String handlingException(String ex); | |
| 44 | - | |
| 45 | - @MessageTemplate("{taking-off}") | |
| 46 | - String takingOff(); | |
| 47 | - | |
| 48 | - @MessageTemplate("{engine-off}") | |
| 49 | - String engineOff(String ex); | |
| 50 | - | |
| 51 | - @MessageTemplate("{setting-up-bean-manager}") | |
| 52 | - String settingUpBeanManagerException(String util); | |
| 53 | - | |
| 54 | - @MessageTemplate("{processing-fail}") | |
| 55 | - String processingFail(); | |
| 56 | - | |
| 57 | -} | |
| 58 | 0 | \ No newline at end of file |
demoiselle-core/src/main/java/org/demoiselle/jee/stereotype/BusinessController.java
| ... | ... | @@ -1,36 +0,0 @@ |
| 1 | -/* | |
| 2 | - * Demoiselle Framework | |
| 3 | - * | |
| 4 | - * License: GNU Lesser General Public License (LGPL), version 3 or later. | |
| 5 | - * See the lgpl.txt file in the root directory or <https://www.gnu.org/licenses/lgpl.html>. | |
| 6 | - */ | |
| 7 | -package org.demoiselle.jee.stereotype; | |
| 8 | - | |
| 9 | -import javax.enterprise.inject.Stereotype; | |
| 10 | -import java.lang.annotation.Inherited; | |
| 11 | -import java.lang.annotation.Retention; | |
| 12 | -import java.lang.annotation.Target; | |
| 13 | - | |
| 14 | -import static java.lang.annotation.ElementType.TYPE; | |
| 15 | -import static java.lang.annotation.RetentionPolicy.RUNTIME; | |
| 16 | - | |
| 17 | -/** | |
| 18 | - * Identifies a <b>business controller</b> class. Business controller objects typically implement the controller design | |
| 19 | - * pattern, i.e., they contain no data elements but methods that orchestrate interaction among business entities. | |
| 20 | - * <p> | |
| 21 | - * A <i>Business Controller</i> is: | |
| 22 | - * <ul> | |
| 23 | - * <li>defined when annotated with {@code @BusinessController}</li> | |
| 24 | - * <li>automatically injected whenever {@code @Inject} is used</li> | |
| 25 | - * </ul> | |
| 26 | - * | |
| 27 | - * @author SERPRO | |
| 28 | - * @see Controller | |
| 29 | - */ | |
| 30 | -@Controller | |
| 31 | -@Stereotype | |
| 32 | -@Inherited | |
| 33 | -@Target(TYPE) | |
| 34 | -@Retention(RUNTIME) | |
| 35 | -public @interface BusinessController { | |
| 36 | -} |
demoiselle-core/src/main/java/org/demoiselle/jee/stereotype/Controller.java
| ... | ... | @@ -1,28 +0,0 @@ |
| 1 | -/* | |
| 2 | - * Demoiselle Framework | |
| 3 | - * | |
| 4 | - * License: GNU Lesser General Public License (LGPL), version 3 or later. | |
| 5 | - * See the lgpl.txt file in the root directory or <https://www.gnu.org/licenses/lgpl.html>. | |
| 6 | - */ | |
| 7 | -package org.demoiselle.jee.stereotype; | |
| 8 | - | |
| 9 | -import javax.interceptor.InterceptorBinding; | |
| 10 | -import java.lang.annotation.Inherited; | |
| 11 | -import java.lang.annotation.Retention; | |
| 12 | -import java.lang.annotation.Target; | |
| 13 | - | |
| 14 | -import static java.lang.annotation.ElementType.METHOD; | |
| 15 | -import static java.lang.annotation.ElementType.TYPE; | |
| 16 | -import static java.lang.annotation.RetentionPolicy.RUNTIME; | |
| 17 | - | |
| 18 | -/** | |
| 19 | - * Identifies a <b>controller</b> class or stereotype, the latter being most suitable for it. | |
| 20 | - * | |
| 21 | - * @author SERPRO | |
| 22 | - */ | |
| 23 | -@InterceptorBinding | |
| 24 | -@Inherited | |
| 25 | -@Target({ TYPE, METHOD }) | |
| 26 | -@Retention(RUNTIME) | |
| 27 | -public @interface Controller { | |
| 28 | -} |
demoiselle-core/src/main/java/org/demoiselle/jee/stereotype/PersistenceController.java
| ... | ... | @@ -1,37 +0,0 @@ |
| 1 | -/* | |
| 2 | - * Demoiselle Framework | |
| 3 | - * | |
| 4 | - * License: GNU Lesser General Public License (LGPL), version 3 or later. | |
| 5 | - * See the lgpl.txt file in the root directory or <https://www.gnu.org/licenses/lgpl.html>. | |
| 6 | - */ | |
| 7 | -package org.demoiselle.jee.stereotype; | |
| 8 | - | |
| 9 | -import javax.enterprise.inject.Stereotype; | |
| 10 | -import java.lang.annotation.Inherited; | |
| 11 | -import java.lang.annotation.Retention; | |
| 12 | -import java.lang.annotation.Target; | |
| 13 | - | |
| 14 | -import static java.lang.annotation.ElementType.TYPE; | |
| 15 | -import static java.lang.annotation.RetentionPolicy.RUNTIME; | |
| 16 | - | |
| 17 | -/** | |
| 18 | - * Identifies a <b>persistence controller</b> class. A persistence controller is | |
| 19 | - * a layer which provides simplified access to data stored in persistent storage | |
| 20 | - * of some kind, such as an entity-relational database. | |
| 21 | - * <p> | |
| 22 | - * A <i>Persitence Controller</i> is: | |
| 23 | - * <ul> | |
| 24 | - * <li>defined when annotated with {@code @PersistenceController}</li> | |
| 25 | - * <li>automatically injected whenever {@code @Inject} is used</li> | |
| 26 | - * </ul> | |
| 27 | - * | |
| 28 | - * @author SERPRO | |
| 29 | - * @see Controller | |
| 30 | - */ | |
| 31 | -@Controller | |
| 32 | -@Stereotype | |
| 33 | -@Inherited | |
| 34 | -@Target(TYPE) | |
| 35 | -@Retention(RUNTIME) | |
| 36 | -public @interface PersistenceController { | |
| 37 | -} |
demoiselle-core/src/main/java/org/demoiselle/jee/stereotype/RestController.java
| ... | ... | @@ -1,36 +0,0 @@ |
| 1 | -/* | |
| 2 | - * Demoiselle Framework | |
| 3 | - * | |
| 4 | - * License: GNU Lesser General Public License (LGPL), version 3 or later. | |
| 5 | - * See the lgpl.txt file in the root directory or <https://www.gnu.org/licenses/lgpl.html>. | |
| 6 | - */ | |
| 7 | -package org.demoiselle.jee.stereotype; | |
| 8 | - | |
| 9 | -import javax.enterprise.inject.Stereotype; | |
| 10 | -import java.lang.annotation.Inherited; | |
| 11 | -import java.lang.annotation.Retention; | |
| 12 | -import java.lang.annotation.Target; | |
| 13 | - | |
| 14 | -import static java.lang.annotation.ElementType.TYPE; | |
| 15 | -import static java.lang.annotation.RetentionPolicy.RUNTIME; | |
| 16 | - | |
| 17 | -/** | |
| 18 | - * Identifies a <b>facade</b> class. A facade is an object that provides a | |
| 19 | - * simplified interface to a larger body of code, such as a class library. | |
| 20 | - * <p> | |
| 21 | - * A <i>Facade</i> is: | |
| 22 | - * <ul> | |
| 23 | - * <li>defined when annotated with {@code @FacadeController}</li> | |
| 24 | - * <li>automatically injected whenever {@code @Inject} is used</li> | |
| 25 | - * </ul> | |
| 26 | - * | |
| 27 | - * @author SERPRO | |
| 28 | - * @see Controller | |
| 29 | - */ | |
| 30 | -@Controller | |
| 31 | -@Stereotype | |
| 32 | -@Inherited | |
| 33 | -@Target(TYPE) | |
| 34 | -@Retention(RUNTIME) | |
| 35 | -public @interface RestController { | |
| 36 | -} |
demoiselle-parent/pom.xml
| 1 | 1 | <?xml version="1.0" encoding="UTF-8"?> |
| 2 | 2 | <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
| 3 | - xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | |
| 4 | - | |
| 5 | - <artifactId>demoiselle-parent</artifactId> | |
| 6 | - <packaging>pom</packaging> | |
| 7 | - <modelVersion>4.0.0</modelVersion> | |
| 8 | - | |
| 9 | - <name>Demoiselle Parent POM</name> | |
| 10 | - | |
| 11 | - <parent> | |
| 12 | - <groupId>org.demoiselle.jee</groupId> | |
| 13 | - <artifactId>demoiselle-build</artifactId> | |
| 14 | - <version>3.0.0-BETA1-SNAPSHOT</version> | |
| 15 | - </parent> | |
| 16 | - | |
| 17 | - <properties> | |
| 18 | - <!-- General --> | |
| 19 | - <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | |
| 20 | - | |
| 21 | - <!-- Dependencies versions --> | |
| 22 | - <javaee.version>7.0</javaee.version> | |
| 23 | - <cdi.version>1.2</cdi.version> | |
| 24 | - <validation.version>1.1.0.Final</validation.version> | |
| 25 | - <transaction.version>1.2</transaction.version> | |
| 26 | - <jstl.version>1.2</jstl.version> | |
| 27 | - <el.version>3.0.0</el.version> | |
| 28 | - <servlet.version>3.1.0</servlet.version> | |
| 29 | - <persistence.version>1.0.2</persistence.version> | |
| 30 | - <rest.version>2.0</rest.version> | |
| 31 | - <concurrent.version>1.0</concurrent.version> | |
| 32 | - <hibernate.version>5.1.0.Final</hibernate.version> | |
| 33 | - <hibernate.validator.version>5.2.4.Final</hibernate.validator.version> | |
| 34 | - <commons.configuration.version>2.0</commons.configuration.version> | |
| 35 | - <jaxrs.version>2.0.1</jaxrs.version> | |
| 36 | - <javaee.version>7.0</javaee.version> | |
| 37 | - <deltaspike.version>1.7.1</deltaspike.version> | |
| 38 | - <ejb.version>3.2</ejb.version> | |
| 39 | - <cache.version>1.0.0</cache.version> | |
| 40 | - | |
| 41 | - <!-- Maven plugin versions --> | |
| 42 | - <maven.compiler.plugin.version>3.5.1</maven.compiler.plugin.version> | |
| 43 | - <maven.war.plugin.version>2.6</maven.war.plugin.version> | |
| 44 | - <maven.compiler.source>1.8</maven.compiler.source> | |
| 45 | - <maven.compiler.target>1.8</maven.compiler.target> | |
| 46 | - | |
| 47 | - </properties> | |
| 48 | - | |
| 49 | - <dependencyManagement> | |
| 50 | - | |
| 51 | - <dependencies> | |
| 52 | - | |
| 53 | - <!-- jsr-299 api --> | |
| 54 | - <dependency> | |
| 55 | - <groupId>javax.enterprise</groupId> | |
| 56 | - <artifactId>cdi-api</artifactId> | |
| 57 | - <scope>provided</scope> | |
| 58 | - <version>${cdi.version}</version> | |
| 59 | - </dependency> | |
| 60 | - | |
| 61 | - <!-- jsr-349 api --> | |
| 62 | - <dependency> | |
| 63 | - <artifactId>validation-api</artifactId> | |
| 64 | - <groupId>javax.validation</groupId> | |
| 65 | - <scope>provided</scope> | |
| 66 | - <version>${validation.version}</version> | |
| 67 | - </dependency> | |
| 68 | - | |
| 69 | - <!-- jsr-341 api and impl --> | |
| 70 | - <dependency> | |
| 71 | - <groupId>org.glassfish</groupId> | |
| 72 | - <artifactId>javax.el</artifactId> | |
| 73 | - <scope>provided</scope> | |
| 74 | - <version>${el.version}</version> | |
| 75 | - </dependency> | |
| 76 | - | |
| 77 | - <!-- jsr-342 api --> | |
| 78 | - <dependency> | |
| 79 | - <groupId>javax</groupId> | |
| 80 | - <artifactId>javaee-api</artifactId> | |
| 81 | - <scope>provided</scope> | |
| 82 | - <version>${javaee.version}</version> | |
| 83 | - </dependency> | |
| 84 | - | |
| 85 | - <!-- jsr-340 api --> | |
| 86 | - <dependency> | |
| 87 | - <groupId>javax.servlet</groupId> | |
| 88 | - <artifactId>javax.servlet-api</artifactId> | |
| 89 | - <scope>provided</scope> | |
| 90 | - <version>${servlet.version}</version> | |
| 91 | - </dependency> | |
| 92 | - <dependency> | |
| 93 | - <groupId>javax.servlet</groupId> | |
| 94 | - <artifactId>jstl</artifactId> | |
| 95 | - <scope>provided</scope> | |
| 96 | - <version>${jstl.version}</version> | |
| 97 | - </dependency> | |
| 98 | - | |
| 99 | - <!-- jsr-338 api --> | |
| 100 | - <dependency> | |
| 101 | - <groupId>org.hibernate</groupId> | |
| 102 | - <artifactId>hibernate-entitymanager</artifactId> | |
| 103 | - <scope>provided</scope> | |
| 104 | - <version>${hibernate.version}</version> | |
| 105 | - </dependency> | |
| 106 | - | |
| 107 | - <!-- jsr-339 api --> | |
| 108 | - <dependency> | |
| 109 | - <groupId>javax.ws.rs</groupId> | |
| 110 | - <artifactId>javax.ws.rs-api</artifactId> | |
| 111 | - <scope>provided</scope> | |
| 112 | - <version>${jaxrs.version}</version> | |
| 113 | - </dependency> | |
| 114 | - | |
| 115 | - <!-- jsr-342 api --> | |
| 116 | - <dependency> | |
| 117 | - <groupId>javax</groupId> | |
| 118 | - <artifactId>javaee-web-api</artifactId> | |
| 119 | - <version>${javaee.version}</version> | |
| 120 | - </dependency> | |
| 121 | - | |
| 122 | - <!-- jsr-318 api --> | |
| 123 | - <dependency> | |
| 124 | - <groupId>javax.ejb</groupId> | |
| 125 | - <artifactId>javax.ejb-api</artifactId> | |
| 126 | - <version>${ejb.version}</version> | |
| 127 | - <scope>provided</scope> | |
| 128 | - </dependency> | |
| 129 | - | |
| 130 | - <!-- jsr-107 api --> | |
| 131 | - <dependency> | |
| 132 | - <groupId>javax.cache</groupId> | |
| 133 | - <artifactId>cache-api</artifactId> | |
| 134 | - <version>${cache.version}</version> | |
| 135 | - </dependency> | |
| 136 | - | |
| 137 | - <!-- jsr-107 api --> | |
| 138 | - <dependency> | |
| 139 | - <groupId>javax.persistence</groupId> | |
| 140 | - <artifactId>persistence-api</artifactId> | |
| 141 | - <version>${persistence.version}</version> | |
| 142 | - </dependency> | |
| 143 | - | |
| 144 | - <dependency> | |
| 145 | - <groupId>javax.transaction</groupId> | |
| 146 | - <artifactId>javax.transaction-api</artifactId> | |
| 147 | - <version>${transaction.version}</version> | |
| 148 | - </dependency> | |
| 149 | - | |
| 150 | - <dependency> | |
| 151 | - <groupId>javax.json</groupId> | |
| 152 | - <artifactId>javax.json-api</artifactId> | |
| 153 | - <version>1.0</version> | |
| 154 | - </dependency> | |
| 155 | - | |
| 156 | - <!-- configuration e messages --> | |
| 157 | - <dependency> | |
| 158 | - <groupId>org.apache.deltaspike.core</groupId> | |
| 159 | - <artifactId>deltaspike-core-api</artifactId> | |
| 160 | - <scope>compile</scope> | |
| 161 | - <version>${deltaspike.version}</version> | |
| 162 | - </dependency> | |
| 163 | - <dependency> | |
| 164 | - <groupId>org.apache.deltaspike.core</groupId> | |
| 165 | - <artifactId>deltaspike-core-impl</artifactId> | |
| 166 | - <scope>runtime</scope> | |
| 167 | - <version>${deltaspike.version}</version> | |
| 168 | - </dependency> | |
| 169 | - | |
| 170 | - <!-- demoiselle --> | |
| 171 | - <dependency> | |
| 172 | - <groupId>org.demoiselle.jee</groupId> | |
| 173 | - <artifactId>demoiselle-core</artifactId> | |
| 174 | - <version>${project.version}</version> | |
| 175 | - </dependency> | |
| 176 | - | |
| 177 | - </dependencies> | |
| 178 | - | |
| 179 | - </dependencyManagement> | |
| 3 | + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | |
| 4 | + | |
| 5 | + <artifactId>demoiselle-parent</artifactId> | |
| 6 | + <packaging>pom</packaging> | |
| 7 | + <modelVersion>4.0.0</modelVersion> | |
| 8 | + | |
| 9 | + <name>Demoiselle Parent POM</name> | |
| 10 | + | |
| 11 | + <parent> | |
| 12 | + <groupId>org.demoiselle.jee</groupId> | |
| 13 | + <artifactId>demoiselle-build</artifactId> | |
| 14 | + <version>3.0.0-BETA1-SNAPSHOT</version> | |
| 15 | + </parent> | |
| 16 | + | |
| 17 | + <properties> | |
| 18 | + <!-- General --> | |
| 19 | + <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | |
| 20 | + | |
| 21 | + <!-- Dependencies versions --> | |
| 22 | + <javaee.version>7.0</javaee.version> | |
| 23 | + <cdi.version>1.2</cdi.version> | |
| 24 | + <validation.version>1.1.0.Final</validation.version> | |
| 25 | + <transaction.version>1.2</transaction.version> | |
| 26 | + <jstl.version>1.2</jstl.version> | |
| 27 | + <el.version>3.0.0</el.version> | |
| 28 | + <servlet.version>3.1.0</servlet.version> | |
| 29 | + <persistence.version>1.0.2</persistence.version> | |
| 30 | + <rest.version>2.0</rest.version> | |
| 31 | + <concurrent.version>1.0</concurrent.version> | |
| 32 | + <hibernate.version>5.1.0.Final</hibernate.version> | |
| 33 | + <hibernate.validator.version>5.2.4.Final</hibernate.validator.version> | |
| 34 | + <commons.configuration.version>2.0</commons.configuration.version> | |
| 35 | + <jaxrs.version>2.0.1</jaxrs.version> | |
| 36 | + <javaee.version>7.0</javaee.version> | |
| 37 | + <deltaspike.version>1.7.1</deltaspike.version> | |
| 38 | + <ejb.version>3.2</ejb.version> | |
| 39 | + <cache.version>1.0.0</cache.version> | |
| 40 | + | |
| 41 | + <!-- Maven plugin versions --> | |
| 42 | + <maven.compiler.plugin.version>3.5.1</maven.compiler.plugin.version> | |
| 43 | + <maven.war.plugin.version>2.6</maven.war.plugin.version> | |
| 44 | + <maven.compiler.source>1.8</maven.compiler.source> | |
| 45 | + <maven.compiler.target>1.8</maven.compiler.target> | |
| 46 | + | |
| 47 | + </properties> | |
| 48 | + | |
| 49 | + <dependencyManagement> | |
| 50 | + | |
| 51 | + <dependencies> | |
| 52 | + | |
| 53 | + <!-- jsr-299 api --> | |
| 54 | + <dependency> | |
| 55 | + <groupId>javax.enterprise</groupId> | |
| 56 | + <artifactId>cdi-api</artifactId> | |
| 57 | + <scope>provided</scope> | |
| 58 | + <version>${cdi.version}</version> | |
| 59 | + </dependency> | |
| 60 | + | |
| 61 | + <!-- jsr-349 api --> | |
| 62 | + <dependency> | |
| 63 | + <artifactId>validation-api</artifactId> | |
| 64 | + <groupId>javax.validation</groupId> | |
| 65 | + <scope>provided</scope> | |
| 66 | + <version>${validation.version}</version> | |
| 67 | + </dependency> | |
| 68 | + | |
| 69 | + <!-- jsr-341 api and impl --> | |
| 70 | + <dependency> | |
| 71 | + <groupId>org.glassfish</groupId> | |
| 72 | + <artifactId>javax.el</artifactId> | |
| 73 | + <scope>provided</scope> | |
| 74 | + <version>${el.version}</version> | |
| 75 | + </dependency> | |
| 76 | + | |
| 77 | + <!-- jsr-342 api --> | |
| 78 | + <dependency> | |
| 79 | + <groupId>javax</groupId> | |
| 80 | + <artifactId>javaee-api</artifactId> | |
| 81 | + <scope>provided</scope> | |
| 82 | + <version>${javaee.version}</version> | |
| 83 | + </dependency> | |
| 84 | + | |
| 85 | + <!-- jsr-340 api --> | |
| 86 | + <dependency> | |
| 87 | + <groupId>javax.servlet</groupId> | |
| 88 | + <artifactId>javax.servlet-api</artifactId> | |
| 89 | + <scope>provided</scope> | |
| 90 | + <version>${servlet.version}</version> | |
| 91 | + </dependency> | |
| 92 | + <dependency> | |
| 93 | + <groupId>javax.servlet</groupId> | |
| 94 | + <artifactId>jstl</artifactId> | |
| 95 | + <scope>provided</scope> | |
| 96 | + <version>${jstl.version}</version> | |
| 97 | + </dependency> | |
| 98 | + | |
| 99 | + <!-- jsr-338 api --> | |
| 100 | + <dependency> | |
| 101 | + <groupId>org.hibernate</groupId> | |
| 102 | + <artifactId>hibernate-entitymanager</artifactId> | |
| 103 | + <scope>provided</scope> | |
| 104 | + <version>${hibernate.version}</version> | |
| 105 | + </dependency> | |
| 106 | + | |
| 107 | + <!-- jsr-339 api --> | |
| 108 | + <dependency> | |
| 109 | + <groupId>javax.ws.rs</groupId> | |
| 110 | + <artifactId>javax.ws.rs-api</artifactId> | |
| 111 | + <scope>provided</scope> | |
| 112 | + <version>${jaxrs.version}</version> | |
| 113 | + </dependency> | |
| 114 | + | |
| 115 | + <!-- jsr-342 api --> | |
| 116 | + <dependency> | |
| 117 | + <groupId>javax</groupId> | |
| 118 | + <artifactId>javaee-web-api</artifactId> | |
| 119 | + <version>${javaee.version}</version> | |
| 120 | + </dependency> | |
| 121 | + | |
| 122 | + <!-- jsr-318 api --> | |
| 123 | + <dependency> | |
| 124 | + <groupId>javax.ejb</groupId> | |
| 125 | + <artifactId>javax.ejb-api</artifactId> | |
| 126 | + <version>${ejb.version}</version> | |
| 127 | + <scope>provided</scope> | |
| 128 | + </dependency> | |
| 129 | + | |
| 130 | + <!-- jsr-107 api --> | |
| 131 | + <dependency> | |
| 132 | + <groupId>javax.cache</groupId> | |
| 133 | + <artifactId>cache-api</artifactId> | |
| 134 | + <version>${cache.version}</version> | |
| 135 | + </dependency> | |
| 136 | + | |
| 137 | + <!-- jsr-107 api --> | |
| 138 | + <dependency> | |
| 139 | + <groupId>javax.persistence</groupId> | |
| 140 | + <artifactId>persistence-api</artifactId> | |
| 141 | + <version>${persistence.version}</version> | |
| 142 | + </dependency> | |
| 143 | + | |
| 144 | + <dependency> | |
| 145 | + <groupId>javax.transaction</groupId> | |
| 146 | + <artifactId>javax.transaction-api</artifactId> | |
| 147 | + <version>${transaction.version}</version> | |
| 148 | + </dependency> | |
| 149 | + | |
| 150 | + <dependency> | |
| 151 | + <groupId>javax.json</groupId> | |
| 152 | + <artifactId>javax.json-api</artifactId> | |
| 153 | + <version>1.0</version> | |
| 154 | + </dependency> | |
| 155 | + | |
| 156 | + <!-- configuration e messages --> | |
| 157 | + <dependency> | |
| 158 | + <groupId>org.apache.deltaspike.core</groupId> | |
| 159 | + <artifactId>deltaspike-core-api</artifactId> | |
| 160 | + <scope>compile</scope> | |
| 161 | + <version>${deltaspike.version}</version> | |
| 162 | + </dependency> | |
| 163 | + <dependency> | |
| 164 | + <groupId>org.apache.deltaspike.core</groupId> | |
| 165 | + <artifactId>deltaspike-core-impl</artifactId> | |
| 166 | + <scope>runtime</scope> | |
| 167 | + <version>${deltaspike.version}</version> | |
| 168 | + </dependency> | |
| 169 | + | |
| 170 | + <!-- demoiselle --> | |
| 171 | + <dependency> | |
| 172 | + <groupId>org.demoiselle.jee</groupId> | |
| 173 | + <artifactId>demoiselle-core</artifactId> | |
| 174 | + <version>${project.version}</version> | |
| 175 | + </dependency> | |
| 176 | + | |
| 177 | + <dependency> | |
| 178 | + <groupId>org.demoiselle.jee</groupId> | |
| 179 | + <artifactId>demoiselle-security</artifactId> | |
| 180 | + <version>${project.version}</version> | |
| 181 | + </dependency> | |
| 182 | + | |
| 183 | + </dependencies> | |
| 184 | + | |
| 185 | + </dependencyManagement> | |
| 180 | 186 | |
| 181 | 187 | </project> | ... | ... |
| ... | ... | @@ -0,0 +1,37 @@ |
| 1 | +<?xml version="1.0" encoding="UTF-8"?> | |
| 2 | +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | |
| 3 | + <modelVersion>4.0.0</modelVersion> | |
| 4 | + <artifactId>demoiselle-rest</artifactId> | |
| 5 | + <packaging>jar</packaging> | |
| 6 | + | |
| 7 | + <name>Demoiselle Rest</name> | |
| 8 | + <description> | |
| 9 | + Demoiselle Rest | |
| 10 | + </description> | |
| 11 | + | |
| 12 | + <parent> | |
| 13 | + <groupId>org.demoiselle.jee</groupId> | |
| 14 | + <artifactId>demoiselle-parent</artifactId> | |
| 15 | + <version>3.0.0-BETA1-SNAPSHOT</version> | |
| 16 | + <relativePath>../demoiselle-parent</relativePath> | |
| 17 | + </parent> | |
| 18 | + | |
| 19 | + <dependencies> | |
| 20 | + | |
| 21 | + <dependency> | |
| 22 | + <groupId>org.demoiselle.jee</groupId> | |
| 23 | + <artifactId>demoiselle-core</artifactId> | |
| 24 | + </dependency> | |
| 25 | + | |
| 26 | + <dependency> | |
| 27 | + <groupId>javax.ws.rs</groupId> | |
| 28 | + <artifactId>javax.ws.rs-api</artifactId> | |
| 29 | + </dependency> | |
| 30 | + | |
| 31 | + <dependency> | |
| 32 | + <groupId>javax.json</groupId> | |
| 33 | + <artifactId>javax.json-api</artifactId> | |
| 34 | + </dependency> | |
| 35 | + | |
| 36 | + </dependencies> | |
| 37 | +</project> | ... | ... |
demoiselle-rest/src/main/java/org/demoiselle/jee/ws/jaxrs/JaxRsFilter.java
0 → 100644
| ... | ... | @@ -0,0 +1,59 @@ |
| 1 | +/* | |
| 2 | + * Demoiselle Framework | |
| 3 | + * | |
| 4 | + * License: GNU Lesser General Public License (LGPL), version 3 or later. | |
| 5 | + * See the lgpl.txt file in the root directory or <https://www.gnu.org/licenses/lgpl.html>. | |
| 6 | + */ | |
| 7 | +package org.demoiselle.jee.ws.jaxrs; | |
| 8 | + | |
| 9 | +import java.util.logging.Logger; | |
| 10 | +import javax.annotation.PostConstruct; | |
| 11 | +import javax.inject.Inject; | |
| 12 | +import javax.ws.rs.client.ClientRequestContext; | |
| 13 | +import javax.ws.rs.client.ClientRequestFilter; | |
| 14 | +import javax.ws.rs.client.ClientResponseContext; | |
| 15 | +import javax.ws.rs.client.ClientResponseFilter; | |
| 16 | +import javax.ws.rs.container.ContainerRequestContext; | |
| 17 | +import javax.ws.rs.container.ContainerRequestFilter; | |
| 18 | +import javax.ws.rs.container.ContainerResponseContext; | |
| 19 | +import javax.ws.rs.container.ContainerResponseFilter; | |
| 20 | +import javax.ws.rs.container.PreMatching; | |
| 21 | +import javax.ws.rs.ext.Provider; | |
| 22 | + | |
| 23 | +/** | |
| 24 | + * | |
| 25 | + * @author 70744416353 | |
| 26 | + */ | |
| 27 | +@Provider | |
| 28 | +@PreMatching | |
| 29 | +public class JaxRsFilter implements ClientRequestFilter, ClientResponseFilter, ContainerRequestFilter, ContainerResponseFilter { | |
| 30 | + | |
| 31 | + @Inject | |
| 32 | + private Logger LOG; | |
| 33 | + | |
| 34 | + @Override | |
| 35 | + public void filter(ClientRequestContext requestContext) { | |
| 36 | + } | |
| 37 | + | |
| 38 | + @Override | |
| 39 | + public void filter(ClientRequestContext requestContext, ClientResponseContext responseContext) { | |
| 40 | + } | |
| 41 | + | |
| 42 | + @Override | |
| 43 | + public void filter(ContainerRequestContext requestContext) { | |
| 44 | + } | |
| 45 | + | |
| 46 | + @Override | |
| 47 | + public void filter(ContainerRequestContext requestContext, ContainerResponseContext response) { | |
| 48 | + response.getHeaders().putSingle("Demoiselle", "3.0.0"); | |
| 49 | + response.getHeaders().putSingle("Access-Control-Allow-Origin", "*"); | |
| 50 | + response.getHeaders().putSingle("Access-Control-Allow-Methods", "OPTIONS, GET, POST, PUT, DELETE"); | |
| 51 | + response.getHeaders().putSingle("Access-Control-Allow-Headers", "Content-Type"); | |
| 52 | + } | |
| 53 | + | |
| 54 | + @PostConstruct | |
| 55 | + public void init() { | |
| 56 | + LOG.info("Demoiselle Module - Rest"); | |
| 57 | + } | |
| 58 | + | |
| 59 | +} | ... | ... |
demoiselle-rest/src/main/java/org/demoiselle/jee/ws/jaxrs/crud/package-info.java
0 → 100644
| ... | ... | @@ -0,0 +1,11 @@ |
| 1 | +/* | |
| 2 | + * Demoiselle Framework | |
| 3 | + * | |
| 4 | + * License: GNU Lesser General Public License (LGPL), version 3 or later. | |
| 5 | + * See the lgpl.txt file in the root directory or <https://www.gnu.org/licenses/lgpl.html>. | |
| 6 | + */ | |
| 7 | +/** | |
| 8 | + * Esta pacote tem o objetivo de conter as classes relacionadas aos | |
| 9 | + * facilitadores de CRUD do framework Demoiselle. | |
| 10 | + */ | |
| 11 | +package org.demoiselle.jee.ws.jaxrs.crud; | |
| 0 | 12 | \ No newline at end of file | ... | ... |
demoiselle-rest/src/main/java/org/demoiselle/jee/ws/jaxrs/exception/DemoiselleRESTException.java
0 → 100644
| ... | ... | @@ -0,0 +1,41 @@ |
| 1 | +/* | |
| 2 | + * Demoiselle Framework | |
| 3 | + * | |
| 4 | + * License: GNU Lesser General Public License (LGPL), version 3 or later. | |
| 5 | + * See the lgpl.txt file in the root directory or <https://www.gnu.org/licenses/lgpl.html>. | |
| 6 | + */ | |
| 7 | +package org.demoiselle.jee.ws.jaxrs.exception; | |
| 8 | + | |
| 9 | +import java.util.HashMap; | |
| 10 | + | |
| 11 | +import org.demoiselle.jee.core.exception.DemoiselleException; | |
| 12 | + | |
| 13 | +public class DemoiselleRESTException extends DemoiselleException { | |
| 14 | + | |
| 15 | + private static final long serialVersionUID = 519965615171844237L; | |
| 16 | + | |
| 17 | + private HashMap<String, String> messages = new HashMap<String, String>(); | |
| 18 | + | |
| 19 | + private int statusCode; | |
| 20 | + | |
| 21 | + public DemoiselleRESTException() { | |
| 22 | + | |
| 23 | + } | |
| 24 | + | |
| 25 | + public DemoiselleRESTException(String string) { | |
| 26 | + super(string); | |
| 27 | + } | |
| 28 | + | |
| 29 | + public int getStatusCode() { | |
| 30 | + return statusCode; | |
| 31 | + } | |
| 32 | + | |
| 33 | + public void addMessage(String field, String msg) { | |
| 34 | + this.statusCode = 422; | |
| 35 | + messages.put(field, msg); | |
| 36 | + } | |
| 37 | + | |
| 38 | + public HashMap<String, String> getMessages() { | |
| 39 | + return messages; | |
| 40 | + } | |
| 41 | +} | ... | ... |
demoiselle-rest/src/main/java/org/demoiselle/jee/ws/jaxrs/exception/mapper/GenericExceptionMapper.java
0 → 100644
| ... | ... | @@ -0,0 +1,68 @@ |
| 1 | +/* | |
| 2 | + * Demoiselle Framework | |
| 3 | + * | |
| 4 | + * License: GNU Lesser General Public License (LGPL), version 3 or later. | |
| 5 | + * See the lgpl.txt file in the root directory or <https://www.gnu.org/licenses/lgpl.html>. | |
| 6 | + */ | |
| 7 | +package org.demoiselle.jee.ws.jaxrs.exception.mapper; | |
| 8 | + | |
| 9 | +import java.io.PrintWriter; | |
| 10 | +import java.io.StringWriter; | |
| 11 | +import java.util.HashMap; | |
| 12 | + | |
| 13 | +import javax.ws.rs.WebApplicationException; | |
| 14 | +import javax.ws.rs.core.MediaType; | |
| 15 | +import javax.ws.rs.core.Response; | |
| 16 | +import javax.ws.rs.ext.ExceptionMapper; | |
| 17 | +import javax.ws.rs.ext.Provider; | |
| 18 | + | |
| 19 | +import org.demoiselle.jee.ws.jaxrs.exception.DemoiselleRESTException; | |
| 20 | + | |
| 21 | +@Provider | |
| 22 | +public class GenericExceptionMapper implements ExceptionMapper<Exception> { | |
| 23 | + | |
| 24 | + public Response toResponse(Exception ex) { | |
| 25 | + | |
| 26 | + StringWriter errorStackTrace = new StringWriter(); | |
| 27 | + ex.printStackTrace(new PrintWriter(errorStackTrace)); | |
| 28 | + | |
| 29 | + // Verifica se a exception é de validação de PAYLOAD do REST | |
| 30 | + if (ex.getCause() instanceof DemoiselleRESTException) { | |
| 31 | + DemoiselleRESTException exDemoiselleREST = (DemoiselleRESTException) ex.getCause(); | |
| 32 | + if (!exDemoiselleREST.getMessages().isEmpty()) { | |
| 33 | + return Response.status(exDemoiselleREST.getStatusCode()).entity(exDemoiselleREST.getMessages()) | |
| 34 | + .type(MediaType.APPLICATION_JSON).build(); | |
| 35 | + } | |
| 36 | + } | |
| 37 | + | |
| 38 | + HashMap<String, String> entity = new HashMap<String, String>(); | |
| 39 | + | |
| 40 | + // No caso de existir message ele mostra a MESSAGE da Exception | |
| 41 | + if (ex.getMessage() != null) { | |
| 42 | + entity.put("error", ex.getMessage()); | |
| 43 | + | |
| 44 | + // Pega toda as mensagens da stacktrace | |
| 45 | + int level = 1; | |
| 46 | + while (ex.getCause() != null) { | |
| 47 | + ex = (Exception) ex.getCause(); | |
| 48 | + if (!ex.getMessage().isEmpty()) { | |
| 49 | + entity.put("inner_cause_" + level, ex.getMessage()); | |
| 50 | + } | |
| 51 | + level += 1; | |
| 52 | + } | |
| 53 | + | |
| 54 | + // Por padrão retorna SERVER ERROR, mas tenta encontrar o status do RESPONSE se for WebApplicationException | |
| 55 | + // http://docs.oracle.com/javaee/7/api/javax/ws/rs/WebApplicationException.html | |
| 56 | + int responseCode = Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(); | |
| 57 | + if (ex instanceof WebApplicationException) { | |
| 58 | + responseCode = ((WebApplicationException)ex).getResponse().getStatus(); | |
| 59 | + } | |
| 60 | + | |
| 61 | + return Response.status(responseCode).entity(entity).type(MediaType.APPLICATION_JSON).build(); | |
| 62 | + } | |
| 63 | + | |
| 64 | + entity.put("error", "Erro interno desconhecido no servidor."); | |
| 65 | + return Response.status(500).entity(entity).type(MediaType.APPLICATION_JSON).build(); | |
| 66 | + } | |
| 67 | + | |
| 68 | +} | ... | ... |
demoiselle-rest/src/main/java/org/demoiselle/jee/ws/jaxrs/interceptor/ValidatePayload.java
0 → 100644
| ... | ... | @@ -0,0 +1,25 @@ |
| 1 | +/* | |
| 2 | + * Demoiselle Framework | |
| 3 | + * | |
| 4 | + * License: GNU Lesser General Public License (LGPL), version 3 or later. | |
| 5 | + * See the lgpl.txt file in the root directory or <https://www.gnu.org/licenses/lgpl.html>. | |
| 6 | + */ | |
| 7 | +package org.demoiselle.jee.ws.jaxrs.interceptor; | |
| 8 | + | |
| 9 | +import static java.lang.annotation.ElementType.METHOD; | |
| 10 | +import static java.lang.annotation.ElementType.TYPE; | |
| 11 | +import static java.lang.annotation.RetentionPolicy.RUNTIME; | |
| 12 | + | |
| 13 | +import java.lang.annotation.Inherited; | |
| 14 | +import java.lang.annotation.Retention; | |
| 15 | +import java.lang.annotation.Target; | |
| 16 | + | |
| 17 | +import javax.interceptor.InterceptorBinding; | |
| 18 | + | |
| 19 | +@Inherited | |
| 20 | +@InterceptorBinding | |
| 21 | +@Target({ METHOD, TYPE }) | |
| 22 | +@Retention(RUNTIME) | |
| 23 | +public @interface ValidatePayload { | |
| 24 | + | |
| 25 | +} | |
| 0 | 26 | \ No newline at end of file | ... | ... |
demoiselle-rest/src/main/java/org/demoiselle/jee/ws/jaxrs/interceptor/ValidatePayloadInterceptor.java
0 → 100644
| ... | ... | @@ -0,0 +1,62 @@ |
| 1 | +/* | |
| 2 | + * Demoiselle Framework | |
| 3 | + * | |
| 4 | + * License: GNU Lesser General Public License (LGPL), version 3 or later. | |
| 5 | + * See the lgpl.txt file in the root directory or <https://www.gnu.org/licenses/lgpl.html>. | |
| 6 | + */ | |
| 7 | +package org.demoiselle.jee.ws.jaxrs.interceptor; | |
| 8 | + | |
| 9 | +import java.io.Serializable; | |
| 10 | +import java.util.HashSet; | |
| 11 | +import java.util.Set; | |
| 12 | + | |
| 13 | +import javax.interceptor.AroundInvoke; | |
| 14 | +import javax.interceptor.Interceptor; | |
| 15 | +import javax.interceptor.InvocationContext; | |
| 16 | +import javax.validation.ConstraintViolation; | |
| 17 | +import javax.validation.UnexpectedTypeException; | |
| 18 | +import javax.validation.Validation; | |
| 19 | +import javax.validation.Validator; | |
| 20 | +import javax.validation.ValidatorFactory; | |
| 21 | + | |
| 22 | +import org.demoiselle.jee.ws.jaxrs.exception.DemoiselleRESTException; | |
| 23 | + | |
| 24 | +@Interceptor | |
| 25 | +@ValidatePayload | |
| 26 | +public class ValidatePayloadInterceptor implements Serializable { | |
| 27 | + | |
| 28 | + private static final long serialVersionUID = 1L; | |
| 29 | + | |
| 30 | + @AroundInvoke | |
| 31 | + public Object manage(final InvocationContext ic) throws Exception { | |
| 32 | + DemoiselleRESTException ex = new DemoiselleRESTException(); | |
| 33 | + Set<ConstraintViolation<?>> violations = new HashSet<ConstraintViolation<?>>(); | |
| 34 | + for (Object params : ic.getParameters()) { | |
| 35 | + if (params != null) { | |
| 36 | + ValidatorFactory dfv = Validation.buildDefaultValidatorFactory(); | |
| 37 | + Validator validator = dfv.getValidator(); | |
| 38 | + try { | |
| 39 | + violations.addAll(validator.validate(params)); | |
| 40 | + for (ConstraintViolation<?> violation : violations) { | |
| 41 | + String field = (violation.getRootBeanClass().getSimpleName() + "_" | |
| 42 | + + violation.getPropertyPath()).toLowerCase(); | |
| 43 | + // GPMessage msg = | |
| 44 | + // GPMessage.INVALID_FIELD_P1.setSufix(violation.getConstraintDescriptor() | |
| 45 | + // .getAnnotation().annotationType().getSimpleName().toLowerCase()); | |
| 46 | + | |
| 47 | + ex.addMessage(field, violation.getMessage()); | |
| 48 | + } | |
| 49 | + } catch (UnexpectedTypeException cause) { | |
| 50 | + // GPMessage msg = GPMessage.GENERAL_ERROR_P1; | |
| 51 | + // msg.setParam(cause.getMessage()); | |
| 52 | + throw new DemoiselleRESTException("ERRO GENERICO -> ALTERAR"); | |
| 53 | + } | |
| 54 | + } | |
| 55 | + } | |
| 56 | + | |
| 57 | + if (!violations.isEmpty() && !ex.getMessages().isEmpty()) { | |
| 58 | + throw ex; | |
| 59 | + } | |
| 60 | + return ic.proceed(); | |
| 61 | + } | |
| 62 | +} | |
| 0 | 63 | \ No newline at end of file | ... | ... |
demoiselle-security-basic/pom.xml
| 1 | 1 | <?xml version="1.0" encoding="UTF-8"?> |
| 2 | 2 | <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> |
| 3 | 3 | <modelVersion>4.0.0</modelVersion> |
| 4 | - <groupId>org.demoiselle.jee</groupId> | |
| 5 | 4 | <artifactId>demoiselle-security-basic</artifactId> |
| 6 | - <version>3.0.0-SNAPSHOT</version> | |
| 7 | 5 | <packaging>jar</packaging> |
| 8 | - <properties> | |
| 9 | - <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | |
| 10 | - <maven.compiler.source>1.8</maven.compiler.source> | |
| 11 | - <maven.compiler.target>1.8</maven.compiler.target> | |
| 12 | - </properties> | |
| 6 | + | |
| 7 | + <name>Demoiselle Security Basic</name> | |
| 8 | + <description> | |
| 9 | + Demoiselle Security Basic | |
| 10 | + </description> | |
| 11 | + | |
| 12 | + <parent> | |
| 13 | + <groupId>org.demoiselle.jee</groupId> | |
| 14 | + <artifactId>demoiselle-parent</artifactId> | |
| 15 | + <version>3.0.0-BETA1-SNAPSHOT</version> | |
| 16 | + <relativePath>../demoiselle-parent</relativePath> | |
| 17 | + </parent> | |
| 18 | + | |
| 13 | 19 | <dependencies> |
| 14 | 20 | |
| 15 | 21 | <dependency> |
| 16 | - <groupId>${project.groupId}</groupId> | |
| 17 | - <artifactId>demoiselle-core</artifactId> | |
| 18 | - <version>${project.version}</version> | |
| 19 | - </dependency> | |
| 20 | - | |
| 21 | - <dependency> | |
| 22 | - <groupId>${project.groupId}</groupId> | |
| 23 | - <artifactId>demoiselle-ws-jaxrs</artifactId> | |
| 24 | - <version>${project.version}</version> | |
| 25 | - </dependency> | |
| 26 | - | |
| 27 | - <dependency> | |
| 28 | - <groupId>${project.groupId}</groupId> | |
| 22 | + <groupId>org.demoiselle.jee</groupId> | |
| 29 | 23 | <artifactId>demoiselle-security</artifactId> |
| 30 | - <version>${project.version}</version> | |
| 31 | 24 | </dependency> |
| 32 | 25 | |
| 33 | 26 | </dependencies> | ... | ... |
demoiselle-security-basic/src/main/java/org/demoiselle/jee/security/basic/impl/TokensManagerImpl.java
| ... | ... | @@ -6,14 +6,17 @@ |
| 6 | 6 | package org.demoiselle.jee.security.basic.impl; |
| 7 | 7 | |
| 8 | 8 | import java.security.Principal; |
| 9 | +import java.util.List; | |
| 9 | 10 | import java.util.Map; |
| 10 | 11 | import java.util.UUID; |
| 11 | 12 | import java.util.concurrent.ConcurrentHashMap; |
| 12 | 13 | import java.util.logging.Logger; |
| 13 | 14 | import javax.enterprise.context.Dependent; |
| 15 | +import javax.enterprise.context.RequestScoped; | |
| 14 | 16 | import javax.inject.Inject; |
| 15 | -import org.demoiselle.jee.security.Token; | |
| 16 | -import org.demoiselle.jee.security.interfaces.TokensManager; | |
| 17 | +import org.demoiselle.jee.core.interfaces.security.DemoisellePrincipal; | |
| 18 | +import org.demoiselle.jee.core.interfaces.security.Token; | |
| 19 | +import org.demoiselle.jee.core.interfaces.security.TokensManager; | |
| 17 | 20 | |
| 18 | 21 | /** |
| 19 | 22 | * |
| ... | ... | @@ -27,25 +30,41 @@ public class TokensManagerImpl implements TokensManager { |
| 27 | 30 | @Inject |
| 28 | 31 | private Logger logger; |
| 29 | 32 | |
| 33 | + @Inject | |
| 34 | + @RequestScoped | |
| 35 | + private Token token; | |
| 36 | + | |
| 37 | + @Inject | |
| 38 | + @RequestScoped | |
| 39 | + private Principal loggedUser; | |
| 40 | + | |
| 30 | 41 | @Override |
| 31 | - public Principal getUser(Token token) { | |
| 32 | - return repo.get(token.getKey()); | |
| 42 | + public Principal getUser() { | |
| 43 | + if (loggedUser == null) { | |
| 44 | + if (token.getKey() != null && !token.getKey().isEmpty()) { | |
| 45 | + loggedUser = repo.get(token.getKey()); | |
| 46 | + return loggedUser; | |
| 47 | + } | |
| 48 | + } | |
| 49 | + return loggedUser; | |
| 33 | 50 | } |
| 34 | 51 | |
| 35 | 52 | @Override |
| 36 | - public Token getToken(Principal user) { | |
| 53 | + public void setUser(Principal user) { | |
| 37 | 54 | String value = null; |
| 38 | 55 | if (!repo.containsValue(user)) { |
| 39 | 56 | value = UUID.randomUUID().toString(); |
| 40 | 57 | repo.put(value, user); |
| 41 | - } else { | |
| 42 | - for (Map.Entry<String, Principal> entry : repo.entrySet()) { | |
| 43 | - if (entry.getValue().equals(user)) { | |
| 44 | - return entry.getKey(); | |
| 45 | - } | |
| 46 | - } | |
| 58 | + token.setKey(value); | |
| 59 | + token.setType("Basic"); | |
| 47 | 60 | } |
| 48 | - return value; | |
| 49 | 61 | } |
| 50 | 62 | |
| 63 | + @Override | |
| 64 | + public boolean validate() { | |
| 65 | + return true;//(getUser() != null && repo.get(token.getKey()).); | |
| 66 | + } | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 51 | 70 | } | ... | ... |
demoiselle-security-jwt/pom.xml
| 1 | 1 | <?xml version="1.0" encoding="UTF-8"?> |
| 2 | 2 | <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> |
| 3 | 3 | <modelVersion>4.0.0</modelVersion> |
| 4 | - <groupId>org.demoiselle.jee</groupId> | |
| 5 | 4 | <artifactId>demoiselle-security-jwt</artifactId> |
| 6 | - <version>3.0.0-SNAPSHOT</version> | |
| 7 | 5 | <packaging>jar</packaging> |
| 8 | - <properties> | |
| 9 | - <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | |
| 10 | - <maven.compiler.source>1.8</maven.compiler.source> | |
| 11 | - <maven.compiler.target>1.8</maven.compiler.target> | |
| 12 | - </properties> | |
| 6 | + | |
| 7 | + <name>Demoiselle Security JWT</name> | |
| 8 | + <description> | |
| 9 | + Demoiselle Security JWT | |
| 10 | + </description> | |
| 11 | + | |
| 12 | + <parent> | |
| 13 | + <groupId>org.demoiselle.jee</groupId> | |
| 14 | + <artifactId>demoiselle-parent</artifactId> | |
| 15 | + <version>3.0.0-BETA1-SNAPSHOT</version> | |
| 16 | + <relativePath>../demoiselle-parent</relativePath> | |
| 17 | + </parent> | |
| 18 | + | |
| 13 | 19 | <dependencies> |
| 14 | 20 | |
| 15 | 21 | <dependency> |
| 16 | - <groupId>${project.groupId}</groupId> | |
| 17 | - <artifactId>demoiselle-core</artifactId> | |
| 18 | - <version>${project.version}</version> | |
| 19 | - </dependency> | |
| 20 | - | |
| 21 | - <dependency> | |
| 22 | - <groupId>${project.groupId}</groupId> | |
| 22 | + <groupId>org.demoiselle.jee</groupId> | |
| 23 | 23 | <artifactId>demoiselle-security</artifactId> |
| 24 | - <version>${project.version}</version> | |
| 25 | 24 | </dependency> |
| 26 | - | |
| 25 | + | |
| 27 | 26 | <dependency> |
| 28 | 27 | <groupId>org.bitbucket.b_c</groupId> |
| 29 | 28 | <artifactId>jose4j</artifactId> |
| ... | ... | @@ -36,6 +35,6 @@ |
| 36 | 35 | <version>2.2.2</version> |
| 37 | 36 | <scope>compile</scope> |
| 38 | 37 | </dependency> |
| 39 | - | |
| 38 | + | |
| 40 | 39 | </dependencies> |
| 41 | 40 | </project> | ... | ... |
demoiselle-security-jwt/src/main/java/org/demoiselle/jee/security/jwt/impl/TokensManagerImpl.java
| ... | ... | @@ -13,7 +13,8 @@ import java.util.logging.Logger; |
| 13 | 13 | import javax.enterprise.context.Dependent; |
| 14 | 14 | import javax.inject.Inject; |
| 15 | 15 | import javax.servlet.http.HttpServletRequest; |
| 16 | -import org.demoiselle.jee.security.interfaces.TokensManager; | |
| 16 | +import org.demoiselle.jee.core.security.LoggedUser; | |
| 17 | +import org.demoiselle.jee.core.security.TokensManager; | |
| 17 | 18 | import org.jose4j.jwk.RsaJsonWebKey; |
| 18 | 19 | import org.jose4j.jwk.RsaJwkGenerator; |
| 19 | 20 | import org.jose4j.jws.AlgorithmIdentifiers; |
| ... | ... | @@ -49,8 +50,8 @@ public class TokensManagerImpl implements TokensManager { |
| 49 | 50 | } |
| 50 | 51 | |
| 51 | 52 | @Override |
| 52 | - public Principal getUser(String jwt) { | |
| 53 | - Principal usuario = null; | |
| 53 | + public LoggedUser getUser(String jwt) { | |
| 54 | + LoggedUser usuario = null; | |
| 54 | 55 | if (jwt != null && !jwt.isEmpty()) { |
| 55 | 56 | JwtConsumer jwtConsumer = new JwtConsumerBuilder() |
| 56 | 57 | .setRequireExpirationTime() // the JWT must have an expiration time |
| ... | ... | @@ -62,7 +63,7 @@ public class TokensManagerImpl implements TokensManager { |
| 62 | 63 | |
| 63 | 64 | try { |
| 64 | 65 | JwtClaims jwtClaims = jwtConsumer.processToClaims(jwt); |
| 65 | - usuario = new Gson().fromJson((String) jwtClaims.getClaimValue("user"), Principal.class); | |
| 66 | + usuario = new Gson().fromJson((String) jwtClaims.getClaimValue("user"), LoggedUser.class); | |
| 66 | 67 | |
| 67 | 68 | String ip = httpRequest.getRemoteAddr(); |
| 68 | 69 | if (!ip.equalsIgnoreCase((String) jwtClaims.getClaimValue("ip"))) { |
| ... | ... | @@ -76,7 +77,7 @@ public class TokensManagerImpl implements TokensManager { |
| 76 | 77 | } |
| 77 | 78 | |
| 78 | 79 | @Override |
| 79 | - public String getToken(Principal user) { | |
| 80 | + public String setUser(LoggedUser user) { | |
| 80 | 81 | try { |
| 81 | 82 | JwtClaims claims = new JwtClaims(); |
| 82 | 83 | claims.setIssuer("demoiselle"); | ... | ... |
| ... | ... | @@ -0,0 +1,27 @@ |
| 1 | +<?xml version="1.0" encoding="UTF-8"?> | |
| 2 | +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | |
| 3 | + <modelVersion>4.0.0</modelVersion> | |
| 4 | + <artifactId>demoiselle-security-token</artifactId> | |
| 5 | + <packaging>jar</packaging> | |
| 6 | + | |
| 7 | + <name>Demoiselle Security Token</name> | |
| 8 | + <description> | |
| 9 | + Demoiselle Security Token | |
| 10 | + </description> | |
| 11 | + | |
| 12 | + <parent> | |
| 13 | + <groupId>org.demoiselle.jee</groupId> | |
| 14 | + <artifactId>demoiselle-parent</artifactId> | |
| 15 | + <version>3.0.0-BETA1-SNAPSHOT</version> | |
| 16 | + <relativePath>../demoiselle-parent</relativePath> | |
| 17 | + </parent> | |
| 18 | + | |
| 19 | + <dependencies> | |
| 20 | + | |
| 21 | + <dependency> | |
| 22 | + <groupId>org.demoiselle.jee</groupId> | |
| 23 | + <artifactId>demoiselle-security</artifactId> | |
| 24 | + </dependency> | |
| 25 | + | |
| 26 | + </dependencies> | |
| 27 | +</project> | ... | ... |
demoiselle-security-token/src/main/java/org/demoiselle/jee/security/basic/impl/TokensManagerImpl.java
0 → 100644
| ... | ... | @@ -0,0 +1,90 @@ |
| 1 | +/* | |
| 2 | + * To change this license header, choose License Headers in Project Properties. | |
| 3 | + * To change this template file, choose Tools | Templates | |
| 4 | + * and open the template in the editor. | |
| 5 | + */ | |
| 6 | +package org.demoiselle.jee.security.basic.impl; | |
| 7 | + | |
| 8 | +import java.security.Principal; | |
| 9 | +import java.util.List; | |
| 10 | +import java.util.Map; | |
| 11 | +import java.util.UUID; | |
| 12 | +import java.util.concurrent.ConcurrentHashMap; | |
| 13 | +import java.util.logging.Logger; | |
| 14 | +import javax.enterprise.context.Dependent; | |
| 15 | +import javax.enterprise.context.RequestScoped; | |
| 16 | +import javax.inject.Inject; | |
| 17 | +import org.demoiselle.jee.core.interfaces.security.Token; | |
| 18 | +import org.demoiselle.jee.core.interfaces.security.TokensManager; | |
| 19 | + | |
| 20 | +/** | |
| 21 | + * | |
| 22 | + * @author 70744416353 | |
| 23 | + */ | |
| 24 | +@Dependent | |
| 25 | +public class TokensManagerImpl implements TokensManager { | |
| 26 | + | |
| 27 | + private static ConcurrentHashMap<String, Principal> repo = new ConcurrentHashMap<>(); | |
| 28 | + | |
| 29 | + @Inject | |
| 30 | + private Logger logger; | |
| 31 | + | |
| 32 | + @Inject | |
| 33 | + @RequestScoped | |
| 34 | + private Token token; | |
| 35 | + | |
| 36 | + @Inject | |
| 37 | + @RequestScoped | |
| 38 | + private Principal loggedUser; | |
| 39 | + | |
| 40 | + @Override | |
| 41 | + public Principal getUser() { | |
| 42 | + if (loggedUser == null) { | |
| 43 | + if (token.getKey() != null && !token.getKey().isEmpty()) { | |
| 44 | + loggedUser = repo.get(token.getKey()); | |
| 45 | + return loggedUser; | |
| 46 | + } | |
| 47 | + } | |
| 48 | + return loggedUser; | |
| 49 | + } | |
| 50 | + | |
| 51 | + @Override | |
| 52 | + public void setUser(Principal user) { | |
| 53 | + String value = null; | |
| 54 | + if (!repo.containsValue(user)) { | |
| 55 | + value = UUID.randomUUID().toString(); | |
| 56 | + repo.put(value, user); | |
| 57 | + token.setKey(value); | |
| 58 | + token.setType("Basic"); | |
| 59 | + } | |
| 60 | + } | |
| 61 | + | |
| 62 | + @Override | |
| 63 | + public boolean validate() { | |
| 64 | + return true;//(getUser() != null && repo.get(token.getKey()).); | |
| 65 | + } | |
| 66 | + | |
| 67 | + @Override | |
| 68 | + public Token getToken() { | |
| 69 | + return token; | |
| 70 | + } | |
| 71 | + | |
| 72 | + @Override | |
| 73 | + public void setToken(Token token) { | |
| 74 | + String key = null; | |
| 75 | + if (repo.containsKey(token.getKey())) { | |
| 76 | + loggedUser = repo.get(key); | |
| 77 | + } | |
| 78 | + } | |
| 79 | + | |
| 80 | + @Override | |
| 81 | + public void setRoles(List<String> roles) { | |
| 82 | + | |
| 83 | + } | |
| 84 | + | |
| 85 | + @Override | |
| 86 | + public void setPermissions(Map<String, String> permissions) { | |
| 87 | + | |
| 88 | + } | |
| 89 | + | |
| 90 | +} | ... | ... |
demoiselle-security-token/src/main/resources/demoiselle.properties
0 → 100644
demoiselle-security-token/src/main/resources/messages.properties
0 → 100644
demoiselle-security/pom.xml
| 1 | 1 | <?xml version="1.0" encoding="UTF-8"?> |
| 2 | 2 | <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
| 3 | - xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | |
| 4 | - <modelVersion>4.0.0</modelVersion> | |
| 5 | - <artifactId>demoiselle-security</artifactId> | |
| 6 | - <packaging>jar</packaging> | |
| 3 | + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | |
| 4 | + <modelVersion>4.0.0</modelVersion> | |
| 5 | + <artifactId>demoiselle-security</artifactId> | |
| 6 | + <packaging>jar</packaging> | |
| 7 | 7 | |
| 8 | - <name>Demoiselle Security</name> | |
| 9 | - <description> | |
| 10 | - Demoiselle Security | |
| 11 | - </description> | |
| 8 | + <name>Demoiselle Security</name> | |
| 9 | + <description> | |
| 10 | + Demoiselle Security | |
| 11 | + </description> | |
| 12 | 12 | |
| 13 | - <parent> | |
| 14 | - <groupId>org.demoiselle.jee</groupId> | |
| 15 | - <artifactId>demoiselle-parent</artifactId> | |
| 16 | - <version>3.0.0-BETA1-SNAPSHOT</version> | |
| 17 | - <relativePath>../demoiselle-parent</relativePath> | |
| 18 | - </parent> | |
| 13 | + <parent> | |
| 14 | + <groupId>org.demoiselle.jee</groupId> | |
| 15 | + <artifactId>demoiselle-parent</artifactId> | |
| 16 | + <version>3.0.0-BETA1-SNAPSHOT</version> | |
| 17 | + <relativePath>../demoiselle-parent</relativePath> | |
| 18 | + </parent> | |
| 19 | 19 | |
| 20 | - <dependencies> | |
| 20 | + <dependencies> | |
| 21 | 21 | |
| 22 | - <dependency> | |
| 23 | - <groupId>org.demoiselle.jee</groupId> | |
| 24 | - <artifactId>demoiselle-core</artifactId> | |
| 25 | - </dependency> | |
| 22 | + <dependency> | |
| 23 | + <groupId>org.demoiselle.jee</groupId> | |
| 24 | + <artifactId>demoiselle-core</artifactId> | |
| 25 | + </dependency> | |
| 26 | 26 | |
| 27 | - </dependencies> | |
| 27 | + </dependencies> | |
| 28 | 28 | </project> | ... | ... |
demoiselle-security/src/main/java/org/demoiselle/jee/security/JaxRsFilter.java
| ... | ... | @@ -1,76 +0,0 @@ |
| 1 | -/* | |
| 2 | - * Demoiselle Framework | |
| 3 | - * | |
| 4 | - * License: GNU Lesser General Public License (LGPL), version 3 or later. | |
| 5 | - * See the lgpl.txt file in the root directory or <https://www.gnu.org/licenses/lgpl.html>. | |
| 6 | - */ | |
| 7 | -package org.demoiselle.jee.security; | |
| 8 | - | |
| 9 | -import java.io.IOException; | |
| 10 | -import org.demoiselle.jee.security.interfaces.SecurityContext; | |
| 11 | -import java.util.logging.Logger; | |
| 12 | -import javax.annotation.PostConstruct; | |
| 13 | -import javax.inject.Inject; | |
| 14 | -import javax.ws.rs.client.ClientRequestContext; | |
| 15 | -import javax.ws.rs.client.ClientRequestFilter; | |
| 16 | -import javax.ws.rs.client.ClientResponseContext; | |
| 17 | -import javax.ws.rs.client.ClientResponseFilter; | |
| 18 | -import javax.ws.rs.container.ContainerRequestContext; | |
| 19 | -import javax.ws.rs.container.ContainerRequestFilter; | |
| 20 | -import javax.ws.rs.container.ContainerResponseContext; | |
| 21 | -import javax.ws.rs.container.ContainerResponseFilter; | |
| 22 | -import javax.ws.rs.container.PreMatching; | |
| 23 | -import javax.ws.rs.ext.Provider; | |
| 24 | - | |
| 25 | -/** | |
| 26 | - * | |
| 27 | - * @author 70744416353 | |
| 28 | - */ | |
| 29 | -@Provider | |
| 30 | -@PreMatching | |
| 31 | -public class JaxRsFilter implements ClientRequestFilter, ClientResponseFilter, ContainerRequestFilter, ContainerResponseFilter { | |
| 32 | - | |
| 33 | - @Inject | |
| 34 | - private Logger LOG; | |
| 35 | - | |
| 36 | - @Inject | |
| 37 | - private SecurityContext securityContext; | |
| 38 | - | |
| 39 | - @PostConstruct | |
| 40 | - public void init() { | |
| 41 | - LOG.info("Demoiselle Module - Security"); | |
| 42 | - } | |
| 43 | - | |
| 44 | - @Override | |
| 45 | - public void filter(ContainerRequestContext requestContext, ContainerResponseContext responseContext) { | |
| 46 | - responseContext.getHeaders().putSingle("Authorization", "enabled"); | |
| 47 | - responseContext.getHeaders().putSingle("x-content-type-options", "nosniff"); | |
| 48 | - responseContext.getHeaders().putSingle("x-frame-options", "SAMEORIGIN"); | |
| 49 | - responseContext.getHeaders().putSingle("x-xss-protection", "1; mode=block"); | |
| 50 | - } | |
| 51 | - | |
| 52 | - @Override | |
| 53 | - public void filter(ContainerRequestContext requestContext) throws IOException { | |
| 54 | - try { | |
| 55 | - if (requestContext.getHeaders().containsKey("Authorization")) { | |
| 56 | - String token = requestContext.getHeaders().get("Authorization").toString().replace("[", "").replace("]", ""); | |
| 57 | - if (!token.isEmpty()) { | |
| 58 | - securityContext.setToken(token); | |
| 59 | - } | |
| 60 | - } | |
| 61 | - } catch (Exception e) { | |
| 62 | - } | |
| 63 | - | |
| 64 | - } | |
| 65 | - | |
| 66 | - @Override | |
| 67 | - public void filter(ClientRequestContext requestContext) throws IOException { | |
| 68 | - | |
| 69 | - } | |
| 70 | - | |
| 71 | - @Override | |
| 72 | - public void filter(ClientRequestContext requestContext, ClientResponseContext responseContext) throws IOException { | |
| 73 | - | |
| 74 | - } | |
| 75 | - | |
| 76 | -} |
demoiselle-security/src/main/java/org/demoiselle/jee/security/LoggedUser.java
| ... | ... | @@ -1,67 +0,0 @@ |
| 1 | -/* | |
| 2 | - * Demoiselle Framework | |
| 3 | - * | |
| 4 | - * License: GNU Lesser General Public License (LGPL), version 3 or later. | |
| 5 | - * See the lgpl.txt file in the root directory or <https://www.gnu.org/licenses/lgpl.html>. | |
| 6 | - */ | |
| 7 | -package org.demoiselle.jee.security; | |
| 8 | - | |
| 9 | -import java.util.List; | |
| 10 | -import java.util.Map; | |
| 11 | - | |
| 12 | -import javax.enterprise.context.RequestScoped; | |
| 13 | - | |
| 14 | -/** | |
| 15 | - * | |
| 16 | - * @author 70744416353 | |
| 17 | - */ | |
| 18 | -@RequestScoped | |
| 19 | -public class LoggedUser { | |
| 20 | - | |
| 21 | - private String id; | |
| 22 | - private String username; | |
| 23 | - private String email; | |
| 24 | - private Map<String, String> premissions; | |
| 25 | - private List<String> roles; | |
| 26 | - | |
| 27 | - public String getId() { | |
| 28 | - return id; | |
| 29 | - } | |
| 30 | - | |
| 31 | - public void setId(String id) { | |
| 32 | - this.id = id; | |
| 33 | - } | |
| 34 | - | |
| 35 | - public String getUsername() { | |
| 36 | - return username; | |
| 37 | - } | |
| 38 | - | |
| 39 | - public void setUsername(String username) { | |
| 40 | - this.username = username; | |
| 41 | - } | |
| 42 | - | |
| 43 | - public String getEmail() { | |
| 44 | - return email; | |
| 45 | - } | |
| 46 | - | |
| 47 | - public void setEmail(String email) { | |
| 48 | - this.email = email; | |
| 49 | - } | |
| 50 | - | |
| 51 | - public Map<String, String> getPremissions() { | |
| 52 | - return premissions; | |
| 53 | - } | |
| 54 | - | |
| 55 | - public void setPremissions(Map<String, String> premissions) { | |
| 56 | - this.premissions = premissions; | |
| 57 | - } | |
| 58 | - | |
| 59 | - public List<String> getRoles() { | |
| 60 | - return roles; | |
| 61 | - } | |
| 62 | - | |
| 63 | - public void setRoles(List<String> roles) { | |
| 64 | - this.roles = roles; | |
| 65 | - } | |
| 66 | - | |
| 67 | -} |
demoiselle-security/src/main/java/org/demoiselle/jee/security/Token.java
| ... | ... | @@ -1,28 +0,0 @@ |
| 1 | -/* | |
| 2 | - * Demoiselle Framework | |
| 3 | - * | |
| 4 | - * License: GNU Lesser General Public License (LGPL), version 3 or later. | |
| 5 | - * See the lgpl.txt file in the root directory or <https://www.gnu.org/licenses/lgpl.html>. | |
| 6 | - */ | |
| 7 | -package org.demoiselle.jee.security; | |
| 8 | - | |
| 9 | -import javax.enterprise.context.RequestScoped; | |
| 10 | - | |
| 11 | -/** | |
| 12 | - * | |
| 13 | - * @author 70744416353 | |
| 14 | - */ | |
| 15 | -@RequestScoped | |
| 16 | -public class Token { | |
| 17 | - | |
| 18 | - private String key; | |
| 19 | - | |
| 20 | - public String getKey() { | |
| 21 | - return key; | |
| 22 | - } | |
| 23 | - | |
| 24 | - public void setKey(String key) { | |
| 25 | - this.key = key; | |
| 26 | - } | |
| 27 | - | |
| 28 | -} |
demoiselle-security/src/main/java/org/demoiselle/jee/security/annotation/LoggedIn.java
0 → 100644
| ... | ... | @@ -0,0 +1,31 @@ |
| 1 | +/* | |
| 2 | + * Demoiselle Framework | |
| 3 | + * | |
| 4 | + * License: GNU Lesser General Public License (LGPL), version 3 or later. | |
| 5 | + * See the lgpl.txt file in the root directory or <https://www.gnu.org/licenses/lgpl.html>. | |
| 6 | + */ | |
| 7 | +package org.demoiselle.jee.security.annotation; | |
| 8 | + | |
| 9 | +import javax.interceptor.InterceptorBinding; | |
| 10 | +import java.lang.annotation.Inherited; | |
| 11 | +import java.lang.annotation.Retention; | |
| 12 | +import java.lang.annotation.Target; | |
| 13 | + | |
| 14 | +import static java.lang.annotation.ElementType.METHOD; | |
| 15 | +import static java.lang.annotation.ElementType.TYPE; | |
| 16 | +import static java.lang.annotation.RetentionPolicy.RUNTIME; | |
| 17 | + | |
| 18 | +/** | |
| 19 | + * <p> | |
| 20 | + * Indicates that a specific permission is required in order to invocate the annotated method or class. | |
| 21 | + * </p> | |
| 22 | + * | |
| 23 | + * @author SERPRO | |
| 24 | + */ | |
| 25 | + | |
| 26 | +@Inherited | |
| 27 | +@InterceptorBinding | |
| 28 | +@Target({ METHOD, TYPE }) | |
| 29 | +@Retention(RUNTIME) | |
| 30 | +public @interface LoggedIn { | |
| 31 | +} | ... | ... |
demoiselle-security/src/main/java/org/demoiselle/jee/security/annotation/RequiredPermission.java
0 → 100644
| ... | ... | @@ -0,0 +1,35 @@ |
| 1 | +/* | |
| 2 | + * Demoiselle Framework | |
| 3 | + * | |
| 4 | + * License: GNU Lesser General Public License (LGPL), version 3 or later. | |
| 5 | + * See the lgpl.txt file in the root directory or <https://www.gnu.org/licenses/lgpl.html>. | |
| 6 | + */ | |
| 7 | +package org.demoiselle.jee.security.annotation; | |
| 8 | + | |
| 9 | +import javax.enterprise.util.Nonbinding; | |
| 10 | +import javax.interceptor.InterceptorBinding; | |
| 11 | +import java.lang.annotation.Inherited; | |
| 12 | +import java.lang.annotation.Retention; | |
| 13 | +import java.lang.annotation.Target; | |
| 14 | + | |
| 15 | +import static java.lang.annotation.ElementType.METHOD; | |
| 16 | +import static java.lang.annotation.ElementType.TYPE; | |
| 17 | +import static java.lang.annotation.RetentionPolicy.RUNTIME; | |
| 18 | + | |
| 19 | +/** | |
| 20 | + * Indicates that a specific permission is required in order to invocate the annotated method or class. | |
| 21 | + * | |
| 22 | + * @author SERPRO | |
| 23 | + */ | |
| 24 | +@Inherited | |
| 25 | +@InterceptorBinding | |
| 26 | +@Target({ METHOD, TYPE }) | |
| 27 | +@Retention(RUNTIME) | |
| 28 | +public @interface RequiredPermission { | |
| 29 | + | |
| 30 | + @Nonbinding | |
| 31 | + String resource() default ""; | |
| 32 | + | |
| 33 | + @Nonbinding | |
| 34 | + String operation() default ""; | |
| 35 | +} | ... | ... |
demoiselle-security/src/main/java/org/demoiselle/jee/security/annotation/RequiredRole.java
0 → 100644
| ... | ... | @@ -0,0 +1,35 @@ |
| 1 | +/* | |
| 2 | + * Demoiselle Framework | |
| 3 | + * | |
| 4 | + * License: GNU Lesser General Public License (LGPL), version 3 or later. | |
| 5 | + * See the lgpl.txt file in the root directory or <https://www.gnu.org/licenses/lgpl.html>. | |
| 6 | + */ | |
| 7 | +package org.demoiselle.jee.security.annotation; | |
| 8 | + | |
| 9 | +import javax.enterprise.util.Nonbinding; | |
| 10 | +import javax.interceptor.InterceptorBinding; | |
| 11 | +import java.lang.annotation.Inherited; | |
| 12 | +import java.lang.annotation.Retention; | |
| 13 | +import java.lang.annotation.Target; | |
| 14 | + | |
| 15 | +import static java.lang.annotation.ElementType.METHOD; | |
| 16 | +import static java.lang.annotation.ElementType.TYPE; | |
| 17 | +import static java.lang.annotation.RetentionPolicy.RUNTIME; | |
| 18 | + | |
| 19 | +/** | |
| 20 | + * <p> | |
| 21 | + * Indicates that the annotated method or class requires the user to have one or more roles associated in order to be | |
| 22 | + * invocated. | |
| 23 | + * </p> | |
| 24 | + * | |
| 25 | + * @author SERPRO | |
| 26 | + */ | |
| 27 | +@Inherited | |
| 28 | +@InterceptorBinding | |
| 29 | +@Target({ METHOD, TYPE }) | |
| 30 | +@Retention(RUNTIME) | |
| 31 | +public @interface RequiredRole { | |
| 32 | + | |
| 33 | + @Nonbinding | |
| 34 | + String[] value(); | |
| 35 | +} | ... | ... |
demoiselle-security/src/main/java/org/demoiselle/jee/security/annotations/LoggedIn.java
| ... | ... | @@ -1,31 +0,0 @@ |
| 1 | -/* | |
| 2 | - * Demoiselle Framework | |
| 3 | - * | |
| 4 | - * License: GNU Lesser General Public License (LGPL), version 3 or later. | |
| 5 | - * See the lgpl.txt file in the root directory or <https://www.gnu.org/licenses/lgpl.html>. | |
| 6 | - */ | |
| 7 | -package org.demoiselle.jee.security.annotations; | |
| 8 | - | |
| 9 | -import javax.interceptor.InterceptorBinding; | |
| 10 | -import java.lang.annotation.Inherited; | |
| 11 | -import java.lang.annotation.Retention; | |
| 12 | -import java.lang.annotation.Target; | |
| 13 | - | |
| 14 | -import static java.lang.annotation.ElementType.METHOD; | |
| 15 | -import static java.lang.annotation.ElementType.TYPE; | |
| 16 | -import static java.lang.annotation.RetentionPolicy.RUNTIME; | |
| 17 | - | |
| 18 | -/** | |
| 19 | - * <p> | |
| 20 | - * Indicates that a specific permission is required in order to invocate the annotated method or class. | |
| 21 | - * </p> | |
| 22 | - * | |
| 23 | - * @author SERPRO | |
| 24 | - */ | |
| 25 | - | |
| 26 | -@Inherited | |
| 27 | -@InterceptorBinding | |
| 28 | -@Target({ METHOD, TYPE }) | |
| 29 | -@Retention(RUNTIME) | |
| 30 | -public @interface LoggedIn { | |
| 31 | -} |
demoiselle-security/src/main/java/org/demoiselle/jee/security/annotations/RequiredPermission.java
| ... | ... | @@ -1,35 +0,0 @@ |
| 1 | -/* | |
| 2 | - * Demoiselle Framework | |
| 3 | - * | |
| 4 | - * License: GNU Lesser General Public License (LGPL), version 3 or later. | |
| 5 | - * See the lgpl.txt file in the root directory or <https://www.gnu.org/licenses/lgpl.html>. | |
| 6 | - */ | |
| 7 | -package org.demoiselle.jee.security.annotations; | |
| 8 | - | |
| 9 | -import javax.enterprise.util.Nonbinding; | |
| 10 | -import javax.interceptor.InterceptorBinding; | |
| 11 | -import java.lang.annotation.Inherited; | |
| 12 | -import java.lang.annotation.Retention; | |
| 13 | -import java.lang.annotation.Target; | |
| 14 | - | |
| 15 | -import static java.lang.annotation.ElementType.METHOD; | |
| 16 | -import static java.lang.annotation.ElementType.TYPE; | |
| 17 | -import static java.lang.annotation.RetentionPolicy.RUNTIME; | |
| 18 | - | |
| 19 | -/** | |
| 20 | - * Indicates that a specific permission is required in order to invocate the annotated method or class. | |
| 21 | - * | |
| 22 | - * @author SERPRO | |
| 23 | - */ | |
| 24 | -@Inherited | |
| 25 | -@InterceptorBinding | |
| 26 | -@Target({ METHOD, TYPE }) | |
| 27 | -@Retention(RUNTIME) | |
| 28 | -public @interface RequiredPermission { | |
| 29 | - | |
| 30 | - @Nonbinding | |
| 31 | - String resource() default ""; | |
| 32 | - | |
| 33 | - @Nonbinding | |
| 34 | - String operation() default ""; | |
| 35 | -} |
demoiselle-security/src/main/java/org/demoiselle/jee/security/annotations/RequiredRole.java
| ... | ... | @@ -1,35 +0,0 @@ |
| 1 | -/* | |
| 2 | - * Demoiselle Framework | |
| 3 | - * | |
| 4 | - * License: GNU Lesser General Public License (LGPL), version 3 or later. | |
| 5 | - * See the lgpl.txt file in the root directory or <https://www.gnu.org/licenses/lgpl.html>. | |
| 6 | - */ | |
| 7 | -package org.demoiselle.jee.security.annotations; | |
| 8 | - | |
| 9 | -import javax.enterprise.util.Nonbinding; | |
| 10 | -import javax.interceptor.InterceptorBinding; | |
| 11 | -import java.lang.annotation.Inherited; | |
| 12 | -import java.lang.annotation.Retention; | |
| 13 | -import java.lang.annotation.Target; | |
| 14 | - | |
| 15 | -import static java.lang.annotation.ElementType.METHOD; | |
| 16 | -import static java.lang.annotation.ElementType.TYPE; | |
| 17 | -import static java.lang.annotation.RetentionPolicy.RUNTIME; | |
| 18 | - | |
| 19 | -/** | |
| 20 | - * <p> | |
| 21 | - * Indicates that the annotated method or class requires the user to have one or more roles associated in order to be | |
| 22 | - * invocated. | |
| 23 | - * </p> | |
| 24 | - * | |
| 25 | - * @author SERPRO | |
| 26 | - */ | |
| 27 | -@Inherited | |
| 28 | -@InterceptorBinding | |
| 29 | -@Target({ METHOD, TYPE }) | |
| 30 | -@Retention(RUNTIME) | |
| 31 | -public @interface RequiredRole { | |
| 32 | - | |
| 33 | - @Nonbinding | |
| 34 | - String[] value(); | |
| 35 | -} |
demoiselle-security/src/main/java/org/demoiselle/jee/security/filter/JaxRsFilter.java
0 → 100644
| ... | ... | @@ -0,0 +1,79 @@ |
| 1 | +/* | |
| 2 | + * Demoiselle Framework | |
| 3 | + * | |
| 4 | + * License: GNU Lesser General Public License (LGPL), version 3 or later. | |
| 5 | + * See the lgpl.txt file in the root directory or <https://www.gnu.org/licenses/lgpl.html>. | |
| 6 | + */ | |
| 7 | +package org.demoiselle.jee.security.filter; | |
| 8 | + | |
| 9 | +import java.io.IOException; | |
| 10 | +import java.util.logging.Logger; | |
| 11 | +import javax.annotation.PostConstruct; | |
| 12 | +import javax.inject.Inject; | |
| 13 | +import javax.ws.rs.client.ClientRequestContext; | |
| 14 | +import javax.ws.rs.client.ClientRequestFilter; | |
| 15 | +import javax.ws.rs.client.ClientResponseContext; | |
| 16 | +import javax.ws.rs.client.ClientResponseFilter; | |
| 17 | +import javax.ws.rs.container.ContainerRequestContext; | |
| 18 | +import javax.ws.rs.container.ContainerRequestFilter; | |
| 19 | +import javax.ws.rs.container.ContainerResponseContext; | |
| 20 | +import javax.ws.rs.container.ContainerResponseFilter; | |
| 21 | +import javax.ws.rs.container.PreMatching; | |
| 22 | +import javax.ws.rs.ext.Provider; | |
| 23 | +import org.demoiselle.jee.core.interfaces.security.SecurityContext; | |
| 24 | +import org.demoiselle.jee.core.interfaces.security.Token; | |
| 25 | + | |
| 26 | +/** | |
| 27 | + * | |
| 28 | + * @author 70744416353 | |
| 29 | + */ | |
| 30 | +@Provider | |
| 31 | +@PreMatching | |
| 32 | +public class JaxRsFilter implements ClientRequestFilter, ClientResponseFilter, ContainerRequestFilter, ContainerResponseFilter { | |
| 33 | + | |
| 34 | + @Inject | |
| 35 | + private Logger LOG; | |
| 36 | + | |
| 37 | + @Inject | |
| 38 | + private Token token; | |
| 39 | + | |
| 40 | + @PostConstruct | |
| 41 | + public void init() { | |
| 42 | + LOG.info("Demoiselle Module - Security"); | |
| 43 | + } | |
| 44 | + | |
| 45 | + @Override | |
| 46 | + public void filter(ContainerRequestContext requestContext, ContainerResponseContext responseContext) { | |
| 47 | + responseContext.getHeaders().putSingle("Authorization", "enabled"); | |
| 48 | + responseContext.getHeaders().putSingle("x-content-type-options", "nosniff"); | |
| 49 | + responseContext.getHeaders().putSingle("x-frame-options", "SAMEORIGIN"); | |
| 50 | + responseContext.getHeaders().putSingle("x-xss-protection", "1; mode=block"); | |
| 51 | + } | |
| 52 | + | |
| 53 | + @Override | |
| 54 | + public void filter(ContainerRequestContext requestContext) throws IOException { | |
| 55 | + try { | |
| 56 | + if (requestContext.getHeaders().containsKey("Authorization")) { | |
| 57 | + String chave = requestContext.getHeaders().get("Authorization").toString().replace("[", "").replace("]", ""); | |
| 58 | + if (!chave.isEmpty()) { | |
| 59 | + token.setType(chave.split(" ")[0]); | |
| 60 | + token.setKey(chave.split(" ")[1]); | |
| 61 | + } | |
| 62 | + } | |
| 63 | + } catch (Exception e) { | |
| 64 | + LOG.fine(e.getMessage()); | |
| 65 | + } | |
| 66 | + | |
| 67 | + } | |
| 68 | + | |
| 69 | + @Override | |
| 70 | + public void filter(ClientRequestContext requestContext) throws IOException { | |
| 71 | + | |
| 72 | + } | |
| 73 | + | |
| 74 | + @Override | |
| 75 | + public void filter(ClientRequestContext requestContext, ClientResponseContext responseContext) throws IOException { | |
| 76 | + | |
| 77 | + } | |
| 78 | + | |
| 79 | +} | ... | ... |
demoiselle-security/src/main/java/org/demoiselle/jee/security/impl/SecurityContextImpl.java
| ... | ... | @@ -7,18 +7,17 @@ |
| 7 | 7 | package org.demoiselle.jee.security.impl; |
| 8 | 8 | |
| 9 | 9 | import java.security.Principal; |
| 10 | +import java.util.List; | |
| 10 | 11 | import java.util.Map; |
| 11 | -import java.util.Set; | |
| 12 | - | |
| 13 | 12 | import javax.enterprise.context.Dependent; |
| 14 | 13 | import javax.inject.Inject; |
| 15 | 14 | |
| 16 | 15 | import org.demoiselle.jee.core.util.ResourceBundle; |
| 17 | -import org.demoiselle.jee.security.LoggedUser; | |
| 18 | -import org.demoiselle.jee.security.Token; | |
| 16 | + | |
| 19 | 17 | import org.demoiselle.jee.security.exception.NotLoggedInException; |
| 20 | -import org.demoiselle.jee.security.interfaces.SecurityContext; | |
| 21 | -import org.demoiselle.jee.security.interfaces.TokensManager; | |
| 18 | +import org.demoiselle.jee.core.interfaces.security.SecurityContext; | |
| 19 | +import org.demoiselle.jee.core.interfaces.security.Token; | |
| 20 | +import org.demoiselle.jee.core.interfaces.security.TokensManager; | |
| 22 | 21 | |
| 23 | 22 | /** |
| 24 | 23 | * <p> |
| ... | ... | @@ -36,12 +35,6 @@ public class SecurityContextImpl implements SecurityContext { |
| 36 | 35 | private TokensManager tm; |
| 37 | 36 | |
| 38 | 37 | @Inject |
| 39 | - private Token token; | |
| 40 | - | |
| 41 | - @Inject | |
| 42 | - private LoggedUser loggedUser; | |
| 43 | - | |
| 44 | - @Inject | |
| 45 | 38 | private ResourceBundle bundle; |
| 46 | 39 | |
| 47 | 40 | /** |
| ... | ... | @@ -70,20 +63,10 @@ public class SecurityContextImpl implements SecurityContext { |
| 70 | 63 | */ |
| 71 | 64 | @Override |
| 72 | 65 | public boolean isLoggedIn() { |
| 73 | - return getUser() != null; | |
| 66 | + return tm.validate(); | |
| 74 | 67 | } |
| 75 | 68 | |
| 76 | - /** | |
| 77 | - * @see org.demoiselle.security.SecurityContext#getUser() | |
| 78 | - */ | |
| 79 | 69 | @Override |
| 80 | - public Principal getUser() { | |
| 81 | -// if (token.getKey() != null && !token.getKey().isEmpty()) { | |
| 82 | -// return tm.getUser(token.getKey()); | |
| 83 | -// } | |
| 84 | - return null;//token.getPrincipal(); | |
| 85 | - } | |
| 86 | - | |
| 87 | 70 | public void checkLoggedIn() throws NotLoggedInException { |
| 88 | 71 | if (!isLoggedIn()) { |
| 89 | 72 | throw new NotLoggedInException(bundle.getString("user-not-authenticated")); |
| ... | ... | @@ -91,46 +74,13 @@ public class SecurityContextImpl implements SecurityContext { |
| 91 | 74 | } |
| 92 | 75 | |
| 93 | 76 | @Override |
| 94 | - public void setRoles(Set<String> roles) { | |
| 95 | - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. | |
| 96 | - } | |
| 97 | - | |
| 98 | - @Override | |
| 99 | - public void setPermission(Map<String, String> permissions) { | |
| 100 | - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. | |
| 101 | - } | |
| 102 | - | |
| 103 | - @Override | |
| 104 | - public Set<String> getResources(String operation) { | |
| 105 | - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. | |
| 106 | - } | |
| 107 | - | |
| 108 | - @Override | |
| 109 | - public Set<String> getOperations(String resources) { | |
| 110 | - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. | |
| 111 | - } | |
| 112 | - | |
| 113 | - @Override | |
| 114 | - public void setUser(Principal principal) { | |
| 115 | -// token.setKey(tm.getToken(principal)); | |
| 116 | -// token.setPrincipal(principal); | |
| 117 | - } | |
| 118 | - | |
| 119 | - @Override | |
| 120 | - public String getToken() { | |
| 121 | -// if (token.getKey() != null && token.getKey().isEmpty()) { | |
| 122 | -// token.setKey(tm.getToken(token.getPrincipal())); | |
| 123 | -// } | |
| 124 | - return token.getKey(); | |
| 77 | + public Principal getUser() { | |
| 78 | + return tm.getUser(); | |
| 125 | 79 | } |
| 126 | 80 | |
| 127 | 81 | @Override |
| 128 | - public void setToken(String chave) { | |
| 129 | -// token.setPrincipal(tm.getUser(chave)); | |
| 130 | -// if (token.getPrincipal() == null) { | |
| 131 | -// throw new NotLoggedInException(bundle.getString("user-not-authenticated")); | |
| 132 | -// } | |
| 133 | - token.setKey(chave); | |
| 82 | + public void setUser(Principal loggedUser) { | |
| 83 | + tm.setUser(loggedUser); | |
| 134 | 84 | } |
| 135 | 85 | |
| 136 | 86 | } | ... | ... |
demoiselle-security/src/main/java/org/demoiselle/jee/security/impl/TokenImpl.java
0 → 100644
| ... | ... | @@ -0,0 +1,41 @@ |
| 1 | +/* | |
| 2 | + * To change this license header, choose License Headers in Project Properties. | |
| 3 | + * To change this template file, choose Tools | Templates | |
| 4 | + * and open the template in the editor. | |
| 5 | + */ | |
| 6 | +package org.demoiselle.jee.security.impl; | |
| 7 | + | |
| 8 | +import javax.enterprise.context.Dependent; | |
| 9 | +import org.demoiselle.jee.core.interfaces.security.Token; | |
| 10 | + | |
| 11 | +/** | |
| 12 | + * | |
| 13 | + * @author 70744416353 | |
| 14 | + */ | |
| 15 | +@Dependent | |
| 16 | +public class TokenImpl implements Token { | |
| 17 | + | |
| 18 | + private String key; | |
| 19 | + private String type; | |
| 20 | + | |
| 21 | + @Override | |
| 22 | + public String getKey() { | |
| 23 | + return key; | |
| 24 | + } | |
| 25 | + | |
| 26 | + @Override | |
| 27 | + public void setKey(String key) { | |
| 28 | + this.key = key; | |
| 29 | + } | |
| 30 | + | |
| 31 | + @Override | |
| 32 | + public String getType() { | |
| 33 | + return type; | |
| 34 | + } | |
| 35 | + | |
| 36 | + @Override | |
| 37 | + public void setType(String type) { | |
| 38 | + this.type = type; | |
| 39 | + } | |
| 40 | + | |
| 41 | +} | ... | ... |
demoiselle-security/src/main/java/org/demoiselle/jee/security/interceptor/LoggedInInterceptor.java
| ... | ... | @@ -12,8 +12,8 @@ import javax.interceptor.AroundInvoke; |
| 12 | 12 | import javax.interceptor.Interceptor; |
| 13 | 13 | import javax.interceptor.InvocationContext; |
| 14 | 14 | import java.io.Serializable; |
| 15 | -import org.demoiselle.jee.security.annotations.LoggedIn; | |
| 16 | -import org.demoiselle.jee.security.interfaces.SecurityContext; | |
| 15 | +import org.demoiselle.jee.security.annotation.LoggedIn; | |
| 16 | +import org.demoiselle.jee.core.interfaces.security.SecurityContext; | |
| 17 | 17 | |
| 18 | 18 | /** |
| 19 | 19 | * <p> | ... | ... |
demoiselle-security/src/main/java/org/demoiselle/jee/security/interceptor/RequiredPermissionInterceptor.java
| ... | ... | @@ -9,19 +9,18 @@ package org.demoiselle.jee.security.interceptor; |
| 9 | 9 | import org.demoiselle.jee.security.exception.AuthorizationException; |
| 10 | 10 | |
| 11 | 11 | import javax.annotation.Priority; |
| 12 | -import javax.enterprise.inject.spi.CDI; | |
| 13 | 12 | import javax.interceptor.AroundInvoke; |
| 14 | 13 | import javax.interceptor.Interceptor; |
| 15 | 14 | import javax.interceptor.InvocationContext; |
| 16 | 15 | import java.io.Serializable; |
| 16 | +import java.security.Principal; | |
| 17 | 17 | import java.util.logging.Logger; |
| 18 | 18 | import javax.inject.Inject; |
| 19 | -import static javax.sql.rowset.spi.SyncFactory.getLogger; | |
| 20 | 19 | import org.demoiselle.jee.core.annotation.Name; |
| 21 | 20 | import org.demoiselle.jee.core.util.ResourceBundle; |
| 22 | 21 | import org.demoiselle.jee.core.util.Strings; |
| 23 | -import org.demoiselle.jee.security.annotations.RequiredPermission; | |
| 24 | -import org.demoiselle.jee.security.interfaces.SecurityContext; | |
| 22 | +import org.demoiselle.jee.security.annotation.RequiredPermission; | |
| 23 | +import org.demoiselle.jee.core.interfaces.security.SecurityContext; | |
| 25 | 24 | |
| 26 | 25 | /** |
| 27 | 26 | * <p> |
| ... | ... | @@ -38,6 +37,12 @@ public class RequiredPermissionInterceptor implements Serializable { |
| 38 | 37 | private static final long serialVersionUID = 1L; |
| 39 | 38 | |
| 40 | 39 | @Inject |
| 40 | + private SecurityContext securityContext; | |
| 41 | + | |
| 42 | + @Inject | |
| 43 | + private Principal loggedUser; | |
| 44 | + | |
| 45 | + @Inject | |
| 41 | 46 | private ResourceBundle bundle; |
| 42 | 47 | |
| 43 | 48 | @Inject |
| ... | ... | @@ -66,17 +71,17 @@ public class RequiredPermissionInterceptor implements Serializable { |
| 66 | 71 | String operation = getOperation(ic); |
| 67 | 72 | String username = null; |
| 68 | 73 | |
| 69 | - if (getSecurityContext().isLoggedIn()) { | |
| 70 | - username = getSecurityContext().getUser().getName(); | |
| 71 | - getLogger().finest(bundle.getString("access-checking", username, operation, resource)); | |
| 74 | + if (securityContext.isLoggedIn()) { | |
| 75 | + username = loggedUser.getName(); | |
| 76 | + logger.finest(bundle.getString("access-checking", username, operation, resource)); | |
| 72 | 77 | } |
| 73 | 78 | |
| 74 | - if (!getSecurityContext().hasPermission(resource, operation)) { | |
| 75 | - getLogger().severe(bundle.getString("access-denied", username, operation, resource)); | |
| 79 | + if (securityContext.hasPermission(resource, operation)) { | |
| 80 | + logger.severe(bundle.getString("access-denied", username, operation, resource)); | |
| 76 | 81 | throw new AuthorizationException(bundle.getString("access-denied-ui", resource, operation)); |
| 77 | 82 | } |
| 78 | 83 | |
| 79 | - getLogger().fine(bundle.getString("access-allowed", username, operation, resource)); | |
| 84 | + logger.fine(bundle.getString("access-allowed", username, operation, resource)); | |
| 80 | 85 | return ic.proceed(); |
| 81 | 86 | } |
| 82 | 87 | |
| ... | ... | @@ -144,7 +149,4 @@ public class RequiredPermissionInterceptor implements Serializable { |
| 144 | 149 | } |
| 145 | 150 | } |
| 146 | 151 | |
| 147 | - private SecurityContext getSecurityContext() { | |
| 148 | - return CDI.current().select(SecurityContext.class).get(); | |
| 149 | - } | |
| 150 | 152 | } | ... | ... |
demoiselle-security/src/main/java/org/demoiselle/jee/security/interceptor/RequiredRoleInterceptor.java
| ... | ... | @@ -9,11 +9,11 @@ package org.demoiselle.jee.security.interceptor; |
| 9 | 9 | import org.demoiselle.jee.security.exception.AuthorizationException; |
| 10 | 10 | |
| 11 | 11 | import javax.annotation.Priority; |
| 12 | -import javax.enterprise.inject.spi.CDI; | |
| 13 | 12 | import javax.interceptor.AroundInvoke; |
| 14 | 13 | import javax.interceptor.Interceptor; |
| 15 | 14 | import javax.interceptor.InvocationContext; |
| 16 | 15 | import java.io.Serializable; |
| 16 | +import java.security.Principal; | |
| 17 | 17 | import java.util.ArrayList; |
| 18 | 18 | import java.util.Arrays; |
| 19 | 19 | import java.util.List; |
| ... | ... | @@ -21,8 +21,8 @@ import java.util.List; |
| 21 | 21 | import java.util.logging.Logger; |
| 22 | 22 | import javax.inject.Inject; |
| 23 | 23 | import org.demoiselle.jee.core.util.ResourceBundle; |
| 24 | -import org.demoiselle.jee.security.annotations.RequiredRole; | |
| 25 | -import org.demoiselle.jee.security.interfaces.SecurityContext; | |
| 24 | +import org.demoiselle.jee.security.annotation.RequiredRole; | |
| 25 | +import org.demoiselle.jee.core.interfaces.security.SecurityContext; | |
| 26 | 26 | |
| 27 | 27 | /** |
| 28 | 28 | * <p> |
| ... | ... | @@ -39,6 +39,12 @@ public class RequiredRoleInterceptor implements Serializable { |
| 39 | 39 | private static final long serialVersionUID = 1L; |
| 40 | 40 | |
| 41 | 41 | @Inject |
| 42 | + private SecurityContext securityContext; | |
| 43 | + | |
| 44 | + @Inject | |
| 45 | + private Principal loggedUser; | |
| 46 | + | |
| 47 | + @Inject | |
| 42 | 48 | private ResourceBundle bundle; |
| 43 | 49 | |
| 44 | 50 | @Inject |
| ... | ... | @@ -64,27 +70,27 @@ public class RequiredRoleInterceptor implements Serializable { |
| 64 | 70 | public Object manage(final InvocationContext ic) throws Exception { |
| 65 | 71 | List<String> roles = getRoles(ic); |
| 66 | 72 | |
| 67 | - if (getSecurityContext().isLoggedIn()) { | |
| 73 | + if (securityContext.isLoggedIn()) { | |
| 68 | 74 | logger.info( |
| 69 | - bundle.getString("has-role-verification", getSecurityContext().getUser().getName(), roles)); | |
| 75 | + bundle.getString("has-role-verification", loggedUser.getName(), roles)); | |
| 70 | 76 | } |
| 71 | 77 | |
| 72 | 78 | List<String> userRoles = new ArrayList<String>(); |
| 73 | 79 | |
| 74 | 80 | for (String role : roles) { |
| 75 | - if (getSecurityContext().hasRole(role)) { | |
| 81 | + if (securityContext.hasRole(role)) { | |
| 76 | 82 | userRoles.add(role); |
| 77 | 83 | } |
| 78 | 84 | } |
| 79 | 85 | |
| 80 | 86 | if (userRoles.isEmpty()) { |
| 81 | 87 | logger.severe( |
| 82 | - bundle.getString("does-not-have-role", getSecurityContext().getUser().getName(), roles)); | |
| 88 | + bundle.getString("does-not-have-role", loggedUser.getName(), roles)); | |
| 83 | 89 | |
| 84 | 90 | throw new AuthorizationException(bundle.getString("does-not-have-role-ui", roles)); |
| 85 | 91 | } |
| 86 | 92 | |
| 87 | - logger.fine(bundle.getString("user-has-role", getSecurityContext().getUser().getName(), userRoles)); | |
| 93 | + logger.fine(bundle.getString("user-has-role", loggedUser.getName(), userRoles)); | |
| 88 | 94 | |
| 89 | 95 | return ic.proceed(); |
| 90 | 96 | } |
| ... | ... | @@ -110,8 +116,4 @@ public class RequiredRoleInterceptor implements Serializable { |
| 110 | 116 | return Arrays.asList(roles); |
| 111 | 117 | } |
| 112 | 118 | |
| 113 | - private SecurityContext getSecurityContext() { | |
| 114 | - return CDI.current().select(SecurityContext.class).get(); | |
| 115 | - } | |
| 116 | - | |
| 117 | 119 | } | ... | ... |
demoiselle-security/src/main/java/org/demoiselle/jee/security/interfaces/LoggedUser.java
| ... | ... | @@ -1,38 +0,0 @@ |
| 1 | -/* | |
| 2 | - * Demoiselle Framework | |
| 3 | - * | |
| 4 | - * License: GNU Lesser General Public License (LGPL), version 3 or later. | |
| 5 | - * See the lgpl.txt file in the root directory or <https://www.gnu.org/licenses/lgpl.html>. | |
| 6 | - */ | |
| 7 | -package org.demoiselle.jee.security.interfaces; | |
| 8 | - | |
| 9 | -import java.io.Serializable; | |
| 10 | -import java.security.Principal; | |
| 11 | -import java.util.List; | |
| 12 | -import java.util.Map; | |
| 13 | - | |
| 14 | -import javax.enterprise.context.RequestScoped; | |
| 15 | - | |
| 16 | -/** | |
| 17 | - * <p> | |
| 18 | - * Structure used to handle both authentication and authorizations mechanisms. | |
| 19 | - * </p> | |
| 20 | - * | |
| 21 | - * @author SERPRO | |
| 22 | - */ | |
| 23 | -@RequestScoped | |
| 24 | -public interface LoggedUser extends Principal, Serializable { | |
| 25 | - | |
| 26 | - public String getId(); | |
| 27 | - | |
| 28 | - public void setId(String id); | |
| 29 | - | |
| 30 | - public Map<String, String> getPermissions(); | |
| 31 | - | |
| 32 | - public void setPermissions(Map<String, String> premissions); | |
| 33 | - | |
| 34 | - public List<String> getRoles(); | |
| 35 | - | |
| 36 | - public void setRoles(List<String> roles); | |
| 37 | - | |
| 38 | -} |
demoiselle-security/src/main/java/org/demoiselle/jee/security/interfaces/SecurityContext.java
| ... | ... | @@ -1,86 +0,0 @@ |
| 1 | -/* | |
| 2 | - * Demoiselle Framework | |
| 3 | - * | |
| 4 | - * License: GNU Lesser General Public License (LGPL), version 3 or later. | |
| 5 | - * See the lgpl.txt file in the root directory or <https://www.gnu.org/licenses/lgpl.html>. | |
| 6 | - */ | |
| 7 | -package org.demoiselle.jee.security.interfaces; | |
| 8 | - | |
| 9 | -import java.io.Serializable; | |
| 10 | -import java.security.Principal; | |
| 11 | -import java.util.Map; | |
| 12 | -import java.util.Set; | |
| 13 | -import org.demoiselle.jee.security.exception.AuthorizationException; | |
| 14 | -import org.demoiselle.jee.security.exception.NotLoggedInException; | |
| 15 | - | |
| 16 | -/** | |
| 17 | - * <p> | |
| 18 | - * Structure used to handle both authentication and authorizations mechanisms. | |
| 19 | - * </p> | |
| 20 | - * | |
| 21 | - * @author SERPRO | |
| 22 | - */ | |
| 23 | -public interface SecurityContext extends Serializable { | |
| 24 | - | |
| 25 | - /** | |
| 26 | - * Checks if a specific user is logged in. | |
| 27 | - * | |
| 28 | - * @return {@code true} if the user is logged in | |
| 29 | - */ | |
| 30 | - boolean isLoggedIn(); | |
| 31 | - | |
| 32 | - /** | |
| 33 | - * @throws NotLoggedInException if there is no user logged in a specific | |
| 34 | - * session | |
| 35 | - */ | |
| 36 | - void checkLoggedIn(); | |
| 37 | - | |
| 38 | - /** | |
| 39 | - * Checks if the logged user has permission to execute an specific operation | |
| 40 | - * on a specific resource. | |
| 41 | - * | |
| 42 | - * @param resource resource to be checked | |
| 43 | - * @param operation operation to be checked | |
| 44 | - * @return {@code true} if the user has the permission | |
| 45 | - * @throws AuthorizationException When the permission checking fails, this | |
| 46 | - * exception is thrown. | |
| 47 | - * @throws NotLoggedInException if there is no user logged in a specific | |
| 48 | - * session. | |
| 49 | - */ | |
| 50 | - boolean hasPermission(String resource, String operation); | |
| 51 | - | |
| 52 | - /** | |
| 53 | - * Checks if the logged user has an specific role | |
| 54 | - * | |
| 55 | - * @param role role to be checked | |
| 56 | - * @return {@code true} if the user has the role | |
| 57 | - * @throws AuthorizationException When the permission checking fails, this | |
| 58 | - * exception is thrown. | |
| 59 | - * @throws NotLoggedInException if there is no user logged in a specific | |
| 60 | - * session. | |
| 61 | - */ | |
| 62 | - boolean hasRole(String role); | |
| 63 | - | |
| 64 | - /** | |
| 65 | - * Return the user logged in the session. | |
| 66 | - * | |
| 67 | - * @return the user logged in a specific authenticated session. If there is | |
| 68 | - * no active session {@code null} is returned. | |
| 69 | - */ | |
| 70 | - Principal getUser(); | |
| 71 | - | |
| 72 | - void setUser(Principal principal); | |
| 73 | - | |
| 74 | - String getToken(); | |
| 75 | - | |
| 76 | - void setToken(String token); | |
| 77 | - | |
| 78 | - void setRoles(Set<String> roles); | |
| 79 | - | |
| 80 | - void setPermission(Map<String, String> permissions); | |
| 81 | - | |
| 82 | - Set<String> getResources(String operation); | |
| 83 | - | |
| 84 | - Set<String> getOperations(String resources); | |
| 85 | - | |
| 86 | -} |
demoiselle-security/src/main/java/org/demoiselle/jee/security/interfaces/TokensManager.java
| ... | ... | @@ -1,27 +0,0 @@ |
| 1 | -/* | |
| 2 | - * Demoiselle Framework | |
| 3 | - * | |
| 4 | - * License: GNU Lesser General Public License (LGPL), version 3 or later. | |
| 5 | - * See the lgpl.txt file in the root directory or <https://www.gnu.org/licenses/lgpl.html>. | |
| 6 | - */ | |
| 7 | -package org.demoiselle.jee.security.interfaces; | |
| 8 | - | |
| 9 | -import java.io.Serializable; | |
| 10 | - | |
| 11 | -import org.demoiselle.jee.security.LoggedUser; | |
| 12 | -import org.demoiselle.jee.security.Token; | |
| 13 | - | |
| 14 | -/** | |
| 15 | - * <p> | |
| 16 | - * Structure used to handle both authentication and authorizations mechanisms. | |
| 17 | - * </p> | |
| 18 | - * | |
| 19 | - * @author SERPRO | |
| 20 | - */ | |
| 21 | -public interface TokensManager extends Serializable { | |
| 22 | - | |
| 23 | - public LoggedUser getUser(Token token); | |
| 24 | - | |
| 25 | - public String create(LoggedUser user); | |
| 26 | - | |
| 27 | -} |
demoiselle-ws-jaxrs/.gitignore
demoiselle-ws-jaxrs/pom.xml
| ... | ... | @@ -1,37 +0,0 @@ |
| 1 | -<?xml version="1.0" encoding="UTF-8"?> | |
| 2 | -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | |
| 3 | - <modelVersion>4.0.0</modelVersion> | |
| 4 | - <artifactId>demoiselle-ws-jaxrs</artifactId> | |
| 5 | - <packaging>jar</packaging> | |
| 6 | - | |
| 7 | - <name>Demoiselle Web Service</name> | |
| 8 | - <description> | |
| 9 | - Demoiselle Web Service | |
| 10 | - </description> | |
| 11 | - | |
| 12 | - <parent> | |
| 13 | - <groupId>org.demoiselle.jee</groupId> | |
| 14 | - <artifactId>demoiselle-parent</artifactId> | |
| 15 | - <version>3.0.0-BETA1-SNAPSHOT</version> | |
| 16 | - <relativePath>../demoiselle-parent</relativePath> | |
| 17 | - </parent> | |
| 18 | - | |
| 19 | - <dependencies> | |
| 20 | - | |
| 21 | - <dependency> | |
| 22 | - <groupId>org.demoiselle.jee</groupId> | |
| 23 | - <artifactId>demoiselle-core</artifactId> | |
| 24 | - </dependency> | |
| 25 | - | |
| 26 | - <dependency> | |
| 27 | - <groupId>javax.ws.rs</groupId> | |
| 28 | - <artifactId>javax.ws.rs-api</artifactId> | |
| 29 | - </dependency> | |
| 30 | - | |
| 31 | - <dependency> | |
| 32 | - <groupId>javax.json</groupId> | |
| 33 | - <artifactId>javax.json-api</artifactId> | |
| 34 | - </dependency> | |
| 35 | - | |
| 36 | - </dependencies> | |
| 37 | -</project> |
demoiselle-ws-jaxrs/src/main/java/org/demoiselle/jee/ws/jaxrs/JaxRsFilter.java
| ... | ... | @@ -1,59 +0,0 @@ |
| 1 | -/* | |
| 2 | - * Demoiselle Framework | |
| 3 | - * | |
| 4 | - * License: GNU Lesser General Public License (LGPL), version 3 or later. | |
| 5 | - * See the lgpl.txt file in the root directory or <https://www.gnu.org/licenses/lgpl.html>. | |
| 6 | - */ | |
| 7 | -package org.demoiselle.jee.ws.jaxrs; | |
| 8 | - | |
| 9 | -import java.util.logging.Logger; | |
| 10 | -import javax.annotation.PostConstruct; | |
| 11 | -import javax.inject.Inject; | |
| 12 | -import javax.ws.rs.client.ClientRequestContext; | |
| 13 | -import javax.ws.rs.client.ClientRequestFilter; | |
| 14 | -import javax.ws.rs.client.ClientResponseContext; | |
| 15 | -import javax.ws.rs.client.ClientResponseFilter; | |
| 16 | -import javax.ws.rs.container.ContainerRequestContext; | |
| 17 | -import javax.ws.rs.container.ContainerRequestFilter; | |
| 18 | -import javax.ws.rs.container.ContainerResponseContext; | |
| 19 | -import javax.ws.rs.container.ContainerResponseFilter; | |
| 20 | -import javax.ws.rs.container.PreMatching; | |
| 21 | -import javax.ws.rs.ext.Provider; | |
| 22 | - | |
| 23 | -/** | |
| 24 | - * | |
| 25 | - * @author 70744416353 | |
| 26 | - */ | |
| 27 | -@Provider | |
| 28 | -@PreMatching | |
| 29 | -public class JaxRsFilter implements ClientRequestFilter, ClientResponseFilter, ContainerRequestFilter, ContainerResponseFilter { | |
| 30 | - | |
| 31 | - @Inject | |
| 32 | - private Logger LOG; | |
| 33 | - | |
| 34 | - @Override | |
| 35 | - public void filter(ClientRequestContext requestContext) { | |
| 36 | - } | |
| 37 | - | |
| 38 | - @Override | |
| 39 | - public void filter(ClientRequestContext requestContext, ClientResponseContext responseContext) { | |
| 40 | - } | |
| 41 | - | |
| 42 | - @Override | |
| 43 | - public void filter(ContainerRequestContext requestContext) { | |
| 44 | - } | |
| 45 | - | |
| 46 | - @Override | |
| 47 | - public void filter(ContainerRequestContext requestContext, ContainerResponseContext response) { | |
| 48 | - response.getHeaders().putSingle("Demoiselle", "3.0.0"); | |
| 49 | - response.getHeaders().putSingle("Access-Control-Allow-Origin", "*"); | |
| 50 | - response.getHeaders().putSingle("Access-Control-Allow-Methods", "OPTIONS, GET, POST, PUT, DELETE"); | |
| 51 | - response.getHeaders().putSingle("Access-Control-Allow-Headers", "Content-Type"); | |
| 52 | - } | |
| 53 | - | |
| 54 | - @PostConstruct | |
| 55 | - public void init() { | |
| 56 | - LOG.info("Demoiselle Module - Rest"); | |
| 57 | - } | |
| 58 | - | |
| 59 | -} |
demoiselle-ws-jaxrs/src/main/java/org/demoiselle/jee/ws/jaxrs/crud/package-info.java
| ... | ... | @@ -1,11 +0,0 @@ |
| 1 | -/* | |
| 2 | - * Demoiselle Framework | |
| 3 | - * | |
| 4 | - * License: GNU Lesser General Public License (LGPL), version 3 or later. | |
| 5 | - * See the lgpl.txt file in the root directory or <https://www.gnu.org/licenses/lgpl.html>. | |
| 6 | - */ | |
| 7 | -/** | |
| 8 | - * Esta pacote tem o objetivo de conter as classes relacionadas aos | |
| 9 | - * facilitadores de CRUD do framework Demoiselle. | |
| 10 | - */ | |
| 11 | -package org.demoiselle.jee.ws.jaxrs.crud; | |
| 12 | 0 | \ No newline at end of file |
demoiselle-ws-jaxrs/src/main/java/org/demoiselle/jee/ws/jaxrs/exception/DemoiselleRESTException.java
| ... | ... | @@ -1,41 +0,0 @@ |
| 1 | -/* | |
| 2 | - * Demoiselle Framework | |
| 3 | - * | |
| 4 | - * License: GNU Lesser General Public License (LGPL), version 3 or later. | |
| 5 | - * See the lgpl.txt file in the root directory or <https://www.gnu.org/licenses/lgpl.html>. | |
| 6 | - */ | |
| 7 | -package org.demoiselle.jee.ws.jaxrs.exception; | |
| 8 | - | |
| 9 | -import java.util.HashMap; | |
| 10 | - | |
| 11 | -import org.demoiselle.jee.core.exception.DemoiselleException; | |
| 12 | - | |
| 13 | -public class DemoiselleRESTException extends DemoiselleException { | |
| 14 | - | |
| 15 | - private static final long serialVersionUID = 519965615171844237L; | |
| 16 | - | |
| 17 | - private HashMap<String, String> messages = new HashMap<String, String>(); | |
| 18 | - | |
| 19 | - private int statusCode; | |
| 20 | - | |
| 21 | - public DemoiselleRESTException() { | |
| 22 | - | |
| 23 | - } | |
| 24 | - | |
| 25 | - public DemoiselleRESTException(String string) { | |
| 26 | - super(string); | |
| 27 | - } | |
| 28 | - | |
| 29 | - public int getStatusCode() { | |
| 30 | - return statusCode; | |
| 31 | - } | |
| 32 | - | |
| 33 | - public void addMessage(String field, String msg) { | |
| 34 | - this.statusCode = 422; | |
| 35 | - messages.put(field, msg); | |
| 36 | - } | |
| 37 | - | |
| 38 | - public HashMap<String, String> getMessages() { | |
| 39 | - return messages; | |
| 40 | - } | |
| 41 | -} |
demoiselle-ws-jaxrs/src/main/java/org/demoiselle/jee/ws/jaxrs/exception/mapper/GenericExceptionMapper.java
| ... | ... | @@ -1,68 +0,0 @@ |
| 1 | -/* | |
| 2 | - * Demoiselle Framework | |
| 3 | - * | |
| 4 | - * License: GNU Lesser General Public License (LGPL), version 3 or later. | |
| 5 | - * See the lgpl.txt file in the root directory or <https://www.gnu.org/licenses/lgpl.html>. | |
| 6 | - */ | |
| 7 | -package org.demoiselle.jee.ws.jaxrs.exception.mapper; | |
| 8 | - | |
| 9 | -import java.io.PrintWriter; | |
| 10 | -import java.io.StringWriter; | |
| 11 | -import java.util.HashMap; | |
| 12 | - | |
| 13 | -import javax.ws.rs.WebApplicationException; | |
| 14 | -import javax.ws.rs.core.MediaType; | |
| 15 | -import javax.ws.rs.core.Response; | |
| 16 | -import javax.ws.rs.ext.ExceptionMapper; | |
| 17 | -import javax.ws.rs.ext.Provider; | |
| 18 | - | |
| 19 | -import org.demoiselle.jee.ws.jaxrs.exception.DemoiselleRESTException; | |
| 20 | - | |
| 21 | -@Provider | |
| 22 | -public class GenericExceptionMapper implements ExceptionMapper<Exception> { | |
| 23 | - | |
| 24 | - public Response toResponse(Exception ex) { | |
| 25 | - | |
| 26 | - StringWriter errorStackTrace = new StringWriter(); | |
| 27 | - ex.printStackTrace(new PrintWriter(errorStackTrace)); | |
| 28 | - | |
| 29 | - // Verifica se a exception é de validação de PAYLOAD do REST | |
| 30 | - if (ex.getCause() instanceof DemoiselleRESTException) { | |
| 31 | - DemoiselleRESTException exDemoiselleREST = (DemoiselleRESTException) ex.getCause(); | |
| 32 | - if (!exDemoiselleREST.getMessages().isEmpty()) { | |
| 33 | - return Response.status(exDemoiselleREST.getStatusCode()).entity(exDemoiselleREST.getMessages()) | |
| 34 | - .type(MediaType.APPLICATION_JSON).build(); | |
| 35 | - } | |
| 36 | - } | |
| 37 | - | |
| 38 | - HashMap<String, String> entity = new HashMap<String, String>(); | |
| 39 | - | |
| 40 | - // No caso de existir message ele mostra a MESSAGE da Exception | |
| 41 | - if (ex.getMessage() != null) { | |
| 42 | - entity.put("error", ex.getMessage()); | |
| 43 | - | |
| 44 | - // Pega toda as mensagens da stacktrace | |
| 45 | - int level = 1; | |
| 46 | - while (ex.getCause() != null) { | |
| 47 | - ex = (Exception) ex.getCause(); | |
| 48 | - if (!ex.getMessage().isEmpty()) { | |
| 49 | - entity.put("inner_cause_" + level, ex.getMessage()); | |
| 50 | - } | |
| 51 | - level += 1; | |
| 52 | - } | |
| 53 | - | |
| 54 | - // Por padrão retorna SERVER ERROR, mas tenta encontrar o status do RESPONSE se for WebApplicationException | |
| 55 | - // http://docs.oracle.com/javaee/7/api/javax/ws/rs/WebApplicationException.html | |
| 56 | - int responseCode = Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(); | |
| 57 | - if (ex instanceof WebApplicationException) { | |
| 58 | - responseCode = ((WebApplicationException)ex).getResponse().getStatus(); | |
| 59 | - } | |
| 60 | - | |
| 61 | - return Response.status(responseCode).entity(entity).type(MediaType.APPLICATION_JSON).build(); | |
| 62 | - } | |
| 63 | - | |
| 64 | - entity.put("error", "Erro interno desconhecido no servidor."); | |
| 65 | - return Response.status(500).entity(entity).type(MediaType.APPLICATION_JSON).build(); | |
| 66 | - } | |
| 67 | - | |
| 68 | -} |
demoiselle-ws-jaxrs/src/main/java/org/demoiselle/jee/ws/jaxrs/interceptor/ValidatePayload.java
| ... | ... | @@ -1,25 +0,0 @@ |
| 1 | -/* | |
| 2 | - * Demoiselle Framework | |
| 3 | - * | |
| 4 | - * License: GNU Lesser General Public License (LGPL), version 3 or later. | |
| 5 | - * See the lgpl.txt file in the root directory or <https://www.gnu.org/licenses/lgpl.html>. | |
| 6 | - */ | |
| 7 | -package org.demoiselle.jee.ws.jaxrs.interceptor; | |
| 8 | - | |
| 9 | -import static java.lang.annotation.ElementType.METHOD; | |
| 10 | -import static java.lang.annotation.ElementType.TYPE; | |
| 11 | -import static java.lang.annotation.RetentionPolicy.RUNTIME; | |
| 12 | - | |
| 13 | -import java.lang.annotation.Inherited; | |
| 14 | -import java.lang.annotation.Retention; | |
| 15 | -import java.lang.annotation.Target; | |
| 16 | - | |
| 17 | -import javax.interceptor.InterceptorBinding; | |
| 18 | - | |
| 19 | -@Inherited | |
| 20 | -@InterceptorBinding | |
| 21 | -@Target({ METHOD, TYPE }) | |
| 22 | -@Retention(RUNTIME) | |
| 23 | -public @interface ValidatePayload { | |
| 24 | - | |
| 25 | -} | |
| 26 | 0 | \ No newline at end of file |
demoiselle-ws-jaxrs/src/main/java/org/demoiselle/jee/ws/jaxrs/interceptor/ValidatePayloadInterceptor.java
| ... | ... | @@ -1,62 +0,0 @@ |
| 1 | -/* | |
| 2 | - * Demoiselle Framework | |
| 3 | - * | |
| 4 | - * License: GNU Lesser General Public License (LGPL), version 3 or later. | |
| 5 | - * See the lgpl.txt file in the root directory or <https://www.gnu.org/licenses/lgpl.html>. | |
| 6 | - */ | |
| 7 | -package org.demoiselle.jee.ws.jaxrs.interceptor; | |
| 8 | - | |
| 9 | -import java.io.Serializable; | |
| 10 | -import java.util.HashSet; | |
| 11 | -import java.util.Set; | |
| 12 | - | |
| 13 | -import javax.interceptor.AroundInvoke; | |
| 14 | -import javax.interceptor.Interceptor; | |
| 15 | -import javax.interceptor.InvocationContext; | |
| 16 | -import javax.validation.ConstraintViolation; | |
| 17 | -import javax.validation.UnexpectedTypeException; | |
| 18 | -import javax.validation.Validation; | |
| 19 | -import javax.validation.Validator; | |
| 20 | -import javax.validation.ValidatorFactory; | |
| 21 | - | |
| 22 | -import org.demoiselle.jee.ws.jaxrs.exception.DemoiselleRESTException; | |
| 23 | - | |
| 24 | -@Interceptor | |
| 25 | -@ValidatePayload | |
| 26 | -public class ValidatePayloadInterceptor implements Serializable { | |
| 27 | - | |
| 28 | - private static final long serialVersionUID = 1L; | |
| 29 | - | |
| 30 | - @AroundInvoke | |
| 31 | - public Object manage(final InvocationContext ic) throws Exception { | |
| 32 | - DemoiselleRESTException ex = new DemoiselleRESTException(); | |
| 33 | - Set<ConstraintViolation<?>> violations = new HashSet<ConstraintViolation<?>>(); | |
| 34 | - for (Object params : ic.getParameters()) { | |
| 35 | - if (params != null) { | |
| 36 | - ValidatorFactory dfv = Validation.buildDefaultValidatorFactory(); | |
| 37 | - Validator validator = dfv.getValidator(); | |
| 38 | - try { | |
| 39 | - violations.addAll(validator.validate(params)); | |
| 40 | - for (ConstraintViolation<?> violation : violations) { | |
| 41 | - String field = (violation.getRootBeanClass().getSimpleName() + "_" | |
| 42 | - + violation.getPropertyPath()).toLowerCase(); | |
| 43 | - // GPMessage msg = | |
| 44 | - // GPMessage.INVALID_FIELD_P1.setSufix(violation.getConstraintDescriptor() | |
| 45 | - // .getAnnotation().annotationType().getSimpleName().toLowerCase()); | |
| 46 | - | |
| 47 | - ex.addMessage(field, violation.getMessage()); | |
| 48 | - } | |
| 49 | - } catch (UnexpectedTypeException cause) { | |
| 50 | - // GPMessage msg = GPMessage.GENERAL_ERROR_P1; | |
| 51 | - // msg.setParam(cause.getMessage()); | |
| 52 | - throw new DemoiselleRESTException("ERRO GENERICO -> ALTERAR"); | |
| 53 | - } | |
| 54 | - } | |
| 55 | - } | |
| 56 | - | |
| 57 | - if (!violations.isEmpty() && !ex.getMessages().isEmpty()) { | |
| 58 | - throw ex; | |
| 59 | - } | |
| 60 | - return ic.proceed(); | |
| 61 | - } | |
| 62 | -} | |
| 63 | 0 | \ No newline at end of file |
pom.xml
| 1 | 1 | <?xml version="1.0" encoding="UTF-8"?> |
| 2 | 2 | <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
| 3 | - xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | |
| 4 | - <modelVersion>4.0.0</modelVersion> | |
| 5 | - | |
| 6 | - <groupId>org.demoiselle.jee</groupId> | |
| 7 | - <artifactId>demoiselle-build</artifactId> | |
| 8 | - <packaging>pom</packaging> | |
| 9 | - <version>3.0.0-BETA1-SNAPSHOT</version> | |
| 10 | - | |
| 11 | - <name>Demoiselle Framework</name> | |
| 12 | - <description>Framework de integração para Java EE 7 baseado na especificação CDI 1.2 (JSR 346).</description> | |
| 13 | - <url>http://demoiselle.io</url> | |
| 14 | - | |
| 15 | - <licenses> | |
| 16 | - <license> | |
| 17 | - <name>GNU Lesser General Public License, Version 3</name> | |
| 18 | - <url>http://www.gnu.org/licenses/lgpl-3.0.txt</url> | |
| 19 | - </license> | |
| 20 | - </licenses> | |
| 21 | - | |
| 22 | - <organization> | |
| 23 | - <name>SERPRO - Serviço Federal de Processamento de Dados</name> | |
| 24 | - <url>http://www.serpro.gov.br</url> | |
| 25 | - </organization> | |
| 26 | - | |
| 27 | - <developers> | |
| 28 | - | |
| 29 | - <developer> | |
| 30 | - <name>Cassio Maes da Fonseca</name> | |
| 31 | - <email>cassiomaes@gmail.com</email> | |
| 32 | - <organization>SERPRO</organization> | |
| 33 | - <organizationUrl>http://www.serpro.gov.br</organizationUrl> | |
| 34 | - </developer> | |
| 35 | - | |
| 36 | - <developer> | |
| 37 | - <name>Clovis Lemes Ferreira Junior</name> | |
| 38 | - <email>clovisjunior2009@gmail.com</email> | |
| 39 | - <organization>SERPRO</organization> | |
| 40 | - <organizationUrl>http://www.serpro.gov.br</organizationUrl> | |
| 41 | - </developer> | |
| 42 | - | |
| 43 | - <developer> | |
| 44 | - <name>Julian Cesar dos Santos</name> | |
| 45 | - <email>juliancesar@gmail.com</email> | |
| 46 | - <organization>SERPRO</organization> | |
| 47 | - <organizationUrl>http://www.serpro.gov.br</organizationUrl> | |
| 48 | - </developer> | |
| 49 | - | |
| 50 | - <developer> | |
| 51 | - <name>Paulo Gladson Ximenes Pinheiro</name> | |
| 52 | - <email>paulopinheiro777@gmail.com</email> | |
| 53 | - <organization>SERPRO</organization> | |
| 54 | - <organizationUrl>http://www.serpro.gov.br</organizationUrl> | |
| 55 | - </developer> | |
| 56 | - | |
| 57 | - <developer> | |
| 58 | - <name>Vanderson Botelho da Silva</name> | |
| 59 | - <email>botelhojp@gmail.com</email> | |
| 60 | - <organization>SERPRO</organization> | |
| 61 | - <organizationUrl>http://www.serpro.gov.br</organizationUrl> | |
| 62 | - </developer> | |
| 63 | - | |
| 64 | - </developers> | |
| 3 | + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | |
| 4 | + <modelVersion>4.0.0</modelVersion> | |
| 5 | + | |
| 6 | + <groupId>org.demoiselle.jee</groupId> | |
| 7 | + <artifactId>demoiselle-build</artifactId> | |
| 8 | + <packaging>pom</packaging> | |
| 9 | + <version>3.0.0-BETA1-SNAPSHOT</version> | |
| 10 | + | |
| 11 | + <name>Demoiselle Framework</name> | |
| 12 | + <description>Framework de integração para Java EE 7 baseado na especificação CDI 1.2 (JSR 346).</description> | |
| 13 | + <url>http://demoiselle.io</url> | |
| 14 | + | |
| 15 | + <licenses> | |
| 16 | + <license> | |
| 17 | + <name>GNU Lesser General Public License, Version 3</name> | |
| 18 | + <url>http://www.gnu.org/licenses/lgpl-3.0.txt</url> | |
| 19 | + </license> | |
| 20 | + </licenses> | |
| 21 | + | |
| 22 | + <organization> | |
| 23 | + <name>SERPRO - Serviço Federal de Processamento de Dados</name> | |
| 24 | + <url>http://www.serpro.gov.br</url> | |
| 25 | + </organization> | |
| 26 | + | |
| 27 | + <developers> | |
| 28 | + | |
| 29 | + <developer> | |
| 30 | + <name>Cassio Maes da Fonseca</name> | |
| 31 | + <email>cassiomaes@gmail.com</email> | |
| 32 | + <organization>SERPRO</organization> | |
| 33 | + <organizationUrl>http://www.serpro.gov.br</organizationUrl> | |
| 34 | + </developer> | |
| 35 | + | |
| 36 | + <developer> | |
| 37 | + <name>Clovis Lemes Ferreira Junior</name> | |
| 38 | + <email>clovisjunior2009@gmail.com</email> | |
| 39 | + <organization>SERPRO</organization> | |
| 40 | + <organizationUrl>http://www.serpro.gov.br</organizationUrl> | |
| 41 | + </developer> | |
| 42 | + | |
| 43 | + <developer> | |
| 44 | + <name>Julian Cesar dos Santos</name> | |
| 45 | + <email>juliancesar@gmail.com</email> | |
| 46 | + <organization>SERPRO</organization> | |
| 47 | + <organizationUrl>http://www.serpro.gov.br</organizationUrl> | |
| 48 | + </developer> | |
| 49 | + | |
| 50 | + <developer> | |
| 51 | + <name>Paulo Gladson Ximenes Pinheiro</name> | |
| 52 | + <email>paulopinheiro777@gmail.com</email> | |
| 53 | + <organization>SERPRO</organization> | |
| 54 | + <organizationUrl>http://www.serpro.gov.br</organizationUrl> | |
| 55 | + </developer> | |
| 56 | + | |
| 57 | + <developer> | |
| 58 | + <name>Vanderson Botelho da Silva</name> | |
| 59 | + <email>botelhojp@gmail.com</email> | |
| 60 | + <organization>SERPRO</organization> | |
| 61 | + <organizationUrl>http://www.serpro.gov.br</organizationUrl> | |
| 62 | + </developer> | |
| 63 | + | |
| 64 | + </developers> | |
| 65 | 65 | |
| 66 | - <modules> | |
| 67 | - <module>demoiselle-parent</module> | |
| 68 | - <module>demoiselle-core</module> | |
| 69 | - <module>demoiselle-persistence-jpa</module> | |
| 70 | - <module>demoiselle-security</module> | |
| 71 | - <module>demoiselle-ws-jaxrs</module> | |
| 72 | - </modules> | |
| 73 | - | |
| 74 | - <properties> | |
| 75 | - <project.alias>framework</project.alias> | |
| 76 | - <java.version>1.8</java.version> | |
| 77 | - <maven.compiler.source>1.8</maven.compiler.source> | |
| 78 | - <maven.compiler.target>1.8</maven.compiler.target> | |
| 79 | - <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | |
| 80 | - </properties> | |
| 66 | + <modules> | |
| 67 | + <module>demoiselle-parent</module> | |
| 68 | + <module>demoiselle-core</module> | |
| 69 | + <module>demoiselle-persistence-jpa</module> | |
| 70 | + <module>demoiselle-rest</module> | |
| 71 | + <module>demoiselle-security</module> | |
| 72 | + <module>demoiselle-security-basic</module> | |
| 73 | + <!--<module>demoiselle-security-jwt</module>--> | |
| 74 | + </modules> | |
| 75 | + | |
| 76 | + <properties> | |
| 77 | + <project.alias>framework</project.alias> | |
| 78 | + <java.version>1.8</java.version> | |
| 79 | + <maven.compiler.source>1.8</maven.compiler.source> | |
| 80 | + <maven.compiler.target>1.8</maven.compiler.target> | |
| 81 | + <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | |
| 82 | + </properties> | |
| 81 | 83 | |
| 82 | - <build> | |
| 83 | - <plugins> | |
| 84 | - <plugin> | |
| 85 | - <groupId>org.apache.maven.plugins</groupId> | |
| 86 | - <artifactId>maven-assembly-plugin</artifactId> | |
| 87 | - <version>2.6</version> | |
| 88 | - </plugin> | |
| 89 | - | |
| 90 | - <plugin> | |
| 91 | - <groupId>org.apache.maven.plugins</groupId> | |
| 92 | - <artifactId>maven-deploy-plugin</artifactId> | |
| 93 | - <version>2.8.2</version> | |
| 94 | - </plugin> | |
| 84 | + <build> | |
| 85 | + <plugins> | |
| 86 | + <plugin> | |
| 87 | + <groupId>org.apache.maven.plugins</groupId> | |
| 88 | + <artifactId>maven-assembly-plugin</artifactId> | |
| 89 | + <version>2.6</version> | |
| 90 | + </plugin> | |
| 91 | + | |
| 92 | + <plugin> | |
| 93 | + <groupId>org.apache.maven.plugins</groupId> | |
| 94 | + <artifactId>maven-deploy-plugin</artifactId> | |
| 95 | + <version>2.8.2</version> | |
| 96 | + </plugin> | |
| 95 | 97 | |
| 96 | - <plugin> | |
| 97 | - <groupId>org.apache.maven.plugins</groupId> | |
| 98 | - <artifactId>maven-source-plugin</artifactId> | |
| 99 | - <version>2.2.1</version> | |
| 100 | - <executions> | |
| 101 | - <execution> | |
| 102 | - <id>attach-sources</id> | |
| 103 | - <goals> | |
| 104 | - <goal>jar-no-fork</goal> | |
| 105 | - </goals> | |
| 106 | - </execution> | |
| 107 | - </executions> | |
| 108 | - </plugin> | |
| 109 | -<!-- | |
| 110 | - <plugin> | |
| 111 | - <groupId>org.apache.maven.plugins</groupId> | |
| 112 | - <artifactId>maven-javadoc-plugin</artifactId> | |
| 113 | - <version>2.9.1</version> | |
| 114 | - <executions> | |
| 115 | - <execution> | |
| 116 | - <id>attach-javadocs</id> | |
| 117 | - <goals> | |
| 118 | - <goal>jar</goal> | |
| 119 | - </goals> | |
| 120 | - </execution> | |
| 121 | - </executions> | |
| 122 | - </plugin> | |
| 123 | - --> | |
| 124 | - <plugin> | |
| 125 | - <groupId>org.apache.maven.plugins</groupId> | |
| 126 | - <artifactId>maven-gpg-plugin</artifactId> | |
| 127 | - <version>1.5</version> | |
| 128 | - <executions> | |
| 129 | - <execution> | |
| 130 | - <id>sign-artifacts</id> | |
| 131 | - <phase>verify</phase> | |
| 132 | - <goals> | |
| 133 | - <goal>sign</goal> | |
| 134 | - </goals> | |
| 135 | - </execution> | |
| 136 | - </executions> | |
| 137 | - </plugin> | |
| 138 | - | |
| 139 | - <plugin> | |
| 140 | - <groupId>org.sonatype.plugins</groupId> | |
| 141 | - <artifactId>nexus-staging-maven-plugin</artifactId> | |
| 142 | - <version>1.6.3</version> | |
| 143 | - <extensions>true</extensions> | |
| 144 | - <configuration> | |
| 145 | - <serverId>sonatype-nexus-staging</serverId> | |
| 146 | - <nexusUrl>https://oss.sonatype.org/</nexusUrl> | |
| 147 | - <autoReleaseAfterClose>false</autoReleaseAfterClose> | |
| 148 | - </configuration> | |
| 149 | - </plugin> | |
| 150 | - | |
| 151 | - <plugin> | |
| 152 | - <groupId>org.apache.maven.plugins</groupId> | |
| 153 | - <artifactId>maven-release-plugin</artifactId> | |
| 154 | - <version>2.5</version> | |
| 155 | - <configuration> | |
| 156 | - <autoVersionSubmodules>true</autoVersionSubmodules> | |
| 157 | - <useReleaseProfile>false</useReleaseProfile> | |
| 158 | - <releaseProfiles>release</releaseProfiles> | |
| 159 | - <goals>deploy</goals> | |
| 160 | - </configuration> | |
| 161 | - </plugin> | |
| 162 | - </plugins> | |
| 163 | - | |
| 164 | - </build> | |
| 165 | - | |
| 166 | - <scm> | |
| 167 | - <connection>scm:git:git@github.com:demoiselle/${project.alias}.git</connection> | |
| 168 | - <developerConnection>scm:git:git@github.com:demoiselle/${project.alias}.git</developerConnection> | |
| 169 | - <url>http://github.com/demoiselle/${project.alias}</url> | |
| 170 | - <tag>HEAD</tag> | |
| 171 | - </scm> | |
| 172 | - | |
| 173 | - <distributionManagement> | |
| 174 | - <site> | |
| 175 | - <id>demoiselle.sourceforge.net</id> | |
| 176 | - <url>${site.url}</url> | |
| 177 | - </site> | |
| 178 | - | |
| 179 | - <snapshotRepository> | |
| 180 | - <id>sonatype-nexus-snapshots</id> | |
| 181 | - <url>https://oss.sonatype.org/content/repositories/snapshots</url> | |
| 182 | - </snapshotRepository> | |
| 183 | - | |
| 184 | - <repository> | |
| 185 | - <id>sonatype-nexus-staging</id> | |
| 186 | - <url>https://oss.sonatype.org/service/local/staging/deploy/maven2/</url> | |
| 187 | - </repository> | |
| 188 | - </distributionManagement> | |
| 189 | - | |
| 190 | - <repositories> | |
| 191 | - <repository> | |
| 192 | - <id>sonatype-nexus-snapshots</id> | |
| 193 | - <name>Sonatype Nexus Snapshots</name> | |
| 194 | - <url>https://oss.sonatype.org/content/repositories/snapshots</url> | |
| 195 | - <snapshots> | |
| 196 | - <enabled>true</enabled> | |
| 197 | - </snapshots> | |
| 198 | - <releases> | |
| 199 | - <enabled>false</enabled> | |
| 200 | - </releases> | |
| 201 | - </repository> | |
| 202 | - | |
| 203 | - <repository> | |
| 204 | - <id>sonatype-nexus-releases</id> | |
| 205 | - <name>Sonatype Nexus Releases</name> | |
| 206 | - <url>https://oss.sonatype.org/content/repositories/releases</url> | |
| 207 | - <snapshots> | |
| 208 | - <enabled>false</enabled> | |
| 209 | - </snapshots> | |
| 210 | - <releases> | |
| 211 | - <enabled>true</enabled> | |
| 212 | - </releases> | |
| 213 | - </repository> | |
| 214 | - </repositories> | |
| 98 | + <plugin> | |
| 99 | + <groupId>org.apache.maven.plugins</groupId> | |
| 100 | + <artifactId>maven-source-plugin</artifactId> | |
| 101 | + <version>2.2.1</version> | |
| 102 | + <executions> | |
| 103 | + <execution> | |
| 104 | + <id>attach-sources</id> | |
| 105 | + <goals> | |
| 106 | + <goal>jar-no-fork</goal> | |
| 107 | + </goals> | |
| 108 | + </execution> | |
| 109 | + </executions> | |
| 110 | + </plugin> | |
| 111 | + <!-- | |
| 112 | + <plugin> | |
| 113 | + <groupId>org.apache.maven.plugins</groupId> | |
| 114 | + <artifactId>maven-javadoc-plugin</artifactId> | |
| 115 | + <version>2.9.1</version> | |
| 116 | + <executions> | |
| 117 | + <execution> | |
| 118 | + <id>attach-javadocs</id> | |
| 119 | + <goals> | |
| 120 | + <goal>jar</goal> | |
| 121 | + </goals> | |
| 122 | + </execution> | |
| 123 | + </executions> | |
| 124 | + </plugin> | |
| 125 | + --> | |
| 126 | + <!-- <plugin> | |
| 127 | + <groupId>org.apache.maven.plugins</groupId> | |
| 128 | + <artifactId>maven-gpg-plugin</artifactId> | |
| 129 | + <version>1.5</version> | |
| 130 | + <executions> | |
| 131 | + <execution> | |
| 132 | + <id>sign-artifacts</id> | |
| 133 | + <phase>verify</phase> | |
| 134 | + <goals> | |
| 135 | + <goal>sign</goal> | |
| 136 | + </goals> | |
| 137 | + </execution> | |
| 138 | + </executions> | |
| 139 | + </plugin>--> | |
| 140 | + | |
| 141 | + <plugin> | |
| 142 | + <groupId>org.sonatype.plugins</groupId> | |
| 143 | + <artifactId>nexus-staging-maven-plugin</artifactId> | |
| 144 | + <version>1.6.3</version> | |
| 145 | + <extensions>true</extensions> | |
| 146 | + <configuration> | |
| 147 | + <serverId>sonatype-nexus-staging</serverId> | |
| 148 | + <nexusUrl>https://oss.sonatype.org/</nexusUrl> | |
| 149 | + <autoReleaseAfterClose>false</autoReleaseAfterClose> | |
| 150 | + </configuration> | |
| 151 | + </plugin> | |
| 152 | + | |
| 153 | + <plugin> | |
| 154 | + <groupId>org.apache.maven.plugins</groupId> | |
| 155 | + <artifactId>maven-release-plugin</artifactId> | |
| 156 | + <version>2.5</version> | |
| 157 | + <configuration> | |
| 158 | + <autoVersionSubmodules>true</autoVersionSubmodules> | |
| 159 | + <useReleaseProfile>false</useReleaseProfile> | |
| 160 | + <releaseProfiles>release</releaseProfiles> | |
| 161 | + <goals>deploy</goals> | |
| 162 | + </configuration> | |
| 163 | + </plugin> | |
| 164 | + </plugins> | |
| 165 | + | |
| 166 | + </build> | |
| 167 | + | |
| 168 | + <scm> | |
| 169 | + <connection>scm:git:git@github.com:demoiselle/${project.alias}.git</connection> | |
| 170 | + <developerConnection>scm:git:git@github.com:demoiselle/${project.alias}.git</developerConnection> | |
| 171 | + <url>http://github.com/demoiselle/${project.alias}</url> | |
| 172 | + <tag>HEAD</tag> | |
| 173 | + </scm> | |
| 174 | + | |
| 175 | + <distributionManagement> | |
| 176 | + <site> | |
| 177 | + <id>demoiselle.sourceforge.net</id> | |
| 178 | + <url>${site.url}</url> | |
| 179 | + </site> | |
| 180 | + | |
| 181 | + <snapshotRepository> | |
| 182 | + <id>sonatype-nexus-snapshots</id> | |
| 183 | + <url>https://oss.sonatype.org/content/repositories/snapshots</url> | |
| 184 | + </snapshotRepository> | |
| 185 | + | |
| 186 | + <repository> | |
| 187 | + <id>sonatype-nexus-staging</id> | |
| 188 | + <url>https://oss.sonatype.org/service/local/staging/deploy/maven2/</url> | |
| 189 | + </repository> | |
| 190 | + </distributionManagement> | |
| 191 | + | |
| 192 | + <repositories> | |
| 193 | + <repository> | |
| 194 | + <id>sonatype-nexus-snapshots</id> | |
| 195 | + <name>Sonatype Nexus Snapshots</name> | |
| 196 | + <url>https://oss.sonatype.org/content/repositories/snapshots</url> | |
| 197 | + <snapshots> | |
| 198 | + <enabled>true</enabled> | |
| 199 | + </snapshots> | |
| 200 | + <releases> | |
| 201 | + <enabled>false</enabled> | |
| 202 | + </releases> | |
| 203 | + </repository> | |
| 204 | + | |
| 205 | + <repository> | |
| 206 | + <id>sonatype-nexus-releases</id> | |
| 207 | + <name>Sonatype Nexus Releases</name> | |
| 208 | + <url>https://oss.sonatype.org/content/repositories/releases</url> | |
| 209 | + <snapshots> | |
| 210 | + <enabled>false</enabled> | |
| 211 | + </snapshots> | |
| 212 | + <releases> | |
| 213 | + <enabled>true</enabled> | |
| 214 | + </releases> | |
| 215 | + </repository> | |
| 216 | + </repositories> | |
| 215 | 217 | |
| 216 | 218 | </project> | ... | ... |