Commit 747b465e7a4d15ac46161d07afd294004c06c91e

Authored by Cleverson Sacramento
2 parents eed30b2f 05b10599
Exists in master

Merge branch '2.3' of https://github.com/demoiselle/framework.git into 2.3

impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/bootstrap/AbstractStrategyBootstrap.java 0 → 100644
... ... @@ -0,0 +1,118 @@
  1 +/*
  2 + * Demoiselle Framework
  3 + * Copyright (C) 2010 SERPRO
  4 + * ----------------------------------------------------------------------------
  5 + * This file is part of Demoiselle Framework.
  6 + *
  7 + * Demoiselle Framework is free software; you can redistribute it and/or
  8 + * modify it under the terms of the GNU Lesser General Public License version 3
  9 + * as published by the Free Software Foundation.
  10 + *
  11 + * This program is distributed in the hope that it will be useful,
  12 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14 + * GNU General Public License for more details.
  15 + *
  16 + * You should have received a copy of the GNU Lesser General Public License version 3
  17 + * along with this program; if not, see <http://www.gnu.org/licenses/>
  18 + * or write to the Free Software Foundation, Inc., 51 Franklin Street,
  19 + * Fifth Floor, Boston, MA 02110-1301, USA.
  20 + * ----------------------------------------------------------------------------
  21 + * Este arquivo é parte do Framework Demoiselle.
  22 + *
  23 + * O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou
  24 + * modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação
  25 + * do Software Livre (FSF).
  26 + *
  27 + * Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA
  28 + * GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou
  29 + * APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português
  30 + * para maiores detalhes.
  31 + *
  32 + * Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título
  33 + * "LICENCA.txt", junto com esse programa. Se não, acesse <http://www.gnu.org/licenses/>
  34 + * ou escreva para a Fundação do Software Livre (FSF) Inc.,
  35 + * 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA.
  36 + */
  37 +package br.gov.frameworkdemoiselle.internal.bootstrap;
  38 +
  39 +import javax.enterprise.event.Observes;
  40 +import javax.enterprise.inject.spi.BeforeBeanDiscovery;
  41 +import javax.enterprise.inject.spi.ProcessAnnotatedType;
  42 +
  43 +import org.apache.commons.configuration.Configuration;
  44 +import org.apache.commons.configuration.PropertiesConfiguration;
  45 +
  46 +import br.gov.frameworkdemoiselle.configuration.ConfigurationException;
  47 +import br.gov.frameworkdemoiselle.util.Reflections;
  48 +import br.gov.frameworkdemoiselle.util.Strings;
  49 +
  50 +public abstract class AbstractStrategyBootstrap<T, D extends T> extends AbstractBootstrap {
  51 +
  52 + private Class<T> type;
  53 +
  54 + private Class<D> defaultClass;
  55 +
  56 + private Class<? extends T> selected;
  57 +
  58 + private Class<T> getType() {
  59 + if (this.type == null) {
  60 + this.type = Reflections.getGenericTypeArgument(this.getClass(), 0);
  61 + }
  62 +
  63 + return this.type;
  64 + }
  65 +
  66 + private Class<D> getDefaultClass() {
  67 + if (this.defaultClass == null) {
  68 + this.defaultClass = Reflections.getGenericTypeArgument(this.getClass(), 1);
  69 + }
  70 +
  71 + return this.defaultClass;
  72 + }
  73 +
  74 + public void beforeBeanDiscovery(@Observes final BeforeBeanDiscovery event) {
  75 + selected = loadSelected();
  76 + }
  77 +
  78 + public <A> void processAnnotatedType(@Observes final ProcessAnnotatedType<A> event) {
  79 + Class<A> annotated = event.getAnnotatedType().getJavaClass();
  80 +
  81 + if (Reflections.isOfType(annotated, getType()) && annotated != selected) {
  82 + event.veto();
  83 + }
  84 + }
  85 +
  86 + @SuppressWarnings("unchecked")
  87 + private Class<T> loadSelected() {
  88 + Class<T> result = null;
  89 + String canonicalName = null;
  90 + String typeName = getType().getSimpleName().toLowerCase();
  91 + String key = null;
  92 +
  93 + try {
  94 + Configuration config = new PropertiesConfiguration("demoiselle.properties");
  95 + canonicalName = config.getString(getConfigurationKey(), getDefaultClass().getCanonicalName());
  96 +
  97 + ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
  98 + result = (Class<T>) Class.forName(canonicalName, false, classLoader);
  99 + result.asSubclass(getType());
  100 +
  101 + } catch (org.apache.commons.configuration.ConfigurationException cause) {
  102 + throw new ConfigurationException(getBundle().getString("file-not-found", "demoiselle.properties"));
  103 +
  104 + } catch (ClassNotFoundException cause) {
  105 + key = Strings.getString("{0}-class-not-found", typeName);
  106 + throw new ConfigurationException(getBundle().getString(key, canonicalName));
  107 +
  108 + } catch (ClassCastException cause) {
  109 + key = Strings.getString("{0}-class-must-be-of-type", typeName);
  110 + throw new ConfigurationException(getBundle().getString(key, canonicalName, getType()));
  111 + }
  112 +
  113 + return result;
  114 + }
  115 +
  116 + public abstract String getConfigurationKey();
  117 +
  118 +}
