Commit 765af464a07f2bd6d4aed7f720a7cdb7764ef1ae
1 parent
310bb0d4
Exists in
master
Inclusão do projeto de exemplo de segurança
Showing
14 changed files
with
788 additions
and
12 deletions
Show diff stats
example/pom.xml
| ... | ... | @@ -49,19 +49,7 @@ |
| 49 | 49 | |
| 50 | 50 | <modules> |
| 51 | 51 | <module>initializer</module> |
| 52 | - <!-- | |
| 53 | - <module>configuration</module> | |
| 54 | - <module>exception-handler</module> | |
| 55 | - <module>logger</module> | |
| 56 | - <module>message</module> | |
| 57 | - <module>pagination</module> | |
| 58 | - <module>parameter</module> | |
| 59 | - <module>resource-bundle</module> | |
| 60 | 52 | <module>security</module> |
| 61 | - <module>jpa-transaction</module> | |
| 62 | - <module>jta-transaction</module> | |
| 63 | - <module>twophasecommit</module> | |
| 64 | - --> | |
| 65 | 53 | </modules> |
| 66 | 54 | |
| 67 | 55 | <build> | ... | ... |
| ... | ... | @@ -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 | +<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0" | |
| 38 | + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> | |
| 39 | + | |
| 40 | + <modelVersion>4.0.0</modelVersion> | |
| 41 | + | |
| 42 | + <artifactId>demoiselle-security-example</artifactId> | |
| 43 | + <packaging>jar</packaging> | |
| 44 | + | |
| 45 | + <name></name> | |
| 46 | + <description></description> | |
| 47 | + <url></url> | |
| 48 | + | |
| 49 | + <parent> | |
| 50 | + <groupId>br.gov.frameworkdemoiselle</groupId> | |
| 51 | + <artifactId>demoiselle-minimal-parent</artifactId> | |
| 52 | + <version>2.3.0-RC1-SNAPSHOT</version> | |
| 53 | + <relativePath>../../parent/minimal/pom.xml</relativePath> | |
| 54 | + </parent> | |
| 55 | + | |
| 56 | + <dependencies> | |
| 57 | + <dependency> | |
| 58 | + <groupId>org.slf4j</groupId> | |
| 59 | + <artifactId>slf4j-log4j12</artifactId> | |
| 60 | + <scope>test</scope> | |
| 61 | + </dependency> | |
| 62 | + </dependencies> | |
| 63 | + | |
| 64 | + <repositories> | |
| 65 | + <repository> | |
| 66 | + <id>demoiselle.sourceforge.net-release</id> | |
| 67 | + <url>http://demoiselle.sourceforge.net/repository/release</url> | |
| 68 | + </repository> | |
| 69 | + </repositories> | |
| 70 | + | |
| 71 | + <properties> | |
| 72 | + <demoiselle.junit.version>2.3.0-RC1-SNAPSHOT</demoiselle.junit.version> | |
| 73 | + </properties> | |
| 74 | +</project> | |
| 0 | 75 | \ No newline at end of file | ... | ... |
| ... | ... | @@ -0,0 +1,64 @@ |
| 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 example; | |
| 38 | + | |
| 39 | +import br.gov.frameworkdemoiselle.security.RequiredPermission; | |
| 40 | +import br.gov.frameworkdemoiselle.security.RequiredRole; | |
| 41 | + | |
| 42 | +public class Hello { | |
| 43 | + | |
| 44 | + @RequiredPermission(resource = "Hello") | |
| 45 | + public void say1() { | |
| 46 | + System.out.println("Hello 1"); | |
| 47 | + } | |
| 48 | + | |
| 49 | + @RequiredPermission(resource = "World", operation = "scream") | |
| 50 | + public void say2() { | |
| 51 | + System.out.println("Hello 2"); | |
| 52 | + } | |
| 53 | + | |
| 54 | + @RequiredRole("admin") | |
| 55 | + public void say3() { | |
| 56 | + System.out.println("Hello 3"); | |
| 57 | + } | |
| 58 | + | |
| 59 | + @RequiredRole("jedi") | |
| 60 | + @RequiredPermission(resource = "World", operation = "say4") | |
| 61 | + public void say4() { | |
| 62 | + System.out.println("Hello 4"); | |
| 63 | + } | |
| 64 | +} | ... | ... |
example/security/src/main/java/example/MyAuthenticator.java
0 → 100755
| ... | ... | @@ -0,0 +1,81 @@ |
| 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 example; | |
| 38 | + | |
| 39 | +import javax.enterprise.context.SessionScoped; | |
| 40 | +import javax.inject.Inject; | |
| 41 | + | |
| 42 | +import br.gov.frameworkdemoiselle.security.Authenticator; | |
| 43 | +import br.gov.frameworkdemoiselle.security.User; | |
| 44 | + | |
| 45 | +@SessionScoped | |
| 46 | +public class MyAuthenticator implements Authenticator { | |
| 47 | + | |
| 48 | + private static final long serialVersionUID = 1L; | |
| 49 | + | |
| 50 | + @Inject | |
| 51 | + private MyCredentials credentials; | |
| 52 | + | |
| 53 | + private User user; | |
| 54 | + | |
| 55 | + @Override | |
| 56 | + public boolean authenticate() { | |
| 57 | + boolean authenticated = false; | |
| 58 | + | |
| 59 | + String username = credentials.getUsername(); | |
| 60 | + String password = credentials.getPassword(); | |
| 61 | + | |
| 62 | + if ("santos.dumont".equals(username) && "secret".equals(password)) { | |
| 63 | + user = new MyUser(credentials.getUsername()); | |
| 64 | + user.setAttribute("roles", credentials.getRoles()); | |
| 65 | + | |
| 66 | + authenticated = true; | |
| 67 | + } | |
| 68 | + | |
| 69 | + return authenticated; | |
| 70 | + } | |
| 71 | + | |
| 72 | + @Override | |
| 73 | + public User getUser() { | |
| 74 | + return user; | |
| 75 | + } | |
| 76 | + | |
| 77 | + @Override | |
| 78 | + public void unAuthenticate() { | |
| 79 | + user = null; | |
| 80 | + } | |
| 81 | +} | ... | ... |
example/security/src/main/java/example/MyAuthorizer.java
0 → 100755
| ... | ... | @@ -0,0 +1,71 @@ |
| 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 example; | |
| 38 | + | |
| 39 | +import java.util.List; | |
| 40 | + | |
| 41 | +import javax.inject.Inject; | |
| 42 | + | |
| 43 | +import br.gov.frameworkdemoiselle.security.Authorizer; | |
| 44 | +import br.gov.frameworkdemoiselle.security.SecurityContext; | |
| 45 | + | |
| 46 | +public class MyAuthorizer implements Authorizer { | |
| 47 | + | |
| 48 | + private static final long serialVersionUID = 1L; | |
| 49 | + | |
| 50 | + @Inject | |
| 51 | + private SecurityContext securityContext; | |
| 52 | + | |
| 53 | + @Override | |
| 54 | + @SuppressWarnings("unchecked") | |
| 55 | + public boolean hasRole(String role) { | |
| 56 | + List<String> roles = (List<String>) securityContext.getUser().getAttribute("roles"); | |
| 57 | + | |
| 58 | + return roles.contains(role); | |
| 59 | + } | |
| 60 | + | |
| 61 | + @Override | |
| 62 | + public boolean hasPermission(String resource, String operation) { | |
| 63 | + boolean permitted = false; | |
| 64 | + | |
| 65 | + if (resource.equals("Hello") && operation.equals("say1")) { | |
| 66 | + permitted = true; | |
| 67 | + } | |
| 68 | + | |
| 69 | + return permitted; | |
| 70 | + } | |
| 71 | +} | ... | ... |
example/security/src/main/java/example/MyCredentials.java
0 → 100755
| ... | ... | @@ -0,0 +1,79 @@ |
| 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 example; | |
| 38 | + | |
| 39 | +import java.io.Serializable; | |
| 40 | +import java.util.ArrayList; | |
| 41 | +import java.util.List; | |
| 42 | + | |
| 43 | +import javax.enterprise.context.RequestScoped; | |
| 44 | + | |
| 45 | +@RequestScoped | |
| 46 | +public class MyCredentials implements Serializable { | |
| 47 | + | |
| 48 | + private static final long serialVersionUID = 1L; | |
| 49 | + | |
| 50 | + private String username; | |
| 51 | + | |
| 52 | + private String password; | |
| 53 | + | |
| 54 | + private List<String> roles = new ArrayList<String>(); | |
| 55 | + | |
| 56 | + public String getUsername() { | |
| 57 | + return username; | |
| 58 | + } | |
| 59 | + | |
| 60 | + public void setUsername(String username) { | |
| 61 | + this.username = username; | |
| 62 | + } | |
| 63 | + | |
| 64 | + public String getPassword() { | |
| 65 | + return password; | |
| 66 | + } | |
| 67 | + | |
| 68 | + public void setPassword(String password) { | |
| 69 | + this.password = password; | |
| 70 | + } | |
| 71 | + | |
| 72 | + public List<String> getRoles() { | |
| 73 | + return roles; | |
| 74 | + } | |
| 75 | + | |
| 76 | + public void addRole(String role) { | |
| 77 | + this.roles.add(role); | |
| 78 | + } | |
| 79 | +} | ... | ... |
| ... | ... | @@ -0,0 +1,70 @@ |
| 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 example; | |
| 38 | + | |
| 39 | +import java.util.HashMap; | |
| 40 | +import java.util.Map; | |
| 41 | + | |
| 42 | +import br.gov.frameworkdemoiselle.security.User; | |
| 43 | + | |
| 44 | +public class MyUser implements User { | |
| 45 | + | |
| 46 | + private static final long serialVersionUID = 1L; | |
| 47 | + | |
| 48 | + private final String username; | |
| 49 | + | |
| 50 | + private Map<String, Object> attrs = new HashMap<String, Object>(); | |
| 51 | + | |
| 52 | + public MyUser(String username) { | |
| 53 | + this.username = username; | |
| 54 | + } | |
| 55 | + | |
| 56 | + @Override | |
| 57 | + public String getId() { | |
| 58 | + return this.username; | |
| 59 | + } | |
| 60 | + | |
| 61 | + @Override | |
| 62 | + public Object getAttribute(Object key) { | |
| 63 | + return this.attrs.get(key); | |
| 64 | + } | |
| 65 | + | |
| 66 | + @Override | |
| 67 | + public void setAttribute(Object key, Object value) { | |
| 68 | + this.attrs.put((String) key, value); | |
| 69 | + } | |
| 70 | +} | ... | ... |
| ... | ... | @@ -0,0 +1,39 @@ |
| 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 | +<beans xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/beans_1_0.xsd"> | |
| 38 | + | |
| 39 | +</beans> | ... | ... |
example/security/src/main/resources/demoiselle.properties
0 → 100755
| ... | ... | @@ -0,0 +1,37 @@ |
| 1 | +# Demoiselle Framework | |
| 2 | +# Copyright (C) 2010 SERPRO | |
| 3 | +# ---------------------------------------------------------------------------- | |
| 4 | +# This file is part of Demoiselle Framework. | |
| 5 | +# | |
| 6 | +# Demoiselle Framework is free software; you can redistribute it and/or | |
| 7 | +# modify it under the terms of the GNU Lesser General Public License version 3 | |
| 8 | +# as published by the Free Software Foundation. | |
| 9 | +# | |
| 10 | +# This program is distributed in the hope that it will be useful, | |
| 11 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 12 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 13 | +# GNU General Public License for more details. | |
| 14 | +# | |
| 15 | +# You should have received a copy of the GNU Lesser General Public License version 3 | |
| 16 | +# along with this program; if not, see <http://www.gnu.org/licenses/> | |
| 17 | +# or write to the Free Software Foundation, Inc., 51 Franklin Street, | |
| 18 | +# Fifth Floor, Boston, MA 02110-1301, USA. | |
| 19 | +# ---------------------------------------------------------------------------- | |
| 20 | +# Este arquivo é parte do Framework Demoiselle. | |
| 21 | +# | |
| 22 | +# O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou | |
| 23 | +# modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação | |
| 24 | +# do Software Livre (FSF). | |
| 25 | +# | |
| 26 | +# Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA | |
| 27 | +# GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou | |
| 28 | +# APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português | |
| 29 | +# para maiores detalhes. | |
| 30 | +# | |
| 31 | +# Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título | |
| 32 | +# "LICENCA.txt", junto com esse programa. Se não, acesse <http://www.gnu.org/licenses/> | |
| 33 | +# ou escreva para a Fundação do Software Livre (FSF) Inc., | |
| 34 | +# 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA. | |
| 35 | + | |
| 36 | +#frameworkdemoiselle.security.authenticator.class=example.MyAuthenticator | |
| 37 | +#frameworkdemoiselle.security.authorizer.class=example.MyAuthorizer | ... | ... |
example/security/src/test/java/example/AunthenticationTest.java
0 → 100755
| ... | ... | @@ -0,0 +1,83 @@ |
| 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 example; | |
| 38 | + | |
| 39 | +import static junit.framework.Assert.assertFalse; | |
| 40 | +import static junit.framework.Assert.assertTrue; | |
| 41 | + | |
| 42 | +import javax.inject.Inject; | |
| 43 | + | |
| 44 | +import org.junit.Test; | |
| 45 | +import org.junit.runner.RunWith; | |
| 46 | + | |
| 47 | +import br.gov.frameworkdemoiselle.junit.DemoiselleRunner; | |
| 48 | +import br.gov.frameworkdemoiselle.security.SecurityContext; | |
| 49 | + | |
| 50 | +@RunWith(DemoiselleRunner.class) | |
| 51 | +public class AunthenticationTest { | |
| 52 | + | |
| 53 | + @Inject | |
| 54 | + private MyCredentials credential; | |
| 55 | + | |
| 56 | + @Inject | |
| 57 | + private SecurityContext securityContext; | |
| 58 | + | |
| 59 | + @Test | |
| 60 | + public void isNotLogged() { | |
| 61 | + assertFalse(securityContext.isLoggedIn()); | |
| 62 | + } | |
| 63 | + | |
| 64 | + @Test | |
| 65 | + public void loginFailed() { | |
| 66 | + credential.setUsername("santos.dumont"); | |
| 67 | + credential.setPassword("123"); | |
| 68 | + securityContext.login(); | |
| 69 | + | |
| 70 | + assertFalse(securityContext.isLoggedIn()); | |
| 71 | + } | |
| 72 | + | |
| 73 | + @Test | |
| 74 | + public void loginSuccessful() { | |
| 75 | + credential.setUsername("santos.dumont"); | |
| 76 | + credential.setPassword("secret"); | |
| 77 | + securityContext.login(); | |
| 78 | + | |
| 79 | + assertTrue(securityContext.isLoggedIn()); | |
| 80 | + | |
| 81 | + securityContext.logout(); | |
| 82 | + } | |
| 83 | +} | ... | ... |
example/security/src/test/java/example/AunthorizationTest.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 example; | |
| 38 | + | |
| 39 | +import static junit.framework.Assert.fail; | |
| 40 | + | |
| 41 | +import javax.inject.Inject; | |
| 42 | + | |
| 43 | +import org.junit.After; | |
| 44 | +import org.junit.Before; | |
| 45 | +import org.junit.Test; | |
| 46 | +import org.junit.runner.RunWith; | |
| 47 | + | |
| 48 | +import br.gov.frameworkdemoiselle.junit.DemoiselleRunner; | |
| 49 | +import br.gov.frameworkdemoiselle.security.AuthorizationException; | |
| 50 | +import br.gov.frameworkdemoiselle.security.SecurityContext; | |
| 51 | +import br.gov.frameworkdemoiselle.util.Beans; | |
| 52 | + | |
| 53 | +@RunWith(DemoiselleRunner.class) | |
| 54 | +public class AunthorizationTest { | |
| 55 | + | |
| 56 | + @Inject | |
| 57 | + private Hello hello; | |
| 58 | + | |
| 59 | + @Before | |
| 60 | + public void before() { | |
| 61 | + MyCredentials myCredentials = Beans.getReference(MyCredentials.class); | |
| 62 | + | |
| 63 | + myCredentials.setUsername("santos.dumont"); | |
| 64 | + myCredentials.setPassword("secret"); | |
| 65 | + myCredentials.addRole("admin"); | |
| 66 | + myCredentials.addRole("jedi"); | |
| 67 | + | |
| 68 | + SecurityContext securityContext = Beans.getReference(SecurityContext.class); | |
| 69 | + securityContext.login(); | |
| 70 | + } | |
| 71 | + | |
| 72 | + @After | |
| 73 | + public void after() { | |
| 74 | + SecurityContext securityContext = Beans.getReference(SecurityContext.class); | |
| 75 | + securityContext.logout(); | |
| 76 | + } | |
| 77 | + | |
| 78 | + @Test | |
| 79 | + public void accessSuccessfulSaying1() { | |
| 80 | + hello.say1(); | |
| 81 | + } | |
| 82 | + | |
| 83 | + @Test(expected = AuthorizationException.class) | |
| 84 | + public void accessFailedSaying2() { | |
| 85 | + hello.say2(); | |
| 86 | + fail(); | |
| 87 | + } | |
| 88 | + | |
| 89 | + @Test | |
| 90 | + public void accessFailedSaying3() { | |
| 91 | + hello.say3(); | |
| 92 | + } | |
| 93 | + | |
| 94 | + @Test(expected = AuthorizationException.class) | |
| 95 | + public void accessFailedSaying4() { | |
| 96 | + hello.say4(); | |
| 97 | + fail(); | |
| 98 | + } | |
| 99 | +} | ... | ... |
| ... | ... | @@ -0,0 +1,47 @@ |
| 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 | +<beans xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/beans_1_0.xsd"> | |
| 38 | + | |
| 39 | + <interceptors> | |
| 40 | + <class>br.gov.frameworkdemoiselle.internal.interceptor.ExceptionHandlerInterceptor</class> | |
| 41 | + <class>br.gov.frameworkdemoiselle.internal.interceptor.RequiredPermissionInterceptor</class> | |
| 42 | + <class>br.gov.frameworkdemoiselle.internal.interceptor.RequiredRoleInterceptor</class> | |
| 43 | + <class>br.gov.frameworkdemoiselle.internal.interceptor.TransactionalInterceptor</class> | |
| 44 | + <class>br.gov.frameworkdemoiselle.internal.interceptor.ConfigurationInterceptor</class> | |
| 45 | + </interceptors> | |
| 46 | + | |
| 47 | +</beans> | ... | ... |
| ... | ... | @@ -0,0 +1,39 @@ |
| 1 | +# Demoiselle Framework | |
| 2 | +# Copyright (C) 2010 SERPRO | |
| 3 | +# ---------------------------------------------------------------------------- | |
| 4 | +# This file is part of Demoiselle Framework. | |
| 5 | +# | |
| 6 | +# Demoiselle Framework is free software; you can redistribute it and/or | |
| 7 | +# modify it under the terms of the GNU Lesser General Public License version 3 | |
| 8 | +# as published by the Free Software Foundation. | |
| 9 | +# | |
| 10 | +# This program is distributed in the hope that it will be useful, | |
| 11 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 12 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 13 | +# GNU General Public License for more details. | |
| 14 | +# | |
| 15 | +# You should have received a copy of the GNU Lesser General Public License version 3 | |
| 16 | +# along with this program; if not, see <http://www.gnu.org/licenses/> | |
| 17 | +# or write to the Free Software Foundation, Inc., 51 Franklin Street, | |
| 18 | +# Fifth Floor, Boston, MA 02110-1301, USA. | |
| 19 | +# ---------------------------------------------------------------------------- | |
| 20 | +# Este arquivo é parte do Framework Demoiselle. | |
| 21 | +# | |
| 22 | +# O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou | |
| 23 | +# modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação | |
| 24 | +# do Software Livre (FSF). | |
| 25 | +# | |
| 26 | +# Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA | |
| 27 | +# GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou | |
| 28 | +# APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português | |
| 29 | +# para maiores detalhes. | |
| 30 | +# | |
| 31 | +# Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título | |
| 32 | +# "LICENCA.txt", junto com esse programa. Se não, acesse <http://www.gnu.org/licenses/> | |
| 33 | +# ou escreva para a Fundação do Software Livre (FSF) Inc., | |
| 34 | +# 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA. | |
| 35 | + | |
| 36 | +log4j.rootLogger=INFO, A1 | |
| 37 | +log4j.appender.A1=org.apache.log4j.ConsoleAppender | |
| 38 | +log4j.appender.A1.layout=org.apache.log4j.PatternLayout | |
| 39 | +log4j.appender.A1.layout.ConversionPattern=%-4r %-5p %c - %m%n | ... | ... |