public interface CallbackHandler {
public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException;
}
public interface NameCallback {
public void setName(String name);
}
public interface PasswordCallback {
public void setPassword(char[]);
}
public interface ContextCallback {
public void com.ibm.pvcws.wss.auth.CallbackContext getContext();
}
public interface X509BSCallback {
public void setCert(java.security.cert.X509Certificate);
public void setKeyStorePath(String kspath);
public void setAlias (String alias);
}
public interface LTPABinaryCallback {
public void setBinary(String binary);
}
import com.ibm.pvcws.wss.auth.CallbackContext;
import com.ibm.pvcws.wss.auth.CallbackHandlerConfig;
import com.ibm.pvcws.wss.auth.callback.ContextCallback;
import java.io.IOException;
import javax.security.auth.callback.Callback;
import javax.security.auth.callback.CallbackHandler;
import javax.security.auth.callback.NameCallback;
import javax.security.auth.callback.PasswordCallbackimport;
import javax.security.auth.callback.UnsupportedCallbackException;
public class UsernameTokenCustomCallbackHandler implements CallbackHandler {
public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException {
if ((callbacks == null) || (callbacks.length == 0)) {
throw new UnsupportedCallbackException(null, "There is no callback.");
}
// Gets necessary information from callbacks.
NameCallback namec = null;
PasswordCallback pwdc = null;
CallbackContext ctx = null;
int lc = callbacks.length;
for (int i = 0; i < lc; i++) {
Callback c = callbacks[i];
if (c instanceof NameCallback) {
namec = (NameCallback)c;
} else if (c instanceof PasswordCallback) {
pwdc = (PasswordCallback)c;
} else if (c instanceof ContextCallback) {
ContextCallback cc = (ContextCallback)c;
ctx = cc.getContext();
} else {
throw new UnsupportedCallbackException(c, "Unknown callback: " + c.getClass().getName());
}
}
// Gets the configuration if necessary.
CallbackHandlerConfig c = (CallbackHandlerConfig)ctx.getConfiguration();
// Gets the username and password dynamically (based on the configuration if necessary).
String username = ...;
char[] password = ...;
// Sets the username and password to the callback.
namec.setName(username);
pwdc.setPassword(password);
}
}
import com.ibm.pvcws.wss.auth.CallbackContext;
import com.ibm.pvcws.wss.auth.CallbackHandlerConfig
import com.ibm.pvcws.wss.auth.callback.ContextCallback;
import com.ibm.pvcws.wss.auth.callback.LTPABinaryCallback;
import java.io.IOException;
import javax.security.auth.callback.Callback;
import javax.security.auth.callback.CallbackHandler;
import javax.security.auth.callback.NameCallback;
import javax.security.auth.callback.PasswordCallbackimport;
import javax.security.auth.callback.UnsupportedCallbackException;
public class LTPATokenCustomCallbackHandler implements CallbackHandler {
public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException {
if ((callbacks == null) || (callbacks.length == 0)) {
throw new UnsupportedCallbackException(null, "There is no callback.");
}
// Gets necessary information from callbacks.
LTPABinaryCallback binaryc = null;
CallbackContext ctx = null;
int lc = callbacks.length;
for (int i = 0; i < lc; i++) {
Callback c = callbacks[i];
if (c instanceof LTPABinaryCallback) {
binaryc = (LTPABinaryCallback)c;
} else if (c instanceof ContextCallback) {
ContextCallback cc = (ContextCallback)c;
ctx = cc.getContext();
} else {
throw new UnsupportedCallbackException(c, "Unknown callback: " + c.getClass().getName());
}
}
// Gets the configuration if necessary.
CallbackHandlerConfig c = (CallbackHandlerConfig)ctx.getConfiguration();
// Gets the username and password dynamically (based on the configuration if necessary).
String username = ...;
char[] password = ...;
// Gets the authentication server URI dynamically (based on the configuraiton if necessary).
String serverURI = …;
/* Use the ServerURL to connect to the authentication server where you can POST the username
and password to retrieve the LTPA Token. e.g in the case of WebSphere Application Server, The
URL is http://<hostname>:<port>/j_security_check. You can do HTTP POST to retrieve the tokens.
The application server returns LTPA Tokens in the form of cookies. They are already Base64 encoded.
You can extract the appropriate token and pass it the setBinary method below. */
// Gets the Base64 encoded content of the LTPA token using the information above.
String content = null;
// Sets the LTPA token to the callback.
binaryc.setBinary(content);
}
}
사용자 정의 콜백 핸들러를 개발하고 나면 웹 서비스 클라이언트 프로젝트에서 웹 서비스 보안 구성도 업데이트해야 합니다.
디바이스용 Lotus® Expeditor는 LTPA 기반 콜백 핸들러를 지원하지 않습니다.