Commit 0a8b63041025674e8689fc6df0b7cd13056bcda7
1 parent
459726a3
Exists in
master
Colocando as mensagens no resource bundle
Showing
3 changed files
with
76 additions
and
3 deletions
Show diff stats
impl/extension/jaas/src/main/java/br/gov/frameworkdemoiselle/security/JAASAuthenticator.java
| ... | ... | @@ -54,6 +54,9 @@ import javax.security.auth.login.LoginException; |
| 54 | 54 | |
| 55 | 55 | import br.gov.frameworkdemoiselle.annotation.Priority; |
| 56 | 56 | import br.gov.frameworkdemoiselle.internal.configuration.JAASConfig; |
| 57 | +import br.gov.frameworkdemoiselle.internal.producer.ResourceBundleProducer; | |
| 58 | +import br.gov.frameworkdemoiselle.util.ResourceBundle; | |
| 59 | +import br.gov.frameworkdemoiselle.util.Strings; | |
| 57 | 60 | |
| 58 | 61 | @SessionScoped |
| 59 | 62 | @Priority(EXTENSIONS_L1_PRIORITY) |
| ... | ... | @@ -61,6 +64,8 @@ public class JAASAuthenticator implements Authenticator { |
| 61 | 64 | |
| 62 | 65 | private static final long serialVersionUID = 1L; |
| 63 | 66 | |
| 67 | + private ResourceBundle bundle; | |
| 68 | + | |
| 64 | 69 | private User user; |
| 65 | 70 | |
| 66 | 71 | private final Subject subject; |
| ... | ... | @@ -136,7 +141,13 @@ public class JAASAuthenticator implements Authenticator { |
| 136 | 141 | } |
| 137 | 142 | |
| 138 | 143 | public LoginContext createLoginContext() throws LoginException { |
| 139 | - return new LoginContext(config.getLoginModuleName(), this.subject, createCallbackHandler()); | |
| 144 | + String name = config.getLoginModuleName(); | |
| 145 | + | |
| 146 | + if (Strings.isEmpty(name)) { | |
| 147 | + throw new SecurityException(getBundle().getString("required-login-module-name")); | |
| 148 | + } | |
| 149 | + | |
| 150 | + return new LoginContext(name, this.subject, createCallbackHandler()); | |
| 140 | 151 | } |
| 141 | 152 | |
| 142 | 153 | private CallbackHandler createCallbackHandler() { |
| ... | ... | @@ -151,10 +162,20 @@ public class JAASAuthenticator implements Authenticator { |
| 151 | 162 | ((PasswordCallback) callbacks[i]).setPassword(credentials.getPassword().toCharArray()); |
| 152 | 163 | |
| 153 | 164 | } else { |
| 154 | - System.out.println("XXXXXXXXXXXXXXXXXXXXXXXXXXXX Unsupported callback " + callbacks[i]); | |
| 165 | + // TODO Utilizar o logger... | |
| 166 | + | |
| 167 | + System.out.println(getBundle().getString("unsupported-callback", callbacks[i])); | |
| 155 | 168 | } |
| 156 | 169 | } |
| 157 | 170 | } |
| 158 | 171 | }; |
| 159 | 172 | } |
| 173 | + | |
| 174 | + private ResourceBundle getBundle() { | |
| 175 | + if (this.bundle == null) { | |
| 176 | + this.bundle = ResourceBundleProducer.create("demoiselle-jaas-bundle"); | |
| 177 | + } | |
| 178 | + | |
| 179 | + return this.bundle; | |
| 180 | + } | |
| 160 | 181 | } | ... | ... |
impl/extension/jaas/src/main/java/br/gov/frameworkdemoiselle/security/JAASAuthorizer.java
| ... | ... | @@ -44,14 +44,19 @@ import java.util.Enumeration; |
| 44 | 44 | |
| 45 | 45 | import javax.security.auth.Subject; |
| 46 | 46 | |
| 47 | +import br.gov.frameworkdemoiselle.DemoiselleException; | |
| 47 | 48 | import br.gov.frameworkdemoiselle.annotation.Priority; |
| 49 | +import br.gov.frameworkdemoiselle.internal.producer.ResourceBundleProducer; | |
| 48 | 50 | import br.gov.frameworkdemoiselle.util.Beans; |
| 51 | +import br.gov.frameworkdemoiselle.util.ResourceBundle; | |
| 49 | 52 | |
| 50 | 53 | @Priority(EXTENSIONS_L1_PRIORITY) |
| 51 | 54 | public class JAASAuthorizer implements Authorizer { |
| 52 | 55 | |
| 53 | 56 | private static final long serialVersionUID = 1L; |
| 54 | 57 | |
| 58 | + private ResourceBundle bundle; | |
| 59 | + | |
| 55 | 60 | @Override |
| 56 | 61 | public boolean hasRole(String role) { |
| 57 | 62 | boolean result = false; |
| ... | ... | @@ -83,6 +88,15 @@ public class JAASAuthorizer implements Authorizer { |
| 83 | 88 | |
| 84 | 89 | @Override |
| 85 | 90 | public boolean hasPermission(String resource, String operation) { |
| 86 | - return true; | |
| 91 | + throw new DemoiselleException(getBundle().getString("has-permission-not-supported", | |
| 92 | + RequiredPermission.class.getSimpleName())); | |
| 93 | + } | |
| 94 | + | |
| 95 | + private ResourceBundle getBundle() { | |
| 96 | + if (this.bundle == null) { | |
| 97 | + this.bundle = ResourceBundleProducer.create("demoiselle-jaas-bundle"); | |
| 98 | + } | |
| 99 | + | |
| 100 | + return this.bundle; | |
| 87 | 101 | } |
| 88 | 102 | } | ... | ... |
impl/extension/jaas/src/main/resources/demoiselle-jaas-bundle.properties
0 → 100644
| ... | ... | @@ -0,0 +1,38 @@ |
| 1 | +# Demoiselle Framework | |
| 2 | +# Copyright (C) 2010 SERPRO | |
| 3 | +# ---------------------------------------------------------------------------- | |
| 4 | +# This file is part of Demoiselle Framework. | |
| 5 | +# | |
| 6 | +# Demoiselle Framework is free software; you can redistribute it and/or | |
| 7 | +# modify it under the terms of the GNU Lesser General Public License version 3 | |
| 8 | +# as published by the Free Software Foundation. | |
| 9 | +# | |
| 10 | +# This program is distributed in the hope that it will be useful, | |
| 11 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 12 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 13 | +# GNU General Public License for more details. | |
| 14 | +# | |
| 15 | +# You should have received a copy of the GNU Lesser General Public License version 3 | |
| 16 | +# along with this program; if not, see <http://www.gnu.org/licenses/> | |
| 17 | +# or write to the Free Software Foundation, Inc., 51 Franklin Street, | |
| 18 | +# Fifth Floor, Boston, MA 02110-1301, USA. | |
| 19 | +# ---------------------------------------------------------------------------- | |
| 20 | +# Este arquivo é parte do Framework Demoiselle. | |
| 21 | +# | |
| 22 | +# O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou | |
| 23 | +# modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação | |
| 24 | +# do Software Livre (FSF). | |
| 25 | +# | |
| 26 | +# Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA | |
| 27 | +# GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou | |
| 28 | +# APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português | |
| 29 | +# para maiores detalhes. | |
| 30 | +# | |
| 31 | +# Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título | |
| 32 | +# "LICENCA.txt", junto com esse programa. Se não, acesse <http://www.gnu.org/licenses/> | |
| 33 | +# ou escreva para a Fundação do Software Livre (FSF) Inc., | |
| 34 | +# 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA. | |
| 35 | + | |
| 36 | +has-permission-not-supported=N\u00E3o \u00E9 poss\u00EDvel utilizar @{0}, pois esta funcionalidade n\u00E3o \u00E9 suportada pelo JAAS | |
| 37 | +unsupported-callback=Callback n\u00E3o suportado\: {0} | |
| 38 | +required-login-module-name=\u00C9 preciso definir a propriedade frameworkdemoiselle.security.login.module.name no arquivo demoiselle.properties | ... | ... |