Commit 2bb898daab2db6c80b5c268e2ed99523f16a58ca

Authored by Luciano Borges
1 parent 1e5f442a
Exists in master

Adição dos testes do RequiredRole Interceptor.

impl/core/src/main/java/br/gov/frameworkdemoiselle/security/RequiredRoleInterceptor.java
... ... @@ -121,9 +121,9 @@ public class RequiredRoleInterceptor implements Serializable {
121 121 String[] roles = {};
122 122  
123 123 if (ic.getMethod().getAnnotation(RequiredRole.class) == null) {
124   - if (ic.getTarget().getClass().getAnnotation(RequiredRole.class) != null) {
125   - roles = ic.getTarget().getClass().getAnnotation(RequiredRole.class).value();
126   - }
  124 + //if (ic.getTarget().getClass().getAnnotation(RequiredRole.class) != null) {
  125 + roles = ic.getTarget().getClass().getAnnotation(RequiredRole.class).value();
  126 + //}
127 127 } else {
128 128 roles = ic.getMethod().getAnnotation(RequiredRole.class).value();
129 129 }
... ...
impl/core/src/test/java/security/interceptor/requiredrole/ClassAndMethodWithRole.java 0 → 100644
... ... @@ -0,0 +1,55 @@
  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.interceptor.requiredrole;
  38 +
  39 +import br.gov.frameworkdemoiselle.security.RequiredRole;
  40 +
  41 +@RequiredRole("role1")
  42 +public class ClassAndMethodWithRole {
  43 +
  44 + private String attr;
  45 +
  46 + public String getAttr() {
  47 + return attr;
  48 + }
  49 +
  50 + @RequiredRole("role2")
  51 + public void setAttr(String attr) {
  52 + this.attr = attr;
  53 + }
  54 +
  55 +}
... ...
impl/core/src/test/java/security/interceptor/requiredrole/ClassWithCorrectRole.java 0 → 100644
... ... @@ -0,0 +1,54 @@
  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.interceptor.requiredrole;
  38 +
  39 +import br.gov.frameworkdemoiselle.security.RequiredRole;
  40 +
  41 +@RequiredRole("role")
  42 +public class ClassWithCorrectRole {
  43 +
  44 + private String attr;
  45 +
  46 + public String getAttr() {
  47 + return attr;
  48 + }
  49 +
  50 + public void setAttr(String attr) {
  51 + this.attr = attr;
  52 + }
  53 +
  54 +}
... ...
impl/core/src/test/java/security/interceptor/requiredrole/ClassWithWrongRole.java 0 → 100644
... ... @@ -0,0 +1,54 @@
  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.interceptor.requiredrole;
  38 +
  39 +import br.gov.frameworkdemoiselle.security.RequiredRole;
  40 +
  41 +@RequiredRole("other")
  42 +public class ClassWithWrongRole {
  43 +
  44 + private String attr;
  45 +
  46 + public String getAttr() {
  47 + return attr;
  48 + }
  49 +
  50 + public void setAttr(String attr) {
  51 + this.attr = attr;
  52 + }
  53 +
  54 +}
... ...
impl/core/src/test/java/security/interceptor/requiredrole/CustomAuthorizerMultipleRoles.java 0 → 100644
... ... @@ -0,0 +1,55 @@
  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.interceptor.requiredrole;
  38 +
  39 +import br.gov.frameworkdemoiselle.security.Authorizer;
  40 +
  41 +public class CustomAuthorizerMultipleRoles implements Authorizer {
  42 +
  43 + private static final long serialVersionUID = 1L;
  44 +
  45 + @Override
  46 + public boolean hasRole(String role) {
  47 + return "role1".equals(role) || "role2".equals(role);
  48 + }
  49 +
  50 + @Override
  51 + public boolean hasPermission(String resource, String operation) {
  52 + return "resource".equals(resource) && "operation".equals(operation);
  53 + }
  54 +
  55 +}
... ...
impl/core/src/test/java/security/interceptor/requiredrole/CustomAuthorizerOneRole.java 0 → 100644
... ... @@ -0,0 +1,55 @@
  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.interceptor.requiredrole;
  38 +
  39 +import br.gov.frameworkdemoiselle.security.Authorizer;
  40 +
  41 +public class CustomAuthorizerOneRole implements Authorizer {
  42 +
  43 + private static final long serialVersionUID = 1L;
  44 +
  45 + @Override
  46 + public boolean hasRole(String role) {
  47 + return "role".equals(role);
  48 + }
  49 +
  50 + @Override
  51 + public boolean hasPermission(String resource, String operation) {
  52 + return "resource".equals(resource) && "operation".equals(operation);
  53 + }
  54 +
  55 +}
... ...
impl/core/src/test/java/security/interceptor/requiredrole/MethodsWithRole.java 0 → 100644
... ... @@ -0,0 +1,59 @@
  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.interceptor.requiredrole;
  38 +
  39 +import br.gov.frameworkdemoiselle.security.RequiredRole;
  40 +
  41 +public class MethodsWithRole {
  42 +
  43 + private String attr = "default";
  44 +
  45 + public String getAttr() {
  46 + return attr;
  47 + }
  48 +
  49 + @RequiredRole("role")
  50 + public void setAttrWithCorrectRole(String attr) {
  51 + this.attr = attr;
  52 + }
  53 +
  54 + @RequiredRole("wrong")
  55 + public void setAttrWithWrongRole(String attr) {
  56 + this.attr = attr;
  57 + }
  58 +
  59 +}
... ...
impl/core/src/test/java/security/interceptor/requiredrole/MethodsWithTwoRoles.java 0 → 100644
... ... @@ -0,0 +1,54 @@
  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.interceptor.requiredrole;
  38 +
  39 +import br.gov.frameworkdemoiselle.security.RequiredRole;
  40 +
  41 +public class MethodsWithTwoRoles {
  42 +
  43 + private String attr = "default";
  44 +
  45 + public String getAttr() {
  46 + return attr;
  47 + }
  48 +
  49 + @RequiredRole({ "role1", "role2" })
  50 + public void setAttr(String attr) {
  51 + this.attr = attr;
  52 + }
  53 +
  54 +}
... ...
impl/core/src/test/java/security/interceptor/requiredrole/RequiredRoleInterceptorMultipleRoleTest.java 0 → 100644
... ... @@ -0,0 +1,104 @@
  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.interceptor.requiredrole;
  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.After;
  47 +import org.junit.Before;
  48 +import org.junit.Test;
  49 +import org.junit.runner.RunWith;
  50 +
  51 +import security.interceptor.loggedin.CustomAuthenticator;
  52 +import test.Tests;
  53 +import br.gov.frameworkdemoiselle.context.SessionContext;
  54 +import br.gov.frameworkdemoiselle.security.SecurityContext;
  55 +import br.gov.frameworkdemoiselle.util.Beans;
  56 +
  57 +@RunWith(Arquillian.class)
  58 +public class RequiredRoleInterceptorMultipleRoleTest {
  59 +
  60 + @Inject
  61 + private SecurityContext securityContext;
  62 +
  63 + @Inject
  64 + private ClassAndMethodWithRole classAndMethodWithRole;
  65 +
  66 + @Inject
  67 + private MethodsWithTwoRoles methodsWithTwoRoles;
  68 +
  69 + @Deployment
  70 + public static JavaArchive createDeployment() {
  71 + JavaArchive deployment = Tests.createDeployment();
  72 + deployment.addClass(ClassAndMethodWithRole.class);
  73 + deployment.addClass(MethodsWithTwoRoles.class);
  74 + deployment.addClass(CustomAuthenticator.class);
  75 + deployment.addClass(CustomAuthorizerMultipleRoles.class);
  76 + return deployment;
  77 + }
  78 +
  79 + @Before
  80 + public void activeContext() {
  81 + SessionContext sessionContext = Beans.getReference(SessionContext.class);
  82 + sessionContext.activate();
  83 + securityContext.login();
  84 + }
  85 +
  86 + @Test
  87 + public void roleOnClassAndMethod() {
  88 + classAndMethodWithRole.setAttr("new value");
  89 + assertEquals("new value", classAndMethodWithRole.getAttr());
  90 + }
  91 +
  92 + @Test
  93 + public void methosdWithTwoRoles() {
  94 + methodsWithTwoRoles.setAttr("new value");
  95 + assertEquals("new value", methodsWithTwoRoles.getAttr());
  96 + }
  97 +
  98 + @After
  99 + public void deactiveContext() {
  100 + securityContext.logout();
  101 + SessionContext ctx = Beans.getReference(SessionContext.class);
  102 + ctx.deactivate();
  103 + }
  104 +}
... ...
impl/core/src/test/java/security/interceptor/requiredrole/RequiredRoleInterceptorOneRoleTest.java 0 → 100644
... ... @@ -0,0 +1,121 @@
  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.interceptor.requiredrole;
  38 +
  39 +import static junit.framework.Assert.assertEquals;
  40 +import static org.junit.Assert.fail;
  41 +
  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.After;
  48 +import org.junit.Before;
  49 +import org.junit.Test;
  50 +import org.junit.runner.RunWith;
  51 +
  52 +import security.interceptor.loggedin.CustomAuthenticator;
  53 +import test.Tests;
  54 +import br.gov.frameworkdemoiselle.context.SessionContext;
  55 +import br.gov.frameworkdemoiselle.security.AuthorizationException;
  56 +import br.gov.frameworkdemoiselle.security.SecurityContext;
  57 +import br.gov.frameworkdemoiselle.util.Beans;
  58 +
  59 +@RunWith(Arquillian.class)
  60 +public class RequiredRoleInterceptorOneRoleTest {
  61 +
  62 + @Inject
  63 + private SecurityContext securityContext;
  64 +
  65 + @Inject
  66 + private ClassWithWrongRole classWithWrongRole;
  67 +
  68 + @Inject
  69 + private ClassWithCorrectRole classWithCorrectRole;
  70 +
  71 + @Inject
  72 + private MethodsWithRole methodsWithRole;
  73 +
  74 + @Deployment
  75 + public static JavaArchive createDeployment() {
  76 + JavaArchive deployment = Tests.createDeployment();
  77 + deployment.addClass(ClassWithWrongRole.class);
  78 + deployment.addClass(ClassWithCorrectRole.class);
  79 + deployment.addClass(MethodsWithRole.class);
  80 + deployment.addClass(CustomAuthenticator.class);
  81 + deployment.addClass(CustomAuthorizerOneRole.class);
  82 + return deployment;
  83 + }
  84 +
  85 + @Before
  86 + public void activeContext() {
  87 + SessionContext sessionContext = Beans.getReference(SessionContext.class);
  88 + sessionContext.activate();
  89 + securityContext.login();
  90 + }
  91 +
  92 + @Test(expected = AuthorizationException.class)
  93 + public void wrongRoleOnClass() {
  94 + classWithWrongRole.getAttr();
  95 + }
  96 +
  97 + @Test
  98 + public void correctRoleOnClass() {
  99 + classWithCorrectRole.setAttr("new value");
  100 + assertEquals("new value", classWithCorrectRole.getAttr());
  101 + }
  102 +
  103 + @Test(expected = AuthorizationException.class)
  104 + public void wrongRoleOnMethod() {
  105 + methodsWithRole.setAttrWithWrongRole("new value");
  106 + fail();
  107 + }
  108 +
  109 + @Test
  110 + public void correctRoleOnMethod() {
  111 + methodsWithRole.setAttrWithCorrectRole("new value");
  112 + assertEquals("new value", methodsWithRole.getAttr());
  113 + }
  114 +
  115 + @After
  116 + public void deactiveContext() {
  117 + securityContext.logout();
  118 + SessionContext ctx = Beans.getReference(SessionContext.class);
  119 + ctx.deactivate();
  120 + }
  121 +}
... ...
impl/core/src/test/java/security/interceptor/requiredrole/RequiredRoleInterceptorWithoutLoggedInTest.java 0 → 100644
... ... @@ -0,0 +1,74 @@
  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.interceptor.requiredrole;
  38 +
  39 +import static org.junit.Assert.fail;
  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.custom.CustomAuthenticator;
  50 +import test.Tests;
  51 +import br.gov.frameworkdemoiselle.security.NotLoggedInException;
  52 +
  53 +@RunWith(Arquillian.class)
  54 +public class RequiredRoleInterceptorWithoutLoggedInTest {
  55 +
  56 + @Inject
  57 + private ClassWithCorrectRole classWithCorrectRole;
  58 +
  59 + @Deployment
  60 + public static JavaArchive createDeployment() {
  61 + JavaArchive deployment = Tests.createDeployment();
  62 + deployment.addClass(ClassWithCorrectRole.class);
  63 + deployment.addClass(CustomAuthenticator.class);
  64 + deployment.addClass(CustomAuthorizerOneRole.class);
  65 + return deployment;
  66 + }
  67 +
  68 + @Test(expected = NotLoggedInException.class)
  69 + public void correctRoleOnClass() {
  70 + classWithCorrectRole.setAttr("new value");
  71 + fail();
  72 + }
  73 +
  74 +}
... ...