모바일 웹 서비스 클라이언트에 대한 사용자 정의 콜백 핸들러 개발

웹 서비스 보안 런타임은 다음과 같은 세 가지의 기본 콜백 핸들러를 제공합니다.
일반적인 일부 시나리오에 이와 같은 콜백 핸들러를 사용할 수 있습니다. 그러나 위에 설명되지 않은 다른 방식으로 정보를 획득하려면 사용자 정의 인증기가 필요합니다. 예를 들어, 사용자 자신의 사용자 레지스트리에서 동적으로 클라이언트의 사용자 이름 및 비밀번호를 추출하려는 경우가 그렇습니다. 사용자 정의 콜백 핸들러가 필요한 경우, javax.security.auth.callback.CallbackHandler 인터페이스를 구현하는 클래스를 개발해야 합니다. CallbackHandler 인터페이스는 다음의 두 메소드로 구성됩니다.
public interface CallbackHandler {
    public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException;
}
CallbackHandler.handle() 메소드에는 사용자 이름 및 비밀번호와 같은 필요한 정보를 전달하기 위한 콜백이 필요합니다. 다음은 웹 서비스 보안 런타임에서 사용되는 콜백의 목록입니다.
다음은 사용할 수 있는 이와 같은 콜백에 대한 메소드입니다.
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);
}
콜백 핸들러는 필요한 콜백 정보를 설정하여 콜백 핸들러를 호출하는 토큰 생성기에 리턴합니다. 결과적으로, 프로그래밍 스타일은 토큰 생성기에 따라 다릅니다. UsernameTokenGenerator를 사용하여, 다음과 같이 사용자 정의 콜백 핸들러를 개발할 수 있습니다.
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);
    }

}
LTPATokenGenrator를 사용하여, 다음과 같이 사용자 정의 콜백 핸들러를 개발할 수 있습니다.
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);
    }

}

사용자 정의 콜백 핸들러를 개발하고 나면 웹 서비스 클라이언트 프로젝트에서 웹 서비스 보안 구성도 업데이트해야 합니다.

device_small.jpg 디바이스용 Lotus® Expeditor는 LTPA 기반 콜백 핸들러를 지원하지 않습니다.



라이브러리 | 지원 | | 교육 | 이용약관 |

마지막 업데이트 날짜: 2008년 10월 21일
© Copyright IBM Corporation 2006, 2008. All Rights Reserved.
이 Information Center는 Built on Eclipse™입니다. (http://www.eclipse.org 웹 사이트 참조)