1 package prefuse.util.io; 2 3 import java.net.Authenticator ; 4 import java.net.PasswordAuthentication ; 5 6 12 public class PasswordAuthenticator extends Authenticator { 13 14 private String m_username; 15 private String m_password; 16 private PasswordAuthentication m_auth; 17 18 23 PasswordAuthenticator(String username, String password) { 24 this.m_password = password; 25 this.m_username = username; 26 } 27 28 32 String getPassword() { 33 return m_password; 34 } 35 36 40 void setPassword(String password) { 41 this.m_password = password; 42 this.m_auth = null; 43 } 44 45 49 String getUsername() { 50 return m_username; 51 } 52 53 57 void setUsername(String username) { 58 this.m_username = username; 59 this.m_auth = null; 60 } 61 62 66 protected PasswordAuthentication getPasswordAuthentication() { 67 if ( m_auth == null ) { 68 m_auth = new PasswordAuthentication ( 69 m_username, m_password.toCharArray()); 70 } 71 return m_auth; 72 } 73 74 76 80 public static void setAuthentication(String username, String password) { 81 Authenticator.setDefault(new PasswordAuthenticator(username,password)); 82 } 83 84 } | Popular Tags |