Rev 216 | Go to most recent revision | 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 | import br.com.ec.domain.modal.Usuario; |
| 12 | |||
| 13 | public class SistemaAuthentication implements Authentication { |
||
| 14 | |||
| 15 | private static final long serialVersionUID = 1L; |
||
| 16 | |||
| 17 | private String login; |
||
| 18 | private String credencials; |
||
| 218 | espaco | 19 | // private Usuario usuario; |
| 20 | private UsuarioDTO usuario; |
||
| 216 | espaco | 21 | private Collection<GrantedAuthority> authorities; |
| 22 | private boolean isAuthenticated; |
||
| 23 | |||
| 24 | /** |
||
| 25 | * Cria um Authentication autenticado (authenticated = true). |
||
| 26 | * |
||
| 27 | * @param login |
||
| 28 | * @param credentiais |
||
| 29 | * @param usuario |
||
| 30 | * @param authorities |
||
| 31 | */ |
||
| 218 | espaco | 32 | public SistemaAuthentication(String login, String credencials, UsuarioDTO usuario, Collection<GrantedAuthority> authorities) { |
| 216 | espaco | 33 | this.login = login; |
| 34 | this.credencials = credencials; |
||
| 35 | this.usuario = usuario; |
||
| 36 | this.authorities = authorities; |
||
| 37 | setAuthenticated(true); |
||
| 38 | } |
||
| 39 | |||
| 40 | public Object getPrincipal() { |
||
| 41 | return login; |
||
| 42 | } |
||
| 43 | |||
| 44 | public String getName() { |
||
| 45 | return login; |
||
| 46 | } |
||
| 47 | |||
| 48 | public String getLogin() { |
||
| 49 | return login; |
||
| 50 | } |
||
| 51 | |||
| 52 | public Object getCredentials() { |
||
| 53 | return credencials; |
||
| 54 | } |
||
| 55 | |||
| 56 | /** |
||
| 57 | * @return usuario obtido no processo de autenticao ou nulo se nao autenticado. |
||
| 58 | */ |
||
| 218 | espaco | 59 | public UsuarioDTO getDetails() { |
| 216 | espaco | 60 | return usuario; |
| 61 | } |
||
| 62 | |||
| 63 | public Collection<GrantedAuthority> getAuthorities() { |
||
| 64 | return authorities; |
||
| 65 | } |
||
| 66 | |||
| 67 | public boolean isAuthenticated() { |
||
| 68 | return isAuthenticated; |
||
| 69 | } |
||
| 70 | |||
| 71 | public void setAuthenticated(boolean isAuthenticated) throws IllegalArgumentException { |
||
| 72 | this.isAuthenticated = isAuthenticated; |
||
| 73 | } |
||
| 74 | |||
| 75 | @Override |
||
| 76 | public boolean equals(Object objeto) { |
||
| 218 | espaco | 77 | return EqualsBuilder.reflectionEquals(this, objeto); |
| 216 | espaco | 78 | } |
| 79 | |||
| 80 | @Override |
||
| 81 | public int hashCode() { |
||
| 218 | espaco | 82 | return HashCodeBuilder.reflectionHashCode(this); |
| 216 | espaco | 83 | } |
| 84 | |||
| 85 | } |