1 17 package org.apache.geronimo.security.jaas; 18 19 import java.io.Serializable ; 20 import java.util.Arrays ; 21 import javax.security.auth.DestroyFailedException ; 22 import javax.security.auth.Destroyable ; 23 import javax.security.auth.RefreshFailedException ; 24 import javax.security.auth.Refreshable ; 25 26 27 33 public class UsernamePasswordCredential implements Destroyable , Refreshable , Serializable { 34 35 private String username; 36 private char[] password; 37 private boolean destroyed; 38 39 public UsernamePasswordCredential(String username, char[] password) { 40 assert username != null; 41 assert password != null; 42 43 this.username = username; 44 this.password = new char[password.length]; 45 System.arraycopy(password, 0, this.password, 0, password.length); 46 } 47 48 public String getUsername() { 49 return username; 50 } 51 52 public char[] getPassword() { 53 return password; 54 } 55 56 public void destroy() throws DestroyFailedException { 57 Arrays.fill(password, ' '); 58 59 username = null; 60 password = null; 61 destroyed = true; 62 } 63 64 public boolean isDestroyed() { 65 return destroyed; 66 } 67 68 public void refresh() throws RefreshFailedException { 69 } 70 71 public boolean isCurrent() { 72 return !destroyed; 73 } 74 75 public boolean equals(Object o) { 76 if (this == o) return true; 77 if (!(o instanceof UsernamePasswordCredential)) return false; 78 79 final UsernamePasswordCredential credential = (UsernamePasswordCredential) o; 80 81 if (destroyed != credential.destroyed) return false; 82 if (!Arrays.equals(password, credential.password)) return false; 83 if (username != null ? !username.equals(credential.username) : credential.username != null) return false; 84 85 return true; 86 } 87 88 public int hashCode() { 89 int result; 90 result = (username != null ? username.hashCode() : 0); 91 result = 29 * result + (destroyed ? 1 : 0); 92 return result; 93 } 94 } 95 | Popular Tags |