You are viewing a plain text version of this content. The canonical link for it is here.
Posted to fx-dev@ws.apache.org by we...@apache.org on 2004/10/24 14:40:42 UTC

cvs commit: ws-fx/wss4j/src/org/apache/ws/axis/security WSDoAllSender.java

werner      2004/10/24 05:40:42

  Modified:    wss4j/src/org/apache/ws/axis/security/util AxisUtil.java
               wss4j/src/org/apache/ws/axis/security WSDoAllSender.java
  Log:
  Enhancements to support "siging with key derived from UsernameToken",
  refer to E-mail conversation in ws-fx mailing list (Oct, 20, 2004).
  
  Revision  Changes    Path
  1.10      +4 -2      ws-fx/wss4j/src/org/apache/ws/axis/security/util/AxisUtil.java
  
  Index: AxisUtil.java
  ===================================================================
  RCS file: /home/cvs/ws-fx/wss4j/src/org/apache/ws/axis/security/util/AxisUtil.java,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- AxisUtil.java	12 Aug 2004 17:42:09 -0000	1.9
  +++ AxisUtil.java	24 Oct 2004 12:40:42 -0000	1.10
  @@ -20,7 +20,6 @@
   import org.apache.axis.AxisFault;
   import org.apache.ws.security.handler.WSHandlerConstants;
   import org.apache.ws.security.WSConstants;
  -import org.apache.ws.security.handler.WSHandlerConstants;
   import org.apache.ws.security.util.StringUtil;
   import org.apache.xml.security.c14n.Canonicalizer;
   import org.w3c.dom.Document;
  @@ -109,7 +108,7 @@
               throws AxisFault {
   
           int doAction = 0;
  -
  +        
           if (action == null) {
               return doAction;
           }
  @@ -139,6 +138,9 @@
               } else if (single[i].equals(WSHandlerConstants.NO_SERIALIZATION)) {
                   doAction |= WSConstants.NO_SERIALIZE;
                   actions.add(new Integer(WSConstants.NO_SERIALIZE));
  +            } else if (single[i].equals(WSHandlerConstants.SIGN_WITH_UT_KEY)) {
  +                doAction |= WSConstants.UT_SIGN;
  +                actions.add(new Integer(WSConstants.UT_SIGN));
               } else {
                   throw new AxisFault("WSDoAllSender: Unknown action defined" + single[i]);
               }
  
  
  
  1.24      +45 -3     ws-fx/wss4j/src/org/apache/ws/axis/security/WSDoAllSender.java
  
  Index: WSDoAllSender.java
  ===================================================================
  RCS file: /home/cvs/ws-fx/wss4j/src/org/apache/ws/axis/security/WSDoAllSender.java,v
  retrieving revision 1.23
  retrieving revision 1.24
  diff -u -r1.23 -r1.24
  --- WSDoAllSender.java	12 Aug 2004 17:42:08 -0000	1.23
  +++ WSDoAllSender.java	24 Oct 2004 12:40:42 -0000	1.24
  @@ -47,12 +47,15 @@
   import org.apache.ws.security.message.WSSignEnvelope;
   import org.apache.ws.security.util.StringUtil;
   import org.apache.ws.security.util.WSSecurityUtil;
  +import org.apache.xml.security.signature.XMLSignature;
   import org.apache.xml.security.utils.XMLUtils;
   import org.opensaml.SAMLAssertion;
   import org.w3c.dom.Document;
   
   import javax.security.auth.callback.Callback;
   import javax.security.auth.callback.CallbackHandler;
  +import javax.xml.rpc.JAXRPCException;
  +
   import java.io.ByteArrayOutputStream;
   import java.io.UnsupportedEncodingException;
   import java.security.cert.X509Certificate;
  @@ -175,7 +178,7 @@
            * functions. No need to do it for encryption only. Check if username
            * is available and then get a passowrd.
            */
  -        if ((doAction & (WSConstants.SIGN | WSConstants.UT)) != 0) {
  +        if ((doAction & (WSConstants.SIGN | WSConstants.UT | WSConstants.UT_SIGN)) != 0) {
               /*
                * We need a username - if none throw an AxisFault. For encryption
                * there is a specific parameter to get a username.
  @@ -233,6 +236,13 @@
               decodeUTParameter();
           }
           /*
  +         * Here we have action, username, password, and actor, mustUnderstand.
  +         * Now get the action specific parameters.
  +         */
  +        if ((doAction & WSConstants.UT_SIGN) == WSConstants.UT_SIGN) {
  +            decodeUTParameter();
  +        }
  +        /*
            * Get and check the Signature specific parameters first because they
            * may be used for encryption too.
            */
  @@ -293,7 +303,11 @@
                       performTSAction(actionToDo, mu, doc);
                       break;
   
  -                case WSConstants.NO_SERIALIZE:
  +    			case WSConstants.UT_SIGN:
  +    				performUT_SIGNAction(actionToDo, mu, doc);
  +    				break;
  +
  +    			case WSConstants.NO_SERIALIZE:
                       noSerialization = true;
                       break;
               }
  @@ -435,6 +449,33 @@
           }
       }
   
  +    private void performUT_SIGNAction(int actionToDo, boolean mu, Document doc)
  +			throws AxisFault {
  +		String password;
  +		password = getPassword(username, actionToDo,
  +				WSHandlerConstants.PW_CALLBACK_CLASS,
  +				WSHandlerConstants.PW_CALLBACK_REF).getPassword();
  +
  +		WSSAddUsernameToken builder = new WSSAddUsernameToken(actor, mu);
  +		builder.setPasswordType(WSConstants.PASSWORD_TEXT);
  +		builder.preSetUsernameToken(doc, username, password);
  +		builder.addCreated(doc);
  +		builder.addNonce(doc);
  +
  +		WSSignEnvelope sign = new WSSignEnvelope(actor, mu);
  +		sign.setUsernameToken(builder);
  +		sign.setKeyIdentifierType(WSConstants.UT_SIGNING);
  +		sign.setSignatureAlgorithm(XMLSignature.ALGO_ID_MAC_HMAC_SHA1);
  +		try {
  +			sign.build(doc, null);
  +		} catch (WSSecurityException e) {
  +			throw new AxisFault("WSDoAllSender: Error during Signatur with UsernameToken secret"
  +					+ e);
  +		}
  +		builder.build(doc, null, null);
  +	}
  +
  +
       private void performSTAction(int actionToDo, boolean mu, Document doc)
               throws AxisFault {
           WSSAddSAMLToken builder = new WSSAddSAMLToken(actor, mu);
  @@ -808,7 +849,8 @@
           int reason = 0;
   
           switch (doAction) {
  -            case WSConstants.UT:
  +        case WSConstants.UT:
  +        case WSConstants.UT_SIGN:
                   reason = WSPasswordCallback.USERNAME_TOKEN;
                   break;
               case WSConstants.SIGN: