1 23 package com.sun.enterprise.security; 24 25 import java.io.BufferedReader ; 26 import java.io.InputStreamReader ; 27 import java.io.IOException ; 28 import javax.security.auth.callback.*; 29 import com.sun.enterprise.util.LocalStringManagerImpl; 30 import java.util.logging.*; 31 import com.sun.logging.*; 32 33 34 42 public final class TextLoginDialog implements LoginDialog { 43 44 private static Logger _logger=null; 45 static { 46 _logger=LogDomains.getLogger(LogDomains.SECURITY_LOGGER); 47 } 48 49 private String username = null; 50 private String password = null; 51 private static LocalStringManagerImpl localStrings = 52 new LocalStringManagerImpl(TextLoginDialog.class); 53 54 public TextLoginDialog() { 55 if((username == null) || (password == null)) { 56 BufferedReader d = 57 new BufferedReader (new InputStreamReader (System.in)); 58 do { 59 System.out.print 60 (localStrings.getLocalString 61 ("enterprise.security.login.username", 62 "User Name: ")); 63 try { 64 username = d.readLine(); 65 } catch(IOException e) { 66 } 67 } while( (username == null) || 68 (username.trim().length() == 0)); 69 70 do { 71 System.out.print 72 (localStrings.getLocalString 73 ("enterprise.security.login.password", 74 "Password: ")); 75 try { 76 password = d.readLine(); 77 }catch (IOException e) { 78 } 79 }while( (password == null) || (password.trim().length() == 0)); 80 } 81 } 82 83 public TextLoginDialog(Callback[] callbacks) 84 { 85 try { 86 for(int i = 0; i < callbacks.length; i++) { 87 if(callbacks[i] instanceof NameCallback) { 88 NameCallback nc = (NameCallback) callbacks[i]; 89 System.err.print(nc.getPrompt()); 90 System.err.flush(); 91 nc.setName((new BufferedReader 92 (new 93 InputStreamReader (System.in))).readLine()); 94 95 } else if(callbacks[i] instanceof PasswordCallback) { 96 PasswordCallback pc = (PasswordCallback) callbacks[i]; 97 System.err.print(pc.getPrompt()); 98 System.err.flush(); 99 100 String psswd = 101 new BufferedReader 102 (new InputStreamReader (System.in)).readLine(); 103 pc.setPassword(psswd.toCharArray()); 104 105 } else if(callbacks[i] instanceof ChoiceCallback) { 106 ChoiceCallback cc = (ChoiceCallback) callbacks[i]; 107 110 String lbl = (localStrings.getLocalString 111 ("enterprise.security.keystore", 112 "Enter the KeyStore Password ")); 113 String keystorePass = SSLUtils.getKeyStorePass (); 114 System.out.println (lbl+ 115 " : (max 3 tries)"); 116 int cnt=0; 117 for (cnt=0; cnt<3; cnt++){ 118 System.out.println (lbl+" : "); 120 String kp = 121 (new BufferedReader 122 (new InputStreamReader (System.in))).readLine(); 123 if (kp.equals (keystorePass)) { 124 break; 125 } else{ 126 String errmessage = localStrings.getLocalString("enterprise.security.IncorrectKeystorePassword","Incorrect Keystore Password"); 127 System.err.println (errmessage); 128 } 129 } 130 if (cnt>=3){ 131 cc.setSelectedIndex (-1); 132 } else { 133 System.err.println(cc.getPrompt()); 134 System.err.flush(); 135 String [] choices = cc.getChoices(); 136 for(int j = 0; j < choices.length; j++) { 137 System.err.print("[" + j + "] "); 138 System.err.println(choices[j]); 139 } 140 String line = 141 (new BufferedReader 142 (new InputStreamReader (System.in))).readLine(); 143 144 int sel = new Integer (line).intValue(); 145 cc.setSelectedIndex(sel); 147 } 148 } 149 } 150 } catch(Exception e) { 151 _logger.log(Level.SEVERE, 152 "java_security.name_password_entry_exception",e); 153 } 154 155 } 156 157 158 161 public String getUserName() { 162 return username; 163 } 164 167 public String getPassword() { 168 return password; 169 } 170 } 171 | Popular Tags |