diff --git a/impl/core/src/main/java/br/gov/frameworkdemoiselle/security/RequiredRoleInterceptor.java b/impl/core/src/main/java/br/gov/frameworkdemoiselle/security/RequiredRoleInterceptor.java
index 7867912..d26cc73 100644
--- a/impl/core/src/main/java/br/gov/frameworkdemoiselle/security/RequiredRoleInterceptor.java
+++ b/impl/core/src/main/java/br/gov/frameworkdemoiselle/security/RequiredRoleInterceptor.java
@@ -121,9 +121,9 @@ public class RequiredRoleInterceptor implements Serializable {
String[] roles = {};
if (ic.getMethod().getAnnotation(RequiredRole.class) == null) {
- if (ic.getTarget().getClass().getAnnotation(RequiredRole.class) != null) {
- roles = ic.getTarget().getClass().getAnnotation(RequiredRole.class).value();
- }
+ //if (ic.getTarget().getClass().getAnnotation(RequiredRole.class) != null) {
+ roles = ic.getTarget().getClass().getAnnotation(RequiredRole.class).value();
+ //}
} else {
roles = ic.getMethod().getAnnotation(RequiredRole.class).value();
}
diff --git a/impl/core/src/test/java/security/interceptor/requiredrole/ClassAndMethodWithRole.java b/impl/core/src/test/java/security/interceptor/requiredrole/ClassAndMethodWithRole.java
new file mode 100644
index 0000000..e51142f
--- /dev/null
+++ b/impl/core/src/test/java/security/interceptor/requiredrole/ClassAndMethodWithRole.java
@@ -0,0 +1,55 @@
+/*
+ * Demoiselle Framework
+ * Copyright (C) 2010 SERPRO
+ * ----------------------------------------------------------------------------
+ * This file is part of Demoiselle Framework.
+ *
+ * Demoiselle Framework is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License version 3
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License version 3
+ * along with this program; if not, see
+ * or write to the Free Software Foundation, Inc., 51 Franklin Street,
+ * Fifth Floor, Boston, MA 02110-1301, USA.
+ * ----------------------------------------------------------------------------
+ * Este arquivo é parte do Framework Demoiselle.
+ *
+ * O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou
+ * modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação
+ * do Software Livre (FSF).
+ *
+ * Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA
+ * GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou
+ * APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português
+ * para maiores detalhes.
+ *
+ * Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título
+ * "LICENCA.txt", junto com esse programa. Se não, acesse
+ * ou escreva para a Fundação do Software Livre (FSF) Inc.,
+ * 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA.
+ */
+package security.interceptor.requiredrole;
+
+import br.gov.frameworkdemoiselle.security.RequiredRole;
+
+@RequiredRole("role1")
+public class ClassAndMethodWithRole {
+
+ private String attr;
+
+ public String getAttr() {
+ return attr;
+ }
+
+ @RequiredRole("role2")
+ public void setAttr(String attr) {
+ this.attr = attr;
+ }
+
+}
diff --git a/impl/core/src/test/java/security/interceptor/requiredrole/ClassWithCorrectRole.java b/impl/core/src/test/java/security/interceptor/requiredrole/ClassWithCorrectRole.java
new file mode 100644
index 0000000..b094cdb
--- /dev/null
+++ b/impl/core/src/test/java/security/interceptor/requiredrole/ClassWithCorrectRole.java
@@ -0,0 +1,54 @@
+/*
+ * Demoiselle Framework
+ * Copyright (C) 2010 SERPRO
+ * ----------------------------------------------------------------------------
+ * This file is part of Demoiselle Framework.
+ *
+ * Demoiselle Framework is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License version 3
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License version 3
+ * along with this program; if not, see
+ * or write to the Free Software Foundation, Inc., 51 Franklin Street,
+ * Fifth Floor, Boston, MA 02110-1301, USA.
+ * ----------------------------------------------------------------------------
+ * Este arquivo é parte do Framework Demoiselle.
+ *
+ * O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou
+ * modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação
+ * do Software Livre (FSF).
+ *
+ * Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA
+ * GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou
+ * APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português
+ * para maiores detalhes.
+ *
+ * Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título
+ * "LICENCA.txt", junto com esse programa. Se não, acesse
+ * ou escreva para a Fundação do Software Livre (FSF) Inc.,
+ * 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA.
+ */
+package security.interceptor.requiredrole;
+
+import br.gov.frameworkdemoiselle.security.RequiredRole;
+
+@RequiredRole("role")
+public class ClassWithCorrectRole {
+
+ private String attr;
+
+ public String getAttr() {
+ return attr;
+ }
+
+ public void setAttr(String attr) {
+ this.attr = attr;
+ }
+
+}
diff --git a/impl/core/src/test/java/security/interceptor/requiredrole/ClassWithWrongRole.java b/impl/core/src/test/java/security/interceptor/requiredrole/ClassWithWrongRole.java
new file mode 100644
index 0000000..6415119
--- /dev/null
+++ b/impl/core/src/test/java/security/interceptor/requiredrole/ClassWithWrongRole.java
@@ -0,0 +1,54 @@
+/*
+ * Demoiselle Framework
+ * Copyright (C) 2010 SERPRO
+ * ----------------------------------------------------------------------------
+ * This file is part of Demoiselle Framework.
+ *
+ * Demoiselle Framework is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License version 3
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License version 3
+ * along with this program; if not, see
+ * or write to the Free Software Foundation, Inc., 51 Franklin Street,
+ * Fifth Floor, Boston, MA 02110-1301, USA.
+ * ----------------------------------------------------------------------------
+ * Este arquivo é parte do Framework Demoiselle.
+ *
+ * O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou
+ * modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação
+ * do Software Livre (FSF).
+ *
+ * Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA
+ * GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou
+ * APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português
+ * para maiores detalhes.
+ *
+ * Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título
+ * "LICENCA.txt", junto com esse programa. Se não, acesse
+ * ou escreva para a Fundação do Software Livre (FSF) Inc.,
+ * 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA.
+ */
+package security.interceptor.requiredrole;
+
+import br.gov.frameworkdemoiselle.security.RequiredRole;
+
+@RequiredRole("other")
+public class ClassWithWrongRole {
+
+ private String attr;
+
+ public String getAttr() {
+ return attr;
+ }
+
+ public void setAttr(String attr) {
+ this.attr = attr;
+ }
+
+}
diff --git a/impl/core/src/test/java/security/interceptor/requiredrole/CustomAuthorizerMultipleRoles.java b/impl/core/src/test/java/security/interceptor/requiredrole/CustomAuthorizerMultipleRoles.java
new file mode 100644
index 0000000..e256748
--- /dev/null
+++ b/impl/core/src/test/java/security/interceptor/requiredrole/CustomAuthorizerMultipleRoles.java
@@ -0,0 +1,55 @@
+/*
+ * Demoiselle Framework
+ * Copyright (C) 2010 SERPRO
+ * ----------------------------------------------------------------------------
+ * This file is part of Demoiselle Framework.
+ *
+ * Demoiselle Framework is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License version 3
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License version 3
+ * along with this program; if not, see
+ * or write to the Free Software Foundation, Inc., 51 Franklin Street,
+ * Fifth Floor, Boston, MA 02110-1301, USA.
+ * ----------------------------------------------------------------------------
+ * Este arquivo é parte do Framework Demoiselle.
+ *
+ * O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou
+ * modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação
+ * do Software Livre (FSF).
+ *
+ * Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA
+ * GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou
+ * APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português
+ * para maiores detalhes.
+ *
+ * Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título
+ * "LICENCA.txt", junto com esse programa. Se não, acesse
+ * ou escreva para a Fundação do Software Livre (FSF) Inc.,
+ * 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA.
+ */
+package security.interceptor.requiredrole;
+
+import br.gov.frameworkdemoiselle.security.Authorizer;
+
+public class CustomAuthorizerMultipleRoles implements Authorizer {
+
+ private static final long serialVersionUID = 1L;
+
+ @Override
+ public boolean hasRole(String role) {
+ return "role1".equals(role) || "role2".equals(role);
+ }
+
+ @Override
+ public boolean hasPermission(String resource, String operation) {
+ return "resource".equals(resource) && "operation".equals(operation);
+ }
+
+}
diff --git a/impl/core/src/test/java/security/interceptor/requiredrole/CustomAuthorizerOneRole.java b/impl/core/src/test/java/security/interceptor/requiredrole/CustomAuthorizerOneRole.java
new file mode 100644
index 0000000..d23a6bb
--- /dev/null
+++ b/impl/core/src/test/java/security/interceptor/requiredrole/CustomAuthorizerOneRole.java
@@ -0,0 +1,55 @@
+/*
+ * Demoiselle Framework
+ * Copyright (C) 2010 SERPRO
+ * ----------------------------------------------------------------------------
+ * This file is part of Demoiselle Framework.
+ *
+ * Demoiselle Framework is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License version 3
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License version 3
+ * along with this program; if not, see
+ * or write to the Free Software Foundation, Inc., 51 Franklin Street,
+ * Fifth Floor, Boston, MA 02110-1301, USA.
+ * ----------------------------------------------------------------------------
+ * Este arquivo é parte do Framework Demoiselle.
+ *
+ * O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou
+ * modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação
+ * do Software Livre (FSF).
+ *
+ * Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA
+ * GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou
+ * APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português
+ * para maiores detalhes.
+ *
+ * Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título
+ * "LICENCA.txt", junto com esse programa. Se não, acesse
+ * ou escreva para a Fundação do Software Livre (FSF) Inc.,
+ * 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA.
+ */
+package security.interceptor.requiredrole;
+
+import br.gov.frameworkdemoiselle.security.Authorizer;
+
+public class CustomAuthorizerOneRole implements Authorizer {
+
+ private static final long serialVersionUID = 1L;
+
+ @Override
+ public boolean hasRole(String role) {
+ return "role".equals(role);
+ }
+
+ @Override
+ public boolean hasPermission(String resource, String operation) {
+ return "resource".equals(resource) && "operation".equals(operation);
+ }
+
+}
diff --git a/impl/core/src/test/java/security/interceptor/requiredrole/MethodsWithRole.java b/impl/core/src/test/java/security/interceptor/requiredrole/MethodsWithRole.java
new file mode 100644
index 0000000..624cf3f
--- /dev/null
+++ b/impl/core/src/test/java/security/interceptor/requiredrole/MethodsWithRole.java
@@ -0,0 +1,59 @@
+/*
+ * Demoiselle Framework
+ * Copyright (C) 2010 SERPRO
+ * ----------------------------------------------------------------------------
+ * This file is part of Demoiselle Framework.
+ *
+ * Demoiselle Framework is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License version 3
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License version 3
+ * along with this program; if not, see
+ * or write to the Free Software Foundation, Inc., 51 Franklin Street,
+ * Fifth Floor, Boston, MA 02110-1301, USA.
+ * ----------------------------------------------------------------------------
+ * Este arquivo é parte do Framework Demoiselle.
+ *
+ * O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou
+ * modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação
+ * do Software Livre (FSF).
+ *
+ * Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA
+ * GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou
+ * APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português
+ * para maiores detalhes.
+ *
+ * Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título
+ * "LICENCA.txt", junto com esse programa. Se não, acesse
+ * ou escreva para a Fundação do Software Livre (FSF) Inc.,
+ * 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA.
+ */
+package security.interceptor.requiredrole;
+
+import br.gov.frameworkdemoiselle.security.RequiredRole;
+
+public class MethodsWithRole {
+
+ private String attr = "default";
+
+ public String getAttr() {
+ return attr;
+ }
+
+ @RequiredRole("role")
+ public void setAttrWithCorrectRole(String attr) {
+ this.attr = attr;
+ }
+
+ @RequiredRole("wrong")
+ public void setAttrWithWrongRole(String attr) {
+ this.attr = attr;
+ }
+
+}
diff --git a/impl/core/src/test/java/security/interceptor/requiredrole/MethodsWithTwoRoles.java b/impl/core/src/test/java/security/interceptor/requiredrole/MethodsWithTwoRoles.java
new file mode 100644
index 0000000..99c6642
--- /dev/null
+++ b/impl/core/src/test/java/security/interceptor/requiredrole/MethodsWithTwoRoles.java
@@ -0,0 +1,54 @@
+/*
+ * Demoiselle Framework
+ * Copyright (C) 2010 SERPRO
+ * ----------------------------------------------------------------------------
+ * This file is part of Demoiselle Framework.
+ *
+ * Demoiselle Framework is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License version 3
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License version 3
+ * along with this program; if not, see
+ * or write to the Free Software Foundation, Inc., 51 Franklin Street,
+ * Fifth Floor, Boston, MA 02110-1301, USA.
+ * ----------------------------------------------------------------------------
+ * Este arquivo é parte do Framework Demoiselle.
+ *
+ * O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou
+ * modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação
+ * do Software Livre (FSF).
+ *
+ * Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA
+ * GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou
+ * APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português
+ * para maiores detalhes.
+ *
+ * Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título
+ * "LICENCA.txt", junto com esse programa. Se não, acesse
+ * ou escreva para a Fundação do Software Livre (FSF) Inc.,
+ * 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA.
+ */
+package security.interceptor.requiredrole;
+
+import br.gov.frameworkdemoiselle.security.RequiredRole;
+
+public class MethodsWithTwoRoles {
+
+ private String attr = "default";
+
+ public String getAttr() {
+ return attr;
+ }
+
+ @RequiredRole({ "role1", "role2" })
+ public void setAttr(String attr) {
+ this.attr = attr;
+ }
+
+}
diff --git a/impl/core/src/test/java/security/interceptor/requiredrole/RequiredRoleInterceptorMultipleRoleTest.java b/impl/core/src/test/java/security/interceptor/requiredrole/RequiredRoleInterceptorMultipleRoleTest.java
new file mode 100644
index 0000000..9c379fa
--- /dev/null
+++ b/impl/core/src/test/java/security/interceptor/requiredrole/RequiredRoleInterceptorMultipleRoleTest.java
@@ -0,0 +1,104 @@
+/*
+ * Demoiselle Framework
+ * Copyright (C) 2010 SERPRO
+ * ----------------------------------------------------------------------------
+ * This file is part of Demoiselle Framework.
+ *
+ * Demoiselle Framework is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License version 3
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License version 3
+ * along with this program; if not, see
+ * or write to the Free Software Foundation, Inc., 51 Franklin Street,
+ * Fifth Floor, Boston, MA 02110-1301, USA.
+ * ----------------------------------------------------------------------------
+ * Este arquivo é parte do Framework Demoiselle.
+ *
+ * O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou
+ * modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação
+ * do Software Livre (FSF).
+ *
+ * Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA
+ * GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou
+ * APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português
+ * para maiores detalhes.
+ *
+ * Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título
+ * "LICENCA.txt", junto com esse programa. Se não, acesse
+ * ou escreva para a Fundação do Software Livre (FSF) Inc.,
+ * 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA.
+ */
+package security.interceptor.requiredrole;
+
+import static junit.framework.Assert.assertEquals;
+
+import javax.inject.Inject;
+
+import org.jboss.arquillian.container.test.api.Deployment;
+import org.jboss.arquillian.junit.Arquillian;
+import org.jboss.shrinkwrap.api.spec.JavaArchive;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+import security.interceptor.loggedin.CustomAuthenticator;
+import test.Tests;
+import br.gov.frameworkdemoiselle.context.SessionContext;
+import br.gov.frameworkdemoiselle.security.SecurityContext;
+import br.gov.frameworkdemoiselle.util.Beans;
+
+@RunWith(Arquillian.class)
+public class RequiredRoleInterceptorMultipleRoleTest {
+
+ @Inject
+ private SecurityContext securityContext;
+
+ @Inject
+ private ClassAndMethodWithRole classAndMethodWithRole;
+
+ @Inject
+ private MethodsWithTwoRoles methodsWithTwoRoles;
+
+ @Deployment
+ public static JavaArchive createDeployment() {
+ JavaArchive deployment = Tests.createDeployment();
+ deployment.addClass(ClassAndMethodWithRole.class);
+ deployment.addClass(MethodsWithTwoRoles.class);
+ deployment.addClass(CustomAuthenticator.class);
+ deployment.addClass(CustomAuthorizerMultipleRoles.class);
+ return deployment;
+ }
+
+ @Before
+ public void activeContext() {
+ SessionContext sessionContext = Beans.getReference(SessionContext.class);
+ sessionContext.activate();
+ securityContext.login();
+ }
+
+ @Test
+ public void roleOnClassAndMethod() {
+ classAndMethodWithRole.setAttr("new value");
+ assertEquals("new value", classAndMethodWithRole.getAttr());
+ }
+
+ @Test
+ public void methosdWithTwoRoles() {
+ methodsWithTwoRoles.setAttr("new value");
+ assertEquals("new value", methodsWithTwoRoles.getAttr());
+ }
+
+ @After
+ public void deactiveContext() {
+ securityContext.logout();
+ SessionContext ctx = Beans.getReference(SessionContext.class);
+ ctx.deactivate();
+ }
+}
diff --git a/impl/core/src/test/java/security/interceptor/requiredrole/RequiredRoleInterceptorOneRoleTest.java b/impl/core/src/test/java/security/interceptor/requiredrole/RequiredRoleInterceptorOneRoleTest.java
new file mode 100644
index 0000000..bd06974
--- /dev/null
+++ b/impl/core/src/test/java/security/interceptor/requiredrole/RequiredRoleInterceptorOneRoleTest.java
@@ -0,0 +1,121 @@
+/*
+ * Demoiselle Framework
+ * Copyright (C) 2010 SERPRO
+ * ----------------------------------------------------------------------------
+ * This file is part of Demoiselle Framework.
+ *
+ * Demoiselle Framework is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License version 3
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License version 3
+ * along with this program; if not, see
+ * or write to the Free Software Foundation, Inc., 51 Franklin Street,
+ * Fifth Floor, Boston, MA 02110-1301, USA.
+ * ----------------------------------------------------------------------------
+ * Este arquivo é parte do Framework Demoiselle.
+ *
+ * O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou
+ * modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação
+ * do Software Livre (FSF).
+ *
+ * Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA
+ * GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou
+ * APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português
+ * para maiores detalhes.
+ *
+ * Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título
+ * "LICENCA.txt", junto com esse programa. Se não, acesse
+ * ou escreva para a Fundação do Software Livre (FSF) Inc.,
+ * 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA.
+ */
+package security.interceptor.requiredrole;
+
+import static junit.framework.Assert.assertEquals;
+import static org.junit.Assert.fail;
+
+import javax.inject.Inject;
+
+import org.jboss.arquillian.container.test.api.Deployment;
+import org.jboss.arquillian.junit.Arquillian;
+import org.jboss.shrinkwrap.api.spec.JavaArchive;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+import security.interceptor.loggedin.CustomAuthenticator;
+import test.Tests;
+import br.gov.frameworkdemoiselle.context.SessionContext;
+import br.gov.frameworkdemoiselle.security.AuthorizationException;
+import br.gov.frameworkdemoiselle.security.SecurityContext;
+import br.gov.frameworkdemoiselle.util.Beans;
+
+@RunWith(Arquillian.class)
+public class RequiredRoleInterceptorOneRoleTest {
+
+ @Inject
+ private SecurityContext securityContext;
+
+ @Inject
+ private ClassWithWrongRole classWithWrongRole;
+
+ @Inject
+ private ClassWithCorrectRole classWithCorrectRole;
+
+ @Inject
+ private MethodsWithRole methodsWithRole;
+
+ @Deployment
+ public static JavaArchive createDeployment() {
+ JavaArchive deployment = Tests.createDeployment();
+ deployment.addClass(ClassWithWrongRole.class);
+ deployment.addClass(ClassWithCorrectRole.class);
+ deployment.addClass(MethodsWithRole.class);
+ deployment.addClass(CustomAuthenticator.class);
+ deployment.addClass(CustomAuthorizerOneRole.class);
+ return deployment;
+ }
+
+ @Before
+ public void activeContext() {
+ SessionContext sessionContext = Beans.getReference(SessionContext.class);
+ sessionContext.activate();
+ securityContext.login();
+ }
+
+ @Test(expected = AuthorizationException.class)
+ public void wrongRoleOnClass() {
+ classWithWrongRole.getAttr();
+ }
+
+ @Test
+ public void correctRoleOnClass() {
+ classWithCorrectRole.setAttr("new value");
+ assertEquals("new value", classWithCorrectRole.getAttr());
+ }
+
+ @Test(expected = AuthorizationException.class)
+ public void wrongRoleOnMethod() {
+ methodsWithRole.setAttrWithWrongRole("new value");
+ fail();
+ }
+
+ @Test
+ public void correctRoleOnMethod() {
+ methodsWithRole.setAttrWithCorrectRole("new value");
+ assertEquals("new value", methodsWithRole.getAttr());
+ }
+
+ @After
+ public void deactiveContext() {
+ securityContext.logout();
+ SessionContext ctx = Beans.getReference(SessionContext.class);
+ ctx.deactivate();
+ }
+}
diff --git a/impl/core/src/test/java/security/interceptor/requiredrole/RequiredRoleInterceptorWithoutLoggedInTest.java b/impl/core/src/test/java/security/interceptor/requiredrole/RequiredRoleInterceptorWithoutLoggedInTest.java
new file mode 100644
index 0000000..9d79a46
--- /dev/null
+++ b/impl/core/src/test/java/security/interceptor/requiredrole/RequiredRoleInterceptorWithoutLoggedInTest.java
@@ -0,0 +1,74 @@
+/*
+ * Demoiselle Framework
+ * Copyright (C) 2010 SERPRO
+ * ----------------------------------------------------------------------------
+ * This file is part of Demoiselle Framework.
+ *
+ * Demoiselle Framework is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License version 3
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License version 3
+ * along with this program; if not, see
+ * or write to the Free Software Foundation, Inc., 51 Franklin Street,
+ * Fifth Floor, Boston, MA 02110-1301, USA.
+ * ----------------------------------------------------------------------------
+ * Este arquivo é parte do Framework Demoiselle.
+ *
+ * O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou
+ * modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação
+ * do Software Livre (FSF).
+ *
+ * Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA
+ * GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou
+ * APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português
+ * para maiores detalhes.
+ *
+ * Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título
+ * "LICENCA.txt", junto com esse programa. Se não, acesse
+ * ou escreva para a Fundação do Software Livre (FSF) Inc.,
+ * 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA.
+ */
+package security.interceptor.requiredrole;
+
+import static org.junit.Assert.fail;
+
+import javax.inject.Inject;
+
+import org.jboss.arquillian.container.test.api.Deployment;
+import org.jboss.arquillian.junit.Arquillian;
+import org.jboss.shrinkwrap.api.spec.JavaArchive;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+import security.athentication.custom.CustomAuthenticator;
+import test.Tests;
+import br.gov.frameworkdemoiselle.security.NotLoggedInException;
+
+@RunWith(Arquillian.class)
+public class RequiredRoleInterceptorWithoutLoggedInTest {
+
+ @Inject
+ private ClassWithCorrectRole classWithCorrectRole;
+
+ @Deployment
+ public static JavaArchive createDeployment() {
+ JavaArchive deployment = Tests.createDeployment();
+ deployment.addClass(ClassWithCorrectRole.class);
+ deployment.addClass(CustomAuthenticator.class);
+ deployment.addClass(CustomAuthorizerOneRole.class);
+ return deployment;
+ }
+
+ @Test(expected = NotLoggedInException.class)
+ public void correctRoleOnClass() {
+ classWithCorrectRole.setAttr("new value");
+ fail();
+ }
+
+}
--
libgit2 0.21.2