├── .coveralls.yml ├── .gitignore ├── .travis.yml ├── README.md ├── _config.yml ├── demoiselle-configuration ├── .gitignore ├── pom.xml └── src │ ├── main │ ├── java │ │ └── org │ │ │ └── demoiselle │ │ │ └── jee │ │ │ └── configuration │ │ │ ├── ConfigurationBootstrap.java │ │ │ ├── ConfigurationInterceptor.java │ │ │ ├── ConfigurationLoader.java │ │ │ ├── ConfigurationType.java │ │ │ ├── annotation │ │ │ ├── Configuration.java │ │ │ ├── ConfigurationIgnore.java │ │ │ ├── ConfigurationName.java │ │ │ ├── ConfigurationSuppressLogger.java │ │ │ └── package-info.java │ │ │ ├── exception │ │ │ ├── DemoiselleConfigurationException.java │ │ │ └── DemoiselleConfigurationValueExtractorException.java │ │ │ ├── extractor │ │ │ ├── ConfigurationValueExtractor.java │ │ │ ├── impl │ │ │ │ ├── ConfigurationArrayValueExtractor.java │ │ │ │ ├── ConfigurationClassValueExtractor.java │ │ │ │ ├── ConfigurationEnumValueExtractor.java │ │ │ │ ├── ConfigurationInternalDemoiselleValueExtractor.java │ │ │ │ ├── ConfigurationMapValueExtractor.java │ │ │ │ ├── ConfigurationPrimitiveOrWrapperValueExtractor.java │ │ │ │ ├── ConfigurationStringValueExtractor.java │ │ │ │ └── package-info.java │ │ │ └── package-info.java │ │ │ ├── message │ │ │ ├── ConfigurationMessage.java │ │ │ └── package-info.java │ │ │ └── package-info.java │ └── resources │ │ ├── META-INF │ │ ├── beans.xml │ │ └── services │ │ │ └── javax.enterprise.inject.spi.Extension │ │ └── org │ │ └── demoiselle │ │ └── jee │ │ └── configuration │ │ └── message │ │ └── ConfigurationMessage.properties │ └── test │ ├── java │ └── org │ │ └── demoiselle │ │ └── jee │ │ └── configuration │ │ ├── ConfigurationLoaderTest.java │ │ ├── extractor │ │ ├── AbstractConfigurationTest.java │ │ ├── ArrayExtractorTest.java │ │ ├── ClassExtractorTest.java │ │ ├── ConfigurationStringValueExtractorAmbiguousTest.java │ │ ├── ConfigurationStringValueExtractorAmbiguousTest2.java │ │ ├── EnumExtractorTest.java │ │ ├── MapExtractorTest.java │ │ ├── PrimitiveOrWrapperExtractorTest.java │ │ └── StringExtractorTest.java │ │ ├── model │ │ ├── ConfigClassModel.java │ │ ├── ConfigEnum.java │ │ ├── ConfigIncompatibleTypeModel.java │ │ ├── ConfigMapModel.java │ │ ├── ConfigModel.java │ │ ├── ConfigWithNameAnnotationEmptyModel.java │ │ ├── ConfigWithValidationModel.java │ │ └── ConfigWithoutExtractorModel.java │ │ └── util │ │ └── UtilTest.java │ └── resources │ ├── META-INF │ ├── apache-deltaspike.properties │ └── beans.xml │ ├── app-name.properties │ ├── app-name.system │ ├── app-name.xml │ ├── app.properties │ ├── app.system │ └── app.xml ├── demoiselle-core ├── .gitignore ├── demoiselle-core.iml ├── nb-configuration.xml ├── pom.xml └── src │ ├── main │ ├── java │ │ └── org │ │ │ └── demoiselle │ │ │ └── jee │ │ │ └── core │ │ │ ├── api │ │ │ ├── crud │ │ │ │ ├── Crud.java │ │ │ │ ├── Result.java │ │ │ │ └── package-info.java │ │ │ ├── script │ │ │ │ ├── DynamicManagerInterface.java │ │ │ │ └── package-info.java │ │ │ └── security │ │ │ │ ├── DemoiselleUser.java │ │ │ │ ├── SecurityContext.java │ │ │ │ ├── Token.java │ │ │ │ ├── TokenManager.java │ │ │ │ ├── TokenType.java │ │ │ │ └── package-info.java │ │ │ ├── exception │ │ │ ├── DemoiselleException.java │ │ │ ├── DemoiselleLifecycleException.java │ │ │ ├── ExceptionTreatment.java │ │ │ └── package-info.java │ │ │ ├── lifecycle │ │ │ ├── AnnotatedMethodProcessor.java │ │ │ ├── LifecycleBootstrap.java │ │ │ ├── annotation │ │ │ │ ├── DemoiselleLifecyclePriority.java │ │ │ │ ├── Shutdown.java │ │ │ │ └── Startup.java │ │ │ └── package-info.java │ │ │ └── message │ │ │ └── DemoiselleMessage.java │ └── resources │ │ ├── META-INF │ │ ├── beans.xml │ │ └── services │ │ │ └── javax.enterprise.inject.spi.Extension │ │ ├── demoiselle.properties │ │ └── org │ │ └── demoiselle │ │ └── jee │ │ └── core │ │ └── message │ │ └── DemoiselleMessage.properties │ └── test │ ├── java │ └── org │ │ └── demoiselle │ │ └── jee │ │ └── core │ │ ├── CoreTest.java │ │ └── lifecycle │ │ ├── LifecyclePriorityTest.java │ │ └── model │ │ └── PriorityLifecycleModelTest.java │ └── resources │ └── META-INF │ └── beans.xml ├── demoiselle-crud ├── .gitignore ├── pom.xml └── src │ ├── main │ ├── java │ │ └── org │ │ │ └── demoiselle │ │ │ └── jee │ │ │ └── crud │ │ │ ├── AbstractBusiness.java │ │ │ ├── AbstractDAO.java │ │ │ ├── AbstractREST.java │ │ │ ├── CrudFilter.java │ │ │ ├── CrudMessage.java │ │ │ ├── CrudUtilHelper.java │ │ │ ├── DemoiselleRequestContext.java │ │ │ ├── DemoiselleRequestContextImpl.java │ │ │ ├── ReservedHTTPHeaders.java │ │ │ ├── ReservedKeyWords.java │ │ │ ├── Search.java │ │ │ ├── TreeNodeField.java │ │ │ ├── bootstrap │ │ │ ├── PersistenceBootstrap.java │ │ │ └── package-info.java │ │ │ ├── exception │ │ │ ├── DemoiselleCrudException.java │ │ │ └── package-info.java │ │ │ ├── field │ │ │ ├── FieldHelper.java │ │ │ ├── FieldHelperMessage.java │ │ │ └── package-info.java │ │ │ ├── filter │ │ │ ├── FilterHelper.java │ │ │ └── package-info.java │ │ │ ├── package-info.java │ │ │ ├── pagination │ │ │ ├── PaginationHelper.java │ │ │ ├── PaginationHelperConfig.java │ │ │ ├── PaginationHelperMessage.java │ │ │ ├── ResultSet.java │ │ │ └── package-info.java │ │ │ └── sort │ │ │ ├── CrudSort.java │ │ │ ├── SortHelper.java │ │ │ ├── SortHelperMessage.java │ │ │ ├── SortModel.java │ │ │ └── package-info.java │ └── resources │ │ ├── META-INF │ │ ├── beans.xml │ │ └── services │ │ │ └── javax.enterprise.inject.spi.Extension │ │ ├── demoiselle.properties │ │ └── org │ │ └── demoiselle │ │ └── jee │ │ └── crud │ │ ├── CrudMessage.properties │ │ ├── field │ │ └── FieldHelperMessage.properties │ │ ├── pagination │ │ └── PaginationHelperMessage.properties │ │ └── sort │ │ └── SortHelperMessage.properties │ └── test │ ├── groovy │ └── org │ │ └── demoiselle │ │ └── jee │ │ └── crud │ │ ├── CrudFilterSpec.groovy │ │ ├── FieldHelperSpec.groovy │ │ ├── FilterHelperSpec.groovy │ │ ├── PaginationHelperSpec.groovy │ │ └── SortHelperSpec.groovy │ ├── java │ └── org │ │ └── demoiselle │ │ └── jee │ │ └── crud │ │ ├── ErrorMsgForTest.java │ │ ├── UserRestForTest.java │ │ ├── UserRestWithoutAbstractRESTForTest.java │ │ └── entity │ │ ├── AddressModelForTest.java │ │ ├── CountryModelForTest.java │ │ └── UserModelForTest.java │ └── resources │ ├── META-INF │ └── services │ │ └── javax.enterprise.inject.spi.Extension │ └── demoiselle.properties ├── demoiselle-parent-bom ├── .gitignore └── pom.xml ├── demoiselle-parent-rest ├── .gitignore ├── demoiselle-parent-rest.iml └── pom.xml ├── demoiselle-parent ├── .gitignore └── pom.xml ├── demoiselle-rest ├── .gitignore ├── demoiselle-rest.iml ├── pom.xml └── src │ ├── main │ ├── java │ │ └── org │ │ │ └── demoiselle │ │ │ └── jee │ │ │ └── rest │ │ │ ├── DemoiselleRestConfig.java │ │ │ ├── LogExceptionMappers.java │ │ │ ├── annotation │ │ │ └── CacheControl.java │ │ │ ├── exception │ │ │ ├── DemoiselleRestException.java │ │ │ ├── DemoiselleRestExceptionMessage.java │ │ │ ├── mapper │ │ │ │ ├── AnyOtherExceptionMapper.java │ │ │ │ └── ValidationExceptionMapper.java │ │ │ └── treatment │ │ │ │ └── ExceptionTreatmentImpl.java │ │ │ ├── filter │ │ │ ├── CacheControlFilter.java │ │ │ └── RestFilter.java │ │ │ └── message │ │ │ └── DemoiselleRESTMessage.java │ └── resources │ │ ├── META-INF │ │ ├── beans.xml │ │ └── services │ │ │ └── javax.enterprise.inject.spi.Extension │ │ └── org │ │ └── demoiselle │ │ └── jee │ │ └── rest │ │ └── message │ │ └── DemoiselleRESTMessage.properties │ └── test │ └── java │ └── org │ └── demoiselle │ └── jee │ └── rest │ └── DemoiselleRestConfigTest.java ├── demoiselle-script ├── .gitignore ├── README.md ├── demoiselle-script.iml ├── pom.xml └── src │ ├── main │ ├── java │ │ └── org │ │ │ └── demoiselle │ │ │ └── jee │ │ │ └── script │ │ │ ├── DynamicManager.java │ │ │ ├── DynamicManagerCache.java │ │ │ ├── exception │ │ │ └── DemoiselleScriptException.java │ │ │ ├── message │ │ │ └── DemoiselleScriptMessage.java │ │ │ └── package-info.java │ └── resources │ │ ├── META-INF │ │ └── beans.xml │ │ └── org │ │ └── demoiselle │ │ └── jee │ │ └── script │ │ └── message │ │ └── DemoiselleScriptMessage.properties │ └── test │ ├── java │ └── org │ │ └── demoiselle │ │ └── jee │ │ └── script │ │ └── test │ │ └── DynamicManagerTest.java │ └── resources │ ├── META-INF │ └── beans.xml │ └── org │ └── demoiselle │ └── jee │ └── script │ └── message │ └── DemoiselleScriptMessage.properties ├── demoiselle-security-hashcash ├── .gitignore ├── pom.xml └── src │ ├── main │ ├── java │ │ └── org │ │ │ └── demoiselle │ │ │ └── jee │ │ │ └── security │ │ │ └── hashcash │ │ │ ├── DemoiselleSecurityHashCashConfig.java │ │ │ ├── annotation │ │ │ └── HashCash.java │ │ │ ├── execution │ │ │ └── Generator.java │ │ │ └── filter │ │ │ └── HashCashFilter.java │ └── resources │ │ ├── META-INF │ │ └── beans.xml │ │ └── demoiselle.properties │ └── test │ ├── java │ └── org │ │ └── demoiselle │ │ └── jee │ │ └── security │ │ └── hashcash │ │ └── execution │ │ └── HashCashTest.java │ └── resources │ ├── META-INF │ └── beans.xml │ └── demoiselle.properties ├── demoiselle-security-jwt ├── .gitignore ├── demoiselle-security-jwt.iml ├── pom.xml └── src │ ├── main │ ├── java │ │ └── org │ │ │ └── demoiselle │ │ │ └── jee │ │ │ └── security │ │ │ ├── jwt │ │ │ └── impl │ │ │ │ ├── DemoiselleSecurityJWTConfig.java │ │ │ │ └── TokenManagerImpl.java │ │ │ └── message │ │ │ └── DemoiselleSecurityJWTMessages.java │ └── resources │ │ ├── META-INF │ │ └── beans.xml │ │ └── org │ │ └── demoiselle │ │ └── jee │ │ └── security │ │ └── message │ │ └── DemoiselleSecurityJWTMessages.properties │ └── test │ ├── java │ └── org │ │ └── demoiselle │ │ └── jee │ │ └── security │ │ └── jwt │ │ └── impl │ │ ├── ConfigTest.java │ │ ├── DemoiselleSecurityJWTMock.java │ │ ├── DemoiselleSecurityJWTMockError.java │ │ ├── TokenManagerImplMasterTest.java │ │ ├── TokenManagerImplSlaveTest.java │ │ └── TokenManagerImplTest.java │ └── resources │ ├── META-INF │ └── beans.xml │ ├── demoiselle.properties │ ├── demoiselleError.properties │ └── org │ └── demoiselle │ └── jee │ └── security │ └── message │ └── DemoiselleSecurityJWTMessages.properties ├── demoiselle-security-token ├── .gitignore ├── pom.xml └── src │ ├── main │ ├── java │ │ └── org │ │ │ └── demoiselle │ │ │ └── jee │ │ │ └── security │ │ │ └── token │ │ │ └── impl │ │ │ └── TokenManagerImpl.java │ └── resources │ │ └── META-INF │ │ └── beans.xml │ └── test │ ├── java │ └── org │ │ └── demoiselle │ │ └── jee │ │ └── security │ │ └── token │ │ └── impl │ │ └── TokenManagerImplTest.java │ └── resources │ └── META-INF │ └── beans.xml ├── demoiselle-security ├── .gitignore ├── demoiselle-security.iml ├── pom.xml └── src │ ├── main │ ├── java │ │ └── org │ │ │ └── demoiselle │ │ │ └── jee │ │ │ └── security │ │ │ ├── DemoiselleSecurityConfig.java │ │ │ ├── annotation │ │ │ ├── Authenticated.java │ │ │ ├── Cors.java │ │ │ ├── RequiredPermission.java │ │ │ └── RequiredRole.java │ │ │ ├── exception │ │ │ └── DemoiselleSecurityException.java │ │ │ ├── filter │ │ │ ├── CorsFilter.java │ │ │ └── SecurityFilter.java │ │ │ ├── impl │ │ │ ├── DemoiselleUserImpl.java │ │ │ ├── SecurityContextImpl.java │ │ │ └── TokenImpl.java │ │ │ ├── interceptor │ │ │ ├── AuthenticatedInterceptor.java │ │ │ ├── RequiredPermissionInterceptor.java │ │ │ └── RequiredRoleInterceptor.java │ │ │ └── message │ │ │ └── DemoiselleSecurityMessages.java │ └── resources │ │ ├── META-INF │ │ └── beans.xml │ │ ├── demoiselle.properties │ │ └── org │ │ └── demoiselle │ │ └── jee │ │ └── security │ │ └── message │ │ └── DemoiselleSecurityMessages.properties │ └── test │ ├── java │ └── org │ │ └── demoiselle │ │ └── jee │ │ └── security │ │ ├── DemoiselleSecurityConfigTest.java │ │ ├── TokenManagerMock.java │ │ ├── exception │ │ └── DemoiselleSecurityExceptionTest.java │ │ ├── impl │ │ ├── DemoiselleUserImplTest.java │ │ ├── SecurityContextImplTest.java │ │ └── TokenImplTest.java │ │ ├── interceptor │ │ ├── LoggedInInterceptorTest.java │ │ ├── RequiredPermissionInterceptorTest.java │ │ └── RequiredRoleInterceptorTest.java │ │ └── message │ │ └── DemoiselleSecurityMessagesTest.java │ └── resources │ ├── META-INF │ └── beans.xml │ ├── demoiselle.properties │ └── org │ └── demoiselle │ └── jee │ └── security │ └── message │ └── DemoiselleSecurityMessages.properties ├── lgpl.txt ├── licence-lgpl ├── header-definitions.xml └── header.txt └── pom.xml /.coveralls.yml: -------------------------------------------------------------------------------- 1 | COVERALLS_SERVICE_NAME=travis-ci 2 | COVERALLS_REPO_TOKEN=1KLSPMQ8fgROKnkrUq8DbUZ2kux9jdg7C 3 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /nbactions.xml 2 | /persistence/target/ 3 | /core/target/ 4 | /ws/target/ 5 | /security/target/ 6 | /.project 7 | /.settings/ 8 | /basic/target/ 9 | /basic (cópia)/target/ 10 | /jwt/target/ 11 | /target/ 12 | /demoiselle-security-jwt/nbproject/ 13 | /demoiselle-security-token/nbproject/ 14 | /demoiselle-security/nbproject/ 15 | /demoiselle-security-basic/nbproject/ 16 | /demoiselle-rest/nbproject/ 17 | /demoiselle-crud/nbproject/ 18 | /demoiselle-multitenancy-hibernate/ 19 | /.DS_Store 20 | /.idea 21 | **.iml 22 | /demoiselle-security-token (cópia)/nbproject/ 23 | /demoiselle-security-pow/nbproject/ 24 | /demoiselle-security-hashcash/nbproject/ -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: java 2 | jdk: oraclejdk8 3 | addons: 4 | sonarqube: 5 | token: 6 | secure: "a688e735dd959a7bda8303306bcedec5ec463cee" 7 | branches: 8 | only: 9 | - master 10 | - 3.0.0-SNAPSHOT 11 | script: 12 | - mvn clean install -Pjacoco -Pcoveralls coveralls:report sonar:sonar 13 | cache: 14 | directories: 15 | - '$HOME/.m2/repository' 16 | - '$HOME/.sonar/cache' 17 | notifications: 18 | webhooks: 19 | urls: 20 | - https://webhooks.gitter.im/e/112bda97234dac298c06 21 | on_success: change # options: [always|never|change] default: always 22 | on_failure: always # options: [always|never|change] default: always 23 | on_start: never # options: [always|never|change] default: always 24 | slack: 25 | on_success: always 26 | on_failure: always 27 | email: 28 | recipients: 29 | - demoiselle-devel@lists.sourceforge.net 30 | on_success: change 31 | on_failure: always 32 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Demoiselle 3 2 | ----------- 3 | [![Build Status](https://travis-ci.org/demoiselle/framework.svg?branch=master)](https://travis-ci.org/demoiselle/framework) [![Coverage Status](https://coveralls.io/repos/github/demoiselle/framework/badge.svg?branch=master)](https://coveralls.io/github/demoiselle/framework) [![Maven Central](https://maven-badges.herokuapp.com/maven-central/org.demoiselle.jee/demoiselle-core/badge.svg?style=flat-square)](https://maven-badges.herokuapp.com/maven-central/org.demoiselle.jee/demoiselle-core/badge.svg?style=flat-square) [![Join the chat at https://gitter.im/demoiselle](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/demoiselle?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) 4 | 5 | ============= 6 | 7 | O framework Demoiselle implementa o conceito de framework integrador. 8 | Seu objetivo é facilitar a construção de aplicações minimizando tempo 9 | dedicado à escolha e integração de frameworks especialistas, o que 10 | resulta no aumento da produtividade e garante a manutenibilidade dos sistemas. 11 | 12 | Disponibiliza mecanismos reusáveis voltados as funcionalidades mais 13 | comuns de uma aplicação (arquitetura, segurança, transação, mensagem, 14 | configuração, tratamento de exceções, etc). 15 | 16 | O nome Demoiselle é uma homenagem à série de aeroplanos construídos 17 | por Santos Dummont entre 1907 e 1909. Também conhecido como Libellule, 18 | as Demoiselles foram os melhores, menores e mais baratos aviões da sua 19 | época. Como sua intenção era popularizar a aviação com fabricação em larga 20 | escala, o inventor disponibilizou os planos em revistas técnicas para 21 | qualquer pessoa que se interessasse. 22 | 23 | O framework Demoiselle usa a mesma filosofia do “Pai da Aviação”, 24 | tendo sido disponibilizado como software livre em abril de 2009, sob a 25 | licença livre LGPL version 3. Mais informações no [portal](www.frameworkdemoiselle.gov.br). 26 | 27 | 28 | Links úteis 29 | ----------- 30 | 31 | * [Portal](http://demoiselle.io): Central de acesso as informações do Demoiselle 32 | * [Documentação](https://demoiselle.gitbooks.io/documentacao-jee/content): Aprenda sobre o Demoiselle seguindo os vários módulos 33 | * [Fórum/Tracker](https://github.com/demoiselle/framework/issues): Fóruns de discussão e Submissão/acompanhamento de Bugs, Improvements e New Features 34 | * [Lista de discussão](https://lists.sourceforge.net/lists/listinfo/demoiselle-users): Comunicação e troca de experiências entre os usuários do projeto. 35 | 36 | 37 | Repositório Maven 38 | ----------- 39 | 40 | 41 | central.repository 42 | http://repo1.maven.org/maven2 43 | 44 | 45 | 46 | Contribuindo 47 | ------------ 48 | 49 | 1. Faça o seu fork. 50 | 2. Crie o seu branch (ramo) - (`git checkout -b meu_framework`) 51 | 3. Commit seu código (`git commit -am "Explicando o motivo/objetivo"`) 52 | 4. Agora execute o Push para o branch (`git push origin meu_framework`) 53 | 5. Dúvidas, problemas ou sugestões? Crie uma issue no [GitHub][1] com o link para o seu branch 54 | 55 | 56 | [1]: https://github.com/demoiselle/framework/issues 57 | -------------------------------------------------------------------------------- /_config.yml: -------------------------------------------------------------------------------- 1 | theme: jekyll-theme-slate -------------------------------------------------------------------------------- /demoiselle-configuration/.gitignore: -------------------------------------------------------------------------------- 1 | target/ 2 | .project 3 | .settings/ 4 | .classpath 5 | /bin/ 6 | -------------------------------------------------------------------------------- /demoiselle-configuration/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4.0.0 4 | demoiselle-configuration 5 | jar 6 | 7 | Demoiselle JEE Configuration 8 | 9 | Demoiselle Configuration habilita os projetos a usarem configurações em arquivos .properties, .xml ou variáveis de ambiente. 10 | 11 | http://demoiselle.io 12 | 13 | 14 | org.demoiselle.jee 15 | demoiselle-parent 16 | 3.0.6-SNAPSHOT 17 | ../demoiselle-parent 18 | 19 | 20 | 21 | 22 | 23 | org.demoiselle.jee 24 | demoiselle-core 25 | 26 | 27 | 28 | 29 | org.apache.commons 30 | commons-configuration2 31 | 32 | 33 | 34 | 35 | commons-beanutils 36 | commons-beanutils 37 | 38 | 39 | 40 | org.hibernate 41 | hibernate-validator 42 | 43 | 44 | 45 | 46 | 47 | -------------------------------------------------------------------------------- /demoiselle-configuration/src/main/java/org/demoiselle/jee/configuration/ConfigurationBootstrap.java: -------------------------------------------------------------------------------- 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 . 6 | */ 7 | package org.demoiselle.jee.configuration; 8 | 9 | import java.util.Set; 10 | import java.util.concurrent.ConcurrentHashMap; 11 | 12 | import javax.enterprise.event.Observes; 13 | import javax.enterprise.inject.spi.Extension; 14 | import javax.enterprise.inject.spi.ProcessAnnotatedType; 15 | 16 | import org.demoiselle.jee.configuration.extractor.ConfigurationValueExtractor; 17 | 18 | /** 19 | * 20 | * Class responsible for loading all extractors classes that implement the 21 | * {@link ConfigurationValueExtractor} interface. 22 | * 23 | * @author SERPRO 24 | * 25 | */ 26 | public class ConfigurationBootstrap implements Extension { 27 | 28 | private Set> cache; 29 | 30 | protected Set> getCache() { 31 | if (this.cache == null) { 32 | this.cache = ConcurrentHashMap.newKeySet(); 33 | } 34 | 35 | return this.cache; 36 | } 37 | 38 | /** 39 | * Process all classes that extends {@link ConfigurationValueExtractor} and 40 | * add the own class type on cache. 41 | * 42 | * @param pat 43 | * ProcessAnnotatedType used by CDI 44 | */ 45 | public void processAnnotatedType(@Observes final ProcessAnnotatedType pat) { 46 | 47 | Class pcsClass = pat.getAnnotatedType().getJavaClass(); 48 | 49 | if (pcsClass.isAnnotation() || pcsClass.isInterface() || pcsClass.isSynthetic() || pcsClass.isArray() 50 | || pcsClass.isEnum()) { 51 | return; 52 | } 53 | 54 | this.getCache().add(pat.getAnnotatedType().getJavaClass()); 55 | } 56 | 57 | } 58 | -------------------------------------------------------------------------------- /demoiselle-configuration/src/main/java/org/demoiselle/jee/configuration/ConfigurationInterceptor.java: -------------------------------------------------------------------------------- 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 . 6 | */ 7 | package org.demoiselle.jee.configuration; 8 | 9 | import javax.annotation.Priority; 10 | import javax.enterprise.context.Dependent; 11 | import javax.enterprise.inject.spi.CDI; 12 | import javax.interceptor.AroundInvoke; 13 | import javax.interceptor.Interceptor; 14 | import javax.interceptor.InvocationContext; 15 | 16 | import org.demoiselle.jee.configuration.annotation.Configuration; 17 | 18 | /** 19 | * 20 | * Intercepts annotated class with {@link Configuration} and delegates 21 | * processing to the class {@link ConfigurationLoader} 22 | * 23 | * @author SERPRO 24 | */ 25 | @Dependent 26 | @Configuration 27 | @Interceptor 28 | @Priority(Interceptor.Priority.APPLICATION) 29 | public class ConfigurationInterceptor { 30 | 31 | @AroundInvoke 32 | public Object constructConfiguration(final InvocationContext ic) throws Exception { 33 | final ConfigurationLoader configurationLoader = CDI.current().select(ConfigurationLoader.class).get(); 34 | 35 | final Class baseClass = ic.getMethod().getDeclaringClass(); 36 | configurationLoader.load(ic.getTarget(), baseClass); 37 | return ic.proceed(); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /demoiselle-configuration/src/main/java/org/demoiselle/jee/configuration/ConfigurationType.java: -------------------------------------------------------------------------------- 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 . 6 | */ 7 | package org.demoiselle.jee.configuration; 8 | 9 | /** 10 | * Defines the types of sources that can be consumed. 11 | * 12 | * @author SERPRO 13 | * 14 | */ 15 | public enum ConfigurationType { 16 | /** 17 | * Loaded settings {@link System#getProperties()} or 18 | * {@link System#getenv()}. 19 | */ 20 | SYSTEM, 21 | 22 | /** 23 | * Settings loaded from an XML file. 24 | */ 25 | XML, 26 | 27 | /** 28 | * Settings loaded from a properties file. 29 | */ 30 | PROPERTIES 31 | } 32 | -------------------------------------------------------------------------------- /demoiselle-configuration/src/main/java/org/demoiselle/jee/configuration/annotation/ConfigurationIgnore.java: -------------------------------------------------------------------------------- 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 . 6 | */ 7 | package org.demoiselle.jee.configuration.annotation; 8 | 9 | import static java.lang.annotation.ElementType.FIELD; 10 | import static java.lang.annotation.RetentionPolicy.RUNTIME; 11 | 12 | import java.lang.annotation.Retention; 13 | import java.lang.annotation.Target; 14 | 15 | /** 16 | *

