Commit c42db84298e63833f85982a44c7da1895e6073b0
1 parent
50852382
Exists in
master
FWK-198: Remoção da interface User
Task-Url: https://demoiselle.atlassian.net/browse/FWK-198
Showing
21 changed files
with
81 additions
and
239 deletions
Show diff stats
archetype/html-rest/src/main/resources/archetype-resources/src/main/java/rest/AuthREST.java
| 1 | package ${package}.rest; | 1 | package ${package}.rest; |
| 2 | 2 | ||
| 3 | +import java.security.Principal; | ||
| 4 | + | ||
| 3 | import javax.inject.Inject; | 5 | import javax.inject.Inject; |
| 4 | import javax.validation.constraints.NotNull; | 6 | import javax.validation.constraints.NotNull; |
| 5 | import javax.validation.constraints.Size; | 7 | import javax.validation.constraints.Size; |
| @@ -12,7 +14,6 @@ import javax.ws.rs.Produces; | @@ -12,7 +14,6 @@ import javax.ws.rs.Produces; | ||
| 12 | import br.gov.frameworkdemoiselle.security.Credentials; | 14 | import br.gov.frameworkdemoiselle.security.Credentials; |
| 13 | import br.gov.frameworkdemoiselle.security.LoggedIn; | 15 | import br.gov.frameworkdemoiselle.security.LoggedIn; |
| 14 | import br.gov.frameworkdemoiselle.security.SecurityContext; | 16 | import br.gov.frameworkdemoiselle.security.SecurityContext; |
| 15 | -import br.gov.frameworkdemoiselle.security.User; | ||
| 16 | import br.gov.frameworkdemoiselle.util.Beans; | 17 | import br.gov.frameworkdemoiselle.util.Beans; |
| 17 | import br.gov.frameworkdemoiselle.util.ValidatePayload; | 18 | import br.gov.frameworkdemoiselle.util.ValidatePayload; |
| 18 | 19 | ||
| @@ -37,7 +38,7 @@ public class AuthREST { | @@ -37,7 +38,7 @@ public class AuthREST { | ||
| 37 | @GET | 38 | @GET |
| 38 | @LoggedIn | 39 | @LoggedIn |
| 39 | @Produces("application/json") | 40 | @Produces("application/json") |
| 40 | - public User getLoggedInUser() { | 41 | + public Principal getLoggedInUser() { |
| 41 | return securityContext.getUser(); | 42 | return securityContext.getUser(); |
| 42 | } | 43 | } |
| 43 | 44 |
archetype/html-rest/src/main/resources/archetype-resources/src/main/java/security/AppAuthenticator.java
| 1 | package ${package}.security; | 1 | package ${package}.security; |
| 2 | 2 | ||
| 3 | +import java.security.Principal; | ||
| 4 | + | ||
| 3 | import javax.enterprise.context.RequestScoped; | 5 | import javax.enterprise.context.RequestScoped; |
| 4 | 6 | ||
| 5 | import br.gov.frameworkdemoiselle.security.Authenticator; | 7 | import br.gov.frameworkdemoiselle.security.Authenticator; |
| 6 | import br.gov.frameworkdemoiselle.security.Credentials; | 8 | import br.gov.frameworkdemoiselle.security.Credentials; |
| 7 | import br.gov.frameworkdemoiselle.security.InvalidCredentialsException; | 9 | import br.gov.frameworkdemoiselle.security.InvalidCredentialsException; |
| 8 | -import br.gov.frameworkdemoiselle.security.User; | ||
| 9 | import br.gov.frameworkdemoiselle.util.Beans; | 10 | import br.gov.frameworkdemoiselle.util.Beans; |
| 10 | 11 | ||
| 11 | @RequestScoped | 12 | @RequestScoped |
| @@ -13,14 +14,21 @@ public class AppAuthenticator implements Authenticator { | @@ -13,14 +14,21 @@ public class AppAuthenticator implements Authenticator { | ||
| 13 | 14 | ||
| 14 | private static final long serialVersionUID = 1L; | 15 | private static final long serialVersionUID = 1L; |
| 15 | 16 | ||
| 16 | - private User user; | 17 | + private Principal user; |
| 17 | 18 | ||
| 18 | @Override | 19 | @Override |
| 19 | public void authenticate() throws Exception { | 20 | public void authenticate() throws Exception { |
| 20 | - Credentials credentials = Beans.getReference(Credentials.class); | 21 | + final Credentials credentials = Beans.getReference(Credentials.class); |
| 21 | 22 | ||
| 22 | if (credentials.getPassword().equals("secret")) { | 23 | if (credentials.getPassword().equals("secret")) { |
| 23 | - this.user = new AppUser(credentials.getUsername()); | 24 | + this.user = new Principal() { |
| 25 | + | ||
| 26 | + @Override | ||
| 27 | + public String getName() { | ||
| 28 | + return credentials.getUsername(); | ||
| 29 | + } | ||
| 30 | + }; | ||
| 31 | + | ||
| 24 | } else { | 32 | } else { |
| 25 | throw new InvalidCredentialsException(); | 33 | throw new InvalidCredentialsException(); |
| 26 | } | 34 | } |
| @@ -32,7 +40,7 @@ public class AppAuthenticator implements Authenticator { | @@ -32,7 +40,7 @@ public class AppAuthenticator implements Authenticator { | ||
| 32 | } | 40 | } |
| 33 | 41 | ||
| 34 | @Override | 42 | @Override |
| 35 | - public User getUser() { | 43 | + public Principal getUser() { |
| 36 | return this.user; | 44 | return this.user; |
| 37 | } | 45 | } |
| 38 | } | 46 | } |
archetype/html-rest/src/main/resources/archetype-resources/src/main/java/security/AppUser.java
| @@ -1,31 +0,0 @@ | @@ -1,31 +0,0 @@ | ||
| 1 | -package ${package}.security; | ||
| 2 | - | ||
| 3 | -import org.codehaus.jackson.annotate.JsonProperty; | ||
| 4 | - | ||
| 5 | -import br.gov.frameworkdemoiselle.security.User; | ||
| 6 | - | ||
| 7 | -public class AppUser implements User { | ||
| 8 | - | ||
| 9 | - private static final long serialVersionUID = 1L; | ||
| 10 | - | ||
| 11 | - @JsonProperty("username") | ||
| 12 | - private String id; | ||
| 13 | - | ||
| 14 | - public AppUser(String id) { | ||
| 15 | - this.id = id; | ||
| 16 | - } | ||
| 17 | - | ||
| 18 | - @Override | ||
| 19 | - public String getId() { | ||
| 20 | - return this.id; | ||
| 21 | - } | ||
| 22 | - | ||
| 23 | - @Override | ||
| 24 | - public Object getAttribute(Object key) { | ||
| 25 | - return null; | ||
| 26 | - } | ||
| 27 | - | ||
| 28 | - @Override | ||
| 29 | - public void setAttribute(Object key, Object value) { | ||
| 30 | - } | ||
| 31 | -} |
archetype/html-rest/src/main/resources/archetype-resources/src/main/webapp/js/controller/menu.js
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/implementation/DefaultAuthenticator.java
| @@ -37,12 +37,14 @@ | @@ -37,12 +37,14 @@ | ||
| 37 | package br.gov.frameworkdemoiselle.internal.implementation; | 37 | package br.gov.frameworkdemoiselle.internal.implementation; |
| 38 | 38 | ||
| 39 | import static br.gov.frameworkdemoiselle.annotation.Priority.L1_PRIORITY; | 39 | import static br.gov.frameworkdemoiselle.annotation.Priority.L1_PRIORITY; |
| 40 | + | ||
| 41 | +import java.security.Principal; | ||
| 42 | + | ||
| 40 | import br.gov.frameworkdemoiselle.DemoiselleException; | 43 | import br.gov.frameworkdemoiselle.DemoiselleException; |
| 41 | import br.gov.frameworkdemoiselle.annotation.Priority; | 44 | import br.gov.frameworkdemoiselle.annotation.Priority; |
| 42 | import br.gov.frameworkdemoiselle.security.AuthenticationException; | 45 | import br.gov.frameworkdemoiselle.security.AuthenticationException; |
| 43 | import br.gov.frameworkdemoiselle.security.Authenticator; | 46 | import br.gov.frameworkdemoiselle.security.Authenticator; |
| 44 | import br.gov.frameworkdemoiselle.security.SecurityContext; | 47 | import br.gov.frameworkdemoiselle.security.SecurityContext; |
| 45 | -import br.gov.frameworkdemoiselle.security.User; | ||
| 46 | import br.gov.frameworkdemoiselle.util.Beans; | 48 | import br.gov.frameworkdemoiselle.util.Beans; |
| 47 | import br.gov.frameworkdemoiselle.util.NameQualifier; | 49 | import br.gov.frameworkdemoiselle.util.NameQualifier; |
| 48 | import br.gov.frameworkdemoiselle.util.ResourceBundle; | 50 | import br.gov.frameworkdemoiselle.util.ResourceBundle; |
| @@ -80,7 +82,7 @@ public class DefaultAuthenticator implements Authenticator { | @@ -80,7 +82,7 @@ public class DefaultAuthenticator implements Authenticator { | ||
| 80 | * @see br.gov.frameworkdemoiselle.security.Authenticator#getUser() | 82 | * @see br.gov.frameworkdemoiselle.security.Authenticator#getUser() |
| 81 | */ | 83 | */ |
| 82 | @Override | 84 | @Override |
| 83 | - public User getUser() { | 85 | + public Principal getUser() { |
| 84 | throw getException(); | 86 | throw getException(); |
| 85 | } | 87 | } |
| 86 | 88 |
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/implementation/SecurityContextImpl.java
| @@ -36,6 +36,9 @@ | @@ -36,6 +36,9 @@ | ||
| 36 | */ | 36 | */ |
| 37 | package br.gov.frameworkdemoiselle.internal.implementation; | 37 | package br.gov.frameworkdemoiselle.internal.implementation; |
| 38 | 38 | ||
| 39 | +import java.io.Serializable; | ||
| 40 | +import java.security.Principal; | ||
| 41 | + | ||
| 39 | import javax.inject.Named; | 42 | import javax.inject.Named; |
| 40 | 43 | ||
| 41 | import br.gov.frameworkdemoiselle.DemoiselleException; | 44 | import br.gov.frameworkdemoiselle.DemoiselleException; |
| @@ -48,7 +51,6 @@ import br.gov.frameworkdemoiselle.security.AuthorizationException; | @@ -48,7 +51,6 @@ import br.gov.frameworkdemoiselle.security.AuthorizationException; | ||
| 48 | import br.gov.frameworkdemoiselle.security.Authorizer; | 51 | import br.gov.frameworkdemoiselle.security.Authorizer; |
| 49 | import br.gov.frameworkdemoiselle.security.NotLoggedInException; | 52 | import br.gov.frameworkdemoiselle.security.NotLoggedInException; |
| 50 | import br.gov.frameworkdemoiselle.security.SecurityContext; | 53 | import br.gov.frameworkdemoiselle.security.SecurityContext; |
| 51 | -import br.gov.frameworkdemoiselle.security.User; | ||
| 52 | import br.gov.frameworkdemoiselle.util.Beans; | 54 | import br.gov.frameworkdemoiselle.util.Beans; |
| 53 | import br.gov.frameworkdemoiselle.util.NameQualifier; | 55 | import br.gov.frameworkdemoiselle.util.NameQualifier; |
| 54 | import br.gov.frameworkdemoiselle.util.ResourceBundle; | 56 | import br.gov.frameworkdemoiselle.util.ResourceBundle; |
| @@ -213,8 +215,8 @@ public class SecurityContextImpl implements SecurityContext { | @@ -213,8 +215,8 @@ public class SecurityContextImpl implements SecurityContext { | ||
| 213 | * @see br.gov.frameworkdemoiselle.security.SecurityContext#getUser() | 215 | * @see br.gov.frameworkdemoiselle.security.SecurityContext#getUser() |
| 214 | */ | 216 | */ |
| 215 | @Override | 217 | @Override |
| 216 | - public User getUser() { | ||
| 217 | - User user = getAuthenticator().getUser(); | 218 | + public Principal getUser() { |
| 219 | + Principal user = getAuthenticator().getUser(); | ||
| 218 | 220 | ||
| 219 | if (!getConfig().isEnabled() && user == null) { | 221 | if (!getConfig().isEnabled() && user == null) { |
| 220 | user = new EmptyUser(); | 222 | user = new EmptyUser(); |
| @@ -241,22 +243,13 @@ public class SecurityContextImpl implements SecurityContext { | @@ -241,22 +243,13 @@ public class SecurityContextImpl implements SecurityContext { | ||
| 241 | return bundle; | 243 | return bundle; |
| 242 | } | 244 | } |
| 243 | 245 | ||
| 244 | - private static class EmptyUser implements User { | 246 | + private static class EmptyUser implements Principal, Serializable { |
| 245 | 247 | ||
| 246 | private static final long serialVersionUID = 1L; | 248 | private static final long serialVersionUID = 1L; |
| 247 | 249 | ||
| 248 | @Override | 250 | @Override |
| 249 | - public String getId() { | 251 | + public String getName() { |
| 250 | return "demoiselle"; | 252 | return "demoiselle"; |
| 251 | } | 253 | } |
| 252 | - | ||
| 253 | - @Override | ||
| 254 | - public Object getAttribute(Object key) { | ||
| 255 | - return null; | ||
| 256 | - } | ||
| 257 | - | ||
| 258 | - @Override | ||
| 259 | - public void setAttribute(Object key, Object value) { | ||
| 260 | - } | ||
| 261 | } | 254 | } |
| 262 | } | 255 | } |
impl/core/src/main/java/br/gov/frameworkdemoiselle/security/Authenticator.java
| @@ -37,6 +37,7 @@ | @@ -37,6 +37,7 @@ | ||
| 37 | package br.gov.frameworkdemoiselle.security; | 37 | package br.gov.frameworkdemoiselle.security; |
| 38 | 38 | ||
| 39 | import java.io.Serializable; | 39 | import java.io.Serializable; |
| 40 | +import java.security.Principal; | ||
| 40 | 41 | ||
| 41 | /** | 42 | /** |
| 42 | * Defines the methods that should be implemented by anyone who wants an authentication mechanism. | 43 | * Defines the methods that should be implemented by anyone who wants an authentication mechanism. |
| @@ -75,5 +76,5 @@ public interface Authenticator extends Serializable { | @@ -75,5 +76,5 @@ public interface Authenticator extends Serializable { | ||
| 75 | * @see #authenticate() | 76 | * @see #authenticate() |
| 76 | * @see #unauthenticate() | 77 | * @see #unauthenticate() |
| 77 | */ | 78 | */ |
| 78 | - User getUser(); | 79 | + Principal getUser(); |
| 79 | } | 80 | } |
impl/core/src/main/java/br/gov/frameworkdemoiselle/security/RequiredPermissionInterceptor.java
| @@ -85,7 +85,7 @@ public class RequiredPermissionInterceptor implements Serializable { | @@ -85,7 +85,7 @@ public class RequiredPermissionInterceptor implements Serializable { | ||
| 85 | String username = null; | 85 | String username = null; |
| 86 | 86 | ||
| 87 | if (getSecurityContext().isLoggedIn()) { | 87 | if (getSecurityContext().isLoggedIn()) { |
| 88 | - username = getSecurityContext().getUser().getId(); | 88 | + username = getSecurityContext().getUser().getName(); |
| 89 | getLogger().trace(getBundle().getString("access-checking", username, operation, resource)); | 89 | getLogger().trace(getBundle().getString("access-checking", username, operation, resource)); |
| 90 | } | 90 | } |
| 91 | 91 |
impl/core/src/main/java/br/gov/frameworkdemoiselle/security/RequiredRoleInterceptor.java
| @@ -84,7 +84,7 @@ public class RequiredRoleInterceptor implements Serializable { | @@ -84,7 +84,7 @@ public class RequiredRoleInterceptor implements Serializable { | ||
| 84 | 84 | ||
| 85 | if (getSecurityContext().isLoggedIn()) { | 85 | if (getSecurityContext().isLoggedIn()) { |
| 86 | getLogger().info( | 86 | getLogger().info( |
| 87 | - getBundle().getString("has-role-verification", getSecurityContext().getUser().getId(), | 87 | + getBundle().getString("has-role-verification", getSecurityContext().getUser().getName(), |
| 88 | roles)); | 88 | roles)); |
| 89 | } | 89 | } |
| 90 | 90 | ||
| @@ -98,14 +98,14 @@ public class RequiredRoleInterceptor implements Serializable { | @@ -98,14 +98,14 @@ public class RequiredRoleInterceptor implements Serializable { | ||
| 98 | 98 | ||
| 99 | if (userRoles.isEmpty()) { | 99 | if (userRoles.isEmpty()) { |
| 100 | getLogger() | 100 | getLogger() |
| 101 | - .error(getBundle().getString("does-not-have-role", getSecurityContext().getUser().getId(), | 101 | + .error(getBundle().getString("does-not-have-role", getSecurityContext().getUser().getName(), |
| 102 | roles)); | 102 | roles)); |
| 103 | 103 | ||
| 104 | throw new AuthorizationException(getBundle().getString("does-not-have-role-ui", roles)); | 104 | throw new AuthorizationException(getBundle().getString("does-not-have-role-ui", roles)); |
| 105 | } | 105 | } |
| 106 | 106 | ||
| 107 | getLogger().debug( | 107 | getLogger().debug( |
| 108 | - getBundle().getString("user-has-role", getSecurityContext().getUser().getId(), userRoles)); | 108 | + getBundle().getString("user-has-role", getSecurityContext().getUser().getName(), userRoles)); |
| 109 | 109 | ||
| 110 | return ic.proceed(); | 110 | return ic.proceed(); |
| 111 | } | 111 | } |
impl/core/src/main/java/br/gov/frameworkdemoiselle/security/SecurityContext.java
| @@ -37,6 +37,7 @@ | @@ -37,6 +37,7 @@ | ||
| 37 | package br.gov.frameworkdemoiselle.security; | 37 | package br.gov.frameworkdemoiselle.security; |
| 38 | 38 | ||
| 39 | import java.io.Serializable; | 39 | import java.io.Serializable; |
| 40 | +import java.security.Principal; | ||
| 40 | 41 | ||
| 41 | /** | 42 | /** |
| 42 | * Structure used to handle both authentication and authorizations mechanisms. | 43 | * Structure used to handle both authentication and authorizations mechanisms. |
| @@ -111,6 +112,6 @@ public interface SecurityContext extends Serializable { | @@ -111,6 +112,6 @@ public interface SecurityContext extends Serializable { | ||
| 111 | * @return the user logged in a specific authenticated session. If there is no active session {@code null} is | 112 | * @return the user logged in a specific authenticated session. If there is no active session {@code null} is |
| 112 | * returned. | 113 | * returned. |
| 113 | */ | 114 | */ |
| 114 | - User getUser(); | 115 | + Principal getUser(); |
| 115 | 116 | ||
| 116 | } | 117 | } |
impl/core/src/main/java/br/gov/frameworkdemoiselle/security/User.java
| @@ -1,72 +0,0 @@ | @@ -1,72 +0,0 @@ | ||
| 1 | -/* | ||
| 2 | - * Demoiselle Framework | ||
| 3 | - * Copyright (C) 2010 SERPRO | ||
| 4 | - * ---------------------------------------------------------------------------- | ||
| 5 | - * This file is part of Demoiselle Framework. | ||
| 6 | - * | ||
| 7 | - * Demoiselle Framework is free software; you can redistribute it and/or | ||
| 8 | - * modify it under the terms of the GNU Lesser General Public License version 3 | ||
| 9 | - * as published by the Free Software Foundation. | ||
| 10 | - * | ||
| 11 | - * This program is distributed in the hope that it will be useful, | ||
| 12 | - * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 13 | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 14 | - * GNU General Public License for more details. | ||
| 15 | - * | ||
| 16 | - * You should have received a copy of the GNU Lesser General Public License version 3 | ||
| 17 | - * along with this program; if not, see <http://www.gnu.org/licenses/> | ||
| 18 | - * or write to the Free Software Foundation, Inc., 51 Franklin Street, | ||
| 19 | - * Fifth Floor, Boston, MA 02110-1301, USA. | ||
| 20 | - * ---------------------------------------------------------------------------- | ||
| 21 | - * Este arquivo é parte do Framework Demoiselle. | ||
| 22 | - * | ||
| 23 | - * O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou | ||
| 24 | - * modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação | ||
| 25 | - * do Software Livre (FSF). | ||
| 26 | - * | ||
| 27 | - * Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA | ||
| 28 | - * GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou | ||
| 29 | - * APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português | ||
| 30 | - * para maiores detalhes. | ||
| 31 | - * | ||
| 32 | - * Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título | ||
| 33 | - * "LICENCA.txt", junto com esse programa. Se não, acesse <http://www.gnu.org/licenses/> | ||
| 34 | - * ou escreva para a Fundação do Software Livre (FSF) Inc., | ||
| 35 | - * 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA. | ||
| 36 | - */ | ||
| 37 | -package br.gov.frameworkdemoiselle.security; | ||
| 38 | - | ||
| 39 | -import java.io.Serializable; | ||
| 40 | - | ||
| 41 | -/** | ||
| 42 | - * @author SERPRO | ||
| 43 | - */ | ||
| 44 | -public interface User extends Serializable { | ||
| 45 | - | ||
| 46 | - /** | ||
| 47 | - * Returns the id of the logged user. | ||
| 48 | - * | ||
| 49 | - * @return the id of the logged user | ||
| 50 | - */ | ||
| 51 | - String getId(); | ||
| 52 | - | ||
| 53 | - /** | ||
| 54 | - * Return the value associated with the key being passed. | ||
| 55 | - * | ||
| 56 | - * @param key | ||
| 57 | - * the key whose value should be searched | ||
| 58 | - * @return the value associated with the key being passed | ||
| 59 | - */ | ||
| 60 | - Object getAttribute(Object key); | ||
| 61 | - | ||
| 62 | - /** | ||
| 63 | - * Sets an attribute. | ||
| 64 | - * | ||
| 65 | - * @param key | ||
| 66 | - * the key that identifies the value | ||
| 67 | - * @param value | ||
| 68 | - * the value to be stored | ||
| 69 | - */ | ||
| 70 | - void setAttribute(Object key, Object value); | ||
| 71 | - | ||
| 72 | -} |
impl/core/src/test/java/security/athentication/ambiguity/DuplicatedCustomAuthenticator.java
| @@ -36,8 +36,9 @@ | @@ -36,8 +36,9 @@ | ||
| 36 | */ | 36 | */ |
| 37 | package security.athentication.ambiguity; | 37 | package security.athentication.ambiguity; |
| 38 | 38 | ||
| 39 | +import java.security.Principal; | ||
| 40 | + | ||
| 39 | import br.gov.frameworkdemoiselle.security.Authenticator; | 41 | import br.gov.frameworkdemoiselle.security.Authenticator; |
| 40 | -import br.gov.frameworkdemoiselle.security.User; | ||
| 41 | 42 | ||
| 42 | public class DuplicatedCustomAuthenticator implements Authenticator { | 43 | public class DuplicatedCustomAuthenticator implements Authenticator { |
| 43 | 44 | ||
| @@ -52,7 +53,7 @@ public class DuplicatedCustomAuthenticator implements Authenticator { | @@ -52,7 +53,7 @@ public class DuplicatedCustomAuthenticator implements Authenticator { | ||
| 52 | } | 53 | } |
| 53 | 54 | ||
| 54 | @Override | 55 | @Override |
| 55 | - public User getUser() { | 56 | + public Principal getUser() { |
| 56 | return null; | 57 | return null; |
| 57 | } | 58 | } |
| 58 | } | 59 | } |
impl/core/src/test/java/security/athentication/credentials/StrictAuthenticator.java
| @@ -36,37 +36,28 @@ | @@ -36,37 +36,28 @@ | ||
| 36 | */ | 36 | */ |
| 37 | package security.athentication.credentials; | 37 | package security.athentication.credentials; |
| 38 | 38 | ||
| 39 | +import java.security.Principal; | ||
| 40 | + | ||
| 39 | import br.gov.frameworkdemoiselle.security.AuthenticationException; | 41 | import br.gov.frameworkdemoiselle.security.AuthenticationException; |
| 40 | import br.gov.frameworkdemoiselle.security.Authenticator; | 42 | import br.gov.frameworkdemoiselle.security.Authenticator; |
| 41 | -import br.gov.frameworkdemoiselle.security.User; | ||
| 42 | import br.gov.frameworkdemoiselle.util.Beans; | 43 | import br.gov.frameworkdemoiselle.util.Beans; |
| 43 | 44 | ||
| 44 | public class StrictAuthenticator implements Authenticator { | 45 | public class StrictAuthenticator implements Authenticator { |
| 45 | 46 | ||
| 46 | private static final long serialVersionUID = 1L; | 47 | private static final long serialVersionUID = 1L; |
| 47 | 48 | ||
| 48 | - private User currentUser; | 49 | + private Principal currentUser; |
| 49 | 50 | ||
| 50 | @Override | 51 | @Override |
| 51 | - public void authenticate() { | 52 | + public void authenticate() { |
| 52 | 53 | ||
| 53 | Credentials c = Beans.getReference(Credentials.class); | 54 | Credentials c = Beans.getReference(Credentials.class); |
| 54 | if ("demoiselle".equals(c.getLogin())) { | 55 | if ("demoiselle".equals(c.getLogin())) { |
| 55 | - this.currentUser = new User() { | ||
| 56 | - | ||
| 57 | - private static final long serialVersionUID = 1L; | ||
| 58 | - | ||
| 59 | - public String getId() { | ||
| 60 | - return "demoiselle"; | ||
| 61 | - } | 56 | + this.currentUser = new Principal() { |
| 62 | 57 | ||
| 63 | @Override | 58 | @Override |
| 64 | - public Object getAttribute(Object key) { | ||
| 65 | - return null; | ||
| 66 | - } | ||
| 67 | - | ||
| 68 | - @Override | ||
| 69 | - public void setAttribute(Object key, Object value) { | 59 | + public String getName() { |
| 60 | + return "demoiselle"; | ||
| 70 | } | 61 | } |
| 71 | }; | 62 | }; |
| 72 | } else { | 63 | } else { |
| @@ -80,7 +71,7 @@ public class StrictAuthenticator implements Authenticator { | @@ -80,7 +71,7 @@ public class StrictAuthenticator implements Authenticator { | ||
| 80 | } | 71 | } |
| 81 | 72 | ||
| 82 | @Override | 73 | @Override |
| 83 | - public User getUser() { | 74 | + public Principal getUser() { |
| 84 | return this.currentUser; | 75 | return this.currentUser; |
| 85 | } | 76 | } |
| 86 | } | 77 | } |
impl/core/src/test/java/security/athentication/custom/CustomAuthenticator.java
| @@ -36,32 +36,23 @@ | @@ -36,32 +36,23 @@ | ||
| 36 | */ | 36 | */ |
| 37 | package security.athentication.custom; | 37 | package security.athentication.custom; |
| 38 | 38 | ||
| 39 | +import java.security.Principal; | ||
| 40 | + | ||
| 39 | import br.gov.frameworkdemoiselle.security.Authenticator; | 41 | import br.gov.frameworkdemoiselle.security.Authenticator; |
| 40 | -import br.gov.frameworkdemoiselle.security.User; | ||
| 41 | 42 | ||
| 42 | public class CustomAuthenticator implements Authenticator { | 43 | public class CustomAuthenticator implements Authenticator { |
| 43 | 44 | ||
| 44 | private static final long serialVersionUID = 1L; | 45 | private static final long serialVersionUID = 1L; |
| 45 | 46 | ||
| 46 | - private User currentUser; | 47 | + private Principal currentUser; |
| 47 | 48 | ||
| 48 | @Override | 49 | @Override |
| 49 | public void authenticate() { | 50 | public void authenticate() { |
| 50 | - this.currentUser = new User() { | ||
| 51 | - | ||
| 52 | - private static final long serialVersionUID = 1L; | ||
| 53 | - | ||
| 54 | - public String getId() { | ||
| 55 | - return "demoiselle"; | ||
| 56 | - } | 51 | + this.currentUser = new Principal() { |
| 57 | 52 | ||
| 58 | @Override | 53 | @Override |
| 59 | - public Object getAttribute(Object key) { | ||
| 60 | - return null; | ||
| 61 | - } | ||
| 62 | - | ||
| 63 | - @Override | ||
| 64 | - public void setAttribute(Object key, Object value) { | 54 | + public String getName() { |
| 55 | + return "demoiselle"; | ||
| 65 | } | 56 | } |
| 66 | }; | 57 | }; |
| 67 | } | 58 | } |
| @@ -72,7 +63,7 @@ public class CustomAuthenticator implements Authenticator { | @@ -72,7 +63,7 @@ public class CustomAuthenticator implements Authenticator { | ||
| 72 | } | 63 | } |
| 73 | 64 | ||
| 74 | @Override | 65 | @Override |
| 75 | - public User getUser() { | 66 | + public Principal getUser() { |
| 76 | return this.currentUser; | 67 | return this.currentUser; |
| 77 | } | 68 | } |
| 78 | } | 69 | } |
impl/core/src/test/java/security/athentication/custom/CustomAuthenticatorTest.java
| @@ -87,7 +87,7 @@ public class CustomAuthenticatorTest { | @@ -87,7 +87,7 @@ public class CustomAuthenticatorTest { | ||
| 87 | context.login(); | 87 | context.login(); |
| 88 | assertTrue(context.isLoggedIn()); | 88 | assertTrue(context.isLoggedIn()); |
| 89 | assertNotNull(observer.getEvent()); | 89 | assertNotNull(observer.getEvent()); |
| 90 | - assertEquals("demoiselle", context.getUser().getId()); | 90 | + assertEquals("demoiselle", context.getUser().getName()); |
| 91 | 91 | ||
| 92 | ctx.deactivate(); | 92 | ctx.deactivate(); |
| 93 | } | 93 | } |
impl/core/src/test/java/security/athentication/disabled/DisabledAuthenticationTest.java
| @@ -82,7 +82,7 @@ public class DisabledAuthenticationTest { | @@ -82,7 +82,7 @@ public class DisabledAuthenticationTest { | ||
| 82 | @Test | 82 | @Test |
| 83 | public void unauthenticated() { | 83 | public void unauthenticated() { |
| 84 | assertTrue(context.isLoggedIn()); | 84 | assertTrue(context.isLoggedIn()); |
| 85 | - assertEquals("demoiselle", context.getUser().getId()); | 85 | + assertEquals("demoiselle", context.getUser().getName()); |
| 86 | } | 86 | } |
| 87 | 87 | ||
| 88 | @Test | 88 | @Test |
| @@ -90,7 +90,7 @@ public class DisabledAuthenticationTest { | @@ -90,7 +90,7 @@ public class DisabledAuthenticationTest { | ||
| 90 | context.login(); | 90 | context.login(); |
| 91 | assertTrue(context.isLoggedIn()); | 91 | assertTrue(context.isLoggedIn()); |
| 92 | assertNull(event); | 92 | assertNull(event); |
| 93 | - assertEquals("demoiselle", context.getUser().getId()); | 93 | + assertEquals("demoiselle", context.getUser().getName()); |
| 94 | } | 94 | } |
| 95 | 95 | ||
| 96 | @Test | 96 | @Test |
| @@ -98,6 +98,6 @@ public class DisabledAuthenticationTest { | @@ -98,6 +98,6 @@ public class DisabledAuthenticationTest { | ||
| 98 | context.login(); | 98 | context.login(); |
| 99 | context.logout(); | 99 | context.logout(); |
| 100 | assertTrue(context.isLoggedIn()); | 100 | assertTrue(context.isLoggedIn()); |
| 101 | - assertEquals("demoiselle", context.getUser().getId()); | 101 | + assertEquals("demoiselle", context.getUser().getName()); |
| 102 | } | 102 | } |
| 103 | } | 103 | } |
impl/core/src/test/java/security/athentication/error/LoginErrorAuthenticator.java
| @@ -36,15 +36,16 @@ | @@ -36,15 +36,16 @@ | ||
| 36 | */ | 36 | */ |
| 37 | package security.athentication.error; | 37 | package security.athentication.error; |
| 38 | 38 | ||
| 39 | +import java.security.Principal; | ||
| 40 | + | ||
| 39 | import br.gov.frameworkdemoiselle.security.Authenticator; | 41 | import br.gov.frameworkdemoiselle.security.Authenticator; |
| 40 | -import br.gov.frameworkdemoiselle.security.User; | ||
| 41 | 42 | ||
| 42 | public class LoginErrorAuthenticator implements Authenticator { | 43 | public class LoginErrorAuthenticator implements Authenticator { |
| 43 | 44 | ||
| 44 | private static final long serialVersionUID = 1L; | 45 | private static final long serialVersionUID = 1L; |
| 45 | 46 | ||
| 46 | @Override | 47 | @Override |
| 47 | - public void authenticate() { | 48 | + public void authenticate() { |
| 48 | throw new RuntimeException(); | 49 | throw new RuntimeException(); |
| 49 | } | 50 | } |
| 50 | 51 | ||
| @@ -54,7 +55,7 @@ public class LoginErrorAuthenticator implements Authenticator { | @@ -54,7 +55,7 @@ public class LoginErrorAuthenticator implements Authenticator { | ||
| 54 | } | 55 | } |
| 55 | 56 | ||
| 56 | @Override | 57 | @Override |
| 57 | - public User getUser() { | 58 | + public Principal getUser() { |
| 58 | return null; | 59 | return null; |
| 59 | } | 60 | } |
| 60 | } | 61 | } |
impl/core/src/test/java/security/athentication/error/LogoutErrorAuthenticator.java
| @@ -36,32 +36,23 @@ | @@ -36,32 +36,23 @@ | ||
| 36 | */ | 36 | */ |
| 37 | package security.athentication.error; | 37 | package security.athentication.error; |
| 38 | 38 | ||
| 39 | +import java.security.Principal; | ||
| 40 | + | ||
| 39 | import br.gov.frameworkdemoiselle.security.Authenticator; | 41 | import br.gov.frameworkdemoiselle.security.Authenticator; |
| 40 | -import br.gov.frameworkdemoiselle.security.User; | ||
| 41 | 42 | ||
| 42 | public class LogoutErrorAuthenticator implements Authenticator { | 43 | public class LogoutErrorAuthenticator implements Authenticator { |
| 43 | 44 | ||
| 44 | private static final long serialVersionUID = 1L; | 45 | private static final long serialVersionUID = 1L; |
| 45 | - | ||
| 46 | - private User currentUser; | ||
| 47 | - | ||
| 48 | - @Override | ||
| 49 | - public void authenticate() { | ||
| 50 | - this.currentUser = new User() { | ||
| 51 | 46 | ||
| 52 | - private static final long serialVersionUID = 1L; | ||
| 53 | - | ||
| 54 | - public String getId() { | ||
| 55 | - return "demoiselle"; | ||
| 56 | - } | 47 | + private Principal currentUser; |
| 57 | 48 | ||
| 58 | - @Override | ||
| 59 | - public Object getAttribute(Object key) { | ||
| 60 | - return null; | ||
| 61 | - } | 49 | + @Override |
| 50 | + public void authenticate() { | ||
| 51 | + this.currentUser = new Principal() { | ||
| 62 | 52 | ||
| 63 | @Override | 53 | @Override |
| 64 | - public void setAttribute(Object key, Object value) { | 54 | + public String getName() { |
| 55 | + return "demoiselle"; | ||
| 65 | } | 56 | } |
| 66 | }; | 57 | }; |
| 67 | } | 58 | } |
| @@ -72,7 +63,7 @@ public class LogoutErrorAuthenticator implements Authenticator { | @@ -72,7 +63,7 @@ public class LogoutErrorAuthenticator implements Authenticator { | ||
| 72 | } | 63 | } |
| 73 | 64 | ||
| 74 | @Override | 65 | @Override |
| 75 | - public User getUser() { | 66 | + public Principal getUser() { |
| 76 | return currentUser; | 67 | return currentUser; |
| 77 | } | 68 | } |
| 78 | } | 69 | } |
impl/core/src/test/java/security/athentication/selection/SelectedAuthenticatorTest.java
| @@ -72,6 +72,6 @@ public class SelectedAuthenticatorTest { | @@ -72,6 +72,6 @@ public class SelectedAuthenticatorTest { | ||
| 72 | @Test | 72 | @Test |
| 73 | public void selectedAuthenticatorStrategy() { | 73 | public void selectedAuthenticatorStrategy() { |
| 74 | context.login(); | 74 | context.login(); |
| 75 | - assertEquals("demoiselle", context.getUser().getId()); | 75 | + assertEquals("demoiselle", context.getUser().getName()); |
| 76 | } | 76 | } |
| 77 | } | 77 | } |
impl/core/src/test/java/security/interceptor/loggedin/CustomAuthenticator.java
| @@ -36,35 +36,26 @@ | @@ -36,35 +36,26 @@ | ||
| 36 | */ | 36 | */ |
| 37 | package security.interceptor.loggedin; | 37 | package security.interceptor.loggedin; |
| 38 | 38 | ||
| 39 | +import java.security.Principal; | ||
| 40 | + | ||
| 39 | import javax.enterprise.context.SessionScoped; | 41 | import javax.enterprise.context.SessionScoped; |
| 40 | 42 | ||
| 41 | import br.gov.frameworkdemoiselle.security.Authenticator; | 43 | import br.gov.frameworkdemoiselle.security.Authenticator; |
| 42 | -import br.gov.frameworkdemoiselle.security.User; | ||
| 43 | 44 | ||
| 44 | @SessionScoped | 45 | @SessionScoped |
| 45 | public class CustomAuthenticator implements Authenticator { | 46 | public class CustomAuthenticator implements Authenticator { |
| 46 | 47 | ||
| 47 | private static final long serialVersionUID = 1L; | 48 | private static final long serialVersionUID = 1L; |
| 48 | 49 | ||
| 49 | - private User currentUser; | 50 | + private Principal currentUser; |
| 50 | 51 | ||
| 51 | @Override | 52 | @Override |
| 52 | public void authenticate() { | 53 | public void authenticate() { |
| 53 | - this.currentUser = new User() { | ||
| 54 | - | ||
| 55 | - private static final long serialVersionUID = 1L; | ||
| 56 | - | ||
| 57 | - public String getId() { | ||
| 58 | - return "demoiselle"; | ||
| 59 | - } | 54 | + this.currentUser = new Principal() { |
| 60 | 55 | ||
| 61 | @Override | 56 | @Override |
| 62 | - public Object getAttribute(Object key) { | ||
| 63 | - return null; | ||
| 64 | - } | ||
| 65 | - | ||
| 66 | - @Override | ||
| 67 | - public void setAttribute(Object key, Object value) { | 57 | + public String getName() { |
| 58 | + return "demoiselle"; | ||
| 68 | } | 59 | } |
| 69 | }; | 60 | }; |
| 70 | } | 61 | } |
| @@ -75,7 +66,7 @@ public class CustomAuthenticator implements Authenticator { | @@ -75,7 +66,7 @@ public class CustomAuthenticator implements Authenticator { | ||
| 75 | } | 66 | } |
| 76 | 67 | ||
| 77 | @Override | 68 | @Override |
| 78 | - public User getUser() { | 69 | + public Principal getUser() { |
| 79 | return this.currentUser; | 70 | return this.currentUser; |
| 80 | } | 71 | } |
| 81 | } | 72 | } |
impl/extension/servlet/src/main/java/br/gov/frameworkdemoiselle/security/ServletAuthenticator.java
| @@ -89,36 +89,9 @@ public class ServletAuthenticator implements Authenticator { | @@ -89,36 +89,9 @@ public class ServletAuthenticator implements Authenticator { | ||
| 89 | getRequest().getSession().invalidate(); | 89 | getRequest().getSession().invalidate(); |
| 90 | } | 90 | } |
| 91 | 91 | ||
| 92 | - // TODO Criar uma delegação especializada de User ao invés de retornar | ||
| 93 | - // uma inner class | ||
| 94 | @Override | 92 | @Override |
| 95 | - public User getUser() { | ||
| 96 | - final Principal principal = getRequest().getUserPrincipal(); | ||
| 97 | - | ||
| 98 | - User user = null; | ||
| 99 | - | ||
| 100 | - if (principal != null) { | ||
| 101 | - user = new User() { | ||
| 102 | - | ||
| 103 | - private static final long serialVersionUID = 1L; | ||
| 104 | - | ||
| 105 | - @Override | ||
| 106 | - public String getId() { | ||
| 107 | - return principal.getName(); | ||
| 108 | - } | ||
| 109 | - | ||
| 110 | - @Override | ||
| 111 | - public void setAttribute(Object key, Object value) { | ||
| 112 | - } | ||
| 113 | - | ||
| 114 | - @Override | ||
| 115 | - public Object getAttribute(Object key) { | ||
| 116 | - return null; | ||
| 117 | - } | ||
| 118 | - }; | ||
| 119 | - } | ||
| 120 | - | ||
| 121 | - return user; | 93 | + public Principal getUser() { |
| 94 | + return getRequest().getUserPrincipal(); | ||
| 122 | } | 95 | } |
| 123 | 96 | ||
| 124 | protected Credentials getCredentials() { | 97 | protected Credentials getCredentials() { |