1 23 24 29 30 package com.sun.enterprise.webservice; 31 32 import javax.security.auth.callback.Callback ; 33 import javax.security.auth.callback.CallbackHandler ; 34 import javax.security.auth.callback.ChoiceCallback ; 35 import javax.security.auth.callback.NameCallback ; 36 import javax.security.auth.callback.PasswordCallback ; 37 import javax.security.auth.callback.UnsupportedCallbackException ; 38 import java.io.IOException ; 39 import java.util.logging.*; 40 import com.sun.enterprise.appclient.AppContainer; 41 import com.sun.enterprise.security.wss.*; 42 import com.sun.enterprise.security.jauth.callback.*; 43 44 45 46 50 public final class AppclientWSSCallbackHandler extends WSSCallbackHandler { 51 private static final String LOGIN_NAME = "j2eelogin.name"; 52 private static final String LOGIN_PASSWORD = "j2eelogin.password"; 53 private static WSSCallbackHandler INSTANCE = null; 54 55 private AppclientWSSCallbackHandler() { 56 } 57 61 static WSSCallbackHandler newInstance() { 62 if(INSTANCE == null){ 63 INSTANCE = new AppclientWSSCallbackHandler(); 64 } 65 return INSTANCE; 66 } 67 68 public void handle(Callback [] callbacks) 69 throws IOException , UnsupportedCallbackException 70 { 71 if(callbacks == null){ 72 return; 73 } 74 boolean processedSomeAppclientCallbacks = false; 79 for (int i=0; i<callbacks.length; i++){ 80 if(!isSupportedCallback(callbacks[i])){ 81 _logger.log(Level.FINE, "wss-container-auth: UnsupportedCallback : "+ 82 callbacks[i].getClass().getName()); 83 throw new UnsupportedCallbackException (callbacks[i]); 84 } 85 if(!processedSomeAppclientCallbacks){ 86 if((callbacks[i] instanceof NameCallback ) || 87 (callbacks[i] instanceof PasswordCallback ) || 88 (callbacks[i] instanceof ChoiceCallback )) { 89 90 String loginName = System.getProperty(LOGIN_NAME); 91 CallbackHandler callbackHandler = AppContainer.getCallbackHandler(); 92 if(loginName != null){ String password = System.getProperty(LOGIN_PASSWORD); 94 for(int j = 0; j < callbacks.length; j++){ 95 if(callbacks[j] instanceof NameCallback ){ 96 NameCallback nc = (NameCallback )callbacks[j]; 97 nc.setName(loginName); 98 } else if (callbacks[j] instanceof PasswordCallback ){ 99 PasswordCallback pc = (PasswordCallback )callbacks[j]; 100 if(password != null) 101 pc.setPassword(password.toCharArray()); 102 else{ 103 callbackHandler.handle(callbacks); 104 } 105 } 106 } 107 } else{ 108 callbackHandler.handle(callbacks); 114 } 115 processedSomeAppclientCallbacks = true; 116 break; 117 } 118 } 119 processCallback(callbacks[i]); 120 } 121 } 122 123 boolean isSupportedCallback(Callback callback) 124 { 125 boolean supported = false; 126 if (callback instanceof NameCallback ) { 127 supported = true; 128 } else if (callback instanceof PasswordCallback ) { 129 supported = true; 130 } else if (callback instanceof ChoiceCallback ) { 131 supported = true; 132 } else if (callback instanceof CertStoreCallback) { 133 supported = true; 134 } else if (callback instanceof PasswordValidationCallback) { 135 supported = true; 136 } else if (callback instanceof SecretKeyCallback) { 137 supported = true; 138 } else if (callback instanceof PrivateKeyCallback) { 139 supported = true; 140 } else if (callback instanceof TrustStoreCallback) { 141 supported = true; 142 } else { 143 supported = false; 144 } 145 return supported; 146 } 147 148 } 149 | Popular Tags |