... ...
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/bootstrap/AuthenticatorBootstrap.java 0 → 100644
... ... @@ -0,0 +1,48 @@
  1 +/*
  2 + * Demoiselle Framework
  3 + * Copyright (C) 2010 SERPRO
  4 + * ----------------------------------------------------------------------------
  5 + * This file is part of Demoiselle Framework.
  6 + *
  7 + * Demoiselle Framework is free software; you can redistribute it and/or
  8 + * modify it under the terms of the GNU Lesser General Public License version 3
  9 + * as published by the Free Software Foundation.
  10 + *
  11 + * This program is distributed in the hope that it will be useful,
  12 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14 + * GNU General Public License for more details.
  15 + *
  16 + * You should have received a copy of the GNU Lesser General Public License version 3
  17 + * along with this program; if not, see <http://www.gnu.org/licenses/>
  18 + * or write to the Free Software Foundation, Inc., 51 Franklin Street,
  19 + * Fifth Floor, Boston, MA 02110-1301, USA.
  20 + * ----------------------------------------------------------------------------
  21 + * Este arquivo é parte do Framework Demoiselle.
  22 + *
  23 + * O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou
  24 + * modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação
  25 + * do Software Livre (FSF).
  26 + *
  27 + * Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA
  28 + * GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou
  29 + * APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português
  30 + * para maiores detalhes.
  31 + *
  32 + * Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título
  33 + * "LICENCA.txt", junto com esse programa. Se não, acesse <http://www.gnu.org/licenses/>
  34 + * ou escreva para a Fundação do Software Livre (FSF) Inc.,
  35 + * 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA.
  36 + */
  37 +package br.gov.frameworkdemoiselle.internal.bootstrap;
  38 +
  39 +import br.gov.frameworkdemoiselle.internal.implementation.DefaultAuthenticator;
  40 +import br.gov.frameworkdemoiselle.security.Authenticator;
  41 +
  42 +public class AuthenticatorBootstrap extends AbstractStrategyBootstrap<Authenticator, DefaultAuthenticator> {
  43 +
  44 + public String getConfigurationKey() {
  45 + return "frameworkdemoiselle.security.authenticator.class";
  46 + }
  47 +
  48 +}
