Commit 5d1ee785688a960f688074e437e808879256fcb1
1 parent
4049ceea
Exists in
master
Adição de testes (ainda não finalizados) para o
RequiredPermissionInterceptor.
Showing
9 changed files
with
635 additions
and
0 deletions
Show diff stats
impl/core/src/test/java/security/interceptor/requiredpermission/CustomAuthorizer.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.requiredpermission; | |
38 | + | |
39 | +import br.gov.frameworkdemoiselle.security.Authorizer; | |
40 | + | |
41 | +public class CustomAuthorizer 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/requiredpermission/CustomAuthorizer2.java
0 → 100644
... | ... | @@ -0,0 +1,57 @@ |
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.requiredpermission; | |
38 | + | |
39 | +import br.gov.frameworkdemoiselle.security.Authorizer; | |
40 | + | |
41 | +public class CustomAuthorizer2 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 | + System.out.println("###" + resource + " " + operation + "###"); | |
53 | + return "DummyProtectedClassAuthorizedWithoutParams$Proxy$_$$_WeldSubclass".equals(resource) | |
54 | + && ("setDummyAttrib".equals(operation) || "getDummyAttrib".equals(operation)); | |
55 | + } | |
56 | + | |
57 | +} | ... | ... |
impl/core/src/test/java/security/interceptor/requiredpermission/DummyProtectedClassAndMethod.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.requiredpermission; | |
38 | + | |
39 | +import br.gov.frameworkdemoiselle.security.RequiredPermission; | |
40 | + | |
41 | +@RequiredPermission(resource = "resource false", operation = "operation false") | |
42 | +public class DummyProtectedClassAndMethod { | |
43 | + | |
44 | + private String dummyAttrib = "Default"; | |
45 | + | |
46 | + public String getDummyAttrib() { | |
47 | + return dummyAttrib; | |
48 | + } | |
49 | + | |
50 | + public void setDummyAttribWithClassAuthorization(String dummyAttrib) { | |
51 | + this.dummyAttrib = dummyAttrib; | |
52 | + } | |
53 | + | |
54 | + @RequiredPermission(resource = "resource", operation = "operation") | |
55 | + public void setDummyAttribWithAuthorization(String dummyAttrib) { | |
56 | + this.dummyAttrib = dummyAttrib; | |
57 | + } | |
58 | + | |
59 | +} | ... | ... |
impl/core/src/test/java/security/interceptor/requiredpermission/DummyProtectedClassAuthorized.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.requiredpermission; | |
38 | + | |
39 | +import br.gov.frameworkdemoiselle.security.RequiredPermission; | |
40 | + | |
41 | +@RequiredPermission(resource="resource", operation="operation") | |
42 | +public class DummyProtectedClassAuthorized { | |
43 | + | |
44 | + private String dummyAttrib; | |
45 | + | |
46 | + public String getDummyAttrib() { | |
47 | + return dummyAttrib; | |
48 | + } | |
49 | + | |
50 | + public void setDummyAttrib(String dummyAttrib) { | |
51 | + this.dummyAttrib = dummyAttrib; | |
52 | + } | |
53 | + | |
54 | +} | ... | ... |
impl/core/src/test/java/security/interceptor/requiredpermission/DummyProtectedClassAuthorizedWithoutParams.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.requiredpermission; | |
38 | + | |
39 | +import br.gov.frameworkdemoiselle.security.RequiredPermission; | |
40 | + | |
41 | +@RequiredPermission | |
42 | +public class DummyProtectedClassAuthorizedWithoutParams { | |
43 | + | |
44 | + private String dummyAttrib; | |
45 | + | |
46 | + public String getDummyAttrib() { | |
47 | + return dummyAttrib; | |
48 | + } | |
49 | + | |
50 | + public void setDummyAttrib(String dummyAttrib) { | |
51 | + this.dummyAttrib = dummyAttrib; | |
52 | + } | |
53 | + | |
54 | +} | ... | ... |
impl/core/src/test/java/security/interceptor/requiredpermission/DummyProtectedClassUnauthorized.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.requiredpermission; | |
38 | + | |
39 | +import br.gov.frameworkdemoiselle.security.RequiredPermission; | |
40 | + | |
41 | +@RequiredPermission(resource="resource false", operation="operation false") | |
42 | +public class DummyProtectedClassUnauthorized { | |
43 | + | |
44 | + private String dummyAttrib; | |
45 | + | |
46 | + public String getDummyAttrib() { | |
47 | + return dummyAttrib; | |
48 | + } | |
49 | + | |
50 | + public void setDummyAttrib(String dummyAttrib) { | |
51 | + this.dummyAttrib = dummyAttrib; | |
52 | + } | |
53 | + | |
54 | +} | ... | ... |
impl/core/src/test/java/security/interceptor/requiredpermission/DummyProtectedMethods.java
0 → 100644
... | ... | @@ -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.interceptor.requiredpermission; | |
38 | + | |
39 | +import br.gov.frameworkdemoiselle.security.RequiredPermission; | |
40 | + | |
41 | +public class DummyProtectedMethods { | |
42 | + | |
43 | + private String dummyAttrib = "Default"; | |
44 | + | |
45 | + | |
46 | + public String getDummyAttrib() { | |
47 | + return dummyAttrib; | |
48 | + } | |
49 | + | |
50 | + @RequiredPermission(resource="resource", operation="operation") | |
51 | + public void setDummyAttribAuthorized(String dummyAttrib) { | |
52 | + this.dummyAttrib = dummyAttrib; | |
53 | + } | |
54 | + | |
55 | + @RequiredPermission(resource="resource false", operation="operation false") | |
56 | + public void setDummyAttribUnauthorized(String dummyAttrib) { | |
57 | + this.dummyAttrib = dummyAttrib; | |
58 | + } | |
59 | + | |
60 | +} | ... | ... |
impl/core/src/test/java/security/interceptor/requiredpermission/RequiredPermissionInterceptorTest.java
0 → 100644
... | ... | @@ -0,0 +1,143 @@ |
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.requiredpermission; | |
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.Ignore; | |
50 | +import org.junit.Test; | |
51 | +import org.junit.runner.RunWith; | |
52 | + | |
53 | +import security.interceptor.loggedin.CustomAuthenticator; | |
54 | +import test.Tests; | |
55 | +import br.gov.frameworkdemoiselle.context.SessionContext; | |
56 | +import br.gov.frameworkdemoiselle.security.AuthorizationException; | |
57 | +import br.gov.frameworkdemoiselle.security.SecurityContext; | |
58 | +import br.gov.frameworkdemoiselle.util.Beans; | |
59 | + | |
60 | +@RunWith(Arquillian.class) | |
61 | +public class RequiredPermissionInterceptorTest { | |
62 | + | |
63 | + @Inject | |
64 | + private DummyProtectedClassAuthorized protectedClassAuthorized; | |
65 | + | |
66 | + @Inject | |
67 | + private DummyProtectedClassUnauthorized protectedClassUnAuthorized; | |
68 | + | |
69 | + @Inject | |
70 | + private DummyProtectedMethods protectedMethods; | |
71 | + | |
72 | + @Inject | |
73 | + private DummyProtectedClassAndMethod protectedClassAndMethod; | |
74 | + | |
75 | + @Inject | |
76 | + private SecurityContext securityContext; | |
77 | + | |
78 | + @Deployment | |
79 | + public static JavaArchive createDeployment() { | |
80 | + JavaArchive deployment = Tests.createDeployment(); | |
81 | + deployment.addClass(DummyProtectedClassAuthorized.class); | |
82 | + deployment.addClass(DummyProtectedClassUnauthorized.class); | |
83 | + deployment.addClass(DummyProtectedMethods.class); | |
84 | + deployment.addClass(DummyProtectedClassAndMethod.class); | |
85 | + deployment.addClass(CustomAuthenticator.class); | |
86 | + deployment.addClass(CustomAuthorizer.class); | |
87 | + return deployment; | |
88 | + } | |
89 | + | |
90 | + @Before | |
91 | + public void activeContext() { | |
92 | + SessionContext sessionContext = Beans.getReference(SessionContext.class); | |
93 | + sessionContext.activate(); | |
94 | + | |
95 | + securityContext.login(); | |
96 | + } | |
97 | + | |
98 | + @Test(expected=AuthorizationException.class) | |
99 | + public void callProtectedClassAttribNotAuthorized() { | |
100 | + protectedClassUnAuthorized.getDummyAttrib(); | |
101 | + } | |
102 | + | |
103 | + @Test | |
104 | + public void callProtectedClassAttribAuthorized() { | |
105 | + protectedClassAuthorized.setDummyAttrib("Test"); | |
106 | + assertEquals("Test", protectedClassAuthorized.getDummyAttrib()); | |
107 | + } | |
108 | + | |
109 | + @Test(expected=AuthorizationException.class) | |
110 | + public void callProtectedMethodNotAuthorized(){ | |
111 | + protectedMethods.setDummyAttribUnauthorized("Not Authorized"); | |
112 | + } | |
113 | + | |
114 | + @Test | |
115 | + public void callProtectedMethodAuthorized(){ | |
116 | + protectedMethods.setDummyAttribAuthorized("Authorized"); | |
117 | + assertEquals("Authorized", protectedMethods.getDummyAttrib()); | |
118 | + } | |
119 | + | |
120 | + /** | |
121 | + * This test aim to verify the priority of method authorization over class authorization | |
122 | + */ | |
123 | + @Test | |
124 | + public void callNotAnnotatedMethod(){ | |
125 | + try{ | |
126 | + protectedClassAndMethod.setDummyAttribWithClassAuthorization("Class not authorized"); | |
127 | + fail(); | |
128 | + }catch(AuthorizationException cause){ | |
129 | + } | |
130 | + | |
131 | + protectedClassAndMethod.setDummyAttribWithAuthorization("Method authorized"); | |
132 | + } | |
133 | + | |
134 | + | |
135 | + | |
136 | + @After | |
137 | + public void deactiveContext() { | |
138 | + securityContext.logout(); | |
139 | + | |
140 | + SessionContext ctx = Beans.getReference(SessionContext.class); | |
141 | + ctx.deactivate(); | |
142 | + } | |
143 | +} | ... | ... |
impl/core/src/test/java/security/interceptor/requiredpermission/RequiredPermissionInterceptorTest2.java
0 → 100644
... | ... | @@ -0,0 +1,99 @@ |
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.requiredpermission; | |
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.Ignore; | |
50 | +import org.junit.Test; | |
51 | +import org.junit.runner.RunWith; | |
52 | + | |
53 | +import security.interceptor.loggedin.CustomAuthenticator; | |
54 | +import test.Tests; | |
55 | +import br.gov.frameworkdemoiselle.context.SessionContext; | |
56 | +import br.gov.frameworkdemoiselle.security.AuthorizationException; | |
57 | +import br.gov.frameworkdemoiselle.security.SecurityContext; | |
58 | +import br.gov.frameworkdemoiselle.util.Beans; | |
59 | + | |
60 | +@RunWith(Arquillian.class) | |
61 | +public class RequiredPermissionInterceptorTest2 { | |
62 | + | |
63 | + @Inject | |
64 | + private DummyProtectedClassAuthorizedWithoutParams protectedClassAuthorizedWithoutParams; | |
65 | + | |
66 | + @Inject | |
67 | + private SecurityContext securityContext; | |
68 | + | |
69 | + @Deployment | |
70 | + public static JavaArchive createDeployment() { | |
71 | + JavaArchive deployment = Tests.createDeployment(); | |
72 | + deployment.addClass(DummyProtectedClassAuthorizedWithoutParams.class); | |
73 | + deployment.addClass(CustomAuthenticator.class); | |
74 | + deployment.addClass(CustomAuthorizer2.class); | |
75 | + return deployment; | |
76 | + } | |
77 | + | |
78 | + @Before | |
79 | + public void activeContext() { | |
80 | + SessionContext sessionContext = Beans.getReference(SessionContext.class); | |
81 | + sessionContext.activate(); | |
82 | + | |
83 | + securityContext.login(); | |
84 | + } | |
85 | + | |
86 | + @Test | |
87 | + public void callProtectedClassAttribNotAuthorized() { | |
88 | + protectedClassAuthorizedWithoutParams.setDummyAttrib("Test"); | |
89 | + assertEquals("Test", protectedClassAuthorizedWithoutParams.getDummyAttrib()); | |
90 | + } | |
91 | + | |
92 | + @After | |
93 | + public void deactiveContext() { | |
94 | + securityContext.logout(); | |
95 | + | |
96 | + SessionContext ctx = Beans.getReference(SessionContext.class); | |
97 | + ctx.deactivate(); | |
98 | + } | |
99 | +} | ... | ... |