Used in fields of classes annotated with 17 | * to indicate that the system should ignore this field when population the new configuration 18 | * instance with values extracted from the source file.

19 | * 20 | * @author SERPRO 21 | */ 22 | @Target(FIELD) 23 | @Retention(RUNTIME) 24 | public @interface ConfigurationIgnore { 25 | } 26 | -------------------------------------------------------------------------------- /demoiselle-configuration/src/main/java/org/demoiselle/jee/configuration/annotation/ConfigurationName.java: -------------------------------------------------------------------------------- 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 . 6 | */ 7 | package org.demoiselle.jee.configuration.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 | *

24 | * String based non-binding qualifier. 25 | *

26 | * 27 | *

28 | * This annotation is used to qualify beans using an user defined String. 29 | * methods can then read this string and use it to customize the bean creation process. 30 | *

31 | * 32 | *

33 | * The attribute is non-binding (contrary to meaning multiple classes 34 | * qualified with this annotation, even with different values, will be considered the same candidate for 35 | * injection points. To avoid ambiguous resolutions and select which candidate to choose usually you'll need a 36 | * producer method to read the string and select the best fitted candidate. 37 | *

38 | * 39 | *

40 | * The framework classes qualified with this annotation already have such producers and the accepted values for 41 | * this annotation will be detailed in their respective documentations. 42 | *

43 | * 44 | * 45 | * @author SERPRO 46 | * 47 | */ 48 | @Qualifier 49 | @Inherited 50 | @Retention(RUNTIME) 51 | @Target({ TYPE, FIELD, METHOD, PARAMETER }) 52 | public @interface ConfigurationName { 53 | 54 | /** 55 | *

56 | * Specifies a name to access a custom configuration that will change how the annotated bean works. 57 | *

58 | *

59 | * This attribute is nonbinding so you can use the annotation to create 60 | * methods or fields and have only one producer that works with all injection points no matter the value of this attribute. 61 | *

62 | * @return Name of custom settings to personalize how the annotated bean works. 63 | */ 64 | @Nonbinding 65 | String value() default ""; 66 | 67 | } 68 | -------------------------------------------------------------------------------- /demoiselle-configuration/src/main/java/org/demoiselle/jee/configuration/annotation/ConfigurationSuppressLogger.java: -------------------------------------------------------------------------------- 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 . 6 | */ 7 | 8 | package org.demoiselle.jee.configuration.annotation; 9 | 10 | import static java.lang.annotation.ElementType.TYPE; 11 | import static java.lang.annotation.ElementType.FIELD; 12 | import static java.lang.annotation.RetentionPolicy.RUNTIME; 13 | 14 | import java.lang.annotation.Retention; 15 | import java.lang.annotation.Target; 16 | 17 | /** 18 | * 19 | * Annotation used to suppress logger of a Object or Field 20 | * 21 | * @author SERPRO 22 | * 23 | */ 24 | @Target({ TYPE, FIELD }) 25 | @Retention(RUNTIME) 26 | public @interface ConfigurationSuppressLogger { 27 | 28 | } 29 | -------------------------------------------------------------------------------- /demoiselle-configuration/src/main/java/org/demoiselle/jee/configuration/annotation/package-info.java: -------------------------------------------------------------------------------- 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 . 6 | */ 7 | 8 | /** 9 | * It provides the annotations for the Demoiselle Configuration. 10 | * 11 | * @author SERPRO 12 | */ 13 | package org.demoiselle.jee.configuration.annotation; -------------------------------------------------------------------------------- /demoiselle-configuration/src/main/java/org/demoiselle/jee/configuration/exception/DemoiselleConfigurationException.java: -------------------------------------------------------------------------------- 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 . 6 | */ 7 | package org.demoiselle.jee.configuration.exception; 8 | 9 | import org.demoiselle.jee.core.exception.DemoiselleException; 10 | 11 | /** 12 | * 13 | * Main exception Demoiselle Configuration feature 14 | * 15 | * @author SERPRO 16 | */ 17 | public class DemoiselleConfigurationException extends DemoiselleException { 18 | 19 | private static final long serialVersionUID = 1L; 20 | 21 | public DemoiselleConfigurationException(String message) { 22 | super(message); 23 | } 24 | 25 | public DemoiselleConfigurationException(String message, Throwable cause) { 26 | super(message, cause); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /demoiselle-configuration/src/main/java/org/demoiselle/jee/configuration/exception/DemoiselleConfigurationValueExtractorException.java: -------------------------------------------------------------------------------- 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 . 6 | */ 7 | package org.demoiselle.jee.configuration.exception; 8 | 9 | import org.demoiselle.jee.core.exception.DemoiselleException; 10 | 11 | /** 12 | * 13 | * Exception that handles errors on extracting process 14 | * 15 | * @author SERPRO 16 | */ 17 | public class DemoiselleConfigurationValueExtractorException extends DemoiselleException { 18 | 19 | private static final long serialVersionUID = 1L; 20 | 21 | public DemoiselleConfigurationValueExtractorException(String message) { 22 | super(message); 23 | } 24 | 25 | public DemoiselleConfigurationValueExtractorException(String message, Throwable cause) { 26 | super(message, cause); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /demoiselle-configuration/src/main/java/org/demoiselle/jee/configuration/extractor/ConfigurationValueExtractor.java: -------------------------------------------------------------------------------- 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 . 6 | */ 7 | package org.demoiselle.jee.configuration.extractor; 8 | 9 | import java.lang.reflect.Field; 10 | 11 | import org.apache.commons.configuration2.Configuration; 12 | import org.demoiselle.jee.configuration.exception.DemoiselleConfigurationValueExtractorException; 13 | 14 | /** 15 | * Definition interface to extractors. 16 | * 17 | * @author SERPRO 18 | * 19 | */ 20 | public interface ConfigurationValueExtractor { 21 | 22 | /** 23 | * Extracts the value of a source based on the parameters. 24 | * 25 | * @param prefix 26 | * Prefix used in the source file. 27 | * @param key 28 | * Key used in the source file. 29 | * @param field 30 | * Field to be filled. 31 | * @param configuration 32 | * {@link org.apache.commons.configuration2.Configuration} object 33 | * responsible for extracting the value. 34 | * @return Object with the value set at source 35 | * @throws DemoiselleConfigurationValueExtractorException 36 | * Exception issued if an error occurs. 37 | */ 38 | Object getValue(String prefix, String key, Field field, Configuration configuration) throws DemoiselleConfigurationValueExtractorException; 39 | 40 | /** 41 | * Verify the type supported by the extractor 42 | * 43 | * @param field 44 | * Field to be validated. 45 | * @return True if supported and False if it is not supported 46 | */ 47 | boolean isSupported(Field field); 48 | } 49 | -------------------------------------------------------------------------------- /demoiselle-configuration/src/main/java/org/demoiselle/jee/configuration/extractor/impl/ConfigurationArrayValueExtractor.java: -------------------------------------------------------------------------------- 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 . 6 | */ 7 | package org.demoiselle.jee.configuration.extractor.impl; 8 | 9 | import java.lang.reflect.Field; 10 | 11 | import javax.enterprise.context.Dependent; 12 | 13 | import org.apache.commons.configuration2.Configuration; 14 | import org.apache.commons.configuration2.DataConfiguration; 15 | import org.demoiselle.jee.configuration.ConfigurationType; 16 | import org.demoiselle.jee.configuration.exception.DemoiselleConfigurationValueExtractorException; 17 | import org.demoiselle.jee.configuration.extractor.ConfigurationValueExtractor; 18 | 19 | /** 20 | * Adds the data extraction capability of a source ({@link ConfigurationType}) 21 | * for the type of {@link Object[]}. 22 | * 23 | *

24 | * Sample: 25 | *

26 | * 27 | *

28 | * For the extraction of an array type of a properties file the statement made 29 | * in the properties will have the following format: 30 | *

31 | * 32 | *
33 |  * demoiselle.intergerArray=-1
34 |  * demoiselle.intergerArray=0
35 |  * demoiselle.intergerArray=1
36 |  * 
37 | * 38 | * And the configuration class will be declared as follows: 39 | * 40 | *
41 |  * 
42 |  * @Configuration
43 |  * public class MyConfig {
44 |  *     private Integer[] integerArray;
45 |  * 
46 |  *     public Integer[] getIntegerArray() {
47 |  *         return this.integerArray;
48 |  *     }
49 |  * 
50 |  * }
51 |  * 
52 |  * 
53 | * 54 | * @author SERPRO 55 | * 56 | */ 57 | @Dependent 58 | public class ConfigurationArrayValueExtractor implements ConfigurationValueExtractor { 59 | 60 | @Override 61 | public Object getValue(String prefix, String key, Field field, Configuration configuration) throws DemoiselleConfigurationValueExtractorException { 62 | try{ 63 | return new DataConfiguration(configuration).getArray(field.getType().getComponentType(), prefix + key); 64 | } 65 | catch(Exception e){ 66 | throw new DemoiselleConfigurationValueExtractorException(e.getMessage(), e); 67 | } 68 | } 69 | 70 | @Override 71 | public boolean isSupported(Field field) { 72 | return field.getType().isArray(); 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /demoiselle-configuration/src/main/java/org/demoiselle/jee/configuration/extractor/impl/ConfigurationEnumValueExtractor.java: -------------------------------------------------------------------------------- 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 . 6 | */ 7 | package org.demoiselle.jee.configuration.extractor.impl; 8 | 9 | import java.lang.reflect.Field; 10 | 11 | import javax.enterprise.context.Dependent; 12 | 13 | import org.apache.commons.configuration2.Configuration; 14 | import org.demoiselle.jee.configuration.ConfigurationType; 15 | import org.demoiselle.jee.configuration.exception.DemoiselleConfigurationValueExtractorException; 16 | import org.demoiselle.jee.configuration.extractor.ConfigurationValueExtractor; 17 | 18 | /** 19 | * Adds the data extraction capability of a source ({@link ConfigurationType}) 20 | * for the type of {@link Enum}. 21 | * 22 | *

23 | * Sample: 24 | *

25 | * 26 | *

27 | * For the extraction of an Enum type of a properties file the statement made in 28 | * the properties will have the following format: 29 | *

30 | * 31 | *
32 |  * demoiselle.loadedConfigurationType = SYSTEM
33 |  * 
34 | * 35 | * And the configuration class will be declared as follows: 36 | * 37 | *
38 |  *  
39 |  * @Configuration
40 |  * public class BookmarkConfig {
41 |  *
42 |  *  private {@link ConfigurationType} loadedConfigurationType;
43 |  *
44 |  *  public ConfigType getLoadedConfigurationType(){
45 |  *    return loadedConfigurationType;
46 |  *  }
47 |  *
48 |  * }
49 |  * 
50 |  * 
51 | * 52 | * @author SERPRO 53 | * 54 | */ 55 | @Dependent 56 | public class ConfigurationEnumValueExtractor implements ConfigurationValueExtractor { 57 | 58 | @Override 59 | public Object getValue(String prefix, String key, Field field, Configuration configuration) throws DemoiselleConfigurationValueExtractorException { 60 | try{ 61 | String value = configuration.getString(prefix + key); 62 | 63 | if (value != null && !"".equals(value.trim())) { 64 | Object enums[] = field.getType().getEnumConstants(); 65 | 66 | for (int i = 0; i < enums.length; i++) { 67 | if (((Enum) enums[i]).name().equals(value)) { 68 | return enums[i]; 69 | } 70 | } 71 | } 72 | 73 | return null; 74 | } 75 | catch(Exception e){ 76 | throw new DemoiselleConfigurationValueExtractorException(e.getMessage(), e); 77 | } 78 | 79 | } 80 | 81 | @Override 82 | public boolean isSupported(Field field) { 83 | return field.getType().isEnum(); 84 | } 85 | 86 | } 87 | -------------------------------------------------------------------------------- /demoiselle-configuration/src/main/java/org/demoiselle/jee/configuration/extractor/impl/ConfigurationInternalDemoiselleValueExtractor.java: -------------------------------------------------------------------------------- 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 . 6 | */ 7 | package org.demoiselle.jee.configuration.extractor.impl; 8 | 9 | import static java.lang.annotation.ElementType.PACKAGE; 10 | import static java.lang.annotation.RetentionPolicy.RUNTIME; 11 | 12 | import java.lang.annotation.Retention; 13 | import java.lang.annotation.Target; 14 | 15 | @Retention(RUNTIME) 16 | @Target(PACKAGE) 17 | public @interface ConfigurationInternalDemoiselleValueExtractor { 18 | 19 | } 20 | -------------------------------------------------------------------------------- /demoiselle-configuration/src/main/java/org/demoiselle/jee/configuration/extractor/impl/ConfigurationStringValueExtractor.java: -------------------------------------------------------------------------------- 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 . 6 | */ 7 | package org.demoiselle.jee.configuration.extractor.impl; 8 | 9 | import java.lang.reflect.Field; 10 | 11 | import javax.enterprise.context.Dependent; 12 | 13 | import org.apache.commons.configuration2.Configuration; 14 | import org.demoiselle.jee.configuration.ConfigurationType; 15 | import org.demoiselle.jee.configuration.exception.DemoiselleConfigurationValueExtractorException; 16 | import org.demoiselle.jee.configuration.extractor.ConfigurationValueExtractor; 17 | 18 | /** 19 | * Adds the data extraction capability of a source {@link ConfigurationType} for 20 | * the type of {@link String}. 21 | * 22 | *

23 | * Sample: 24 | *

25 | *

26 | * For the extraction of a string type of a properties file the statement made 27 | * in the properties will have the following format: 28 | *

29 | * 30 | *
31 |  * demoiselle.ip=192.168.0.120
32 |  * 
33 | * 34 | * And the configuration class will be declared as follows: 35 | * 36 | *
37 |  * 
38 |  * @Configuration
39 |  * public class BookmarkConfig {
40 |  *
41 |  *     private String ip;
42 |  *
43 |  *     public String getIp() {
44 |  *         return ip;
45 |  *     }
46 |  *
47 |  * }
48 |  * 
49 |  * 
50 | * 51 | * @author SERPRO 52 | * 53 | */ 54 | @Dependent 55 | public class ConfigurationStringValueExtractor implements ConfigurationValueExtractor { 56 | 57 | @Override 58 | public Object getValue(String prefix, String key, Field field, Configuration configuration) throws DemoiselleConfigurationValueExtractorException { 59 | try{ 60 | return configuration.getString(prefix + key); 61 | } 62 | catch(Exception e){ 63 | throw new DemoiselleConfigurationValueExtractorException(e.getMessage(), e); 64 | } 65 | } 66 | 67 | @Override 68 | public boolean isSupported(Field field) { 69 | return field.getType() == String.class; 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /demoiselle-configuration/src/main/java/org/demoiselle/jee/configuration/extractor/impl/package-info.java: -------------------------------------------------------------------------------- 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 . 6 | */ 7 | 8 | /** 9 | * Extractors that implement the 10 | * {@link org.demoiselle.jee.configuration.extractor.ConfigurationValueExtractor} 11 | * interface. 12 | * 13 | * @author SERPRO 14 | * 15 | */ 16 | @ConfigurationInternalDemoiselleValueExtractor 17 | package org.demoiselle.jee.configuration.extractor.impl; -------------------------------------------------------------------------------- /demoiselle-configuration/src/main/java/org/demoiselle/jee/configuration/extractor/package-info.java: -------------------------------------------------------------------------------- 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 . 6 | */ 7 | 8 | /** 9 | * Provides the classes necessary to create the extractors. 10 | * 11 | */ 12 | package org.demoiselle.jee.configuration.extractor; -------------------------------------------------------------------------------- /demoiselle-configuration/src/main/java/org/demoiselle/jee/configuration/message/ConfigurationMessage.java: -------------------------------------------------------------------------------- 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 . 6 | */ 7 | package org.demoiselle.jee.configuration.message; 8 | 9 | import org.apache.deltaspike.core.api.message.MessageBundle; 10 | import org.apache.deltaspike.core.api.message.MessageTemplate; 11 | 12 | /** 13 | * 14 | * Messages used to inform user 15 | * 16 | * @author SERPRO 17 | */ 18 | @MessageBundle 19 | public interface ConfigurationMessage { 20 | 21 | @MessageTemplate("{load-configuration-class}") 22 | String loadConfigurationClass(String name); 23 | 24 | @MessageTemplate("{configuration-name-attribute-cant-be-empty}") 25 | String configurationNameAttributeCantBeEmpty(String annotationName); 26 | 27 | @MessageTemplate("{file-not-found}") 28 | String fileNotFound(String resource); 29 | 30 | @MessageTemplate("{configuration-dot-after-prefix}") 31 | String configurationDotAfterPrefix(String resource); 32 | 33 | @MessageTemplate("{configuration-key-not-found}") 34 | String configurationKeyNotFoud(String keyNotFound); 35 | 36 | @MessageTemplate("{configuration-field-loaded}") 37 | String configurationFieldLoaded(String key, Object value); 38 | 39 | @MessageTemplate("{configuration-not-conversion}") 40 | String configurationNotConversion(String field, String type); 41 | 42 | @MessageTemplate("{configuration-generic-extraction-error}") 43 | String configurationGenericExtractionError(String typeField, String canonicalName); 44 | 45 | @MessageTemplate("{configuration-extractor-not-found}") 46 | String configurationExtractorNotFound(String genericString, String valueExtractorClassName); 47 | 48 | @MessageTemplate("{ambiguous-strategy-resolution}") 49 | String ambigousStrategyResolution(String canonicalName, String string); 50 | 51 | @MessageTemplate("{configuration-error-get-value}") 52 | String configurationErrorGetValue(String fieldName, Object object); 53 | 54 | @MessageTemplate("{configuration-error-set-value}") 55 | String configurationErrorSetValue(Object value, Object field, Object object); 56 | 57 | @MessageTemplate("{fail-create-apache-configuration}") 58 | String failOnCreateApacheConfiguration(String message); 59 | 60 | @MessageTemplate("{configuration-field-suppress}") 61 | String configurationFieldSuppress(String key, String annotationName); 62 | 63 | @MessageTemplate("{cdi-not-already}") 64 | String cdiNotAlready(); 65 | 66 | } 67 | -------------------------------------------------------------------------------- /demoiselle-configuration/src/main/java/org/demoiselle/jee/configuration/message/package-info.java: -------------------------------------------------------------------------------- 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 . 6 | */ 7 | 8 | /** 9 | * It provides the classes necessary for displaying messages. 10 | * 11 | * @author SERPRO 12 | * 13 | */ 14 | package org.demoiselle.jee.configuration.message; -------------------------------------------------------------------------------- /demoiselle-configuration/src/main/java/org/demoiselle/jee/configuration/package-info.java: -------------------------------------------------------------------------------- 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 . 6 | */ 7 | 8 | /** 9 | * Provides Configuration feature 10 | * 11 | * @author SERPRO 12 | */ 13 | package org.demoiselle.jee.configuration; -------------------------------------------------------------------------------- /demoiselle-configuration/src/main/resources/META-INF/beans.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | -------------------------------------------------------------------------------- /demoiselle-configuration/src/main/resources/META-INF/services/javax.enterprise.inject.spi.Extension: -------------------------------------------------------------------------------- 1 | org.demoiselle.jee.configuration.ConfigurationBootstrap -------------------------------------------------------------------------------- /demoiselle-configuration/src/main/resources/org/demoiselle/jee/configuration/message/ConfigurationMessage.properties: -------------------------------------------------------------------------------- 1 | load-configuration-class=Carregando a classe de configura\u00E7\u00E3o %s 2 | configuration-name-attribute-cant-be-empty=A nota\u00E7\u00E3o @%s n\u00E3o pode estar em branco 3 | file-not-found=O arquivo %s n\u00E3o foi encontrado 4 | configuration-dot-after-prefix=N\u00E3o \u00E9 necess\u00E1rio adicionar o ponto ap\u00F3s o prefixo para uma classe de configura\u00E7\u00E3o. \u00C9 recomendado que sejam retirados, pois poder\u00E3o causar erros em vers\u00F5es futuras do Framework. 5 | configuration-key-not-found=-> %s\: [n\u00E3o definada na fonte de configura\u00E7\u00E3o do projeto, maiores informa\u00E7\u00F5es: https://demoiselle.gitbooks.io/documentacao-jee/content/configuration-general.html] 6 | configuration-field-loaded=-> %s = %s 7 | configuration-not-conversion=N\u00E3o \u00E9 poss\u00EDvel converter o valor %s para o tipo %s 8 | configuration-generic-extraction-error=Ocorreu um erro durante a extra\u00E7\u00E3o do tipo %s com o extrator %s 9 | configuration-extractor-not-found=N\u00E3o foi poss\u00EDvel encontrar a classe extratora para o atributo %s. Implemente a interface %s para criar sua classe extratora. 10 | ambiguous-strategy-resolution=Foi detectada ambiguidade da interface %s com as seguintes implementa\u00E7\u00F5es\: %s. Para resolver o conflito, defina explicitamente a implementa\u00E7\u00E3o no demoiselle.properties. 11 | configuration-error-get-value=N\u00E3o \u00E9 poss\u00EDvel obter o valor do campo %s da classe %s 12 | configuration-error-set-value=N\u00E3o \u00E9 poss\u00EDvel setar o valor %s no campo %s da classe %s 13 | fail-create-apache-configuration=Falha ao criar o objeto de Configura\u00E7\u00E3o do Apache, causa: %s 14 | configuration-field-suppress=-> %s = [valor suprimido pela anota\u00E7\u00E3o @%s] 15 | cdi-not-already=CDI n\u00E3o esta pronto para execu\u00E7\u00E3o -------------------------------------------------------------------------------- /demoiselle-configuration/src/test/java/org/demoiselle/jee/configuration/extractor/AbstractConfigurationTest.java: -------------------------------------------------------------------------------- 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 . 6 | */ 7 | package org.demoiselle.jee.configuration.extractor; 8 | 9 | import java.io.IOException; 10 | 11 | import org.demoiselle.jee.configuration.util.UtilTest; 12 | import org.junit.After; 13 | 14 | /** 15 | * 16 | * @author SERPRO 17 | * 18 | */ 19 | public abstract class AbstractConfigurationTest { 20 | 21 | protected String FILE_PREFIX = "app"; 22 | protected String PREFIX = ""; 23 | protected UtilTest utilTest = new UtilTest(); 24 | 25 | @After 26 | public void destroy() throws IOException { 27 | utilTest.deleteFilesAfterTest(); 28 | } 29 | 30 | } 31 | -------------------------------------------------------------------------------- /demoiselle-configuration/src/test/java/org/demoiselle/jee/configuration/extractor/ConfigurationStringValueExtractorAmbiguousTest.java: -------------------------------------------------------------------------------- 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 . 6 | */ 7 | package org.demoiselle.jee.configuration.extractor; 8 | 9 | import java.lang.reflect.Field; 10 | 11 | import javax.enterprise.context.Dependent; 12 | 13 | import org.apache.commons.configuration2.Configuration; 14 | import org.demoiselle.jee.configuration.exception.DemoiselleConfigurationValueExtractorException; 15 | import org.demoiselle.jee.configuration.extractor.impl.ConfigurationStringValueExtractor; 16 | 17 | /** 18 | * 19 | * @author SERPRO 20 | * 21 | */ 22 | @Dependent 23 | public class ConfigurationStringValueExtractorAmbiguousTest implements ConfigurationValueExtractor{ 24 | 25 | @Override 26 | public Object getValue(String prefix, String key, Field field, Configuration configuration) throws DemoiselleConfigurationValueExtractorException { 27 | return new ConfigurationStringValueExtractor().getValue(prefix, key, field, configuration); 28 | } 29 | 30 | @Override 31 | public boolean isSupported(Field field) { 32 | return field.getType() == String.class; 33 | } 34 | 35 | 36 | } 37 | -------------------------------------------------------------------------------- /demoiselle-configuration/src/test/java/org/demoiselle/jee/configuration/extractor/ConfigurationStringValueExtractorAmbiguousTest2.java: -------------------------------------------------------------------------------- 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 . 6 | */ 7 | package org.demoiselle.jee.configuration.extractor; 8 | 9 | import java.lang.reflect.Field; 10 | 11 | import javax.enterprise.context.Dependent; 12 | 13 | import org.apache.commons.configuration2.Configuration; 14 | import org.demoiselle.jee.configuration.exception.DemoiselleConfigurationValueExtractorException; 15 | import org.demoiselle.jee.configuration.extractor.impl.ConfigurationStringValueExtractor; 16 | 17 | /** 18 | * Duplicate class to test ambiguous extractors for String type 19 | * 20 | * @author SERPRO 21 | * 22 | */ 23 | @Dependent 24 | public class ConfigurationStringValueExtractorAmbiguousTest2 implements ConfigurationValueExtractor{ 25 | 26 | @Override 27 | public Object getValue(String prefix, String key, Field field, Configuration configuration) throws DemoiselleConfigurationValueExtractorException { 28 | return new ConfigurationStringValueExtractor().getValue(prefix, key, field, configuration); 29 | } 30 | 31 | @Override 32 | public boolean isSupported(Field field) { 33 | return field.getType() == String.class; 34 | } 35 | 36 | 37 | } 38 | -------------------------------------------------------------------------------- /demoiselle-configuration/src/test/java/org/demoiselle/jee/configuration/model/ConfigClassModel.java: -------------------------------------------------------------------------------- 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 . 6 | */ 7 | package org.demoiselle.jee.configuration.model; 8 | 9 | /** 10 | * 11 | * @author SERPRO 12 | * 13 | */ 14 | public class ConfigClassModel { 15 | 16 | } 17 | -------------------------------------------------------------------------------- /demoiselle-configuration/src/test/java/org/demoiselle/jee/configuration/model/ConfigEnum.java: -------------------------------------------------------------------------------- 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 . 6 | */ 7 | package org.demoiselle.jee.configuration.model; 8 | 9 | /** 10 | * 11 | * @author SERPRO 12 | * 13 | */ 14 | public enum ConfigEnum { 15 | 16 | ENUM1, ENUM2, ENUM3; 17 | 18 | } 19 | -------------------------------------------------------------------------------- /demoiselle-configuration/src/test/java/org/demoiselle/jee/configuration/model/ConfigIncompatibleTypeModel.java: -------------------------------------------------------------------------------- 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 . 6 | */ 7 | package org.demoiselle.jee.configuration.model; 8 | 9 | import org.demoiselle.jee.configuration.annotation.Configuration; 10 | 11 | /** 12 | * 13 | * @author SERPRO 14 | * 15 | */ 16 | @Configuration() 17 | public class ConfigIncompatibleTypeModel { 18 | 19 | private Boolean configBooleanIncompatible; 20 | 21 | public Boolean getConfigBooleanIncompatible() { 22 | return configBooleanIncompatible; 23 | } 24 | 25 | } 26 | -------------------------------------------------------------------------------- /demoiselle-configuration/src/test/java/org/demoiselle/jee/configuration/model/ConfigMapModel.java: -------------------------------------------------------------------------------- 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 . 6 | */ 7 | package org.demoiselle.jee.configuration.model; 8 | 9 | import java.util.Map; 10 | 11 | import org.demoiselle.jee.configuration.ConfigurationType; 12 | import org.demoiselle.jee.configuration.annotation.Configuration; 13 | 14 | /** 15 | * 16 | * @author SERPRO 17 | * 18 | */ 19 | @Configuration(resource = "app", type = ConfigurationType.PROPERTIES, prefix = "demoiselle.configuration") 20 | public class ConfigMapModel { 21 | 22 | private Map configMap; 23 | 24 | public Map getConfigMap() { 25 | return configMap; 26 | } 27 | 28 | } -------------------------------------------------------------------------------- /demoiselle-configuration/src/test/java/org/demoiselle/jee/configuration/model/ConfigWithNameAnnotationEmptyModel.java: -------------------------------------------------------------------------------- 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 . 6 | */ 7 | package org.demoiselle.jee.configuration.model; 8 | 9 | import org.demoiselle.jee.configuration.annotation.ConfigurationName; 10 | 11 | /** 12 | * 13 | * @author SERPRO 14 | * 15 | */ 16 | public class ConfigWithNameAnnotationEmptyModel { 17 | 18 | @ConfigurationName 19 | public String configString; 20 | 21 | public String getConfigString() { 22 | return configString; 23 | } 24 | 25 | } 26 | -------------------------------------------------------------------------------- /demoiselle-configuration/src/test/java/org/demoiselle/jee/configuration/model/ConfigWithValidationModel.java: -------------------------------------------------------------------------------- 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 . 6 | */ 7 | package org.demoiselle.jee.configuration.model; 8 | 9 | import javax.validation.constraints.NotNull; 10 | import javax.validation.constraints.Null; 11 | 12 | import org.demoiselle.jee.configuration.annotation.Configuration; 13 | 14 | /** 15 | * 16 | * @author SERPRO 17 | * 18 | */ 19 | @Configuration() 20 | public class ConfigWithValidationModel { 21 | 22 | @NotNull 23 | private String configString; 24 | 25 | @Null 26 | private Integer configInteger; 27 | 28 | public String getConfigString() { 29 | return configString; 30 | } 31 | 32 | public Integer getConfigInteger() { 33 | return configInteger; 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /demoiselle-configuration/src/test/java/org/demoiselle/jee/configuration/model/ConfigWithoutExtractorModel.java: -------------------------------------------------------------------------------- 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 . 6 | */ 7 | package org.demoiselle.jee.configuration.model; 8 | 9 | import java.util.Set; 10 | 11 | import org.demoiselle.jee.configuration.annotation.Configuration; 12 | 13 | /** 14 | * 15 | * @author SERPRO 16 | * 17 | */ 18 | @Configuration(resource = "app-test", prefix = "") 19 | public class ConfigWithoutExtractorModel { 20 | 21 | private Set field; 22 | 23 | public Set getField() { 24 | return field; 25 | } 26 | 27 | } 28 | -------------------------------------------------------------------------------- /demoiselle-configuration/src/test/resources/META-INF/apache-deltaspike.properties: -------------------------------------------------------------------------------- 1 | deltaspike.testcontrol.mock-support.allow_mocked_beans=true 2 | deltaspike.testcontrol.mock-support.allow_mocked_producers=true -------------------------------------------------------------------------------- /demoiselle-configuration/src/test/resources/META-INF/beans.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | -------------------------------------------------------------------------------- /demoiselle-configuration/src/test/resources/app-name.properties: -------------------------------------------------------------------------------- 1 | config-string = String do properties 2 | config-integer = 154897 3 | config-short = 123 4 | config-long = 10000000000 5 | config-float = 1e8 6 | config-double = 10e43 7 | 8 | config-class-untyped = org.demoiselle.jee7.configuration.Tipo 9 | config-class-typed = org.demoiselle.jee7.configuration.Tipo 10 | 11 | config-byte = 1 12 | 13 | config-map.ip = 10.200.23.98 14 | config-map.url = teste.com 15 | config-map.protocol = https 16 | config-map.port = 439 17 | 18 | config-enum = XML 19 | 20 | config-array-string = a 21 | config-array-string = b 22 | config-array-string = c 23 | config-array-string = d 24 | 25 | config-array-integer = 1 26 | config-array-integer = 2 27 | config-array-integer = 3 28 | config-array-integer = 4 -------------------------------------------------------------------------------- /demoiselle-configuration/src/test/resources/app-name.system: -------------------------------------------------------------------------------- 1 | -Dconfig-string="Configuracao System Name" -Dconfig-integer=15 -Dconfig-short=9 -Dconfig-long=1857123123 -Dconfig-float=1e21 -Dconfig-double=1087e41 -Dconfig-class-untyped=org.demoiselle.jee7.configuration.Tipo -Dconfig-class-typed=org.demoiselle.jee7.configuration.Tipo -Dconfig-byte=15 -Dconfig-map.ip=10.200.24.44 -Dconfig-map.url=http://localhost -Dconfig-enum=SYSTEM -Dconfig-array-string=a1 -Dconfig-array-string=a2 -Dconfig-array-string=a3 -Dconfig-array-integer=1 -Dconfig-array-integer=2 -Dconfig-array-integer=3 -------------------------------------------------------------------------------- /demoiselle-configuration/src/test/resources/app-name.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | String do xml 5 | 154897 6 | 123 7 | 10000000000 8 | 1e8 9 | 10e43 10 | org.demoiselle.jee7.configuration.Tipo 11 | org.demoiselle.jee7.configuration.Tipo 12 | 1 13 | XML 14 | 15 | 16 | 10.200.23.98 17 | teste.com 18 | https 19 | 439 20 | 21 | 22 | a 23 | b 24 | c 25 | d 26 | 27 | 1 28 | 2 29 | 3 30 | 4 31 | -------------------------------------------------------------------------------- /demoiselle-configuration/src/test/resources/app.properties: -------------------------------------------------------------------------------- 1 | configString = String do properties 2 | configInteger = 154897 3 | configShort = 123 4 | configLong = 10000000000 5 | configFloat = 1e8 6 | configDouble = 10e43 7 | 8 | configClassUntyped = org.demoiselle.jee.configuration.model.ConfigClassModel 9 | configClassTyped = org.demoiselle.jee.configuration.model.ConfigClassModel 10 | 11 | configByte = 1 12 | 13 | configMap.ip = 10.200.23.98 14 | configMap.url = teste.com 15 | configMap.protocol = https 16 | configMap.port = 439 17 | 18 | configEnum = ENUM1 19 | 20 | configArrayString = a 21 | configArrayString = b 22 | configArrayString = c 23 | configArrayString = d 24 | 25 | configArrayInteger = 1 26 | configArrayInteger = 2 27 | configArrayInteger = 3 28 | configArrayInteger = 4 -------------------------------------------------------------------------------- /demoiselle-configuration/src/test/resources/app.system: -------------------------------------------------------------------------------- 1 | -DconfigString="Configuracao System" -DconfigInteger=15 -DconfigShort=9 -DconfigLong=1857123123 -DconfigFloat=1e21 -DconfigDouble=1087e41 -DconfigClassUntyped=org.demoiselle.jee7.configuration.Tipo -DconfigClassTyped=org.demoiselle.jee7.configuration.Tipo -DconfigByte=15 -DconfigMap.ip=10.200.24.44 -DconfigMap.url=http://localhost -DconfigEnum=SYSTEM -DconfigArrayString=a1 -DconfigArrayString=a2 -DconfigArrayString=a3 -DconfigArrayInteger=1 -DconfigArrayInteger=2 -DconfigArrayInteger=3 -------------------------------------------------------------------------------- /demoiselle-configuration/src/test/resources/app.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | String do XML 5 | 154897 6 | 123 7 | 10000000000 8 | 1e8 9 | 10e43 10 | org.demoiselle.jee7.configuration.Tipo 11 | org.demoiselle.jee7.configuration.Tipo 12 | 1 13 | XML 14 | 15 | 16 | 10.200.23.98 17 | teste.com 18 | https 19 | 439 20 | 21 | 22 | a 23 | b 24 | c 25 | d 26 | 27 | 1 28 | 2 29 | 3 30 | 4 31 | -------------------------------------------------------------------------------- /demoiselle-core/.gitignore: -------------------------------------------------------------------------------- 1 | /target/ 2 | /bin/ 3 | /.settings/ 4 | /.classpath 5 | /.project 6 | /.DS_Store 7 | -------------------------------------------------------------------------------- /demoiselle-core/nb-configuration.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 9 | 10 | 16 | true 17 | true 18 | 19 | 20 | -------------------------------------------------------------------------------- /demoiselle-core/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4.0.0 4 | 5 | demoiselle-core 6 | jar 7 | 8 | Demoiselle JEE Core 9 | 10 | Contém funcionalidades comuns a todos os módulos framework. 11 | 12 | http://demoiselle.io 13 | 14 | 15 | dd/MM/yyyy HH:mm 16 | ${maven.build.timestamp} 17 | 18 | 19 | 20 | org.demoiselle.jee 21 | demoiselle-parent 22 | 3.0.6-SNAPSHOT 23 | ../demoiselle-parent 24 | 25 | 26 | 27 | 28 | javax 29 | javaee-web-api 30 | 31 | 32 | 33 | javax.enterprise 34 | cdi-api 35 | 36 | 37 | 38 | 39 | org.apache.deltaspike.core 40 | deltaspike-core-api 41 | compile 42 | 43 | 44 | org.apache.deltaspike.core 45 | deltaspike-core-impl 46 | runtime 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | src/main/resources 55 | true 56 | 57 | 58 | 59 | 60 | -------------------------------------------------------------------------------- /demoiselle-core/src/main/java/org/demoiselle/jee/core/api/crud/Crud.java: -------------------------------------------------------------------------------- 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 . 6 | */ 7 | package org.demoiselle.jee.core.api.crud; 8 | 9 | import javax.validation.Valid; 10 | 11 | /** 12 | * 13 | * @author SERPRO 14 | */ 15 | public interface Crud { 16 | 17 | public T persist(@Valid T entity); 18 | 19 | public T mergeFull(@Valid T entity); 20 | 21 | public T mergeHalf(I id, T entity); 22 | 23 | public void remove(I id); 24 | 25 | public Result find(); 26 | 27 | public T find(I id); 28 | 29 | } 30 | -------------------------------------------------------------------------------- /demoiselle-core/src/main/java/org/demoiselle/jee/core/api/crud/Result.java: -------------------------------------------------------------------------------- 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 . 6 | */ 7 | package org.demoiselle.jee.core.api.crud; 8 | 9 | import java.util.List; 10 | 11 | /** 12 | * 13 | * @author SERPRO 14 | * 15 | */ 16 | public interface Result { 17 | 18 | public List getContent(); 19 | public void setContent(List content); 20 | 21 | } 22 | -------------------------------------------------------------------------------- /demoiselle-core/src/main/java/org/demoiselle/jee/core/api/crud/package-info.java: -------------------------------------------------------------------------------- 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 . 6 | */ 7 | /** 8 | * This package has the API for facilitators for the CRUD 9 | * 10 | * @author SERPRO 11 | */ 12 | package org.demoiselle.jee.core.api.crud; 13 | -------------------------------------------------------------------------------- /demoiselle-core/src/main/java/org/demoiselle/jee/core/api/script/DynamicManagerInterface.java: -------------------------------------------------------------------------------- 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 . 6 | */ 7 | package org.demoiselle.jee.core.api.script; 8 | 9 | import java.util.List; 10 | 11 | import javax.script.Bindings; 12 | import javax.script.ScriptEngine; 13 | import javax.script.ScriptException; 14 | 15 | /** 16 | * 17 | * @author SERPRO 18 | */ 19 | public interface DynamicManagerInterface { 20 | 21 | public ScriptEngine loadEngine(String engineName); 22 | 23 | public List listEngines(); 24 | 25 | public void unloadEngine(String engineName); 26 | 27 | public void clearCache(String engineName); 28 | 29 | public Object eval(String engineName, String scriptName, Bindings context) throws ScriptException; 30 | 31 | public Boolean loadScript(String engineName, String scriptName,String source ) throws ScriptException; 32 | 33 | public void removeScript(String engineName, String scriptId); 34 | 35 | public Object getScript(String engineName, String scriptId); 36 | 37 | public int getCacheSize(String engineName); 38 | 39 | } -------------------------------------------------------------------------------- /demoiselle-core/src/main/java/org/demoiselle/jee/core/api/script/package-info.java: -------------------------------------------------------------------------------- 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 . 6 | */ 7 | /** 8 | * This package has the API for facilitators for the Scripts 9 | * 10 | * @author SERPRO 11 | */ 12 | package org.demoiselle.jee.core.api.script; 13 | -------------------------------------------------------------------------------- /demoiselle-core/src/main/java/org/demoiselle/jee/core/api/security/DemoiselleUser.java: -------------------------------------------------------------------------------- 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 . 6 | */ 7 | package org.demoiselle.jee.core.api.security; 8 | 9 | import java.security.Principal; 10 | import java.util.List; 11 | import java.util.Map; 12 | 13 | /** 14 | * DemoiselleUser is the object where logged user is stored 15 | * @author SERPRO 16 | */ 17 | public interface DemoiselleUser extends Principal { 18 | 19 | /** 20 | * @return Identity user 21 | */ 22 | public String getIdentity(); 23 | 24 | /** 25 | * @param id Identity user 26 | */ 27 | public void setIdentity(String id); 28 | 29 | /** 30 | * @param name Principal name 31 | */ 32 | public void setName(String name); 33 | 34 | /** 35 | * @param role Role name 36 | */ 37 | public void addRole(String role); 38 | 39 | /** 40 | * @param role Role name 41 | */ 42 | public void removeRole(String role); 43 | 44 | /** 45 | * @return List of roles 46 | */ 47 | public List getRoles(); 48 | 49 | /** 50 | * 51 | * @return List of permissions 52 | */ 53 | public Map> getPermissions(); 54 | 55 | /** 56 | * @param resource Resource name 57 | * @return List of permissions 58 | */ 59 | public List getPermissions(String resource); 60 | 61 | /** 62 | * 63 | * @param resource Resource name 64 | * @param operation Operation name 65 | */ 66 | public void addPermission(String resource, String operation); 67 | 68 | /** 69 | * 70 | * @param resource Resource name 71 | * @param operation Operation name 72 | */ 73 | public void removePermission(String resource, String operation); 74 | 75 | /** 76 | * 77 | * @return Params 78 | */ 79 | public Map getParams(); 80 | 81 | /** 82 | * 83 | * @param key Key parameter 84 | * @return List of parameter 85 | */ 86 | public String getParams(String key); 87 | 88 | /** 89 | * 90 | * @param key Key parameter 91 | * @param value Value parameter 92 | */ 93 | public void addParam(String key, String value); 94 | 95 | /** 96 | * 97 | * @param key Key parameter 98 | */ 99 | public void removeParam(String key); 100 | 101 | /** 102 | * 103 | * @return Principal clone 104 | */ 105 | public DemoiselleUser clone(); 106 | } 107 | -------------------------------------------------------------------------------- /demoiselle-core/src/main/java/org/demoiselle/jee/core/api/security/SecurityContext.java: -------------------------------------------------------------------------------- 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 . 6 | */ 7 | package org.demoiselle.jee.core.api.security; 8 | 9 | 10 | /** 11 | * Security context is the main object of demoiselle security, in it there are 12 | * interactions that guarantee the use of the module, 13 | * the JWT and Token submodules are connected to it. 14 | * @author SERPRO 15 | */ 16 | public interface SecurityContext { 17 | 18 | /** 19 | * 20 | * @return If the Principal is logged 21 | */ 22 | boolean isLoggedIn(); 23 | 24 | /** 25 | * 26 | * @param resource Resource name 27 | * @param operation Operation name 28 | * @return If the Principal has permission 29 | */ 30 | boolean hasPermission(String resource, String operation); 31 | 32 | /** 33 | * 34 | * @param role Role name 35 | * @return If the Principal has permission 36 | */ 37 | boolean hasRole(String role); 38 | 39 | /** 40 | * 41 | * @return Principal 42 | */ 43 | DemoiselleUser getUser(); 44 | 45 | /** 46 | * Get User 47 | * @param issuer Issuer 48 | * @param audience Audience 49 | * @return Principal Principal 50 | */ 51 | DemoiselleUser getUser(String issuer, String audience); 52 | 53 | /** 54 | * 55 | * @param loggedUser Principal 56 | */ 57 | void setUser(DemoiselleUser loggedUser); 58 | 59 | /** 60 | * Set User 61 | * @param loggedUser Principal 62 | * @param issuer Issuer 63 | * @param audience Audience 64 | */ 65 | void setUser(DemoiselleUser loggedUser, String issuer, String audience); 66 | 67 | /** 68 | * 69 | * @param loggedUser Principal 70 | */ 71 | void removeUser(DemoiselleUser loggedUser); 72 | 73 | } 74 | -------------------------------------------------------------------------------- /demoiselle-core/src/main/java/org/demoiselle/jee/core/api/security/Token.java: -------------------------------------------------------------------------------- 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 . 6 | */ 7 | package org.demoiselle.jee.core.api.security; 8 | 9 | /** 10 | * Object loaded with each request and saves the token that comes in the header 11 | * 12 | * @author SERPRO 13 | */ 14 | public interface Token { 15 | 16 | /** 17 | * @return Key name 18 | */ 19 | public String getKey(); 20 | 21 | /** 22 | * 23 | * @param key Key name 24 | */ 25 | public void setKey(String key); 26 | 27 | /** 28 | * @return Type name 29 | */ 30 | public TokenType getType(); 31 | 32 | /** 33 | * 34 | * @param type Type name 35 | */ 36 | public void setType(TokenType type); 37 | } 38 | -------------------------------------------------------------------------------- /demoiselle-core/src/main/java/org/demoiselle/jee/core/api/security/TokenManager.java: -------------------------------------------------------------------------------- 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 . 6 | */ 7 | package org.demoiselle.jee.core.api.security; 8 | 9 | /** 10 | * 11 | * Token Management, where we store, create and erase the tokens generated by 12 | * the app. We have three suggestions for implementation, basic, JWT and memory, 13 | * but you can implement more is useful for your project or extend existing 14 | * ones. 15 | * 16 | * @author SERPRO 17 | */ 18 | public interface TokenManager { 19 | 20 | /** 21 | * Search the logged user being kept place through token use that is in 22 | * session request 23 | * 24 | * @return See {@link DemoiselleUser} 25 | */ 26 | public DemoiselleUser getUser(); 27 | 28 | /** 29 | * Search the logged user being kept place through token use that is in 30 | * session request 31 | * 32 | * @param issuer 33 | * @param audience 34 | * @return See {@link DemoiselleUser} 35 | */ 36 | public DemoiselleUser getUser(String issuer, String audience); 37 | 38 | /** 39 | * 40 | * Stores the user logged in to be used in the next requests at that time it 41 | * generates a token, depending on the approach, and placed in the token 42 | * object in the request scoped 43 | * 44 | * @param user See {@link DemoiselleUser} 45 | */ 46 | public void setUser(DemoiselleUser user); 47 | 48 | /** 49 | * 50 | * Stores the user logged in to be used in the next requests at that time it 51 | * generates a token, depending on the approach, and placed in the token 52 | * object in the request scoped Allows a token generation for different 53 | * systems, an option for sso 54 | * 55 | * @param user See {@link DemoiselleUser} 56 | * @param issuer 57 | * @param audience 58 | */ 59 | public void setUser(DemoiselleUser user, String issuer, String audience); 60 | 61 | /** 62 | * 63 | * Remove the user logged 64 | * 65 | * @param user See {@link DemoiselleUser} 66 | */ 67 | public void removeUser(DemoiselleUser user); 68 | 69 | /** 70 | * Validates that the user is stored correctly, depending on the chosen 71 | * strategy. 72 | * 73 | * @return Boolean 74 | */ 75 | public boolean validate(); 76 | 77 | /** 78 | * Validates that the user is stored correctly, depending on the chosen 79 | * strategy. 80 | * 81 | * @param issuer 82 | * @param audience 83 | * @return Boolean 84 | */ 85 | public boolean validate(String issuer, String audience); 86 | 87 | } 88 | -------------------------------------------------------------------------------- /demoiselle-core/src/main/java/org/demoiselle/jee/core/api/security/TokenType.java: -------------------------------------------------------------------------------- 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 . 6 | */ 7 | package org.demoiselle.jee.core.api.security; 8 | 9 | /** 10 | * Types of token 11 | * 12 | * @author SERPRO 13 | */ 14 | public enum TokenType { 15 | JWT, 16 | BASIC, 17 | BEARER, 18 | MAC, 19 | TOKEN 20 | } 21 | -------------------------------------------------------------------------------- /demoiselle-core/src/main/java/org/demoiselle/jee/core/api/security/package-info.java: -------------------------------------------------------------------------------- 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 . 6 | */ 7 | /** 8 | * This package has the API for facilitators for the Security 9 | * 10 | * @author SERPRO 11 | */ 12 | package org.demoiselle.jee.core.api.security; 13 | -------------------------------------------------------------------------------- /demoiselle-core/src/main/java/org/demoiselle/jee/core/exception/DemoiselleException.java: -------------------------------------------------------------------------------- 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 . 6 | */ 7 | package org.demoiselle.jee.core.exception; 8 | 9 | /** 10 | * Exception class intended to be used by framework configuration and to be derived by other framework exceptions. 11 | * 12 | * @author SERPRO 13 | */ 14 | public class DemoiselleException extends RuntimeException { 15 | 16 | private static final long serialVersionUID = 1L; 17 | 18 | /** 19 | * Constructor . 20 | * 21 | */ 22 | public DemoiselleException() { 23 | 24 | } 25 | 26 | /** 27 | * Constructor with message. 28 | * 29 | * @param message 30 | * exception message 31 | */ 32 | public DemoiselleException(String message) { 33 | super(message); 34 | } 35 | 36 | /** 37 | * Constructor with cause. 38 | * 39 | * @param cause 40 | * exception cause 41 | */ 42 | public DemoiselleException(Throwable cause) { 43 | super(cause); 44 | } 45 | 46 | /** 47 | * Constructor with message and cause. 48 | * 49 | * @param message 50 | * exception message 51 | * @param cause 52 | * exception cause 53 | */ 54 | public DemoiselleException(String message, Throwable cause) { 55 | super(message, cause); 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /demoiselle-core/src/main/java/org/demoiselle/jee/core/exception/DemoiselleLifecycleException.java: -------------------------------------------------------------------------------- 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 . 6 | */ 7 | package org.demoiselle.jee.core.exception; 8 | 9 | /** 10 | * 11 | * Represents a throw Exceptions from Lifecycle feature 12 | * 13 | * @author SERPRO 14 | * 15 | */ 16 | public class DemoiselleLifecycleException extends DemoiselleException { 17 | 18 | private static final long serialVersionUID = -3751898389838825583L; 19 | 20 | public DemoiselleLifecycleException(Exception e) { 21 | super(e); 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /demoiselle-core/src/main/java/org/demoiselle/jee/core/exception/ExceptionTreatment.java: -------------------------------------------------------------------------------- 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 . 6 | */ 7 | package org.demoiselle.jee.core.exception; 8 | 9 | import javax.servlet.http.HttpServletRequest; 10 | import javax.ws.rs.core.Response; 11 | 12 | /** 13 | * This interface defines a method to treat @Exception classes in Framework. 14 | * 15 | * @author SERPRO 16 | * 17 | */ 18 | public interface ExceptionTreatment { 19 | 20 | public Response getFormatedError(Throwable exception, HttpServletRequest request); 21 | 22 | } 23 | -------------------------------------------------------------------------------- /demoiselle-core/src/main/java/org/demoiselle/jee/core/exception/package-info.java: -------------------------------------------------------------------------------- 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 . 6 | */ 7 | /** 8 | * This package has the facilitators for the Exception 9 | * 10 | * @author SERPRO 11 | */ 12 | package org.demoiselle.jee.core.exception; 13 | -------------------------------------------------------------------------------- /demoiselle-core/src/main/java/org/demoiselle/jee/core/lifecycle/AnnotatedMethodProcessor.java: -------------------------------------------------------------------------------- 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 . 6 | */ 7 | package org.demoiselle.jee.core.lifecycle; 8 | 9 | import javax.enterprise.inject.spi.AnnotatedMethod; 10 | 11 | import org.demoiselle.jee.core.lifecycle.annotation.DemoiselleLifecyclePriority; 12 | 13 | /** 14 | * Represents an annotated method to be processed 15 | * 16 | * @author SERPRO 17 | */ 18 | public class AnnotatedMethodProcessor { 19 | 20 | private AnnotatedMethod annotatedMethod; 21 | 22 | public AnnotatedMethodProcessor(final AnnotatedMethod annotatedMethod) { 23 | this.annotatedMethod = annotatedMethod; 24 | } 25 | 26 | protected AnnotatedMethod getAnnotatedMethod(){ 27 | return this.annotatedMethod; 28 | } 29 | 30 | /** 31 | * 32 | * @param annotatedMethod Represents the method 33 | * @return Get the current Priority annotated with {@link DemoiselleLifecyclePriority} 34 | */ 35 | protected Integer getPriority(AnnotatedMethod annotatedMethod) { 36 | Integer priority = DemoiselleLifecyclePriority.LEVEL_4; 37 | 38 | DemoiselleLifecyclePriority annotation = annotatedMethod.getAnnotation(DemoiselleLifecyclePriority.class); 39 | if (annotation != null) { 40 | priority = annotation.value(); 41 | } 42 | 43 | return priority; 44 | } 45 | 46 | } 47 | -------------------------------------------------------------------------------- /demoiselle-core/src/main/java/org/demoiselle/jee/core/lifecycle/annotation/DemoiselleLifecyclePriority.java: -------------------------------------------------------------------------------- 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 . 6 | */ 7 | package org.demoiselle.jee.core.lifecycle.annotation; 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.Retention; 14 | import java.lang.annotation.Target; 15 | 16 | /** 17 | * Used to prioritize methods annotated with {@link Startup} or {@link Shutdown} 18 | * 19 | * @author SERPRO 20 | */ 21 | @Target({ TYPE, METHOD }) 22 | @Retention(RUNTIME) 23 | public @interface DemoiselleLifecyclePriority { 24 | 25 | /** 26 | * The higher priority 27 | */ 28 | final int LEVEL_1 = 100; 29 | 30 | /** 31 | * Second higher priority 32 | */ 33 | final int LEVEL_2 = LEVEL_1 + 100; 34 | 35 | /** 36 | * Third higher priority 37 | */ 38 | final int LEVEL_3 = LEVEL_2 + 100; 39 | 40 | /** 41 | * The lower priority 42 | */ 43 | final int LEVEL_4 = LEVEL_3 + 100; 44 | 45 | /** 46 | *

47 | * An integer value defines the priority order. The lower the value, the greater priority. 48 | *

49 | * 50 | * @return Priority value, lower values have higher priority. 51 | */ 52 | int value(); 53 | } 54 | -------------------------------------------------------------------------------- /demoiselle-core/src/main/java/org/demoiselle/jee/core/lifecycle/annotation/Shutdown.java: -------------------------------------------------------------------------------- 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 . 6 | */ 7 | package org.demoiselle.jee.core.lifecycle.annotation; 8 | 9 | import static java.lang.annotation.ElementType.METHOD; 10 | import static java.lang.annotation.RetentionPolicy.RUNTIME; 11 | 12 | import java.lang.annotation.Retention; 13 | import java.lang.annotation.Target; 14 | 15 | /** 16 | * Identifies a method eligible to be executed automatically during application finalization. 17 | *

18 | * Take a look at the following usage sample: 19 | *

20 | * 21 | *
22 |  * public class MyClass {
23 |  * 
24 |  *  @Shutdown
25 |  *  @Priority(Priority.MIN_PRIORITY)
26 |  *  public void finalize() {
27 |  *    ...
28 |  *  }
29 |  * }
30 |  * 
31 | * 32 | * See {@link DemoiselleLifecyclePriority} 33 | * 34 | * @author SERPRO 35 | */ 36 | @Target(METHOD) 37 | @Retention(RUNTIME) 38 | public @interface Shutdown { 39 | 40 | } 41 | -------------------------------------------------------------------------------- /demoiselle-core/src/main/java/org/demoiselle/jee/core/lifecycle/annotation/Startup.java: -------------------------------------------------------------------------------- 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 . 6 | */ 7 | package org.demoiselle.jee.core.lifecycle.annotation; 8 | 9 | import static java.lang.annotation.ElementType.METHOD; 10 | import static java.lang.annotation.RetentionPolicy.RUNTIME; 11 | 12 | import java.lang.annotation.Retention; 13 | import java.lang.annotation.Target; 14 | 15 | /** 16 | * Identifies a method eligible to be executed automatically during application initialization. 17 | *

18 | * Take a look at the following usage sample: 19 | *

20 | * 21 | *
22 |  * public class MyClass {
23 |  * 
24 |  *  @Startup
25 |  *  @Priority(Priority.MAX_PRIORITY)
26 |  *  public void init() {
27 |  *    ...
28 |  *  }
29 |  * }
30 |  * 
31 | * 32 | * See {@link DemoiselleLifecyclePriority} 33 | * 34 | * @author SERPRO 35 | */ 36 | @Target(METHOD) 37 | @Retention(RUNTIME) 38 | public @interface Startup { 39 | 40 | } 41 | -------------------------------------------------------------------------------- /demoiselle-core/src/main/java/org/demoiselle/jee/core/lifecycle/package-info.java: -------------------------------------------------------------------------------- 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 . 6 | */ 7 | /** 8 | * Provide Lifecycle feature 9 | * 10 | * @author SERPRO 11 | */ 12 | package org.demoiselle.jee.core.lifecycle; -------------------------------------------------------------------------------- /demoiselle-core/src/main/resources/META-INF/beans.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | -------------------------------------------------------------------------------- /demoiselle-core/src/main/resources/META-INF/services/javax.enterprise.inject.spi.Extension: -------------------------------------------------------------------------------- 1 | org.demoiselle.jee.core.lifecycle.LifecycleBootstrap -------------------------------------------------------------------------------- /demoiselle-core/src/main/resources/demoiselle.properties: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/demoiselle/framework/096baf60f3c2cac7b6abe56d574af1226763210f/demoiselle-core/src/main/resources/demoiselle.properties -------------------------------------------------------------------------------- /demoiselle-core/src/main/resources/org/demoiselle/jee/core/message/DemoiselleMessage.properties: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/demoiselle/framework/096baf60f3c2cac7b6abe56d574af1226763210f/demoiselle-core/src/main/resources/org/demoiselle/jee/core/message/DemoiselleMessage.properties -------------------------------------------------------------------------------- /demoiselle-core/src/test/java/org/demoiselle/jee/core/CoreTest.java: -------------------------------------------------------------------------------- 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 . 6 | */ 7 | package org.demoiselle.jee.core; 8 | 9 | /** 10 | * 11 | * @author SERPRO 12 | */ 13 | public class CoreTest { 14 | 15 | } 16 | -------------------------------------------------------------------------------- /demoiselle-core/src/test/java/org/demoiselle/jee/core/lifecycle/LifecyclePriorityTest.java: -------------------------------------------------------------------------------- 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 . 6 | */ 7 | package org.demoiselle.jee.core.lifecycle; 8 | 9 | import static org.junit.Assert.assertEquals; 10 | 11 | import java.util.ArrayList; 12 | import java.util.List; 13 | 14 | import javax.enterprise.context.ApplicationScoped; 15 | import javax.enterprise.context.Destroyed; 16 | import javax.enterprise.context.Initialized; 17 | import javax.enterprise.event.Event; 18 | import javax.inject.Inject; 19 | 20 | import org.apache.deltaspike.testcontrol.api.junit.CdiTestRunner; 21 | import org.demoiselle.jee.core.lifecycle.model.PriorityLifecycleModelTest; 22 | import org.junit.Before; 23 | import org.junit.Test; 24 | import org.junit.runner.RunWith; 25 | 26 | @RunWith(CdiTestRunner.class) 27 | public class LifecyclePriorityTest { 28 | 29 | @Inject 30 | private PriorityLifecycleModelTest model; 31 | 32 | @Inject 33 | @Destroyed(ApplicationScoped.class) 34 | private Event eventDestroyed; 35 | 36 | @Inject 37 | @Initialized(ApplicationScoped.class) 38 | private Event eventInitialized; 39 | 40 | @Before 41 | public void setUp() { 42 | this.model.getNumbers().clear(); 43 | } 44 | 45 | @Test 46 | public void methodWithStartupAnnotationsShouldBeExecutated() { 47 | 48 | this.eventInitialized.fire(new Object()); 49 | 50 | List numbers = new ArrayList<>(); 51 | numbers.add(1); 52 | numbers.add(2); 53 | numbers.add(3); 54 | numbers.add(4); 55 | 56 | assertEquals(numbers, this.model.getNumbers()); 57 | } 58 | 59 | @Test 60 | public void methodWithShutdownAnnotationShouldBeExecutated() { 61 | 62 | this.eventDestroyed.fire(new Object()); 63 | 64 | List numbers = new ArrayList<>(); 65 | numbers.add(4); 66 | numbers.add(5); 67 | numbers.add(6); 68 | 69 | assertEquals(numbers, this.model.getNumbers()); 70 | } 71 | 72 | } 73 | -------------------------------------------------------------------------------- /demoiselle-core/src/test/java/org/demoiselle/jee/core/lifecycle/model/PriorityLifecycleModelTest.java: -------------------------------------------------------------------------------- 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 . 6 | */ 7 | package org.demoiselle.jee.core.lifecycle.model; 8 | 9 | import java.util.ArrayList; 10 | import java.util.List; 11 | 12 | import javax.enterprise.context.ApplicationScoped; 13 | 14 | import org.demoiselle.jee.core.lifecycle.annotation.DemoiselleLifecyclePriority; 15 | import org.demoiselle.jee.core.lifecycle.annotation.Shutdown; 16 | import org.demoiselle.jee.core.lifecycle.annotation.Startup; 17 | 18 | @ApplicationScoped 19 | public class PriorityLifecycleModelTest { 20 | 21 | private List numbers = new ArrayList<>(); 22 | 23 | @Startup 24 | @DemoiselleLifecyclePriority(DemoiselleLifecyclePriority.LEVEL_1) 25 | public void startupMethod1() { 26 | this.numbers.add(1); 27 | } 28 | 29 | @Startup 30 | @DemoiselleLifecyclePriority(DemoiselleLifecyclePriority.LEVEL_2) 31 | public void startupMethod2() { 32 | this.numbers.add(2); 33 | } 34 | 35 | @Startup 36 | @DemoiselleLifecyclePriority(DemoiselleLifecyclePriority.LEVEL_3) 37 | public void startupMethod3() { 38 | this.numbers.add(3); 39 | } 40 | 41 | @Startup 42 | public void startupMethod4() { 43 | this.numbers.add(4); 44 | } 45 | 46 | @Shutdown 47 | @DemoiselleLifecyclePriority(DemoiselleLifecyclePriority.LEVEL_1) 48 | public void shutdownMethod1() { 49 | this.numbers.add(4); 50 | } 51 | 52 | @Shutdown 53 | @DemoiselleLifecyclePriority(DemoiselleLifecyclePriority.LEVEL_2) 54 | public void shutdownMethod2() { 55 | this.numbers.add(5); 56 | } 57 | 58 | @Shutdown 59 | @DemoiselleLifecyclePriority(DemoiselleLifecyclePriority.LEVEL_3) 60 | public void shutdownMethod3() { 61 | this.numbers.add(6); 62 | } 63 | 64 | public List getNumbers() { 65 | return this.numbers; 66 | } 67 | 68 | } 69 | -------------------------------------------------------------------------------- /demoiselle-core/src/test/resources/META-INF/beans.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | -------------------------------------------------------------------------------- /demoiselle-crud/.gitignore: -------------------------------------------------------------------------------- 1 | .settings 2 | .classpath 3 | .project 4 | /target/ 5 | /bin/ 6 | -------------------------------------------------------------------------------- /demoiselle-crud/src/main/java/org/demoiselle/jee/crud/AbstractBusiness.java: -------------------------------------------------------------------------------- 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 . 6 | */ 7 | package org.demoiselle.jee.crud; 8 | 9 | import javax.inject.Inject; 10 | 11 | import org.demoiselle.jee.core.api.crud.Crud; 12 | import org.demoiselle.jee.core.api.crud.Result; 13 | 14 | public abstract class AbstractBusiness implements Crud { 15 | 16 | @Inject 17 | protected AbstractDAO dao; 18 | 19 | @Override 20 | public T persist(T entity) { 21 | return dao.persist(entity); 22 | } 23 | 24 | @Override 25 | public T mergeFull(T entity) { 26 | return dao.mergeFull(entity); 27 | } 28 | 29 | @Override 30 | public T mergeHalf(I id, T entity) { 31 | return dao.mergeHalf(id, entity); 32 | } 33 | 34 | @Override 35 | public void remove(I id) { 36 | dao.remove(id); 37 | } 38 | 39 | @Override 40 | public Result find() { 41 | return dao.find(); 42 | } 43 | 44 | @Override 45 | public T find(I id) { 46 | return dao.find(id); 47 | } 48 | 49 | } 50 | -------------------------------------------------------------------------------- /demoiselle-crud/src/main/java/org/demoiselle/jee/crud/AbstractREST.java: -------------------------------------------------------------------------------- 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 . 6 | */ 7 | package org.demoiselle.jee.crud; 8 | 9 | import static javax.ws.rs.core.MediaType.APPLICATION_JSON; 10 | 11 | import javax.inject.Inject; 12 | import javax.transaction.Transactional; 13 | import javax.validation.Valid; 14 | import javax.ws.rs.Consumes; 15 | import javax.ws.rs.DELETE; 16 | import javax.ws.rs.GET; 17 | import javax.ws.rs.POST; 18 | import javax.ws.rs.PUT; 19 | import javax.ws.rs.Path; 20 | import javax.ws.rs.PathParam; 21 | import javax.ws.rs.Produces; 22 | import javax.ws.rs.core.Response.Status; 23 | 24 | import org.demoiselle.jee.core.api.crud.Crud; 25 | import org.demoiselle.jee.core.api.crud.Result; 26 | import org.demoiselle.jee.rest.exception.DemoiselleRestException; 27 | 28 | import io.swagger.annotations.ApiOperation; 29 | import io.swagger.jaxrs.PATCH; 30 | 31 | /** 32 | * TODO CLF JAVADOC 33 | * 34 | * @author SERPRO 35 | * 36 | */ 37 | @Produces(APPLICATION_JSON) 38 | @Consumes(APPLICATION_JSON) 39 | public abstract class AbstractREST implements Crud { 40 | 41 | @Inject 42 | protected AbstractBusiness bc; 43 | 44 | @Inject 45 | private CrudMessage crudMessage; 46 | 47 | @POST 48 | @Transactional 49 | @ApiOperation(value = "persist entity") 50 | @Override 51 | public T persist(@Valid T entity) { 52 | return bc.persist(entity); 53 | } 54 | 55 | @PUT 56 | @Transactional 57 | @ApiOperation(value = "full update entity") 58 | @Override 59 | public T mergeFull(@Valid T entity) { 60 | return bc.mergeFull(entity); 61 | } 62 | 63 | @PATCH 64 | @Path("{id}") 65 | @Transactional 66 | @ApiOperation(value = "partial update entity") 67 | @Override 68 | public T mergeHalf(@PathParam("id") final I id, T entity) { 69 | return bc.mergeHalf(id, entity); 70 | } 71 | 72 | @DELETE 73 | @Path("{id}") 74 | @Transactional 75 | @ApiOperation(value = "remove entity") 76 | @Override 77 | public void remove(@PathParam("id") final I id) { 78 | bc.remove(id); 79 | } 80 | 81 | @GET 82 | @Path("{id}") 83 | @Transactional 84 | @ApiOperation(value = "find by ID") 85 | @Override 86 | public T find(@PathParam("id") final I id) { 87 | return bc.find(id); 88 | } 89 | 90 | @GET 91 | @Transactional 92 | @Override 93 | public Result find() { 94 | /* 95 | * For security reasons we opted to throw the exception below so that the developer who is 96 | * extending this class overrides its own find() method using the @Search annotation (...) 97 | * defining the field fields. 98 | * 99 | * TODO CLF definir link de documentação 100 | */ 101 | throw new DemoiselleRestException(crudMessage.methodFindNotImplemented(), Status.NOT_IMPLEMENTED.getStatusCode()); 102 | } 103 | } 104 | -------------------------------------------------------------------------------- /demoiselle-crud/src/main/java/org/demoiselle/jee/crud/CrudMessage.java: -------------------------------------------------------------------------------- 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 . 6 | */ 7 | package org.demoiselle.jee.crud; 8 | 9 | import org.apache.deltaspike.core.api.message.MessageBundle; 10 | import org.apache.deltaspike.core.api.message.MessageTemplate; 11 | 12 | /** 13 | * 14 | * Messages used to inform user about CRUD feature 15 | * 16 | * @author SERPRO 17 | */ 18 | @MessageBundle 19 | public interface CrudMessage { 20 | 21 | @MessageTemplate("{method-find-not-implemented}") 22 | String methodFindNotImplemented(); 23 | 24 | @MessageTemplate("{field-request-does-not-exists-on-search-field}") 25 | String fieldRequestDoesNotExistsOnSearchField(String field); 26 | 27 | @MessageTemplate("{field-request-does-not-exists-on-object}") 28 | String fieldRequestDoesNotExistsOnObject(String field, String className); 29 | 30 | } 31 | -------------------------------------------------------------------------------- /demoiselle-crud/src/main/java/org/demoiselle/jee/crud/DemoiselleRequestContext.java: -------------------------------------------------------------------------------- 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 . 6 | */ 7 | package org.demoiselle.jee.crud; 8 | 9 | import java.util.List; 10 | import java.util.Set; 11 | 12 | import org.demoiselle.jee.crud.sort.SortModel; 13 | 14 | /** 15 | * Class used to make a Context of the Request and Response of CRUD feature. 16 | * 17 | * @author SERPRO 18 | */ 19 | public interface DemoiselleRequestContext { 20 | 21 | Integer getLimit(); 22 | void setLimit(Integer limit); 23 | 24 | Integer getOffset(); 25 | void setOffset(Integer offset); 26 | 27 | Long getCount(); 28 | void setCount(Long count); 29 | 30 | Class getEntityClass(); 31 | void setEntityClass(Class entityClass); 32 | 33 | TreeNodeField> getFilters(); 34 | void setFilters(TreeNodeField> filters); 35 | 36 | List getSorts(); 37 | void setSorts(List sorts); 38 | 39 | TreeNodeField> getFields(); 40 | void setFields(TreeNodeField> fields); 41 | 42 | Boolean isPaginationEnabled(); 43 | void setPaginationEnabled(Boolean isPaginationEnabled); 44 | 45 | } 46 | -------------------------------------------------------------------------------- /demoiselle-crud/src/main/java/org/demoiselle/jee/crud/ReservedHTTPHeaders.java: -------------------------------------------------------------------------------- 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 . 6 | */ 7 | package org.demoiselle.jee.crud; 8 | 9 | /** 10 | * Hold the reserved HTTP Headers. 11 | * 12 | * @author SERPRO 13 | * 14 | */ 15 | public enum ReservedHTTPHeaders { 16 | 17 | // Pagination 18 | HTTP_HEADER_CONTENT_RANGE("Content-Range"), 19 | HTTP_HEADER_ACCEPT_RANGE("Accept-Range"), 20 | HTTP_HEADER_ACCESS_CONTROL_EXPOSE_HEADERS("Access-Control-Expose-Headers"); 21 | 22 | private final String key; 23 | 24 | ReservedHTTPHeaders(String key){ 25 | this.key = key; 26 | } 27 | 28 | public String getKey(){ 29 | return this.key; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /demoiselle-crud/src/main/java/org/demoiselle/jee/crud/ReservedKeyWords.java: -------------------------------------------------------------------------------- 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 . 6 | */ 7 | package org.demoiselle.jee.crud; 8 | 9 | /** 10 | * Hold the reserved keywords. 11 | * 12 | * @author SERPRO 13 | * 14 | */ 15 | public enum ReservedKeyWords { 16 | 17 | // Pagination 18 | DEFAULT_RANGE_KEY("range"), 19 | 20 | // Sort 21 | DEFAULT_SORT_DESC_KEY("desc"), 22 | DEFAULT_SORT_KEY("sort"), 23 | 24 | // Fields 25 | DEFAULT_FIELD_KEY("fields"); 26 | 27 | private final String key; 28 | 29 | ReservedKeyWords(String key){ 30 | this.key = key; 31 | } 32 | 33 | public String getKey(){ 34 | return this.key; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /demoiselle-crud/src/main/java/org/demoiselle/jee/crud/Search.java: -------------------------------------------------------------------------------- 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 . 6 | */ 7 | package org.demoiselle.jee.crud; 8 | 9 | import static java.lang.annotation.ElementType.METHOD; 10 | 11 | import java.lang.annotation.Documented; 12 | import java.lang.annotation.Retention; 13 | import java.lang.annotation.RetentionPolicy; 14 | import java.lang.annotation.Target; 15 | 16 | /** 17 | * Annotation to be used in methods that want to change the 18 | * default paging behavior and determine the fields that can be used by the 19 | * request and in the return of the result. 20 | * 21 | * Ex. 22 | * 23 | *
24 |  * @GET
25 |  * @Search(fields={"field1", "field2"}, withPagination = true, quantityPerPage = 2)
26 |  * public Result myNewMethod(){
27 |  *    ...
28 |  * }
29 |  * 
30 | * 31 | * The method above will filter just 'field1' and 'field2' and the default pagination page will be 2 32 | * register per page. 33 | * 34 | * @author SERPRO 35 | */ 36 | @Documented 37 | @Retention(RetentionPolicy.RUNTIME) 38 | @Target(METHOD) 39 | public @interface Search { 40 | String[] fields(); 41 | boolean withPagination() default true; 42 | int quantityPerPage() default 20; 43 | } 44 | -------------------------------------------------------------------------------- /demoiselle-crud/src/main/java/org/demoiselle/jee/crud/TreeNodeField.java: -------------------------------------------------------------------------------- 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 . 6 | */ 7 | package org.demoiselle.jee.crud; 8 | 9 | import java.util.LinkedList; 10 | import java.util.List; 11 | 12 | /** 13 | * 14 | * This class helps the CRUD feature to hold the fields on a Tree structure. 15 | * 16 | * @author SERPRO 17 | */ 18 | public class TreeNodeField { 19 | 20 | private T key; 21 | private K value; 22 | private TreeNodeField parent; 23 | private List> children; 24 | 25 | public TreeNodeField(T key, K value) { 26 | this.key = key; 27 | this.value = value; 28 | this.children = new LinkedList<>(); 29 | } 30 | 31 | public TreeNodeField addChild(T key, K value) { 32 | TreeNodeField childNode = new TreeNodeField(key, value); 33 | childNode.parent = this; 34 | this.children.add(childNode); 35 | return childNode; 36 | } 37 | 38 | public TreeNodeField getParent() { 39 | return this.parent; 40 | } 41 | 42 | public T getKey() { 43 | return this.key; 44 | } 45 | 46 | public K getValue() { 47 | return this.value; 48 | } 49 | 50 | public List> getChildren() { 51 | return this.children; 52 | } 53 | 54 | public TreeNodeField getChildByKey(T key){ 55 | return getChildren().stream() 56 | .filter( (child) -> child.getKey().equals(key)) 57 | .findAny() 58 | .orElse(null); 59 | } 60 | 61 | public Boolean containsKey(T key){ 62 | return getChildren().stream() 63 | .filter( (child) -> child.getKey().equals(key)).count() > 0; 64 | } 65 | 66 | @Override 67 | public String toString() { 68 | return "TreeNodeField [key=" + key + ", value=" + value + ", children=" + children + "]"; 69 | } 70 | 71 | } 72 | -------------------------------------------------------------------------------- /demoiselle-crud/src/main/java/org/demoiselle/jee/crud/bootstrap/PersistenceBootstrap.java: -------------------------------------------------------------------------------- 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 . 6 | */ 7 | package org.demoiselle.jee.crud.bootstrap; 8 | 9 | import javax.enterprise.event.Observes; 10 | import javax.enterprise.inject.spi.AnnotatedType; 11 | import javax.enterprise.inject.spi.ProcessAnnotatedType; 12 | import javax.persistence.Entity; 13 | 14 | /** 15 | * 16 | * Adding the @Vetoed annotation to all persistent entities is considered a best 17 | * practice in most cases. The purpose of this annotation is to prevent the 18 | * BeanManager from managing an entity as a CDI Bean. 19 | * 20 | * http://www.cdi-spec.org/faq/ Why is @Vetoed a best practice for persistent 21 | * (JPA) entities? 22 | * 23 | * @author SERPRO 24 | * 25 | */ 26 | public class PersistenceBootstrap implements javax.enterprise.inject.spi.Extension { 27 | 28 | @SuppressWarnings({ "rawtypes", "unchecked" }) 29 | public void processAnnotatedType(@Observes final ProcessAnnotatedType pat) { 30 | final AnnotatedType annotatedType = pat.getAnnotatedType(); 31 | if (annotatedType.getJavaClass().isAnnotationPresent(Entity.class)) { 32 | pat.veto(); 33 | } 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /demoiselle-crud/src/main/java/org/demoiselle/jee/crud/bootstrap/package-info.java: -------------------------------------------------------------------------------- 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 . 6 | */ 7 | 8 | /** 9 | * This package is intended to contain as related classes as Bootstrap (SPI) Demoiselle CRUD Framework. 10 | * 11 | * @author SERPRO 12 | */ 13 | package org.demoiselle.jee.crud.bootstrap; 14 | -------------------------------------------------------------------------------- /demoiselle-crud/src/main/java/org/demoiselle/jee/crud/exception/DemoiselleCrudException.java: -------------------------------------------------------------------------------- 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 . 6 | */ 7 | package org.demoiselle.jee.crud.exception; 8 | 9 | import org.demoiselle.jee.rest.exception.DemoiselleRestException; 10 | 11 | /** 12 | * 13 | * Exception for all persistence errors in CRUD. 14 | * 15 | * @author SERPRO 16 | */ 17 | public class DemoiselleCrudException extends DemoiselleRestException { 18 | 19 | private static final long serialVersionUID = 1L; 20 | 21 | public DemoiselleCrudException() { 22 | } 23 | 24 | public DemoiselleCrudException(String message) { 25 | super(message); 26 | } 27 | 28 | public DemoiselleCrudException(Throwable cause) { 29 | super(cause); 30 | } 31 | 32 | public DemoiselleCrudException(String message, Throwable cause) { 33 | super(message, cause); 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /demoiselle-crud/src/main/java/org/demoiselle/jee/crud/exception/package-info.java: -------------------------------------------------------------------------------- 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 . 6 | */ 7 | 8 | /** 9 | * This package is intended to contain as related classes as Exceptions of the CRUD Demoiselle Framework. 10 | * 11 | * @author SERPRO 12 | */ 13 | package org.demoiselle.jee.crud.exception; 14 | -------------------------------------------------------------------------------- /demoiselle-crud/src/main/java/org/demoiselle/jee/crud/field/FieldHelperMessage.java: -------------------------------------------------------------------------------- 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 . 6 | */ 7 | package org.demoiselle.jee.crud.field; 8 | 9 | import org.apache.deltaspike.core.api.message.MessageBundle; 10 | import org.apache.deltaspike.core.api.message.MessageTemplate; 11 | 12 | /** 13 | * Messages used to inform user about Field feature 14 | * 15 | * @author SERPRO 16 | */ 17 | @MessageBundle 18 | public interface FieldHelperMessage { 19 | 20 | @MessageTemplate("{field-request-malformed}") 21 | String fieldRequestMalFormed(String fieldName, String field); 22 | 23 | } 24 | -------------------------------------------------------------------------------- /demoiselle-crud/src/main/java/org/demoiselle/jee/crud/field/package-info.java: -------------------------------------------------------------------------------- 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 . 6 | */ 7 | 8 | /** 9 | * This package is intended to contain as related classes about Field feature of Demoiselle CRUD Framework. 10 | * 11 | * @author SERPRO 12 | */ 13 | package org.demoiselle.jee.crud.field; 14 | -------------------------------------------------------------------------------- /demoiselle-crud/src/main/java/org/demoiselle/jee/crud/filter/package-info.java: -------------------------------------------------------------------------------- 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 . 6 | */ 7 | 8 | /** 9 | * This package is intended to contain as related classes about Filter feature of Demoiselle CRUD Framework. 10 | * 11 | * @author SERPRO 12 | */ 13 | package org.demoiselle.jee.crud.filter; 14 | -------------------------------------------------------------------------------- /demoiselle-crud/src/main/java/org/demoiselle/jee/crud/package-info.java: -------------------------------------------------------------------------------- 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 . 6 | */ 7 | 8 | /** 9 | * This package is intended to contain as related classes of CRUD Demoiselle Framework. 10 | * 11 | * @author SERPRO 12 | */ 13 | package org.demoiselle.jee.crud; 14 | -------------------------------------------------------------------------------- /demoiselle-crud/src/main/java/org/demoiselle/jee/crud/pagination/PaginationHelperConfig.java: -------------------------------------------------------------------------------- 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 . 6 | */ 7 | package org.demoiselle.jee.crud.pagination; 8 | 9 | import org.demoiselle.jee.configuration.annotation.Configuration; 10 | 11 | /** 12 | * Class responsible for hold configuration about Pagination feature. 13 | * 14 | * @author SERPRO 15 | */ 16 | @Configuration(prefix = "demoiselle.crud.pagination") 17 | public class PaginationHelperConfig { 18 | 19 | private Boolean isGlobalEnabled = Boolean.TRUE; 20 | private Integer defaultPagination = new Integer(20); 21 | 22 | public Integer getDefaultPagination() { 23 | return defaultPagination; 24 | } 25 | 26 | public Boolean getIsGlobalEnabled() { 27 | return isGlobalEnabled; 28 | } 29 | 30 | } 31 | -------------------------------------------------------------------------------- /demoiselle-crud/src/main/java/org/demoiselle/jee/crud/pagination/PaginationHelperMessage.java: -------------------------------------------------------------------------------- 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 . 6 | */ 7 | package org.demoiselle.jee.crud.pagination; 8 | 9 | import org.apache.deltaspike.core.api.message.MessageBundle; 10 | import org.apache.deltaspike.core.api.message.MessageTemplate; 11 | 12 | /** 13 | * 14 | * Messages used to inform user about Pagination feature 15 | * 16 | * @author SERPRO 17 | */ 18 | @MessageBundle 19 | public interface PaginationHelperMessage { 20 | 21 | @MessageTemplate("{invalid-range-parameters}") 22 | String invalidRangeParameters(); 23 | 24 | @MessageTemplate("{default-pagination-number-exceed}") 25 | String defaultPaginationNumberExceed(Integer defaultPaginationNumber); 26 | 27 | @MessageTemplate("{pagination-is-not-enabled}") 28 | String paginationIsNotEnabled(); 29 | 30 | } 31 | -------------------------------------------------------------------------------- /demoiselle-crud/src/main/java/org/demoiselle/jee/crud/pagination/ResultSet.java: -------------------------------------------------------------------------------- 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 . 6 | */ 7 | package org.demoiselle.jee.crud.pagination; 8 | 9 | import java.util.LinkedList; 10 | import java.util.List; 11 | 12 | import org.demoiselle.jee.core.api.crud.Result; 13 | import org.demoiselle.jee.crud.AbstractDAO; 14 | 15 | /** 16 | * This classes implements {@link org.demoiselle.jee.core.api.crud.Result} to hold the results came from {@link AbstractDAO} 17 | * 18 | * @author SERPRO 19 | */ 20 | public class ResultSet implements Result{ 21 | 22 | private List content = new LinkedList<>(); 23 | 24 | @Override 25 | public List getContent() { 26 | return content; 27 | } 28 | 29 | @Override 30 | public void setContent(List content) { 31 | this.content = (List) content; 32 | } 33 | 34 | } -------------------------------------------------------------------------------- /demoiselle-crud/src/main/java/org/demoiselle/jee/crud/pagination/package-info.java: -------------------------------------------------------------------------------- 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 . 6 | */ 7 | 8 | /** 9 | * This package is intended to contain as related classes about Pagination feature of Demoiselle CRUD Framework. 10 | * 11 | * @author SERPRO 12 | */ 13 | package org.demoiselle.jee.crud.pagination; 14 | -------------------------------------------------------------------------------- /demoiselle-crud/src/main/java/org/demoiselle/jee/crud/sort/CrudSort.java: -------------------------------------------------------------------------------- 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 . 6 | */ 7 | package org.demoiselle.jee.crud.sort; 8 | 9 | /** 10 | * Enum to hold types supported by Sort feature 11 | * 12 | * @author SERPRO 13 | */ 14 | public enum CrudSort { 15 | 16 | ASC, 17 | DESC 18 | 19 | } 20 | -------------------------------------------------------------------------------- /demoiselle-crud/src/main/java/org/demoiselle/jee/crud/sort/SortHelperMessage.java: -------------------------------------------------------------------------------- 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 . 6 | */ 7 | package org.demoiselle.jee.crud.sort; 8 | 9 | import org.apache.deltaspike.core.api.message.MessageBundle; 10 | import org.apache.deltaspike.core.api.message.MessageTemplate; 11 | 12 | /** 13 | * 14 | * Messages used to inform user about Sort feature 15 | * 16 | * @author SERPRO 17 | */ 18 | @MessageBundle 19 | public interface SortHelperMessage { 20 | 21 | @MessageTemplate("{sort-request-malformed}") 22 | String sortRequestMalFormed(String sort); 23 | 24 | @MessageTemplate("{desc-parameter-without-sort-parameter}") 25 | String descParameterWithoutSortParameter(); 26 | 27 | } 28 | -------------------------------------------------------------------------------- /demoiselle-crud/src/main/java/org/demoiselle/jee/crud/sort/SortModel.java: -------------------------------------------------------------------------------- 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 . 6 | */ 7 | package org.demoiselle.jee.crud.sort; 8 | 9 | /** 10 | * This class helps the Sort feature to hold the type for sort ({@link CrudSort#ASC} or {@link CrudSort#DESC}) 11 | * and the field that will be used to sort 12 | * 13 | * @author SERPRO 14 | */ 15 | public class SortModel { 16 | 17 | private CrudSort type; 18 | private String field; 19 | 20 | public SortModel(CrudSort type, String field){ 21 | this.type = type; 22 | this.field = field; 23 | } 24 | 25 | public CrudSort getType() { 26 | return type; 27 | } 28 | 29 | public String getField() { 30 | return field; 31 | } 32 | 33 | @Override 34 | public String toString() { 35 | return "SortModel [type=" + type + ", field=" + field + "]"; 36 | } 37 | 38 | } 39 | -------------------------------------------------------------------------------- /demoiselle-crud/src/main/java/org/demoiselle/jee/crud/sort/package-info.java: -------------------------------------------------------------------------------- 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 . 6 | */ 7 | 8 | /** 9 | * This package is intended to contain as related classes about Sort feature of Demoiselle CRUD Framework. 10 | * 11 | * @author SERPRO 12 | */ 13 | package org.demoiselle.jee.crud.sort; 14 | -------------------------------------------------------------------------------- /demoiselle-crud/src/main/resources/META-INF/beans.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | -------------------------------------------------------------------------------- /demoiselle-crud/src/main/resources/META-INF/services/javax.enterprise.inject.spi.Extension: -------------------------------------------------------------------------------- 1 | org.demoiselle.jee.crud.bootstrap.PersistenceBootstrap -------------------------------------------------------------------------------- /demoiselle-crud/src/main/resources/demoiselle.properties: -------------------------------------------------------------------------------- 1 | demoiselle.crud.pagination.defaultPagination = 20 2 | demoiselle.crud.pagination.isGlobalEnabled = true -------------------------------------------------------------------------------- /demoiselle-crud/src/main/resources/org/demoiselle/jee/crud/CrudMessage.properties: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/demoiselle/framework/096baf60f3c2cac7b6abe56d574af1226763210f/demoiselle-crud/src/main/resources/org/demoiselle/jee/crud/CrudMessage.properties -------------------------------------------------------------------------------- /demoiselle-crud/src/main/resources/org/demoiselle/jee/crud/field/FieldHelperMessage.properties: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/demoiselle/framework/096baf60f3c2cac7b6abe56d574af1226763210f/demoiselle-crud/src/main/resources/org/demoiselle/jee/crud/field/FieldHelperMessage.properties -------------------------------------------------------------------------------- /demoiselle-crud/src/main/resources/org/demoiselle/jee/crud/pagination/PaginationHelperMessage.properties: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/demoiselle/framework/096baf60f3c2cac7b6abe56d574af1226763210f/demoiselle-crud/src/main/resources/org/demoiselle/jee/crud/pagination/PaginationHelperMessage.properties -------------------------------------------------------------------------------- /demoiselle-crud/src/main/resources/org/demoiselle/jee/crud/sort/SortHelperMessage.properties: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/demoiselle/framework/096baf60f3c2cac7b6abe56d574af1226763210f/demoiselle-crud/src/main/resources/org/demoiselle/jee/crud/sort/SortHelperMessage.properties -------------------------------------------------------------------------------- /demoiselle-crud/src/test/java/org/demoiselle/jee/crud/ErrorMsgForTest.java: -------------------------------------------------------------------------------- 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 . 6 | */ 7 | package org.demoiselle.jee.crud; 8 | 9 | /** 10 | * @author SERPRO 11 | * 12 | */ 13 | public class ErrorMsgForTest { 14 | 15 | public String msg = ""; 16 | public String debbug = ""; 17 | 18 | } 19 | -------------------------------------------------------------------------------- /demoiselle-crud/src/test/java/org/demoiselle/jee/crud/UserRestForTest.java: -------------------------------------------------------------------------------- 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 . 6 | */ 7 | package org.demoiselle.jee.crud; 8 | 9 | import org.demoiselle.jee.core.api.crud.Result; 10 | import org.demoiselle.jee.crud.AbstractREST; 11 | import org.demoiselle.jee.crud.entity.UserModelForTest; 12 | 13 | import javax.ws.rs.GET; 14 | 15 | /** 16 | * 17 | * @author SERPRO 18 | * 19 | */ 20 | public class UserRestForTest extends AbstractREST { 21 | 22 | @Override 23 | @GET 24 | public Result find() { 25 | return null; 26 | } 27 | 28 | @GET 29 | @Search(fields={"name", "address"}, quantityPerPage = 10, withPagination = true) 30 | public Result findWithSearch() { 31 | return null; 32 | } 33 | 34 | @GET 35 | @Search(fields={"name"}, withPagination = false) 36 | public Result findWithSearchAnnotationAndPaginationDisabled(){ 37 | return null; 38 | } 39 | 40 | @GET 41 | @Search(fields={"id", "name", "mail"}) 42 | public Result findWithSearchAndFields(){ 43 | return null; 44 | } 45 | 46 | @GET 47 | @Search(fields={"id", "name", "address(street)"}) 48 | public Result findWithSearchAndFieldsWithSubFields(){ 49 | return null; 50 | } 51 | 52 | @GET 53 | @Search(fields={"*"}) 54 | public Result findWithSearchAndAllFields(){ 55 | return null; 56 | } 57 | 58 | } 59 | -------------------------------------------------------------------------------- /demoiselle-crud/src/test/java/org/demoiselle/jee/crud/UserRestWithoutAbstractRESTForTest.java: -------------------------------------------------------------------------------- 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 . 6 | */ 7 | package org.demoiselle.jee.crud; 8 | 9 | import javax.ws.rs.GET; 10 | import javax.ws.rs.core.Response; 11 | 12 | import org.demoiselle.jee.core.api.crud.Result; 13 | 14 | /** 15 | * 16 | * @author SERPRO 17 | * 18 | */ 19 | public class UserRestWithoutAbstractRESTForTest { 20 | 21 | @GET 22 | public Result find() { 23 | return null; 24 | } 25 | 26 | @GET 27 | public Response findWithException() { 28 | ErrorMsgForTest entity = new ErrorMsgForTest(); 29 | return Response.status(400).entity(entity).type("application/json").build(); 30 | } 31 | 32 | } 33 | -------------------------------------------------------------------------------- /demoiselle-crud/src/test/java/org/demoiselle/jee/crud/entity/AddressModelForTest.java: -------------------------------------------------------------------------------- 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 . 6 | */ 7 | package org.demoiselle.jee.crud.entity; 8 | 9 | /** 10 | * @author SERPRO 11 | * 12 | */ 13 | public class AddressModelForTest { 14 | 15 | private Long id; 16 | private String address; 17 | private String street; 18 | private CountryModelForTest country; 19 | 20 | public Long getId() { 21 | return id; 22 | } 23 | public void setId(Long id) { 24 | this.id = id; 25 | } 26 | public String getAddress() { 27 | return address; 28 | } 29 | public void setAddress(String address) { 30 | this.address = address; 31 | } 32 | public CountryModelForTest getCountry() { 33 | return country; 34 | } 35 | public void setCountry(CountryModelForTest country) { 36 | this.country = country; 37 | } 38 | public String getStreet() { 39 | return street; 40 | } 41 | public void setStreet(String street) { 42 | this.street = street; 43 | } 44 | @Override 45 | public String toString() { 46 | return "AddressModelForTest [id=" + id + ", address=" + address + ", street=" + street + ", country=" + country 47 | + "]"; 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /demoiselle-crud/src/test/java/org/demoiselle/jee/crud/entity/CountryModelForTest.java: -------------------------------------------------------------------------------- 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 . 6 | */ 7 | package org.demoiselle.jee.crud.entity; 8 | 9 | /** 10 | * @author SERPRO 11 | * 12 | */ 13 | public class CountryModelForTest { 14 | 15 | private Long id; 16 | private String name; 17 | 18 | public Long getId() { 19 | return id; 20 | } 21 | public void setId(Long id) { 22 | this.id = id; 23 | } 24 | public String getName() { 25 | return name; 26 | } 27 | public void setName(String name) { 28 | this.name = name; 29 | } 30 | @Override 31 | public String toString() { 32 | return "CountryModelForTest [id=" + id + ", name=" + name + "]"; 33 | } 34 | 35 | } 36 | -------------------------------------------------------------------------------- /demoiselle-crud/src/test/java/org/demoiselle/jee/crud/entity/UserModelForTest.java: -------------------------------------------------------------------------------- 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 . 6 | */ 7 | package org.demoiselle.jee.crud.entity; 8 | 9 | /** 10 | * 11 | * @author SERPRO 12 | * 13 | */ 14 | public class UserModelForTest { 15 | 16 | private Long id; 17 | private String name; 18 | private String mail; 19 | private Integer age; 20 | private AddressModelForTest address; 21 | 22 | public Long getId() { 23 | return id; 24 | } 25 | 26 | public void setId(Long id) { 27 | this.id = id; 28 | } 29 | 30 | public String getName() { 31 | return name; 32 | } 33 | 34 | public void setName(String name) { 35 | this.name = name; 36 | } 37 | 38 | public String getMail() { 39 | return mail; 40 | } 41 | 42 | public void setMail(String mail) { 43 | this.mail = mail; 44 | } 45 | 46 | public Integer getAge() { 47 | return age; 48 | } 49 | 50 | public void setAge(Integer age) { 51 | this.age = age; 52 | } 53 | 54 | public AddressModelForTest getAddress() { 55 | return address; 56 | } 57 | 58 | public void setAddress(AddressModelForTest address) { 59 | this.address = address; 60 | } 61 | 62 | @Override 63 | public String toString() { 64 | return "UserModelForTest [id=" + id + ", name=" + name + ", mail=" + mail + ", age=" + age + ", address=" 65 | + address + "]"; 66 | } 67 | 68 | } 69 | -------------------------------------------------------------------------------- /demoiselle-crud/src/test/resources/META-INF/services/javax.enterprise.inject.spi.Extension: -------------------------------------------------------------------------------- 1 | org.demoiselle.jee.crud.bootstrap.PersistenceBootstrap -------------------------------------------------------------------------------- /demoiselle-crud/src/test/resources/demoiselle.properties: -------------------------------------------------------------------------------- 1 | demoiselle.crud.acceptRange=20 2 | demoiselle.crud.patternsEnabled=true 3 | -------------------------------------------------------------------------------- /demoiselle-parent-bom/.gitignore: -------------------------------------------------------------------------------- 1 | /.settings/ 2 | /.project 3 | /target/ 4 | -------------------------------------------------------------------------------- /demoiselle-parent-rest/.gitignore: -------------------------------------------------------------------------------- 1 | .settings 2 | .classpath 3 | .project 4 | /target/ 5 | /bin/ 6 | -------------------------------------------------------------------------------- /demoiselle-parent/.gitignore: -------------------------------------------------------------------------------- 1 | .settings 2 | .classpath 3 | .project 4 | /target/ 5 | /bin/ 6 | -------------------------------------------------------------------------------- /demoiselle-parent/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | demoiselle-parent 5 | pom 6 | 4.0.0 7 | 8 | Demoiselle JEE Parent 9 | http://demoiselle.io 10 | 11 | 12 | org.demoiselle.jee 13 | demoiselle-build 14 | 3.0.6-SNAPSHOT 15 | 16 | 17 | 18 | ../licence-lgpl 19 | 20 | 21 | 22 | 23 | 24 | org.demoiselle.jee 25 | demoiselle-parent-bom 26 | 3.0.6-SNAPSHOT 27 | import 28 | pom 29 | 30 | 31 | 32 | 33 | 34 | 35 | junit 36 | junit 37 | test 38 | 39 | 40 | 41 | org.hamcrest 42 | hamcrest-core 43 | test 44 | 45 | 46 | 47 | org.apache.deltaspike.modules 48 | deltaspike-test-control-module-api 49 | test 50 | 51 | 52 | 53 | org.apache.deltaspike.modules 54 | deltaspike-test-control-module-impl 55 | test 56 | 57 | 58 | 59 | org.apache.deltaspike.cdictrl 60 | deltaspike-cdictrl-weld 61 | test 62 | 63 | 64 | 65 | org.jboss.weld.se 66 | weld-se-core 67 | test 68 | 69 | 70 | 71 | 72 | 73 | -------------------------------------------------------------------------------- /demoiselle-rest/.gitignore: -------------------------------------------------------------------------------- 1 | .settings 2 | .classpath 3 | .project 4 | /target/ 5 | /bin/ 6 | -------------------------------------------------------------------------------- /demoiselle-rest/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4.0.0 4 | demoiselle-rest 5 | jar 6 | 7 | Demoiselle JEE Rest 8 | 9 | Demoiselle Rest 10 | 11 | http://demoiselle.io 12 | 13 | 14 | org.demoiselle.jee 15 | demoiselle-parent 16 | 3.0.6-SNAPSHOT 17 | ../demoiselle-parent 18 | 19 | 20 | 21 | 22 | 23 | org.demoiselle.jee 24 | demoiselle-core 25 | 26 | 27 | 28 | org.demoiselle.jee 29 | demoiselle-configuration 30 | 31 | 32 | 33 | javax.ws.rs 34 | javax.ws.rs-api 35 | 36 | 37 | 38 | javax.json 39 | javax.json-api 40 | 41 | 42 | 43 | io.swagger 44 | swagger-jaxrs 45 | 46 | 47 | 48 | 49 | -------------------------------------------------------------------------------- /demoiselle-rest/src/main/java/org/demoiselle/jee/rest/DemoiselleRestConfig.java: -------------------------------------------------------------------------------- 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 . 6 | */ 7 | /* 8 | * To change this license header, choose License Headers in Project Properties. 9 | * To change this template file, choose Tools | Templates 10 | * and open the template in the editor. 11 | */ 12 | package org.demoiselle.jee.rest; 13 | 14 | import java.util.HashMap; 15 | import java.util.Map; 16 | 17 | import org.demoiselle.jee.configuration.annotation.Configuration; 18 | 19 | /** 20 | * Configurations of REST module. 21 | * 22 | * @author SERPRO 23 | */ 24 | @Configuration(prefix = "demoiselle.rest") 25 | public class DemoiselleRestConfig { 26 | 27 | private Map sqlError = new HashMap(); 28 | 29 | private boolean showErrorDetails = true; 30 | 31 | /** 32 | * Return true or false if the detailed errors should return to user. 33 | * 34 | * @return true or false 35 | */ 36 | public boolean isShowErrorDetails() { 37 | return showErrorDetails; 38 | } 39 | 40 | /** 41 | * Set if the detailed errors should return to user. 42 | * 43 | * @param showErrorDetails 44 | */ 45 | public void setShowErrorDetails(boolean showErrorDetails) { 46 | this.showErrorDetails = showErrorDetails; 47 | } 48 | 49 | /** 50 | * Set the map of custom database error messages 51 | * 52 | * @param sqlError 53 | */ 54 | public void setSqlError(Map sqlError) { 55 | this.sqlError = sqlError; 56 | } 57 | 58 | /** 59 | * Return the map of custom Sql Error messages from demoiselle.properties loaded by configuration module. 60 | * 61 | * @return mapped sql Errors 62 | */ 63 | public Map getSqlError() { 64 | return this.sqlError; 65 | } 66 | 67 | } -------------------------------------------------------------------------------- /demoiselle-rest/src/main/java/org/demoiselle/jee/rest/LogExceptionMappers.java: -------------------------------------------------------------------------------- 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 . 6 | */ 7 | package org.demoiselle.jee.rest; 8 | 9 | import java.util.logging.Logger; 10 | 11 | import javax.enterprise.event.Observes; 12 | import javax.enterprise.inject.spi.Extension; 13 | import javax.enterprise.inject.spi.ProcessAnnotatedType; 14 | import javax.ws.rs.ext.ExceptionMapper; 15 | 16 | /** 17 | * 18 | * 19 | * @author SERPRO 20 | * 21 | */ 22 | public class LogExceptionMappers implements Extension { 23 | 24 | private static final Logger logger = Logger.getLogger(LogExceptionMappers.class.getName()); 25 | 26 | /** 27 | * Process all classes that extends {@link ExceptionMapper} to log for 28 | * analysis. 29 | * 30 | * @param pat 31 | * ProcessAnnotatedType used by CDI 32 | */ 33 | public void processAnnotatedType(@Observes final ProcessAnnotatedType> pat) { 34 | Class> pcsClass = pat.getAnnotatedType().getJavaClass(); 35 | if (pcsClass.isAnnotationPresent(javax.ws.rs.ext.Provider.class)) { 36 | logger.warning(pcsClass.getCanonicalName()); 37 | } 38 | } 39 | 40 | } 41 | -------------------------------------------------------------------------------- /demoiselle-rest/src/main/java/org/demoiselle/jee/rest/annotation/CacheControl.java: -------------------------------------------------------------------------------- 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 . 6 | */ 7 | package org.demoiselle.jee.rest.annotation; 8 | 9 | import static java.lang.annotation.ElementType.METHOD; 10 | import static java.lang.annotation.ElementType.TYPE; 11 | import java.lang.annotation.Inherited; 12 | import java.lang.annotation.Retention; 13 | import static java.lang.annotation.RetentionPolicy.RUNTIME; 14 | import java.lang.annotation.Target; 15 | import javax.enterprise.util.Nonbinding; 16 | import javax.interceptor.InterceptorBinding; 17 | 18 | /** 19 | * 20 | * @author SERPRO 21 | */ 22 | @Inherited 23 | @InterceptorBinding 24 | @Target({ METHOD, TYPE }) 25 | @Retention(RUNTIME) 26 | public @interface CacheControl { 27 | 28 | @Nonbinding 29 | String value() default "max-age=0"; 30 | } 31 | -------------------------------------------------------------------------------- /demoiselle-rest/src/main/java/org/demoiselle/jee/rest/exception/DemoiselleRestException.java: -------------------------------------------------------------------------------- 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 . 6 | */ 7 | package org.demoiselle.jee.rest.exception; 8 | 9 | import java.util.HashSet; 10 | 11 | import javax.ws.rs.core.Response.Status; 12 | 13 | import org.demoiselle.jee.core.exception.DemoiselleException; 14 | 15 | public class DemoiselleRestException extends DemoiselleException { 16 | 17 | private static final long serialVersionUID = 519_965_615_171_844_237L; 18 | 19 | protected HashSet messages = new HashSet(); 20 | 21 | protected int statusCode = Status.INTERNAL_SERVER_ERROR.getStatusCode(); 22 | 23 | public DemoiselleRestException() { 24 | } 25 | 26 | public DemoiselleRestException(int statusCode) { 27 | this.statusCode = statusCode; 28 | } 29 | 30 | public DemoiselleRestException(String string) { 31 | super(string); 32 | } 33 | 34 | public DemoiselleRestException(String string, int statusCode) { 35 | super(string); 36 | this.statusCode = statusCode; 37 | } 38 | 39 | public DemoiselleRestException(Throwable cause) { 40 | super(cause); 41 | } 42 | 43 | public DemoiselleRestException(String message, Throwable cause) { 44 | super(message, cause); 45 | } 46 | 47 | public int getStatusCode() { 48 | return statusCode; 49 | } 50 | 51 | public void addMessage(String field, String msg) { 52 | messages.add(new DemoiselleRestExceptionMessage(field, msg, null)); 53 | } 54 | 55 | public void addMessage(String error, String error_description, String error_link) { 56 | messages.add(new DemoiselleRestExceptionMessage(error, error_description, error_link)); 57 | } 58 | 59 | public HashSet getMessages() { 60 | return messages; 61 | } 62 | 63 | public void setMessages(HashSet msgs) { 64 | this.messages = msgs; 65 | } 66 | 67 | } 68 | -------------------------------------------------------------------------------- /demoiselle-rest/src/main/java/org/demoiselle/jee/rest/exception/DemoiselleRestExceptionMessage.java: -------------------------------------------------------------------------------- 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 . 6 | */ 7 | package org.demoiselle.jee.rest.exception; 8 | 9 | /** 10 | * Message Exception class intended to be used by REST DemoiselleFramework 11 | * exceptions. 12 | * 13 | * @author SERPRO 14 | */ 15 | public class DemoiselleRestExceptionMessage { 16 | 17 | private String error; 18 | private String error_description; 19 | 20 | private String error_link; 21 | 22 | public DemoiselleRestExceptionMessage(String error, String error_description, String error_link) { 23 | this.error = error; 24 | this.error_description = error_description; 25 | this.error_link = error_link; 26 | } 27 | 28 | public String getError() { 29 | return error; 30 | } 31 | 32 | public void setError(String error) { 33 | this.error = error; 34 | } 35 | 36 | public String getError_description() { 37 | return error_description; 38 | } 39 | 40 | public void setError_description(String error_description) { 41 | this.error_description = error_description; 42 | } 43 | 44 | public String getError_link() { 45 | return error_link; 46 | } 47 | 48 | public void setError_link(String error_link) { 49 | this.error_link = error_link; 50 | } 51 | 52 | } -------------------------------------------------------------------------------- /demoiselle-rest/src/main/java/org/demoiselle/jee/rest/exception/mapper/AnyOtherExceptionMapper.java: -------------------------------------------------------------------------------- 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 . 6 | */ 7 | package org.demoiselle.jee.rest.exception.mapper; 8 | 9 | import java.util.logging.Level; 10 | import java.util.logging.Logger; 11 | 12 | import javax.inject.Inject; 13 | import javax.servlet.http.HttpServletRequest; 14 | import javax.ws.rs.core.Context; 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.core.exception.ExceptionTreatment; 20 | 21 | /** 22 | * Any other exception is mapped by this class and when toResponse method is 23 | * called then sends to @ExceptionTreatment to treat error and return the 24 | * correct format in @Response object. 25 | * 26 | * @author SERPRO 27 | * 28 | */ 29 | @Provider 30 | public class AnyOtherExceptionMapper implements ExceptionMapper { 31 | 32 | private static final Logger logger = Logger.getLogger(AnyOtherExceptionMapper.class.getName()); 33 | 34 | @Context 35 | protected HttpServletRequest httpRequest; 36 | 37 | @Inject 38 | protected ExceptionTreatment exceptionTreatment; 39 | 40 | @Override 41 | public Response toResponse(Throwable exception) { 42 | logger.log(Level.SEVERE, "Using AnyOtherExceptionMapper", exception); 43 | return exceptionTreatment.getFormatedError(exception, httpRequest); 44 | } 45 | 46 | } 47 | -------------------------------------------------------------------------------- /demoiselle-rest/src/main/java/org/demoiselle/jee/rest/exception/mapper/ValidationExceptionMapper.java: -------------------------------------------------------------------------------- 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 . 6 | */ 7 | package org.demoiselle.jee.rest.exception.mapper; 8 | 9 | import java.util.logging.Level; 10 | import java.util.logging.Logger; 11 | 12 | import javax.inject.Inject; 13 | import javax.servlet.http.HttpServletRequest; 14 | import javax.validation.ValidationException; 15 | import javax.ws.rs.core.Context; 16 | import javax.ws.rs.core.Response; 17 | import javax.ws.rs.ext.ExceptionMapper; 18 | import javax.ws.rs.ext.Provider; 19 | 20 | import org.demoiselle.jee.core.exception.ExceptionTreatment; 21 | 22 | /** 23 | * When an exception is thrown, JAX-RS will first try to find an ExceptionMapper 24 | * for that exception’s type. If it cannot find one, it will look for a mapper 25 | * that can handle the exception’s superclass. It will continue this process 26 | * until there are no more superclasses to match against. 27 | * 28 | * { @link 29 | * https://dennis-xlc.gitbooks.io/restful-java-with-jax-rs-2-0-2rd-edition/content/en/part1/chapter7/exception_handling.html 30 | * } 31 | * 32 | * @author SERPRO 33 | * 34 | */ 35 | @Provider 36 | public class ValidationExceptionMapper implements ExceptionMapper { 37 | 38 | private static final Logger logger = Logger.getLogger(AnyOtherExceptionMapper.class.getName()); 39 | 40 | @Context 41 | protected HttpServletRequest httpRequest; 42 | 43 | @Inject 44 | protected ExceptionTreatment exceptionTreatment; 45 | 46 | @Override 47 | public Response toResponse(ValidationException exception) { 48 | logger.log(Level.SEVERE, "Using ValidationExceptionMapper", exception); 49 | return exceptionTreatment.getFormatedError(exception, httpRequest); 50 | } 51 | 52 | } 53 | -------------------------------------------------------------------------------- /demoiselle-rest/src/main/java/org/demoiselle/jee/rest/filter/CacheControlFilter.java: -------------------------------------------------------------------------------- 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 . 6 | */ 7 | package org.demoiselle.jee.rest.filter; 8 | 9 | import java.io.IOException; 10 | import java.lang.reflect.Method; 11 | import javax.annotation.Priority; 12 | import static javax.ws.rs.Priorities.HEADER_DECORATOR; 13 | import javax.ws.rs.container.ContainerRequestContext; 14 | import javax.ws.rs.container.ContainerResponseContext; 15 | import javax.ws.rs.container.ContainerResponseFilter; 16 | import javax.ws.rs.container.ResourceInfo; 17 | import javax.ws.rs.core.Context; 18 | import javax.ws.rs.ext.Provider; 19 | import org.demoiselle.jee.rest.annotation.CacheControl; 20 | 21 | /** 22 | * 23 | * @author SERPRO 24 | */ 25 | @Provider 26 | @Priority(HEADER_DECORATOR) 27 | public class CacheControlFilter implements ContainerResponseFilter { 28 | 29 | @Context 30 | private ResourceInfo info; 31 | 32 | @Override 33 | public void filter(ContainerRequestContext req, ContainerResponseContext res) throws IOException { 34 | if (req.getMethod().equals("GET")) { 35 | Method method = info.getResourceMethod(); 36 | if (method != null) { 37 | CacheControl max = method.getAnnotation(CacheControl.class); 38 | if (max != null) { 39 | res.getHeaders().putSingle("Cache-Control", max.value()); 40 | } 41 | } 42 | } 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /demoiselle-rest/src/main/java/org/demoiselle/jee/rest/filter/RestFilter.java: -------------------------------------------------------------------------------- 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 . 6 | */ 7 | package org.demoiselle.jee.rest.filter; 8 | 9 | import javax.annotation.Priority; 10 | import javax.inject.Inject; 11 | import static javax.ws.rs.Priorities.HEADER_DECORATOR; 12 | import javax.ws.rs.container.ContainerRequestContext; 13 | import javax.ws.rs.container.ContainerResponseContext; 14 | import javax.ws.rs.container.ContainerResponseFilter; 15 | import javax.ws.rs.ext.Provider; 16 | 17 | import org.demoiselle.jee.core.message.DemoiselleMessage; 18 | 19 | /** 20 | * 21 | * @author SERPRO 22 | * 23 | */ 24 | @Provider 25 | @Priority(HEADER_DECORATOR) 26 | public class RestFilter implements ContainerResponseFilter { 27 | 28 | @Inject 29 | private DemoiselleMessage demoiselleMessage; 30 | 31 | @Override 32 | public void filter(ContainerRequestContext requestContext, ContainerResponseContext responseContext) { 33 | responseContext.getHeaders().putSingle("Demoiselle-Version", demoiselleMessage.frameworkName()); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /demoiselle-rest/src/main/java/org/demoiselle/jee/rest/message/DemoiselleRESTMessage.java: -------------------------------------------------------------------------------- 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 . 6 | */ 7 | package org.demoiselle.jee.rest.message; 8 | 9 | import org.apache.deltaspike.core.api.message.MessageBundle; 10 | import org.apache.deltaspike.core.api.message.MessageTemplate; 11 | 12 | /** 13 | * Message class intended to be used by REST module. 14 | * 15 | * @author SERPRO 16 | */ 17 | @MessageBundle 18 | public interface DemoiselleRESTMessage { 19 | 20 | @MessageTemplate("{unhandled-database-exception}") 21 | String unhandledDatabaseException(); 22 | 23 | @MessageTemplate("{unhandled-malformed-input-output-exception}") 24 | String unhandledMalformedInputOutputException(); 25 | 26 | @MessageTemplate("{http-exception}") 27 | String httpException(); 28 | 29 | @MessageTemplate("{unhandled-server-exception}") 30 | String unhandledServerException(); 31 | 32 | } -------------------------------------------------------------------------------- /demoiselle-rest/src/main/resources/META-INF/beans.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | -------------------------------------------------------------------------------- /demoiselle-rest/src/main/resources/META-INF/services/javax.enterprise.inject.spi.Extension: -------------------------------------------------------------------------------- 1 | org.demoiselle.jee.rest.LogExceptionMappers -------------------------------------------------------------------------------- /demoiselle-rest/src/main/resources/org/demoiselle/jee/rest/message/DemoiselleRESTMessage.properties: -------------------------------------------------------------------------------- 1 | unhandled-database-exception=Unhandled database exception 2 | unhandled-malformed-input-output-exception=Unhandled malformed input/output exception 3 | http-exception=Http exception 4 | unhandled-server-exception=Unhandled server exception -------------------------------------------------------------------------------- /demoiselle-rest/src/test/java/org/demoiselle/jee/rest/DemoiselleRestConfigTest.java: -------------------------------------------------------------------------------- 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 . 6 | */ 7 | package org.demoiselle.jee.rest; 8 | 9 | import static org.junit.Assert.assertEquals; 10 | 11 | import javax.inject.Inject; 12 | 13 | import org.apache.deltaspike.testcontrol.api.junit.CdiTestRunner; 14 | import org.junit.After; 15 | import org.junit.AfterClass; 16 | import org.junit.Before; 17 | import org.junit.BeforeClass; 18 | import org.junit.Test; 19 | import org.junit.runner.RunWith; 20 | 21 | /** 22 | * 23 | * @author SERPRO 24 | */ 25 | @RunWith(CdiTestRunner.class) 26 | public class DemoiselleRestConfigTest { 27 | 28 | @BeforeClass 29 | public static void setUpClass() { 30 | } 31 | 32 | @AfterClass 33 | public static void tearDownClass() { 34 | } 35 | 36 | @Inject 37 | private DemoiselleRestConfig instance; 38 | 39 | public DemoiselleRestConfigTest() { 40 | } 41 | 42 | @Before 43 | public void setUp() { 44 | } 45 | 46 | @After 47 | public void tearDown() { 48 | } 49 | 50 | /** 51 | * Test of isErrorDetails method, of class DemoiselleRestConfig. 52 | */ 53 | @Test 54 | public void test1() { 55 | 56 | boolean expResult = instance.isShowErrorDetails(); 57 | assertEquals(expResult, true); 58 | } 59 | 60 | /** 61 | * Test of setshowErrorDetails method, of class DemoiselleRestConfig. 62 | */ 63 | @Test 64 | public void test2() { 65 | instance.setShowErrorDetails(false); 66 | boolean expResult = instance.isShowErrorDetails(); 67 | 68 | assertEquals(expResult, false); 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /demoiselle-script/.gitignore: -------------------------------------------------------------------------------- 1 | .settings 2 | .classpath 3 | .project 4 | /target/ 5 | /bin/ 6 | -------------------------------------------------------------------------------- /demoiselle-script/README.md: -------------------------------------------------------------------------------- 1 | 2 | DynamicManager 3 | -------------------------------------------------- ------------------------------------------------- 4 | Responsible for Managing Scripts, its compilation and execution. 5 | 6 | The implementation of this component is for the use of the facilities provided by the Java Scripting API to build dynamic and scripting languages ​​in which implement compatible engine with JSR-223. 7 | 8 | Using Compiled and Invocable interfaces JSR-223 (implemented in engines) the manager can access the generically methods to compile the code and save the bytecode cache. 9 | 10 | The script allows execution is passed a context with objects that will be accessible to the script code can be manipulated / altered by the same and made available via the same context for the calling code. 11 | 12 | -------------------------------------------------- ------------------------------------------------- 13 | Example of use: 14 | 15 | @Inject DynamicManager dm; 16 | 17 | ... 18 | 19 | 20 | try { 21 | String scriptSource = "int a = X; X= a + a;"; //sourcecode to be compiled . 22 | String scriptName = "test.groovy"; //id to scriptCache 23 | Integer valueX = 1; //value to be passed to script 24 | if( dm.getScript(scriptName) == null ) { //verify if is a cached script 25 | dm.loadEngine("groovy"); //the name of JSR-223 engine to load. 26 | dm.loadScript ( "test.groovy", scriptSource); //load the script into dynamicManager cache. 27 | } 28 | Bindings context = new SimpleBindings(); //create the context to script where 'X' is a key in script to a dynamic variable. 29 | context.put("X", valueX ); //The value can be a class too. 30 | System.out.println("The value of X is " + valueX + " before script execution."); 31 | System.out.println("Running script..."); 32 | dm.eval ( "test.groovy",context); //run the script. 33 | valueX = (Integer) context.get("X"); 34 | System.out.println("The value of X is " + valueX + " after script execution."); 35 | Assert.assertTrue(true); 36 | } catch (ScriptException e) { 37 | e.printStackTrace(); 38 | } 39 | 40 | ... -------------------------------------------------------------------------------- /demoiselle-script/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4.0.0 4 | 5 | demoiselle-script 6 | jar 7 | 8 | Demoiselle JEE Script 9 | 10 | Demoiselle JEE Script 11 | 12 | http://demoiselle.io 13 | 14 | 15 | org.demoiselle.jee 16 | demoiselle-parent 17 | 3.0.6-SNAPSHOT 18 | ../demoiselle-parent 19 | 20 | 21 | 22 | 23 | org.demoiselle.jee 24 | demoiselle-core 25 | 26 | 27 | 28 | org.codehaus.groovy 29 | groovy-all 30 | 31 | 32 | -------------------------------------------------------------------------------- /demoiselle-script/src/main/java/org/demoiselle/jee/script/DynamicManagerCache.java: -------------------------------------------------------------------------------- 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 . 6 | */ 7 | package org.demoiselle.jee.script; 8 | 9 | import java.io.Serializable; 10 | import java.util.Map; 11 | import java.util.concurrent.ConcurrentHashMap; 12 | 13 | import javax.enterprise.context.ApplicationScoped; 14 | 15 | /** 16 | * Dynamic Manage Cache - Responsible for Script Cache 17 | * 18 | * @author SERPRO 19 | */ 20 | @ApplicationScoped 21 | public class DynamicManagerCache implements Serializable { 22 | 23 | private static final long serialVersionUID = 2305168056315491913L; 24 | 25 | static Map> scriptCache = new ConcurrentHashMap>(); 26 | static Map engineList = new ConcurrentHashMap(); 27 | } 28 | -------------------------------------------------------------------------------- /demoiselle-script/src/main/java/org/demoiselle/jee/script/exception/DemoiselleScriptException.java: -------------------------------------------------------------------------------- 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 . 6 | */ 7 | package org.demoiselle.jee.script.exception; 8 | 9 | import org.demoiselle.jee.core.exception.DemoiselleException; 10 | 11 | /** 12 | * 13 | * Main exception Demoiselle Script feature 14 | * 15 | * @author SERPRO 16 | */ 17 | public class DemoiselleScriptException extends DemoiselleException{ 18 | 19 | private static final long serialVersionUID = 1L; 20 | 21 | public DemoiselleScriptException(String message) { 22 | super(message); 23 | } 24 | 25 | public DemoiselleScriptException(String message, Throwable cause) { 26 | super(message, cause); 27 | } 28 | } -------------------------------------------------------------------------------- /demoiselle-script/src/main/java/org/demoiselle/jee/script/message/DemoiselleScriptMessage.java: -------------------------------------------------------------------------------- 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 . 6 | */ 7 | package org.demoiselle.jee.script.message; 8 | 9 | import org.apache.deltaspike.core.api.message.MessageBundle; 10 | import org.apache.deltaspike.core.api.message.MessageTemplate; 11 | 12 | /** 13 | * 14 | * @author SERPRO 15 | */ 16 | @MessageBundle 17 | public interface DemoiselleScriptMessage { 18 | 19 | @MessageTemplate("{error-engine-cannot-load}") 20 | String cannotLoadEngine(String engineName); 21 | 22 | @MessageTemplate("{error-engine-not-loaded}") 23 | String engineNotLoaded(); 24 | 25 | @MessageTemplate("{error-engine-not-compilable}") 26 | String engineNotCompilable(); 27 | 28 | @MessageTemplate("{error-script-not-loaded}") 29 | String scriptNotLoaded(String scriptName); 30 | 31 | } 32 | -------------------------------------------------------------------------------- /demoiselle-script/src/main/java/org/demoiselle/jee/script/package-info.java: -------------------------------------------------------------------------------- 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 . 6 | */ 7 | /** 8 | * This package is intended to contain as classes related to 9 | * DynamicScriptManager of the Demoiselle framework. 10 | * 11 | * @author SERPRO 12 | */ 13 | package org.demoiselle.jee.script; -------------------------------------------------------------------------------- /demoiselle-script/src/main/resources/META-INF/beans.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | -------------------------------------------------------------------------------- /demoiselle-script/src/main/resources/org/demoiselle/jee/script/message/DemoiselleScriptMessage.properties: -------------------------------------------------------------------------------- 1 | error-engine-not-loaded=Script Engine not loaded 2 | error-engine-cannot-load=Cannot load the engine [%s] 3 | error-engine-not-compilable=Engine can't compile code. Interface Compilable not implemented by engine. 4 | error-script-not-loaded=Script not loaded [%s] -------------------------------------------------------------------------------- /demoiselle-script/src/test/resources/META-INF/beans.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /demoiselle-script/src/test/resources/org/demoiselle/jee/script/message/DemoiselleScriptMessage.properties: -------------------------------------------------------------------------------- 1 | error-engine-not-loaded=Script Engine not loaded 2 | error-engine-cannot-load=Cannot load the engine [%s] 3 | error-engine-not-compilable=Engine can't compile code. Interface Compilable not implemented by engine. 4 | error-script-not-loaded=Script not loaded [%s] -------------------------------------------------------------------------------- /demoiselle-security-hashcash/.gitignore: -------------------------------------------------------------------------------- 1 | .settings 2 | .classpath 3 | .project 4 | /target/ 5 | /bin/ 6 | -------------------------------------------------------------------------------- /demoiselle-security-hashcash/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4.0.0 4 | demoiselle-security-hashcash 5 | jar 6 | 7 | Demoiselle JEE Security HashCash 8 | 9 | Demoiselle Security HashCash 10 | 11 | http://demoiselle.io 12 | 13 | 14 | org.demoiselle.jee 15 | demoiselle-parent 16 | 3.0.0-SNAPSHOT 17 | ../demoiselle-parent 18 | 19 | 20 | 21 | org.demoiselle.jee 22 | demoiselle-security-jwt 23 | 24 | 25 | 26 | org.bitbucket.b_c 27 | jose4j 28 | 29 | 30 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /demoiselle-security-hashcash/src/main/java/org/demoiselle/jee/security/hashcash/DemoiselleSecurityHashCashConfig.java: -------------------------------------------------------------------------------- 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 . 6 | */ 7 | package org.demoiselle.jee.security.hashcash; 8 | 9 | import java.io.Serializable; 10 | import org.demoiselle.jee.configuration.annotation.Configuration; 11 | import org.demoiselle.jee.configuration.annotation.ConfigurationSuppressLogger; 12 | 13 | /** 14 | * 15 | * @author SERPRO 16 | */ 17 | @Configuration(prefix = "demoiselle.security.hashcash") 18 | public class DemoiselleSecurityHashCashConfig implements Serializable { 19 | 20 | @ConfigurationSuppressLogger 21 | private String hashcashKey; 22 | 23 | private Long timetoLiveMilliseconds; 24 | 25 | public String getHashcashKey() { 26 | return hashcashKey; 27 | } 28 | 29 | public Long getTimetoLiveMilliseconds() { 30 | return timetoLiveMilliseconds; 31 | } 32 | 33 | } 34 | -------------------------------------------------------------------------------- /demoiselle-security-hashcash/src/main/java/org/demoiselle/jee/security/hashcash/annotation/HashCash.java: -------------------------------------------------------------------------------- 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 . 6 | */ 7 | package org.demoiselle.jee.security.hashcash.annotation; 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 HashCash { 24 | 25 | } 26 | -------------------------------------------------------------------------------- /demoiselle-security-hashcash/src/main/resources/META-INF/beans.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | -------------------------------------------------------------------------------- /demoiselle-security-hashcash/src/main/resources/demoiselle.properties: -------------------------------------------------------------------------------- 1 | demoiselle.security.hashcash.hashcashKey=Demoiselle 2 | demoiselle.security.hashcash.timetoLiveMilliseconds=5000 3 | -------------------------------------------------------------------------------- /demoiselle-security-hashcash/src/test/java/org/demoiselle/jee/security/hashcash/execution/HashCashTest.java: -------------------------------------------------------------------------------- 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 . 6 | */ 7 | package org.demoiselle.jee.security.hashcash.execution; 8 | 9 | import javax.inject.Inject; 10 | import org.apache.deltaspike.testcontrol.api.junit.CdiTestRunner; 11 | import org.junit.After; 12 | import org.junit.AfterClass; 13 | import org.junit.Before; 14 | import org.junit.BeforeClass; 15 | import org.junit.Test; 16 | import static org.junit.Assert.*; 17 | import org.junit.runner.RunWith; 18 | 19 | /** 20 | * 21 | * @author SERPRO 22 | */ 23 | @RunWith(CdiTestRunner.class) 24 | public class HashCashTest { 25 | 26 | @Inject 27 | private Generator gera; 28 | 29 | public HashCashTest() { 30 | } 31 | 32 | @BeforeClass 33 | public static void setUpClass() { 34 | } 35 | 36 | @AfterClass 37 | public static void tearDownClass() { 38 | } 39 | 40 | @Before 41 | public void setUp() { 42 | } 43 | 44 | @After 45 | public void tearDown() { 46 | } 47 | 48 | @Test 49 | public void testMintCash_String_int() throws Exception { 50 | System.out.println("mintCash"); 51 | System.out.println(gera.token()); 52 | 53 | assertEquals(" ", " "); 54 | } 55 | 56 | } 57 | -------------------------------------------------------------------------------- /demoiselle-security-hashcash/src/test/resources/META-INF/beans.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | -------------------------------------------------------------------------------- /demoiselle-security-hashcash/src/test/resources/demoiselle.properties: -------------------------------------------------------------------------------- 1 | demoiselle.security.hashcash.hashcashKey=Demoiselle 2 | demoiselle.security.hashcash.timetoLiveMilliseconds=5000 3 | -------------------------------------------------------------------------------- /demoiselle-security-jwt/.gitignore: -------------------------------------------------------------------------------- 1 | .settings 2 | .classpath 3 | .project 4 | /target/ 5 | /bin/ 6 | -------------------------------------------------------------------------------- /demoiselle-security-jwt/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4.0.0 4 | demoiselle-security-jwt 5 | jar 6 | 7 | Demoiselle JEE Security JWT 8 | 9 | Demoiselle Security JWT 10 | 11 | http://demoiselle.io 12 | 13 | 14 | org.demoiselle.jee 15 | demoiselle-parent 16 | 3.0.6-SNAPSHOT 17 | ../demoiselle-parent 18 | 19 | 20 | 21 | 22 | org.demoiselle.jee 23 | demoiselle-security 24 | 25 | 26 | 27 | org.bitbucket.b_c 28 | jose4j 29 | 30 | 31 | 32 | org.hibernate 33 | hibernate-validator 34 | test 35 | 36 | 37 | 38 | 39 | 40 | -------------------------------------------------------------------------------- /demoiselle-security-jwt/src/main/java/org/demoiselle/jee/security/jwt/impl/DemoiselleSecurityJWTConfig.java: -------------------------------------------------------------------------------- 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 . 6 | */ 7 | package org.demoiselle.jee.security.jwt.impl; 8 | 9 | import java.io.Serializable; 10 | import org.demoiselle.jee.configuration.annotation.Configuration; 11 | import org.demoiselle.jee.configuration.annotation.ConfigurationSuppressLogger; 12 | 13 | /** 14 | * 15 | * @author SERPRO 16 | */ 17 | @Configuration(prefix = "demoiselle.security.jwt") 18 | public class DemoiselleSecurityJWTConfig implements Serializable { 19 | 20 | private static final long serialVersionUID = 638_435_989_235_076_782L; 21 | 22 | private String type; 23 | 24 | @ConfigurationSuppressLogger 25 | private String privateKey; 26 | 27 | private String publicKey; 28 | 29 | private Long timetoLiveMilliseconds; 30 | 31 | private String issuer; 32 | 33 | private String audience; 34 | 35 | private String algorithmIdentifiers; 36 | 37 | public String getType() { 38 | return type; 39 | } 40 | 41 | public String getPrivateKey() { 42 | return privateKey; 43 | } 44 | 45 | public String getPublicKey() { 46 | return publicKey; 47 | } 48 | 49 | public Long getTimetoLiveMilliseconds() { 50 | return timetoLiveMilliseconds; 51 | } 52 | 53 | public String getIssuer() { 54 | return issuer; 55 | } 56 | 57 | public String getAudience() { 58 | return audience; 59 | } 60 | 61 | public String getAlgorithmIdentifiers() { 62 | return algorithmIdentifiers; 63 | } 64 | 65 | } 66 | -------------------------------------------------------------------------------- /demoiselle-security-jwt/src/main/java/org/demoiselle/jee/security/message/DemoiselleSecurityJWTMessages.java: -------------------------------------------------------------------------------- 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 . 6 | */ 7 | package org.demoiselle.jee.security.message; 8 | 9 | import org.apache.deltaspike.core.api.message.MessageBundle; 10 | import org.apache.deltaspike.core.api.message.MessageTemplate; 11 | 12 | /** 13 | * 14 | * @author SERPRO 15 | */ 16 | @MessageBundle 17 | public interface DemoiselleSecurityJWTMessages { 18 | 19 | @MessageTemplate("{general}") 20 | String general(); 21 | 22 | @MessageTemplate("{expired}") 23 | String expired(); 24 | 25 | @MessageTemplate("{master}") 26 | String master(); 27 | 28 | @MessageTemplate("{slave}") 29 | String slave(); 30 | 31 | @MessageTemplate("{error}") 32 | String error(); 33 | 34 | @MessageTemplate("{choose-type}") 35 | String chooseType(); 36 | 37 | @MessageTemplate("{not-type}") 38 | String notType(); 39 | 40 | @MessageTemplate("{put-key}") 41 | String putKey(); 42 | 43 | @MessageTemplate("{not-jwt}") 44 | String notJwt(); 45 | 46 | @MessageTemplate("{type-server}") 47 | String typeServer(String text); 48 | 49 | @MessageTemplate("{primary-key}") 50 | String primaryKey(String text); 51 | 52 | @MessageTemplate("{public-key}") 53 | String publicKey(String text); 54 | 55 | @MessageTemplate("{age-token}") 56 | String ageToken(String text); 57 | 58 | @MessageTemplate("{issuer}") 59 | String issuer(String text); 60 | 61 | @MessageTemplate("{audience}") 62 | String audience(String text); 63 | 64 | } 65 | -------------------------------------------------------------------------------- /demoiselle-security-jwt/src/main/resources/META-INF/beans.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | -------------------------------------------------------------------------------- /demoiselle-security-jwt/src/main/resources/org/demoiselle/jee/security/message/DemoiselleSecurityJWTMessages.properties: -------------------------------------------------------------------------------- 1 | general=Erro na gera\u00e7\u00e3o do token, verifique as configura\u00e7\u00f5es, https://demoiselle.gitbooks.io/documentacao-jee/content/jwt.html 2 | expired=Token inv\u00e1lido 3 | error=Erro 4 | master=master 5 | slave=slave 6 | not-jwt=Opera\u00e7\u00e3o n\u00e3o utilizada para JWT, https://demoiselle.gitbooks.io/documentacao-jee/content/jwt.html 7 | type-server=Type server: %s 8 | primary-key=Primary key: %s 9 | public-key=Public key: %s 10 | age-token=Age token in minutes: %s 11 | issuer=Issuer: %s 12 | audience=Audience: %s 13 | put-key=Coloque as chaves no arquivo demoiselle.properties, https://demoiselle.gitbooks.io/documentacao-jee/content/jwt.html 14 | choose-type=Escolha comportamento do servidor, https://demoiselle.gitbooks.io/documentacao-jee/content/jwt.html 15 | not-type=Os tipos de comportamento n\u00e3o encontrado, https://demoiselle.gitbooks.io/documentacao-jee/content/jwt.html -------------------------------------------------------------------------------- /demoiselle-security-jwt/src/test/java/org/demoiselle/jee/security/jwt/impl/DemoiselleSecurityJWTMock.java: -------------------------------------------------------------------------------- 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 . 6 | */ 7 | package org.demoiselle.jee.security.jwt.impl; 8 | 9 | import java.io.Serializable; 10 | import org.demoiselle.jee.configuration.annotation.Configuration; 11 | import org.demoiselle.jee.configuration.annotation.ConfigurationSuppressLogger; 12 | 13 | /** 14 | * 15 | * @author SERPRO 16 | */ 17 | @Configuration(prefix = "demoiselle.security.jwt", resource = "demoiselle") 18 | public class DemoiselleSecurityJWTMock implements Serializable { 19 | 20 | private static final long serialVersionUID = 638_435_989_235_076_782L; 21 | 22 | private String type; 23 | 24 | @ConfigurationSuppressLogger 25 | private String privateKey; 26 | 27 | private String publicKey; 28 | 29 | private Long timetoLiveMilliseconds; 30 | 31 | private String issuer; 32 | 33 | private String audience; 34 | 35 | private String algorithmIdentifiers; 36 | 37 | public String getType() { 38 | return type; 39 | } 40 | 41 | public String getPrivateKey() { 42 | return privateKey; 43 | } 44 | 45 | public String getPublicKey() { 46 | return publicKey; 47 | } 48 | 49 | public Long getTimetoLiveMilliseconds() { 50 | return timetoLiveMilliseconds; 51 | } 52 | 53 | public String getIssuer() { 54 | return issuer; 55 | } 56 | 57 | public String getAudience() { 58 | return audience; 59 | } 60 | 61 | public String getAlgorithmIdentifiers() { 62 | return algorithmIdentifiers; 63 | } 64 | 65 | } 66 | -------------------------------------------------------------------------------- /demoiselle-security-jwt/src/test/java/org/demoiselle/jee/security/jwt/impl/DemoiselleSecurityJWTMockError.java: -------------------------------------------------------------------------------- 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 . 6 | */ 7 | package org.demoiselle.jee.security.jwt.impl; 8 | 9 | import java.io.Serializable; 10 | import org.demoiselle.jee.configuration.annotation.Configuration; 11 | import org.demoiselle.jee.configuration.annotation.ConfigurationSuppressLogger; 12 | 13 | /** 14 | * 15 | * @author SERPRO 16 | */ 17 | @Configuration(prefix = "demoiselle.security.jwt", resource = "demoiselleError") 18 | public class DemoiselleSecurityJWTMockError implements Serializable { 19 | 20 | private static final long serialVersionUID = 638_435_989_235_076_782L; 21 | 22 | private String type; 23 | 24 | @ConfigurationSuppressLogger 25 | private String privateKey; 26 | 27 | private String publicKey; 28 | 29 | private Long timetoLiveMilliseconds; 30 | 31 | private String issuer; 32 | 33 | private String audience; 34 | 35 | private String algorithmIdentifiers; 36 | 37 | public String getType() { 38 | return type; 39 | } 40 | 41 | public String getPrivateKey() { 42 | return privateKey; 43 | } 44 | 45 | public String getPublicKey() { 46 | return publicKey; 47 | } 48 | 49 | public Long getTimetoLiveMilliseconds() { 50 | return timetoLiveMilliseconds; 51 | } 52 | 53 | public String getIssuer() { 54 | return issuer; 55 | } 56 | 57 | public String getAudience() { 58 | return audience; 59 | } 60 | 61 | public String getAlgorithmIdentifiers() { 62 | return algorithmIdentifiers; 63 | } 64 | 65 | } 66 | -------------------------------------------------------------------------------- /demoiselle-security-jwt/src/test/resources/META-INF/beans.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | -------------------------------------------------------------------------------- /demoiselle-security-jwt/src/test/resources/demoiselle.properties: -------------------------------------------------------------------------------- 1 | # To change this license header, choose License Headers in Project Properties. 2 | # To change this template file, choose Tools | Templates 3 | # and open the template in the editor. 4 | demoiselle.security.jwt.type=master 5 | demoiselle.security.jwt.privateKey=-----BEGIN PRIVATE KEY-----MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQDT0DXVlqqanlkFM4LGAnyqq0eFvpv5470LyABfcNcUiV9yXQVTsVXB9C0da43cpTzdzWxKP3A8y6+Ia9l5JXuhSnYNcwvvoSwQp/2v7ok1lF2dMKRdmSVBISZ65+1LGcy0DCjuT54iA+k4itikwm/kbNWO7TNvK5yfBtCcO+ga/TykyttZoY7FycdcJrOytFMjtQpD6O8wMHduxRwgjRdL73ZktCSIyQofzkdJKWbgAUq5SWNGHn1GWkmsINz5NRlZC44LouL8f3/vy0BbyQkgd8BImGQqCRx0aLEEk2CCn4r7SExa/Eu3l+LUFe9aLL8xrdA0e3E4KitFr7g0EH4rAgMBAAECggEABhUilqGfAJWvhMC37qu/nL8SbLrOi9yIX0A9EoCRDJvtS8F0F7Ut+0Xhzch66G0uVEhD5dXwiS5oOgiu1BXJeRZEUZqOKzF7rHbGiDjXY9yA27S745w0P6yOCFWEsPVqtXjr6/wJVHy8Q81o70JOKEcf0tzo7zZXZxGxB+uIfM3ffGNixX/tOHOERSViBvJsBp7sPZOPdgFQy1yQzYHDHob3V7BoG3bL/6ZXBIKMovBcKPoZuHDSyU1w3UbkFpPf8NbElPeMVoPxSwT1e3gfkKwBdp3bXucUnWBJE/aEkpUuIPTHiI4oGJDapmybLx+UACqp3eid48IDC25qXIq/8QKBgQD2yuECo9mKvP6CAZTl9LUUqYqwf4HLqgzOcCzDdigJaF08jLkI+9c7kMhq5C3R+VpRXCMJVHQSOEyUaOEj/m4QrF2JmfGcLxhqnDm8kZ84nX5anBxASCVcyiM2A37fpXmohczzu+Re8VFbFIMC1qJa5r/7/whmc5UL2jBVbQ7kPwKBgQDbtz6RlZWWnlJh1Dk6PuNczhmjbNRctrsVc2RcvIuZrw3BPGbeFanJVDa9Q9n2owxMs6BoSgIfrf0XGnl71yTSKtCliMyTgxg27g8iVlLA5YPaTIsazScCzLMOJmfzP2RcDBMVg+42Zu2tHhOoRAyNIpM7PQBDk1rLbpBH/HL7FQKBgGwvSW3317BK4yKogNZBbHPvUn3Gl2ZpWA3S/Lx+elSNbHnTknWOuK5C7Kh2+GMYdPA/fJhlbjBif6d7Rl6Z9TPX63Ubh9+YgZKSg3jXOT3/RFmCH5xKRB6l+cN+yspNZsRqSwr5bcX08V4E4t2Gq0s/5h8YkF0hA9BbSF7aXPHPAoGBAJ8m7TunjuO7axFSGOIIC8l9wTSP8IP4GSxAmcJTEQwRsXT3u8vDBWnAhqYyMABnutEUjGz+rusjrOC/XKBIB3P1b414ujdgDno7ltrYjLkNh6TpLRoM4OU2Qb1ONJ4OnTPPy0MafcMKa7+qubJ5GF5jXSLb3QUWB/6z5+88/kzBAoGAWzcBjuAYmRa+Q9GpGRyml1SgS0foaKwycN9Az0IGaNmN+hvKBgoJtUvY5V/sDdNAbLz+1Hpc0s3TJpghmHTVxUrC0VKqhEyXpHIUN2IOjiqoiQbB1stW0GS3N9U4akQfYQrR7u+IcUizfs6OQTmTR3Xp6LryES/rLn0vwZKZIvo=-----END PRIVATE KEY----- 6 | demoiselle.security.jwt.publicKey=-----BEGIN PUBLIC KEY-----MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA09A11Zaqmp5ZBTOCxgJ8qqtHhb6b+eO9C8gAX3DXFIlfcl0FU7FVwfQtHWuN3KU83c1sSj9wPMuviGvZeSV7oUp2DXML76EsEKf9r+6JNZRdnTCkXZklQSEmeuftSxnMtAwo7k+eIgPpOIrYpMJv5GzVju0zbyucnwbQnDvoGv08pMrbWaGOxcnHXCazsrRTI7UKQ+jvMDB3bsUcII0XS+92ZLQkiMkKH85HSSlm4AFKuUljRh59RlpJrCDc+TUZWQuOC6Li/H9/78tAW8kJIHfASJhkKgkcdGixBJNggp+K+0hMWvxLt5fi1BXvWiy/Ma3QNHtxOCorRa+4NBB+KwIDAQAB-----END PUBLIC KEY----- 7 | demoiselle.security.jwt.timetoLiveMilliseconds=9999999999 8 | demoiselle.security.jwt.issuer=STORE 9 | demoiselle.security.jwt.audience=web 10 | demoiselle.security.jwt.algorithmIdentifiers=RS256 -------------------------------------------------------------------------------- /demoiselle-security-jwt/src/test/resources/demoiselleError.properties: -------------------------------------------------------------------------------- 1 | # To change this license header, choose License Headers in Project Properties. 2 | # To change this template file, choose Tools | Templates 3 | # and open the template in the editor. 4 | demoiselle.security.jwt.type=master 5 | demoiselle.security.jwt.privateKey=-----BEGIN PRIVATE KEY-----MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQDT0DXVlqqanlkFM4LGAnyqq0eFvpv5470LyABfcNcUiV9yXQVTsVXB9C0da43cpTzdzWxKP3A8y6+Ia9l5JXuhSnYNcwvvoSwQp/2v7ok1lF2dMKRdmSVBISZ65+1LGcy0DCjuT54iA+k4itikwm/kbNWO7TNvK5yfBtCcO+ga/TykyttZoY7FycdcJrOytFMjtQpD6O8wMHduxRwgjRdL73ZktCSIyQofzkdJKWbgAUq5SWNGHn1GWkmsINz5NRlZC44LouL8f3/vy0BbyQkgd8BImGQqCRx0aLEEk2CCn4r7SExa/Eu3l+LUFe9aLL8xrdA0e3E4KitFr7g0EH4rAgMBAAECggEABhUilqGfAJWvhMC37qu/nL8SbLrOi9yIX0A9EoCRDJvtS8F0F7Ut+0Xhzch66G0uVEhD5dXwiS5oOgiu1BXJeRZEUZqOKzF7rHbGiDjXY9yA27S745w0P6yOCFWEsPVqtXjr6/wJVHy8Q81o70JOKEcf0tzo7zZXZxGxB+uIfM3ffGNixX/tOHOERSViBvJsBp7sPZOPdgFQy1yQzYHDHob3V7BoG3bL/6ZXBIKMovBcKPoZuHDSyU1w3UbkFpPf8NbElPeMVoPxSwT1e3gfkKwBdp3bXucUnWBJE/aEkpUuIPTHiI4oGJDapmybLx+UACqp3eid48IDC25qXIq/8QKBgQD2yuECo9mKvP6CAZTl9LUUqYqwf4HLqgzOcCzDdigJaF08jLkI+9c7kMhq5C3R+VpRXCMJVHQSOEyUaOEj/m4QrF2JmfGcLxhqnDm8kZ84nX5anBxASCVcyiM2A37fpXmohczzu+Re8VFbFIMC1qJa5r/7/whmc5UL2jBVbQ7kPwKBgQDbtz6RlZWWnlJh1Dk6PuNczhmjbNRctrsVc2RcvIuZrw3BPGbeFanJVDa9Q9n2owxMs6BoSgIfrf0XGnl71yTSKtCliMyTgxg27g8iVlLA5YPaTIsazScCzLMOJmfzP2RcDBMVg+42Zu2tHhOoRAyNIpM7PQBDk1rLbpBH/HL7FQKBgGwvSW3317BK4yKogNZBbHPvUn3Gl2ZpWA3S/Lx+elSNbHnTknWOuK5C7Kh2+GMYdPA/fJhlbjBif6d7Rl6Z9TPX63Ubh9+YgZKSg3jXOT3/RFmCH5xKRB6l+cN+yspNZsRqSwr5bcX08V4E4t2Gq0s/5h8YkF0hA9BbSF7aXPHPAoGBAJ8m7TunjuO7axFSGOIIC8l9wTSP8IP4GSxAmcJTEQwRsXT3u8vDBWnAhqYyMABnutEUjGz+rusjrOC/XKBIB3P1b414ujdgDno7ltrYjLkNh6TpLRoM4OU2Qb1ONJ4OnTPPy0MafcMKa7+qubJ5GF5jXSLb3QUWB/6z5+88/kzBAoGAWzcBjuAYmRa+Q9GpGRyml1SgS0foaKwycN9Az0IGaNmN+hvKBgoJtUvY5V/sDdNAbLz+1Hpc0s3TJpghmHTVxUrC0VKqhEyXpHIUN2IOjiqoiQbB1stW0GS3N9U4akQfYQrR7u+IcUizfs6OQTmTR3Xp6LryES/rLn0vwZKZIvo=-----END PRIVATE KEY----- 6 | demoiselle.security.jwt.publicKey=-----BEGIN PUBLIC KEY-----MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA09A11Zaqmp5ZBTOCxgJ8qqtHhb6b+eO9C8gAX3DXFIlfcl0FU7FVwfQtHWuN3KU83c1sSj9wPMuviGvZeSV7oUp2DXML76EsEKf9r+6JNZRdnTCkXZklQSEmeuftSxnMtAwo7k+eIgPpOIrYpMJv5GzVju0zbyucnwbQnDvoGv08pMrbWaGOxcnHXCazsrRTI7UKQ+jvMDB3bsUcII0XS+92ZLQkiMkKH85HSSlm4AFKuUljRh59RlpJrCDc+TUZWQuOC6Li/H9/78tAW8kJIHfASJhkKgkcdGixBJNggp+K+0hMWvxLt5fi1BXvWiy/Ma3QNHtxOCorRa+4NBB+KwIDAQAB-----END PUBLIC KEY----- 7 | demoiselle.security.jwt.timetoLiveMilliseconds=9999999999 8 | demoiselle.security.jwt.issuer=STORE 9 | demoiselle.security.jwt.audience=web 10 | demoiselle.security.jwt.algorithmIdentifiers=RS256 -------------------------------------------------------------------------------- /demoiselle-security-jwt/src/test/resources/org/demoiselle/jee/security/message/DemoiselleSecurityJWTMessages.properties: -------------------------------------------------------------------------------- 1 | general=Erro na gera\u00e7\u00e3o do token, verifique as configura\u00e7\u00f5es, https://demoiselle.gitbooks.io/documentacao-jee/content/jwt.html 2 | expired=Token inv\u00e1lido 3 | error=Erro 4 | master=master 5 | slave=slave 6 | not-jwt=Opera\u00e7\u00e3o n\u00e3o utilizada para JWT, https://demoiselle.gitbooks.io/documentacao-jee/content/jwt.html 7 | type-server=Type server: %s 8 | primary-key=Primary key: %s 9 | public-key=Public key: %s 10 | age-token=Age token in minutes: %s 11 | issuer=Issuer: %s 12 | audience=Audience: %s 13 | put-key=Coloque as chaves no arquivo demoiselle.properties, https://demoiselle.gitbooks.io/documentacao-jee/content/jwt.html 14 | choose-type=Escolha comportamento do servidor, https://demoiselle.gitbooks.io/documentacao-jee/content/jwt.html 15 | not-type=Os tipos de comportamento n\u00e3o encontrado, https://demoiselle.gitbooks.io/documentacao-jee/content/jwt.html -------------------------------------------------------------------------------- /demoiselle-security-token/.gitignore: -------------------------------------------------------------------------------- 1 | .settings 2 | .classpath 3 | .project 4 | .iml 5 | /target/ 6 | /bin/ 7 | -------------------------------------------------------------------------------- /demoiselle-security-token/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4.0.0 4 | demoiselle-security-token 5 | jar 6 | 7 | Demoiselle JEE Security Token 8 | 9 | Demoiselle Security Token 10 | 11 | http://demoiselle.io 12 | 13 | 14 | org.demoiselle.jee 15 | demoiselle-parent 16 | 3.0.6-SNAPSHOT 17 | ../demoiselle-parent 18 | 19 | 20 | 21 | org.demoiselle.jee 22 | demoiselle-security 23 | 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /demoiselle-security-token/src/main/resources/META-INF/beans.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | -------------------------------------------------------------------------------- /demoiselle-security-token/src/test/resources/META-INF/beans.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | -------------------------------------------------------------------------------- /demoiselle-security/.gitignore: -------------------------------------------------------------------------------- 1 | .settings 2 | .classpath 3 | .project 4 | /target/ 5 | /bin/ 6 | -------------------------------------------------------------------------------- /demoiselle-security/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4.0.0 4 | demoiselle-security 5 | jar 6 | 7 | Demoiselle JEE Security 8 | 9 | Demoiselle Security 10 | 11 | http://demoiselle.io 12 | 13 | 14 | org.demoiselle.jee 15 | demoiselle-parent 16 | 3.0.6-SNAPSHOT 17 | ../demoiselle-parent 18 | 19 | 20 | 21 | org.demoiselle.jee 22 | demoiselle-rest 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /demoiselle-security/src/main/java/org/demoiselle/jee/security/DemoiselleSecurityConfig.java: -------------------------------------------------------------------------------- 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 . 6 | */ 7 | package org.demoiselle.jee.security; 8 | 9 | import java.util.Map; 10 | import java.util.concurrent.ConcurrentHashMap; 11 | 12 | import org.demoiselle.jee.configuration.annotation.Configuration; 13 | 14 | /** 15 | * 16 | * @author SERPRO 17 | */ 18 | @Configuration(prefix = "demoiselle.security") 19 | public class DemoiselleSecurityConfig { 20 | 21 | private boolean corsEnabled; 22 | 23 | private final Map paramsHeaderSecuriry = new ConcurrentHashMap<>(); 24 | private final Map paramsHeaderCors = new ConcurrentHashMap<>(); 25 | 26 | public boolean isCorsEnabled() { 27 | return corsEnabled; 28 | } 29 | 30 | public Map getParamsHeaderSecuriry() { 31 | return paramsHeaderSecuriry; 32 | } 33 | 34 | public Map getParamsHeaderCors() { 35 | return paramsHeaderCors; 36 | } 37 | 38 | } 39 | -------------------------------------------------------------------------------- /demoiselle-security/src/main/java/org/demoiselle/jee/security/annotation/Authenticated.java: -------------------------------------------------------------------------------- 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 . 6 | */ 7 | package org.demoiselle.jee.security.annotation; 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.enterprise.util.Nonbinding; 18 | import javax.interceptor.InterceptorBinding; 19 | 20 | /** 21 | *

22 | * Indicates that a authentication is required 23 | *

24 | * @see Documentation 25 | * 26 | * @author SERPRO 27 | */ 28 | @Inherited 29 | @InterceptorBinding 30 | @Target({METHOD, TYPE}) 31 | @Retention(RUNTIME) 32 | public @interface Authenticated { 33 | 34 | @Nonbinding 35 | boolean enable() default true; 36 | 37 | } 38 | -------------------------------------------------------------------------------- /demoiselle-security/src/main/java/org/demoiselle/jee/security/annotation/Cors.java: -------------------------------------------------------------------------------- 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 . 6 | */ 7 | package org.demoiselle.jee.security.annotation; 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.enterprise.util.Nonbinding; 18 | import javax.interceptor.InterceptorBinding; 19 | 20 | /** 21 | *

22 | * Server cors handling 23 | *

24 | * 25 | * @see Documentation 26 | * @author SERPRO 27 | */ 28 | @Inherited 29 | @InterceptorBinding 30 | @Target({METHOD, TYPE}) 31 | @Retention(RUNTIME) 32 | public @interface Cors { 33 | 34 | @Nonbinding 35 | boolean enable() default true; 36 | } 37 | -------------------------------------------------------------------------------- /demoiselle-security/src/main/java/org/demoiselle/jee/security/annotation/RequiredPermission.java: -------------------------------------------------------------------------------- 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 . 6 | */ 7 | package org.demoiselle.jee.security.annotation; 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.enterprise.util.Nonbinding; 18 | import javax.interceptor.InterceptorBinding; 19 | 20 | /** 21 | *

22 | * Indicates that a specific permission is required in order to invocate the 23 | * annotated method or class. 24 | *

25 | * 26 | * @see Documentation 27 | * @author SERPRO 28 | */ 29 | @Inherited 30 | @InterceptorBinding 31 | @Target({METHOD, TYPE}) 32 | @Retention(RUNTIME) 33 | public @interface RequiredPermission { 34 | 35 | @Nonbinding 36 | String resource() default ""; 37 | 38 | @Nonbinding 39 | String operation() default ""; 40 | } 41 | -------------------------------------------------------------------------------- /demoiselle-security/src/main/java/org/demoiselle/jee/security/annotation/RequiredRole.java: -------------------------------------------------------------------------------- 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 . 6 | */ 7 | package org.demoiselle.jee.security.annotation; 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.enterprise.util.Nonbinding; 18 | import javax.interceptor.InterceptorBinding; 19 | 20 | /** 21 | *

22 | * Indicates that the annotated method or class requires the user to have one or 23 | * more roles associated in order to be invocated. 24 | *

25 | * 26 | * @see Documentation 27 | * @author SERPRO 28 | */ 29 | @Inherited 30 | @InterceptorBinding 31 | @Target({METHOD, TYPE}) 32 | @Retention(RUNTIME) 33 | public @interface RequiredRole { 34 | 35 | @Nonbinding 36 | String[] value(); 37 | } 38 | -------------------------------------------------------------------------------- /demoiselle-security/src/main/java/org/demoiselle/jee/security/exception/DemoiselleSecurityException.java: -------------------------------------------------------------------------------- 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 . 6 | */ 7 | package org.demoiselle.jee.security.exception; 8 | 9 | import javax.ws.rs.core.Response.Status; 10 | 11 | import org.demoiselle.jee.rest.exception.DemoiselleRestException; 12 | 13 | /** 14 | * 15 | * @author SERPRO 16 | */ 17 | public class DemoiselleSecurityException extends DemoiselleRestException { 18 | 19 | private static final long serialVersionUID = 519_965_615_171_844_237L; 20 | 21 | public DemoiselleSecurityException(String string) { 22 | super(string); 23 | this.statusCode = Status.INTERNAL_SERVER_ERROR.getStatusCode(); 24 | } 25 | 26 | public DemoiselleSecurityException(String string, int statusCode) { 27 | super(string); 28 | this.statusCode = statusCode; 29 | } 30 | 31 | public DemoiselleSecurityException(String string, int statusCode, Exception ex) { 32 | super(string); 33 | this.statusCode = statusCode; 34 | } 35 | 36 | @Override 37 | public int getStatusCode() { 38 | return statusCode; 39 | } 40 | 41 | } 42 | -------------------------------------------------------------------------------- /demoiselle-security/src/main/java/org/demoiselle/jee/security/filter/CorsFilter.java: -------------------------------------------------------------------------------- 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 . 6 | */ 7 | package org.demoiselle.jee.security.filter; 8 | 9 | import java.io.IOException; 10 | import java.lang.reflect.Method; 11 | import javax.annotation.Priority; 12 | 13 | import javax.inject.Inject; 14 | import static javax.ws.rs.Priorities.AUTHORIZATION; 15 | import javax.ws.rs.container.ContainerRequestContext; 16 | import javax.ws.rs.container.ContainerResponseContext; 17 | import javax.ws.rs.container.ContainerResponseFilter; 18 | import javax.ws.rs.container.ResourceInfo; 19 | import javax.ws.rs.core.Context; 20 | import javax.ws.rs.ext.Provider; 21 | 22 | import org.demoiselle.jee.security.DemoiselleSecurityConfig; 23 | import org.demoiselle.jee.security.annotation.Cors; 24 | 25 | /** 26 | *

27 | * Server cors handling 28 | *

29 | * 30 | * @see 31 | * Documentation 32 | * 33 | * @author SERPRO 34 | */ 35 | @Provider 36 | @Priority(AUTHORIZATION) 37 | public class CorsFilter implements ContainerResponseFilter { 38 | 39 | @Inject 40 | private DemoiselleSecurityConfig config; 41 | 42 | @Context 43 | private ResourceInfo info; 44 | 45 | @Override 46 | public void filter(ContainerRequestContext req, ContainerResponseContext res) throws IOException { 47 | Method method = info.getResourceMethod(); 48 | Class classe = info.getResourceClass(); 49 | boolean corsEnable = config.isCorsEnabled(); 50 | 51 | res.getHeaders().putSingle("Demoiselle-security", "Enable"); 52 | 53 | config.getParamsHeaderSecuriry().entrySet().stream().forEach((entry) -> { 54 | res.getHeaders().putSingle(entry.getKey(), entry.getValue()); 55 | }); 56 | 57 | if (method != null && classe != null && method.getAnnotation(Cors.class) != null) { 58 | corsEnable = method.getAnnotation(Cors.class).enable(); 59 | } 60 | 61 | if (config.isCorsEnabled() && corsEnable) { 62 | config.getParamsHeaderCors().entrySet().stream().forEach((entry) -> { 63 | res.getHeaders().putSingle(entry.getKey(), entry.getValue()); 64 | }); 65 | } else { 66 | res.getHeaders().remove("Access-Control-Allow-Origin"); 67 | res.getHeaders().remove("Access-Control-Allow-Methods"); 68 | } 69 | 70 | } 71 | 72 | } 73 | -------------------------------------------------------------------------------- /demoiselle-security/src/main/java/org/demoiselle/jee/security/filter/SecurityFilter.java: -------------------------------------------------------------------------------- 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 . 6 | */ 7 | package org.demoiselle.jee.security.filter; 8 | 9 | import static javax.ws.rs.core.Response.ok; 10 | 11 | import java.io.IOException; 12 | import java.util.logging.Logger; 13 | 14 | import javax.annotation.Priority; 15 | import javax.inject.Inject; 16 | import static javax.ws.rs.Priorities.AUTHORIZATION; 17 | import javax.ws.rs.container.ContainerRequestContext; 18 | import javax.ws.rs.container.ContainerRequestFilter; 19 | import javax.ws.rs.container.PreMatching; 20 | import javax.ws.rs.core.Response; 21 | import javax.ws.rs.ext.Provider; 22 | 23 | import org.demoiselle.jee.core.api.security.Token; 24 | import org.demoiselle.jee.core.api.security.TokenType; 25 | import org.demoiselle.jee.security.DemoiselleSecurityConfig; 26 | 27 | /** 28 | *

29 | * Server cors handling 30 | *

31 | * 32 | * @see 33 | * Documentation 34 | * 35 | * @author SERPRO 36 | */ 37 | @Provider 38 | @PreMatching 39 | @Priority(AUTHORIZATION) 40 | public class SecurityFilter implements ContainerRequestFilter { 41 | 42 | private static final Logger logger = Logger.getLogger(SecurityFilter.class.getName()); 43 | 44 | @Inject 45 | private DemoiselleSecurityConfig config; 46 | 47 | @Inject 48 | private Token token; 49 | 50 | @Override 51 | public void filter(ContainerRequestContext req) throws IOException { 52 | if (req.getMethod().equals("OPTIONS")) { 53 | Response.ResponseBuilder responseBuilder = ok(); 54 | if (config.isCorsEnabled()) { 55 | config.getParamsHeaderSecuriry().entrySet().stream().forEach((entry) -> { 56 | responseBuilder.header(entry.getKey(), entry.getValue()); 57 | }); 58 | } 59 | req.abortWith(responseBuilder.build()); 60 | } 61 | 62 | try { 63 | if (req.getHeaders().containsKey("Authorization")) { 64 | String chave = req.getHeaders().get("Authorization").toString().replace("[", "").replace("]", ""); 65 | if (!chave.isEmpty()) { 66 | token.setType(TokenType.valueOf(chave.split(" ")[0].toUpperCase())); 67 | token.setKey(chave.split(" ")[1]); 68 | } 69 | } 70 | } catch (Exception e) { 71 | logger.severe(e.getMessage()); 72 | } 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /demoiselle-security/src/main/java/org/demoiselle/jee/security/impl/SecurityContextImpl.java: -------------------------------------------------------------------------------- 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 . 6 | */ 7 | package org.demoiselle.jee.security.impl; 8 | 9 | import java.util.List; 10 | 11 | import javax.enterprise.context.RequestScoped; 12 | import javax.inject.Inject; 13 | 14 | import org.demoiselle.jee.core.api.security.DemoiselleUser; 15 | import org.demoiselle.jee.core.api.security.SecurityContext; 16 | import org.demoiselle.jee.core.api.security.TokenManager; 17 | 18 | /** 19 | *

20 | * It manages the security features and serves as a hub for specific 21 | * imlementations, look at JWT and Token 22 | *

23 | * 24 | * @see Documentation 25 | * 26 | * @author SERPRO 27 | */ 28 | @RequestScoped 29 | public class SecurityContextImpl implements SecurityContext { 30 | 31 | @Inject 32 | private TokenManager tm; 33 | 34 | @Override 35 | public boolean hasPermission(String resource, String operation) { 36 | 37 | List list = getUser().getPermissions().get(resource); 38 | 39 | if (list != null && !list.isEmpty()) { 40 | return list.contains(operation); 41 | } 42 | 43 | return false; 44 | } 45 | 46 | @Override 47 | public boolean hasRole(String role) { 48 | return getUser().getRoles().contains(role); 49 | } 50 | 51 | @Override 52 | public boolean isLoggedIn() { 53 | return tm.validate(); 54 | } 55 | 56 | @Override 57 | public DemoiselleUser getUser() { 58 | return tm.getUser(); 59 | } 60 | 61 | @Override 62 | public void setUser(DemoiselleUser loggedUser) { 63 | tm.setUser(loggedUser); 64 | } 65 | 66 | @Override 67 | public DemoiselleUser getUser(String issuer, String audience) { 68 | return tm.getUser(issuer, audience); 69 | } 70 | 71 | @Override 72 | public void setUser(DemoiselleUser loggedUser, String issuer, String audience) { 73 | tm.setUser(loggedUser, issuer, audience); 74 | } 75 | 76 | @Override 77 | public void removeUser(DemoiselleUser loggedUser) { 78 | tm.removeUser(loggedUser); 79 | } 80 | 81 | } 82 | -------------------------------------------------------------------------------- /demoiselle-security/src/main/java/org/demoiselle/jee/security/impl/TokenImpl.java: -------------------------------------------------------------------------------- 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 . 6 | */ 7 | package org.demoiselle.jee.security.impl; 8 | 9 | import java.util.Objects; 10 | 11 | import javax.enterprise.context.RequestScoped; 12 | 13 | import org.demoiselle.jee.core.api.security.Token; 14 | import org.demoiselle.jee.core.api.security.TokenType; 15 | 16 | /** 17 | *

18 | * Object loaded to each request containing the token sent in http header 19 | *

20 | * 21 | * @see 22 | * Documentation 23 | * 24 | * @author SERPRO 25 | */ 26 | @RequestScoped 27 | public class TokenImpl implements Token { 28 | 29 | private String key; 30 | private TokenType type; 31 | 32 | @Override 33 | public String getKey() { 34 | return key; 35 | } 36 | 37 | @Override 38 | public void setKey(String key) { 39 | this.key = key; 40 | } 41 | 42 | @Override 43 | public TokenType getType() { 44 | return type; 45 | } 46 | 47 | @Override 48 | public void setType(TokenType type) { 49 | this.type = type; 50 | } 51 | 52 | @Override 53 | public int hashCode() { 54 | int hash = 5; 55 | hash = 23 * hash + Objects.hashCode(this.key); 56 | return hash; 57 | } 58 | 59 | @Override 60 | public boolean equals(Object obj) { 61 | if (this == obj) { 62 | return true; 63 | } 64 | if (obj == null) { 65 | return false; 66 | } 67 | if (getClass() != obj.getClass()) { 68 | return false; 69 | } 70 | final TokenImpl other = (TokenImpl) obj; 71 | return Objects.equals(this.key, other.key); 72 | } 73 | 74 | @Override 75 | public String toString() { 76 | return "{" + "\"key\":\"" + key + "\", \"type\":\"" + type.toString() + "\"}"; 77 | } 78 | 79 | } 80 | -------------------------------------------------------------------------------- /demoiselle-security/src/main/java/org/demoiselle/jee/security/interceptor/AuthenticatedInterceptor.java: -------------------------------------------------------------------------------- 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 . 6 | */ 7 | package org.demoiselle.jee.security.interceptor; 8 | 9 | import java.io.Serializable; 10 | 11 | import javax.annotation.Priority; 12 | import javax.inject.Inject; 13 | import javax.interceptor.AroundInvoke; 14 | import javax.interceptor.Interceptor; 15 | import javax.interceptor.InvocationContext; 16 | import static javax.ws.rs.core.Response.Status.FORBIDDEN; 17 | 18 | import org.demoiselle.jee.core.api.security.SecurityContext; 19 | import org.demoiselle.jee.security.annotation.Authenticated; 20 | import org.demoiselle.jee.security.exception.DemoiselleSecurityException; 21 | import org.demoiselle.jee.security.message.DemoiselleSecurityMessages; 22 | 23 | /** 24 | *

25 | * Intercepts calls with {@link Authenticated} annotations. 26 | *

27 | * 28 | * @author SERPRO 29 | */ 30 | @Authenticated 31 | @Interceptor 32 | @Priority(Interceptor.Priority.APPLICATION) 33 | public class AuthenticatedInterceptor implements Serializable { 34 | 35 | private static final long serialVersionUID = 1L; 36 | 37 | @Inject 38 | private SecurityContext securityContext; 39 | 40 | @Inject 41 | private DemoiselleSecurityMessages bundle; 42 | 43 | @AroundInvoke 44 | public Object manage(final InvocationContext ic) throws Exception { 45 | Authenticated logged = ic.getMethod().getAnnotation(Authenticated.class); 46 | 47 | if (logged != null && !logged.enable()) { 48 | return ic.proceed(); 49 | } 50 | 51 | if (!securityContext.isLoggedIn()) { 52 | throw new DemoiselleSecurityException(bundle.userNotAuthenticated(), FORBIDDEN.getStatusCode()); 53 | } 54 | 55 | return ic.proceed(); 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /demoiselle-security/src/main/java/org/demoiselle/jee/security/message/DemoiselleSecurityMessages.java: -------------------------------------------------------------------------------- 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 . 6 | */ 7 | package org.demoiselle.jee.security.message; 8 | 9 | import org.apache.deltaspike.core.api.message.MessageBundle; 10 | import org.apache.deltaspike.core.api.message.MessageTemplate; 11 | 12 | /** 13 | * 14 | * @author SERPRO 15 | */ 16 | @MessageBundle 17 | public interface DemoiselleSecurityMessages { 18 | 19 | @MessageTemplate("{access-checking-permission}") 20 | String accessCheckingPermission(String operacao, String recurso); 21 | 22 | @MessageTemplate("{access-denied}") 23 | String accessDenied(String usuario, String operacao, String recurso); 24 | 25 | @MessageTemplate("{user-not-authenticated}") 26 | String userNotAuthenticated(); 27 | 28 | @MessageTemplate("{invalid-credentials}") 29 | String invalidCredentials(); 30 | 31 | @MessageTemplate("{does-not-have-role}") 32 | String doesNotHaveRole(String role); 33 | 34 | @MessageTemplate("{does-not-have-permission}") 35 | String doesNotHavePermission(String operacao, String recurso); 36 | 37 | } 38 | -------------------------------------------------------------------------------- /demoiselle-security/src/main/resources/META-INF/beans.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | -------------------------------------------------------------------------------- /demoiselle-security/src/main/resources/demoiselle.properties: -------------------------------------------------------------------------------- 1 | demoiselle.security.corsEnabled=false 2 | -------------------------------------------------------------------------------- /demoiselle-security/src/main/resources/org/demoiselle/jee/security/message/DemoiselleSecurityMessages.properties: -------------------------------------------------------------------------------- 1 | access-checking-permission=O usu\u00e1rio n\u00e3o tem permiss\u00e3o para executar a a\u00e7\u00e3o %s no recurso %s 2 | access-checking-role=Verificando permiss\u00e3o do usu\u00e1rio %s para a role %s 3 | access-allowed=O usu\u00e1rio %s acessou o recurso %s com a a\u00e7\u00e3o %s 4 | access-denied=O usu\u00e1rio n\u00e3o possui permiss\u00e3o para executar a a\u00e7\u00e3o %s no recurso %s 5 | user-not-authenticated=Usu\u00e1rio n\u00e3o autenticado 6 | invalid-credentials=Usu\u00e1rio ou senha inv\u00e1lidos 7 | does-not-have-role=O Usu\u00e1rio n\u00e3o possui a role\:%s 8 | does-not-have-permission=O Usu\u00e1rio n\u00e3o possui a permiss\u00e3o para executar a a\u00e7\u00e3o %s no recurso %s 9 | -------------------------------------------------------------------------------- /demoiselle-security/src/test/java/org/demoiselle/jee/security/DemoiselleSecurityConfigTest.java: -------------------------------------------------------------------------------- 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 . 6 | */ 7 | package org.demoiselle.jee.security; 8 | 9 | import static org.junit.Assert.assertEquals; 10 | 11 | import javax.inject.Inject; 12 | 13 | import org.apache.deltaspike.testcontrol.api.junit.CdiTestRunner; 14 | import org.junit.After; 15 | import org.junit.AfterClass; 16 | import org.junit.Before; 17 | import org.junit.BeforeClass; 18 | import org.junit.Test; 19 | import org.junit.runner.RunWith; 20 | 21 | /** 22 | * 23 | * @author SERPRO 24 | */ 25 | @RunWith(CdiTestRunner.class) 26 | public class DemoiselleSecurityConfigTest { 27 | 28 | @Inject 29 | private DemoiselleSecurityConfig instance; 30 | 31 | @BeforeClass 32 | public static void setUpClass() { 33 | } 34 | 35 | @AfterClass 36 | public static void tearDownClass() { 37 | } 38 | 39 | public DemoiselleSecurityConfigTest() { 40 | } 41 | 42 | @Before 43 | public void setUp() { 44 | } 45 | 46 | @After 47 | public void tearDown() { 48 | } 49 | 50 | /** 51 | * Test of isCorsEnabled method, of class DemoiselleSecurityConfig. 52 | */ 53 | @Test 54 | public void test11() { 55 | boolean expResult = true; 56 | boolean result = instance.isCorsEnabled(); 57 | assertEquals(expResult, result); 58 | } 59 | 60 | } 61 | -------------------------------------------------------------------------------- /demoiselle-security/src/test/java/org/demoiselle/jee/security/exception/DemoiselleSecurityExceptionTest.java: -------------------------------------------------------------------------------- 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 . 6 | */ 7 | package org.demoiselle.jee.security.exception; 8 | 9 | import static org.junit.Assert.assertEquals; 10 | 11 | import java.util.HashSet; 12 | 13 | import org.demoiselle.jee.rest.exception.DemoiselleRestExceptionMessage; 14 | import org.junit.After; 15 | import org.junit.AfterClass; 16 | import org.junit.Before; 17 | import org.junit.BeforeClass; 18 | import org.junit.Test; 19 | 20 | /** 21 | * 22 | * @author SERPRO 23 | */ 24 | public class DemoiselleSecurityExceptionTest { 25 | 26 | @BeforeClass 27 | public static void setUpClass() { 28 | } 29 | 30 | @AfterClass 31 | public static void tearDownClass() { 32 | } 33 | private DemoiselleSecurityException instance; 34 | 35 | public DemoiselleSecurityExceptionTest() { 36 | } 37 | 38 | @Before 39 | public void setUp() { 40 | instance = new DemoiselleSecurityException("Teste"); 41 | } 42 | 43 | @After 44 | public void tearDown() { 45 | } 46 | 47 | /** 48 | * Test of getStatusCode method, of class DemoiselleSecurityException. 49 | */ 50 | @Test 51 | public void testGetStatusCode() { 52 | int expResult = 500; 53 | int result = instance.getStatusCode(); 54 | assertEquals(expResult, result); 55 | } 56 | 57 | /** 58 | * Test of addMessage method, of class DemoiselleSecurityException. 59 | */ 60 | @Test 61 | public void testAddMessage() { 62 | instance = new DemoiselleSecurityException("Teste", 500); 63 | String field = "Teste"; 64 | String msg = "Teste"; 65 | instance.addMessage(field, msg); 66 | } 67 | 68 | /** 69 | * Test of getMessages method, of class DemoiselleSecurityException. 70 | */ 71 | @Test 72 | public void testGetMessages() { 73 | HashSet expResult = new HashSet<>(); 74 | HashSet result = instance.getMessages(); 75 | assertEquals(expResult, result); 76 | } 77 | 78 | } 79 | -------------------------------------------------------------------------------- /demoiselle-security/src/test/java/org/demoiselle/jee/security/impl/TokenImplTest.java: -------------------------------------------------------------------------------- 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 . 6 | */ 7 | package org.demoiselle.jee.security.impl; 8 | 9 | import static org.junit.Assert.assertEquals; 10 | import static org.junit.Assert.assertNotEquals; 11 | 12 | import javax.enterprise.context.RequestScoped; 13 | import javax.inject.Inject; 14 | 15 | import org.apache.deltaspike.testcontrol.api.TestControl; 16 | import org.apache.deltaspike.testcontrol.api.junit.CdiTestRunner; 17 | import org.demoiselle.jee.core.api.security.Token; 18 | import org.demoiselle.jee.core.api.security.TokenType; 19 | import org.junit.After; 20 | import org.junit.AfterClass; 21 | import org.junit.Before; 22 | import org.junit.BeforeClass; 23 | import org.junit.Test; 24 | import org.junit.runner.RunWith; 25 | 26 | /** 27 | * 28 | * @author SERPRO 29 | */ 30 | @RunWith(CdiTestRunner.class) 31 | @TestControl(startScopes = RequestScoped.class) 32 | public class TokenImplTest { 33 | 34 | @BeforeClass 35 | public static void setUpClass() { 36 | } 37 | 38 | @AfterClass 39 | public static void tearDownClass() { 40 | } 41 | 42 | @Inject 43 | private Token instance; 44 | 45 | public TokenImplTest() { 46 | } 47 | 48 | @Before 49 | public void setUp() { 50 | } 51 | 52 | @After 53 | public void tearDown() { 54 | } 55 | 56 | @Test 57 | public void test11() { 58 | String key = "123456789"; 59 | instance.setKey(key); 60 | } 61 | 62 | @Test 63 | public void test12() { 64 | String expResult = "123456789"; 65 | String result = instance.getKey(); 66 | assertEquals(expResult, result); 67 | } 68 | 69 | @Test 70 | public void test13() { 71 | instance.setType(TokenType.JWT); 72 | } 73 | 74 | @Test 75 | public void test14() { 76 | TokenType expResult = TokenType.JWT; 77 | TokenType result = instance.getType(); 78 | assertEquals(expResult, result); 79 | } 80 | 81 | @Test 82 | public void test15() { 83 | int expResult = 0; 84 | int result = instance.hashCode(); 85 | assertNotEquals(expResult, result); 86 | } 87 | 88 | @Test 89 | public void test16() { 90 | Object obj = null; 91 | boolean expResult = false; 92 | boolean result = instance.equals(obj); 93 | assertEquals(expResult, result); 94 | } 95 | 96 | @Test 97 | public void test17() { 98 | String expResult = "{\"key\":\"123456789\", \"type\":\"JWT\"}"; 99 | String result = instance.toString(); 100 | assertEquals(expResult, result); 101 | } 102 | 103 | } 104 | -------------------------------------------------------------------------------- /demoiselle-security/src/test/java/org/demoiselle/jee/security/interceptor/LoggedInInterceptorTest.java: -------------------------------------------------------------------------------- 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 . 6 | */ 7 | package org.demoiselle.jee.security.interceptor; 8 | 9 | 10 | import org.junit.After; 11 | import org.junit.AfterClass; 12 | import org.junit.Before; 13 | import org.junit.BeforeClass; 14 | 15 | 16 | /** 17 | * 18 | * @author SERPRO 19 | */ 20 | //@RunWith(CdiTestRunner.class) 21 | public class LoggedInInterceptorTest { 22 | 23 | // @Inject 24 | // private LoggedInInterceptor instance; 25 | @BeforeClass 26 | public static void setUpClass() { 27 | } 28 | 29 | @AfterClass 30 | public static void tearDownClass() { 31 | } 32 | 33 | public LoggedInInterceptorTest() { 34 | } 35 | 36 | @Before 37 | public void setUp() { 38 | } 39 | 40 | @After 41 | public void tearDown() { 42 | } 43 | 44 | //@Test 45 | public void testManage() throws Exception { 46 | // InvocationContext ic = null; 47 | // Object expResult = null; 48 | // Object result = instance.manage(ic); 49 | // assertEquals(expResult, result); 50 | } 51 | 52 | } 53 | -------------------------------------------------------------------------------- /demoiselle-security/src/test/java/org/demoiselle/jee/security/interceptor/RequiredPermissionInterceptorTest.java: -------------------------------------------------------------------------------- 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 . 6 | */ 7 | package org.demoiselle.jee.security.interceptor; 8 | 9 | import static org.junit.Assert.assertEquals; 10 | 11 | import javax.interceptor.InvocationContext; 12 | 13 | import org.junit.After; 14 | import org.junit.AfterClass; 15 | import org.junit.Before; 16 | import org.junit.BeforeClass; 17 | 18 | 19 | /** 20 | * 21 | * @author SERPRO 22 | */ 23 | //@RunWith(CdiTestRunner.class) 24 | public class RequiredPermissionInterceptorTest { 25 | 26 | @BeforeClass 27 | public static void setUpClass() { 28 | } 29 | 30 | @AfterClass 31 | public static void tearDownClass() { 32 | } 33 | 34 | public RequiredPermissionInterceptorTest() { 35 | } 36 | 37 | @Before 38 | public void setUp() { 39 | } 40 | 41 | @After 42 | public void tearDown() { 43 | } 44 | 45 | /** 46 | * Test of manage method, of class RequiredPermissionInterceptor. 47 | */ 48 | //@Test 49 | public void testManage() throws Exception { 50 | InvocationContext ic = null; 51 | RequiredPermissionInterceptor instance = new RequiredPermissionInterceptor(); 52 | Object expResult = null; 53 | Object result = instance.manage(ic); 54 | assertEquals(expResult, result); 55 | } 56 | 57 | } 58 | -------------------------------------------------------------------------------- /demoiselle-security/src/test/java/org/demoiselle/jee/security/interceptor/RequiredRoleInterceptorTest.java: -------------------------------------------------------------------------------- 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 . 6 | */ 7 | package org.demoiselle.jee.security.interceptor; 8 | 9 | import static org.junit.Assert.assertEquals; 10 | 11 | import javax.interceptor.InvocationContext; 12 | 13 | import org.junit.After; 14 | import org.junit.AfterClass; 15 | import org.junit.Before; 16 | import org.junit.BeforeClass; 17 | 18 | 19 | 20 | /** 21 | * 22 | * @author SERPRO 23 | */ 24 | //@RunWith(CdiTestRunner.class) 25 | public class RequiredRoleInterceptorTest { 26 | 27 | @BeforeClass 28 | public static void setUpClass() { 29 | } 30 | 31 | @AfterClass 32 | public static void tearDownClass() { 33 | } 34 | 35 | public RequiredRoleInterceptorTest() { 36 | } 37 | 38 | @Before 39 | public void setUp() { 40 | } 41 | 42 | @After 43 | public void tearDown() { 44 | } 45 | 46 | /** 47 | * Test of manage method, of class RequiredRoleInterceptor. 48 | */ 49 | //@Test 50 | public void testManage() throws Exception { 51 | InvocationContext ic = null; 52 | RequiredRoleInterceptor instance = new RequiredRoleInterceptor(); 53 | Object expResult = null; 54 | Object result = instance.manage(ic); 55 | assertEquals(expResult, result); 56 | } 57 | 58 | } 59 | -------------------------------------------------------------------------------- /demoiselle-security/src/test/resources/META-INF/beans.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /demoiselle-security/src/test/resources/demoiselle.properties: -------------------------------------------------------------------------------- 1 | demoiselle.security.corsEnabled=true 2 | demoiselle.security.paramsHeaderSecuriry= x-content-type-options=nosniff, x-frame-options=SAMEORIGIN, x-xss-protection=1; mode=block 3 | -------------------------------------------------------------------------------- /demoiselle-security/src/test/resources/org/demoiselle/jee/security/message/DemoiselleSecurityMessages.properties: -------------------------------------------------------------------------------- 1 | access-checking-permission=O usu\u00e1rio n\u00e3o tem permiss\u00e3o para executar a a\u00e7\u00e3o %s no recurso %s 2 | access-checking-role=Verificando permiss\u00e3o do usu\u00e1rio %s para a role %s 3 | access-allowed=O usu\u00e1rio %s acessou o recurso %s com a a\u00e7\u00e3o %s 4 | access-denied=O usu\u00e1rio n\u00e3o possui permiss\u00e3o para executar a a\u00e7\u00e3o %s no recurso %s 5 | user-not-authenticated=Usu\u00e1rio n\u00e3o autenticado 6 | invalid-credentials=Usu\u00e1rio ou senha inv\u00e1lidos 7 | does-not-have-role=O Usu\u00e1rio n\u00e3o possui a role\:%s 8 | does-not-have-permission=O Usu\u00e1rio n\u00e3o possui a permiss\u00e3o para executar a a\u00e7\u00e3o %s no recurso %s 9 | -------------------------------------------------------------------------------- /licence-lgpl/header-definitions.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | /* 6 | * 7 | */ 8 | (\s|\t)*/\*.*$ 9 | .*\*/(\s|\t)*$ 10 | false 11 | true 12 | false 13 | 14 | -------------------------------------------------------------------------------- /licence-lgpl/header.txt: -------------------------------------------------------------------------------- 1 | Demoiselle Framework 2 | 3 | License: GNU Lesser General Public License (LGPL), version 3 or later. 4 | See the lgpl.txt file in the root directory or . --------------------------------------------------------------------------------