... ...
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/bootstrap/AuthorizerBootstrap.java 0 → 100644
... ... @@ -0,0 +1,48 @@
  1 +/*
  2 + * Demoiselle Framework
  3 + * Copyright (C) 2010 SERPRO
  4 + * ----------------------------------------------------------------------------
  5 + * This file is part of Demoiselle Framework.
  6 + *
  7 + * Demoiselle Framework is free software; you can redistribute it and/or
  8 + * modify it under the terms of the GNU Lesser General Public License version 3
  9 + * as published by the Free Software Foundation.
  10 + *
  11 + * This program is distributed in the hope that it will be useful,
  12 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14 + * GNU General Public License for more details.
  15 + *
  16 + * You should have received a copy of the GNU Lesser General Public License version 3
  17 + * along with this program; if not, see <http://www.gnu.org/licenses/>
  18 + * or write to the Free Software Foundation, Inc., 51 Franklin Street,
  19 + * Fifth Floor, Boston, MA 02110-1301, USA.
  20 + * ----------------------------------------------------------------------------
  21 + * Este arquivo é parte do Framework Demoiselle.
  22 + *
  23 + * O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou
  24 + * modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação
  25 + * do Software Livre (FSF).
  26 + *
  27 + * Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA
  28 + * GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou
  29 + * APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português
  30 + * para maiores detalhes.
  31 + *
  32 + * Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título
  33 + * "LICENCA.txt", junto com esse programa. Se não, acesse <http://www.gnu.org/licenses/>
  34 + * ou escreva para a Fundação do Software Livre (FSF) Inc.,
  35 + * 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA.
  36 + */
  37 +package br.gov.frameworkdemoiselle.internal.bootstrap;
  38 +
  39 +import br.gov.frameworkdemoiselle.internal.implementation.DefaultAuthorizer;
  40 +import br.gov.frameworkdemoiselle.security.Authorizer;
  41 +
  42 +public class AuthorizerBootstrap extends AbstractStrategyBootstrap<Authorizer, DefaultAuthorizer> {
  43 +
  44 + public String getConfigurationKey() {
  45 + return "frameworkdemoiselle.security.authorizer.class";
  46 + }
  47 +
  48 +}
