001: /*
002: * Copyright 2005 Sun Microsystems, Inc. All
003: * rights reserved. Use of this product is subject
004: * to license terms. Federal Acquisitions:
005: * Commercial Software -- Government Users
006: * Subject to Standard License Terms and
007: * Conditions.
008: *
009: * Sun, Sun Microsystems, the Sun logo, and Sun ONE
010: * are trademarks or registered trademarks of Sun Microsystems,
011: * Inc. in the United States and other countries.
012: */
013:
014: package com.sun.portal.wsrp.producer;
015:
016: import java.io.IOException;
017: import javax.security.auth.callback.Callback;
018: import javax.security.auth.callback.CallbackHandler;
019: import javax.security.auth.callback.UnsupportedCallbackException;
020: import com.sun.portal.wsrp.common.OASISUsernameTokenProfile;
021: import com.sun.portal.wsrp.producer.filter.ProducerThreadLocalizer;
022: import com.sun.xml.wss.impl.callback.PasswordValidationCallback;
023:
024: public class ServerHandler implements CallbackHandler {
025:
026: private UnsupportedCallbackException unsupported = new UnsupportedCallbackException(
027: null, "Unsupported Callback Type Encountered");
028:
029: class UsernameProfileValidator implements
030: PasswordValidationCallback.PasswordValidator {
031:
032: public boolean validate(
033: PasswordValidationCallback.Request request)
034: throws PasswordValidationCallback.PasswordValidationException {
035:
036: PasswordValidationCallback.PlainTextPasswordRequest req = (PasswordValidationCallback.PlainTextPasswordRequest) request;
037:
038: setUserProfile(req.getUsername(), req.getPassword());
039:
040: return true;
041: }
042:
043: private void setUserProfile(String username, String password) {
044: OASISUsernameTokenProfile profile = new OASISUsernameTokenProfile();
045: profile.setUsername(username);
046: profile.setPassword(password);
047: ProducerThreadLocalizer.setTokenProfile(profile);
048: }
049: }
050:
051: class UsernameProfileDigestPasswordValidator extends
052: PasswordValidationCallback.DigestPasswordValidator {
053:
054: public boolean validate(
055: PasswordValidationCallback.Request request)
056: throws PasswordValidationCallback.PasswordValidationException {
057:
058: super .validate(request);
059: PasswordValidationCallback.DigestPasswordRequest req = (PasswordValidationCallback.DigestPasswordRequest) request;
060:
061: setUserProfile(req.getUsername(), req.getPassword());
062:
063: return true;
064: }
065:
066: private void setUserProfile(String username, String password) {
067: OASISUsernameTokenProfile profile = new OASISUsernameTokenProfile();
068: profile.setUsername(username);
069: profile.setPassword(password);
070: ProducerThreadLocalizer.setTokenProfile(profile);
071: }
072: }
073:
074: public void handle(Callback[] callbacks) throws IOException,
075: UnsupportedCallbackException {
076: for (int i = 0; i < callbacks.length; i++) {
077: if (callbacks[i] instanceof PasswordValidationCallback) {
078: PasswordValidationCallback cb = (PasswordValidationCallback) callbacks[i];
079:
080: if (cb.getRequest() instanceof PasswordValidationCallback.PlainTextPasswordRequest) {
081: cb.setValidator(new UsernameProfileValidator());
082: } else if (cb.getRequest() instanceof PasswordValidationCallback.DigestPasswordRequest) {
083: try {
084:
085: PasswordValidationCallback.DigestPasswordRequest req = (PasswordValidationCallback.DigestPasswordRequest) cb
086: .getRequest();
087: IdentityValidator identityValidator = AMIdentityValidator
088: .getInstance();
089: identityValidator.updateRequest(req);
090: } catch (Exception se) {
091: throw new UnsupportedCallbackException(null, se
092: .getMessage());
093: }
094: cb
095: .setValidator(new UsernameProfileDigestPasswordValidator());
096: } else {
097: throw unsupported;
098: }
099:
100: } else {
101: throw unsupported;
102: }
103: }
104: }
105: }
|