Rev 218 | Details | Compare with Previous | Last modification | View Log | RSS feed
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 216 | espaco | 1 | package br.com.ec.shared; |
| 2 | |||
| 3 | import java.util.Collection; |
||
| 4 | |||
| 218 | espaco | 5 | import org.apache.commons.lang.builder.EqualsBuilder; |
| 6 | import org.apache.commons.lang.builder.HashCodeBuilder; |
||
| 216 | espaco | 7 | import org.springframework.security.core.Authentication; |
| 8 | import org.springframework.security.core.GrantedAuthority; |
||
| 9 | |||
| 218 | espaco | 10 | import br.com.ec.domain.dto.UsuarioDTO; |
| 216 | espaco | 11 | |
| 12 | public class SistemaAuthentication implements Authentication { |
||
| 13 | |||
| 14 | private static final long serialVersionUID = 1L; |
||
| 15 | |||
| 16 | private String login; |
||
| 17 | private String credencials; |
||
| 242 | espaco | 18 | private UsuarioDTO usuarioDTO; |
| 218 | espaco | 19 | // private Usuario usuario; |
| 216 | espaco | 20 | private Collection<GrantedAuthority> authorities; |
| 21 | private boolean isAuthenticated; |
||
| 22 | |||
| 23 | /** |
||
| 24 | * Cria um Authentication autenticado (authenticated = true). |
||
| 25 | * |
||
| 26 | * @param login |
||
| 27 | * @param credentiais |
||
| 28 | * @param usuario |
||
| 29 | * @param authorities |
||
| 30 | */ |
||
| 242 | espaco | 31 | public SistemaAuthentication(String login, String credencials, UsuarioDTO usuarioDTO, Collection<GrantedAuthority> authorities) { |
| 216 | espaco | 32 | this.login = login; |
| 33 | this.credencials = credencials; |
||
| 242 | espaco | 34 | this.usuarioDTO = usuarioDTO; |
| 216 | espaco | 35 | this.authorities = authorities; |
| 36 | setAuthenticated(true); |
||
| 37 | } |
||
| 38 | |||
| 39 | public Object getPrincipal() { |
||
| 40 | return login; |
||
| 41 | } |
||
| 42 | |||
| 43 | public String getName() { |
||
| 44 | return login; |
||
| 45 | } |
||
| 46 | |||
| 47 | public String getLogin() { |
||
| 48 | return login; |
||
| 49 | } |
||
| 50 | |||
| 51 | public Object getCredentials() { |
||
| 52 | return credencials; |
||
| 53 | } |
||
| 54 | |||
| 55 | /** |
||
| 56 | * @return usuario obtido no processo de autenticao ou nulo se nao autenticado. |
||
| 57 | */ |
||
| 218 | espaco | 58 | public UsuarioDTO getDetails() { |
| 242 | espaco | 59 | return usuarioDTO; |
| 216 | espaco | 60 | } |
| 61 | |||
| 62 | public Collection<GrantedAuthority> getAuthorities() { |
||
| 63 | return authorities; |
||
| 64 | } |
||
| 65 | |||
| 66 | public boolean isAuthenticated() { |
||
| 67 | return isAuthenticated; |
||
| 68 | } |
||
| 69 | |||
| 70 | public void setAuthenticated(boolean isAuthenticated) throws IllegalArgumentException { |
||
| 71 | this.isAuthenticated = isAuthenticated; |
||
| 72 | } |
||
| 73 | |||
| 74 | @Override |
||
| 75 | public boolean equals(Object objeto) { |
||
| 218 | espaco | 76 | return EqualsBuilder.reflectionEquals(this, objeto); |
| 216 | espaco | 77 | } |
| 78 | |||
| 79 | @Override |
||
| 80 | public int hashCode() { |
||
| 218 | espaco | 81 | return HashCodeBuilder.reflectionHashCode(this); |
| 216 | espaco | 82 | } |
| 83 | |||
| 84 | } |