... ...
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/bootstrap/TransactionBootstrap.java
... ... @@ -36,59 +36,13 @@
36 36 */
37 37 package br.gov.frameworkdemoiselle.internal.bootstrap;
38 38  
39   -import javax.enterprise.event.Observes;
40   -import javax.enterprise.inject.spi.BeforeBeanDiscovery;
41   -import javax.enterprise.inject.spi.ProcessAnnotatedType;
42   -
43   -import org.apache.commons.configuration.Configuration;
44   -import org.apache.commons.configuration.PropertiesConfiguration;
45   -
46   -import br.gov.frameworkdemoiselle.configuration.ConfigurationException;
47 39 import br.gov.frameworkdemoiselle.internal.implementation.DefaultTransaction;
48 40 import br.gov.frameworkdemoiselle.transaction.Transaction;
49   -import br.gov.frameworkdemoiselle.util.Reflections;
50   -
51   -public class TransactionBootstrap extends AbstractBootstrap {
52   -
53   - private static Class<? extends Transaction> selected = loadSelected();
54   -
55   - public void beforeBeanDiscovery(@Observes final BeforeBeanDiscovery event) {
56   - selected = loadSelected();
57   - }
58 41  
59   - public <T> void processAnnotatedType(@Observes final ProcessAnnotatedType<T> event) {
60   - Class<T> annotated = event.getAnnotatedType().getJavaClass();
  42 +public class TransactionBootstrap extends AbstractStrategyBootstrap<Transaction, DefaultTransaction> {
61 43  
62   - if (Reflections.isOfType(annotated, Transaction.class) && annotated != selected) {
63   - event.veto();
64   - }
  44 + public String getConfigurationKey() {
  45 + return "frameworkdemoiselle.transaction.class";
65 46 }
66 47  
67   - @SuppressWarnings("unchecked")
68   - private static Class<Transaction> loadSelected() {
69   - Class<Transaction> result = null;
70   - String canonicalName = null;
71   -
72   - try {
73   - Configuration config = new PropertiesConfiguration("demoiselle.properties");
74   - canonicalName = config.getString("frameworkdemoiselle.transaction.class",
75   - DefaultTransaction.class.getCanonicalName());
76   -
77   - ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
78   - result = (Class<Transaction>) Class.forName(canonicalName, false, classLoader);
79   - result.asSubclass(Transaction.class);
80   -
81   - } catch (org.apache.commons.configuration.ConfigurationException cause) {
82   - throw new ConfigurationException(getBundle().getString("file-not-found", "demoiselle.properties"));
83   -
84   - } catch (ClassNotFoundException cause) {
85   - throw new ConfigurationException(getBundle().getString("transaction-class-not-found", canonicalName));
86   -
87   - } catch (ClassCastException cause) {
88   - throw new ConfigurationException(getBundle().getString("transaction-class-must-be-of-type", canonicalName,
89   - Transaction.class.getCanonicalName()));
90   - }
91   -
92   - return result;
93   - }
94 48 }
... ...
impl/core/src/main/resources/META-INF/services/javax.enterprise.inject.spi.Extension
1 1 br.gov.frameworkdemoiselle.internal.bootstrap.CoreBootstrap
2 2 br.gov.frameworkdemoiselle.internal.bootstrap.TransactionBootstrap
  3 +br.gov.frameworkdemoiselle.internal.bootstrap.AuthenticatorBootstrap
  4 +br.gov.frameworkdemoiselle.internal.bootstrap.AuthorizerBootstrap
3 5 br.gov.frameworkdemoiselle.internal.bootstrap.StartupBootstrap
4 6 br.gov.frameworkdemoiselle.internal.bootstrap.ShutdownBootstrap
... ...
impl/core/src/main/resources/demoiselle-core-bundle.properties
... ... @@ -86,10 +86,15 @@ access-checking=Verificando permiss\u00E3o do usu\u00E1rio &quot;{0}&quot; para executar a
86 86 access-allowed=O usu\u00E1rio "{0}" acessou o recurso "{2}" com a a\u00E7\u00E3o "{1}"
87 87 access-denied=O usu\u00E1rio "{0}" n\u00E3o possui permiss\u00E3o para executar a a\u00E7\u00E3o "{1}" no recurso "{2}"
88 88 access-denied-ui=Voc\u00EA n\u00E3o est\u00E1 autorizado a executar a a\u00E7\u00E3o {1} no recurso {0}
89   -authorizer-not-defined=Nenhuma regra de resolu\u00E7\u00E3o de permiss\u00F5es foi definida. Para utilizar @{0} \u00E9 preciso definir a estrat\u00E9gia de resolu\u00E7\u00E3o de permiss\u00F5es desejada no arquivo beans.xml
  89 +authorizer-not-defined=Nenhuma regra de resolu\u00E7\u00E3o de permiss\u00F5es foi definida. Para utilizar @{0} \u00E9 preciso definir a propriedade frameworkdemoiselle.security.authorizer.class como regra de resolu\u00E7\u00E3o de permiss\u00F5es desejada no arquivo demoiselle.properties.
  90 +authorizer-class-not-found=A classe de resolu\u00E7\u00E3o de permiss\u00F5es "{0}" informada no demoiselle.properties n\u00E3o foi encontrada no classpath.
  91 +authorizer-class-must-be-of-type=A classe de resolu\u00E7\u00E3o de permiss\u00F5es "{0}" informada no demoiselle.properties deve ser do tipo "{1}"
90 92 user-not-authenticated=Usu\u00E1rio n\u00E3o autenticado
91 93 has-role-verification=Verificando se o usu\u00E1rio {0} possui a(s) role(s)\: {1}
92 94 does-not-have-role=Usu\u00E1rio {0} n\u00E3o possui a(s) role(s)\: {1}
93 95 does-not-have-role-ui=Para acessar este recurso \u00E9 necess\u00E1rio ser {0}
94 96 user-has-role=Usu\u00E1rio {0} possui a(s) role(s)\: {1}
95   -authenticator-not-defined=Nenhum mecanismo de autentica\u00E7\u00E3o foi definido. Para utilizar {0} \u00E9 preciso definir o mecanismo de autentica\u00E7\u00E3o desejado no arquivo beans.xml
96 97 \ No newline at end of file
  98 +
  99 +authenticator-not-defined=Nenhum mecanismo de autentica\u00E7\u00E3o foi definido. Para utilizar {0} \u00E9 preciso definir a propriedade frameworkdemoiselle.security.authenticator.class como mecanismo de autentica\u00E7\u00E3o desejado no arquivo demoiselle.properties.
  100 +authenticator-class-not-found=A classe de autentica\u00E7\u00E3o "{0}" informada no demoiselle.properties n\u00E3o foi encontrada no classpath.
  101 +authenticator-class-must-be-of-type=A classe de autentica\u00E7\u00E3o "{0}" informada no demoiselle.properties deve ser do tipo "{1}"
97 102 \ No newline at end of file
... ...
impl/extension/jpa/src/main/resources/META-INF/services/javax.enterprise.inject.spi.Extension
... ... @@ -1 +0,0 @@
1   -br.gov.frameworkdemoiselle.internal.bootstrap.JPATransactionBootstrap
impl/extension/jta/src/main/resources/META-INF/services/javax.enterprise.inject.spi.Extension
... ... @@ -1 +0,0 @@
1   -br.gov.frameworkdemoiselle.internal.bootstrap.JTATransactionBootstrap