Commit 6b5389eb6dd02348c6fe935a0fbd41448733dc63
1 parent
8bfbf37a
Exists in
master
Início da implementação dos testes de segurança
Showing
10 changed files
with
487 additions
and
63 deletions
Show diff stats
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/implementation/DefaultAuthenticator.java
| @@ -85,8 +85,8 @@ public class DefaultAuthenticator implements Authenticator { | @@ -85,8 +85,8 @@ public class DefaultAuthenticator implements Authenticator { | ||
| 85 | } | 85 | } |
| 86 | 86 | ||
| 87 | private DemoiselleException getException() { | 87 | private DemoiselleException getException() { |
| 88 | - return new DemoiselleException(getBundle().getString("authenticator-not-defined", | ||
| 89 | - SecurityContext.class.getSimpleName())); | 88 | + return new AuthenticationException(getBundle().getString("authenticator-not-defined", |
| 89 | + SecurityContext.class.getSimpleName()), new ClassNotFoundException()); | ||
| 90 | } | 90 | } |
| 91 | 91 | ||
| 92 | private static ResourceBundle getBundle() { | 92 | private static ResourceBundle getBundle() { |
impl/core/src/test/java/security/SecurityTests.java
| @@ -1,60 +0,0 @@ | @@ -1,60 +0,0 @@ | ||
| 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 security; | ||
| 38 | - | ||
| 39 | -import java.io.File; | ||
| 40 | - | ||
| 41 | -import org.jboss.shrinkwrap.api.ShrinkWrap; | ||
| 42 | -import org.jboss.shrinkwrap.api.asset.EmptyAsset; | ||
| 43 | -import org.jboss.shrinkwrap.api.spec.JavaArchive; | ||
| 44 | - | ||
| 45 | -public final class SecurityTests { | ||
| 46 | - | ||
| 47 | - private SecurityTests() { | ||
| 48 | - } | ||
| 49 | - | ||
| 50 | - public static JavaArchive createDeployment(Class<?> baseClass) { | ||
| 51 | - return ShrinkWrap | ||
| 52 | - .create(JavaArchive.class) | ||
| 53 | - .addPackages(true, "br") | ||
| 54 | - .addPackages(true, baseClass.getPackage()) | ||
| 55 | - .addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml") | ||
| 56 | - .addAsManifestResource( | ||
| 57 | - new File("src/main/resources/META-INF/services/javax.enterprise.inject.spi.Extension"), | ||
| 58 | - "services/javax.enterprise.inject.spi.Extension"); | ||
| 59 | - } | ||
| 60 | -} |
impl/core/src/test/java/security/athentication/ambiguity/AmbiguousAuthenticatorTest.java
0 → 100644
| @@ -0,0 +1,78 @@ | @@ -0,0 +1,78 @@ | ||
| 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 security.athentication.ambiguity; | ||
| 38 | + | ||
| 39 | +import static junit.framework.Assert.assertEquals; | ||
| 40 | + | ||
| 41 | +import javax.enterprise.inject.AmbiguousResolutionException; | ||
| 42 | +import javax.inject.Inject; | ||
| 43 | + | ||
| 44 | +import org.jboss.arquillian.container.test.api.Deployment; | ||
| 45 | +import org.jboss.arquillian.junit.Arquillian; | ||
| 46 | +import org.jboss.shrinkwrap.api.spec.JavaArchive; | ||
| 47 | +import org.junit.Test; | ||
| 48 | +import org.junit.runner.RunWith; | ||
| 49 | + | ||
| 50 | +import security.athentication.custom.CustomAuthenticator; | ||
| 51 | +import util.Tests; | ||
| 52 | +import br.gov.frameworkdemoiselle.DemoiselleException; | ||
| 53 | +import br.gov.frameworkdemoiselle.security.SecurityContext; | ||
| 54 | +import configuration.resource.ConfigurationResourceTest; | ||
| 55 | + | ||
| 56 | +@RunWith(Arquillian.class) | ||
| 57 | +public class AmbiguousAuthenticatorTest { | ||
| 58 | + | ||
| 59 | + @Inject | ||
| 60 | + private SecurityContext context; | ||
| 61 | + | ||
| 62 | + @Deployment | ||
| 63 | + public static JavaArchive createDeployment() { | ||
| 64 | + JavaArchive deployment = Tests.createDeployment(ConfigurationResourceTest.class); | ||
| 65 | + deployment.addClass(CustomAuthenticator.class); | ||
| 66 | + deployment.addClass(DuplicatedCustomAuthenticator.class); | ||
| 67 | + return deployment; | ||
| 68 | + } | ||
| 69 | + | ||
| 70 | + @Test | ||
| 71 | + public void ambiguousAuthenticatorStrategy() { | ||
| 72 | + try { | ||
| 73 | + context.isLoggedIn(); | ||
| 74 | + } catch (DemoiselleException cause) { | ||
| 75 | + assertEquals(AmbiguousResolutionException.class, cause.getCause().getClass()); | ||
| 76 | + } | ||
| 77 | + } | ||
| 78 | +} |
impl/core/src/test/java/security/athentication/ambiguity/DuplicatedCustomAuthenticator.java
0 → 100644
| @@ -0,0 +1,60 @@ | @@ -0,0 +1,60 @@ | ||
| 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 security.athentication.ambiguity; | ||
| 38 | + | ||
| 39 | +import java.security.Principal; | ||
| 40 | + | ||
| 41 | +import br.gov.frameworkdemoiselle.security.AuthenticationException; | ||
| 42 | +import br.gov.frameworkdemoiselle.security.Authenticator; | ||
| 43 | + | ||
| 44 | +public class DuplicatedCustomAuthenticator implements Authenticator { | ||
| 45 | + | ||
| 46 | + private static final long serialVersionUID = 1L; | ||
| 47 | + | ||
| 48 | + @Override | ||
| 49 | + public void authenticate() throws AuthenticationException { | ||
| 50 | + } | ||
| 51 | + | ||
| 52 | + @Override | ||
| 53 | + public void unAuthenticate() { | ||
| 54 | + } | ||
| 55 | + | ||
| 56 | + @Override | ||
| 57 | + public Principal getUser() { | ||
| 58 | + return null; | ||
| 59 | + } | ||
| 60 | +} |
impl/core/src/test/java/security/athentication/custom/CustomAuthenticator.java
0 → 100644
| @@ -0,0 +1,69 @@ | @@ -0,0 +1,69 @@ | ||
| 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 security.athentication.custom; | ||
| 38 | + | ||
| 39 | +import java.security.Principal; | ||
| 40 | + | ||
| 41 | +import br.gov.frameworkdemoiselle.security.AuthenticationException; | ||
| 42 | +import br.gov.frameworkdemoiselle.security.Authenticator; | ||
| 43 | + | ||
| 44 | +public class CustomAuthenticator implements Authenticator { | ||
| 45 | + | ||
| 46 | + private static final long serialVersionUID = 1L; | ||
| 47 | + | ||
| 48 | + private Principal currentUser; | ||
| 49 | + | ||
| 50 | + @Override | ||
| 51 | + public void authenticate() throws AuthenticationException { | ||
| 52 | + this.currentUser = new Principal() { | ||
| 53 | + | ||
| 54 | + public String getName() { | ||
| 55 | + return "demoiselle"; | ||
| 56 | + } | ||
| 57 | + }; | ||
| 58 | + } | ||
| 59 | + | ||
| 60 | + @Override | ||
| 61 | + public void unAuthenticate() { | ||
| 62 | + this.currentUser = null; | ||
| 63 | + } | ||
| 64 | + | ||
| 65 | + @Override | ||
| 66 | + public Principal getUser() { | ||
| 67 | + return this.currentUser; | ||
| 68 | + } | ||
| 69 | +} |
impl/core/src/test/java/security/athentication/custom/CustomAuthenticatorTest.java
0 → 100644
| @@ -0,0 +1,89 @@ | @@ -0,0 +1,89 @@ | ||
| 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 security.athentication.custom; | ||
| 38 | + | ||
| 39 | +import static org.junit.Assert.assertEquals; | ||
| 40 | +import static org.junit.Assert.assertFalse; | ||
| 41 | +import static org.junit.Assert.assertNull; | ||
| 42 | +import static org.junit.Assert.assertTrue; | ||
| 43 | + | ||
| 44 | +import javax.inject.Inject; | ||
| 45 | + | ||
| 46 | +import org.jboss.arquillian.container.test.api.Deployment; | ||
| 47 | +import org.jboss.arquillian.junit.Arquillian; | ||
| 48 | +import org.jboss.shrinkwrap.api.spec.JavaArchive; | ||
| 49 | +import org.junit.Test; | ||
| 50 | +import org.junit.runner.RunWith; | ||
| 51 | + | ||
| 52 | +import util.Tests; | ||
| 53 | +import br.gov.frameworkdemoiselle.security.SecurityContext; | ||
| 54 | +import configuration.resource.ConfigurationResourceTest; | ||
| 55 | + | ||
| 56 | +@RunWith(Arquillian.class) | ||
| 57 | +public class CustomAuthenticatorTest { | ||
| 58 | + | ||
| 59 | + @Inject | ||
| 60 | + private SecurityContext context; | ||
| 61 | + | ||
| 62 | + @Deployment | ||
| 63 | + public static JavaArchive createDeployment() { | ||
| 64 | + JavaArchive deployment = Tests.createDeployment(ConfigurationResourceTest.class); | ||
| 65 | + deployment.addClass(CustomAuthenticator.class); | ||
| 66 | + return deployment; | ||
| 67 | + } | ||
| 68 | + | ||
| 69 | + @Test | ||
| 70 | + public void unauthenticated() { | ||
| 71 | + assertFalse(context.isLoggedIn()); | ||
| 72 | + assertNull(context.getCurrentUser()); | ||
| 73 | + } | ||
| 74 | + | ||
| 75 | + @Test | ||
| 76 | + public void loginProcess() { | ||
| 77 | + context.login(); | ||
| 78 | + assertTrue(context.isLoggedIn()); | ||
| 79 | + assertEquals("demoiselle", context.getCurrentUser().getName()); | ||
| 80 | + } | ||
| 81 | + | ||
| 82 | + @Test | ||
| 83 | + public void logoutProcess() { | ||
| 84 | + context.login(); | ||
| 85 | + context.logout(); | ||
| 86 | + assertFalse(context.isLoggedIn()); | ||
| 87 | + assertNull(context.getCurrentUser()); | ||
| 88 | + } | ||
| 89 | +} |
impl/core/src/test/java/security/athentication/selection/SelectedAuthenticatorTest.java
0 → 100644
| @@ -0,0 +1,77 @@ | @@ -0,0 +1,77 @@ | ||
| 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 security.athentication.selection; | ||
| 38 | + | ||
| 39 | +import static junit.framework.Assert.assertEquals; | ||
| 40 | + | ||
| 41 | +import javax.inject.Inject; | ||
| 42 | + | ||
| 43 | +import org.jboss.arquillian.container.test.api.Deployment; | ||
| 44 | +import org.jboss.arquillian.junit.Arquillian; | ||
| 45 | +import org.jboss.shrinkwrap.api.spec.JavaArchive; | ||
| 46 | +import org.junit.Test; | ||
| 47 | +import org.junit.runner.RunWith; | ||
| 48 | + | ||
| 49 | +import security.athentication.ambiguity.DuplicatedCustomAuthenticator; | ||
| 50 | +import security.athentication.custom.CustomAuthenticator; | ||
| 51 | +import util.Tests; | ||
| 52 | +import br.gov.frameworkdemoiselle.security.SecurityContext; | ||
| 53 | +import configuration.resource.ConfigurationResourceTest; | ||
| 54 | + | ||
| 55 | +@RunWith(Arquillian.class) | ||
| 56 | +public class SelectedAuthenticatorTest { | ||
| 57 | + | ||
| 58 | + private static final String PATH = "src/test/resources/security/authenticator/selection"; | ||
| 59 | + | ||
| 60 | + @Inject | ||
| 61 | + private SecurityContext context; | ||
| 62 | + | ||
| 63 | + @Deployment | ||
| 64 | + public static JavaArchive createDeployment() { | ||
| 65 | + JavaArchive deployment = Tests.createDeployment(ConfigurationResourceTest.class); | ||
| 66 | + deployment.addClass(CustomAuthenticator.class); | ||
| 67 | + deployment.addClass(DuplicatedCustomAuthenticator.class); | ||
| 68 | + deployment.addAsResource(Tests.createFileAsset(PATH + "/demoiselle.properties"), "demoiselle.properties"); | ||
| 69 | + return deployment; | ||
| 70 | + } | ||
| 71 | + | ||
| 72 | + @Test | ||
| 73 | + public void selectedAuthenticatorStrategy() { | ||
| 74 | + context.login(); | ||
| 75 | + assertEquals("demoiselle", context.getCurrentUser().getName()); | ||
| 76 | + } | ||
| 77 | +} |
impl/core/src/test/java/security/athentication/undefined/UndefinedAuthenticatorTest.java
0 → 100644
| @@ -0,0 +1,72 @@ | @@ -0,0 +1,72 @@ | ||
| 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 security.athentication.undefined; | ||
| 38 | + | ||
| 39 | +import static junit.framework.Assert.assertEquals; | ||
| 40 | + | ||
| 41 | +import javax.inject.Inject; | ||
| 42 | + | ||
| 43 | +import org.jboss.arquillian.container.test.api.Deployment; | ||
| 44 | +import org.jboss.arquillian.junit.Arquillian; | ||
| 45 | +import org.jboss.shrinkwrap.api.spec.JavaArchive; | ||
| 46 | +import org.junit.Test; | ||
| 47 | +import org.junit.runner.RunWith; | ||
| 48 | + | ||
| 49 | +import util.Tests; | ||
| 50 | +import br.gov.frameworkdemoiselle.security.AuthenticationException; | ||
| 51 | +import br.gov.frameworkdemoiselle.security.SecurityContext; | ||
| 52 | + | ||
| 53 | +@RunWith(Arquillian.class) | ||
| 54 | +public class UndefinedAuthenticatorTest { | ||
| 55 | + | ||
| 56 | + @Inject | ||
| 57 | + private SecurityContext context; | ||
| 58 | + | ||
| 59 | + @Deployment | ||
| 60 | + public static JavaArchive createDeployment() { | ||
| 61 | + return Tests.createDeployment(); | ||
| 62 | + } | ||
| 63 | + | ||
| 64 | + @Test | ||
| 65 | + public void undefinedAuthenticatorStrategy() { | ||
| 66 | + try { | ||
| 67 | + context.isLoggedIn(); | ||
| 68 | + } catch (AuthenticationException cause) { | ||
| 69 | + assertEquals(ClassNotFoundException.class, cause.getCause().getClass()); | ||
| 70 | + } | ||
| 71 | + } | ||
| 72 | +} |
impl/core/src/test/java/util/Tests.java
| @@ -49,10 +49,13 @@ public final class Tests { | @@ -49,10 +49,13 @@ public final class Tests { | ||
| 49 | } | 49 | } |
| 50 | 50 | ||
| 51 | public static JavaArchive createDeployment(Class<?> baseClass) { | 51 | public static JavaArchive createDeployment(Class<?> baseClass) { |
| 52 | + return createDeployment().addPackages(true, baseClass.getPackage()); | ||
| 53 | + } | ||
| 54 | + | ||
| 55 | + public static JavaArchive createDeployment() { | ||
| 52 | return ShrinkWrap | 56 | return ShrinkWrap |
| 53 | .create(JavaArchive.class) | 57 | .create(JavaArchive.class) |
| 54 | .addPackages(true, "br") | 58 | .addPackages(true, "br") |
| 55 | - .addPackages(true, baseClass.getPackage()) | ||
| 56 | .addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml") | 59 | .addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml") |
| 57 | .addAsManifestResource( | 60 | .addAsManifestResource( |
| 58 | new File("src/main/resources/META-INF/services/javax.enterprise.inject.spi.Extension"), | 61 | new File("src/main/resources/META-INF/services/javax.enterprise.inject.spi.Extension"), |
impl/core/src/test/resources/security/authenticator/selection/demoiselle.properties
0 → 100644
| @@ -0,0 +1,36 @@ | @@ -0,0 +1,36 @@ | ||
| 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 | +frameworkdemoiselle.security.authenticator.class=security.athentication.custom.CustomAuthenticator | ||
| 0 | \ No newline at end of file | 37 | \ No newline at end of file |