Author: coheigea
Date: Thu Nov 25 16:45:44 2010
New Revision: 1039091
URL: http://svn.apache.org/viewvc?rev=1039091&view=rev
Log:
More or less finished with JSR-105 port + some minor stuff.
Modified:
cxf/sandbox/wss4j-1.6-port/rt/ws/security/src/main/java/org/apache/cxf/ws/security/policy/interceptors/IssuedTokenInterceptorProvider.java
cxf/sandbox/wss4j-1.6-port/rt/ws/security/src/main/java/org/apache/cxf/ws/security/policy/interceptors/SecureConversationInInterceptor.java
cxf/sandbox/wss4j-1.6-port/rt/ws/security/src/main/java/org/apache/cxf/ws/security/policy/interceptors/SecureConversationTokenInterceptorProvider.java
cxf/sandbox/wss4j-1.6-port/rt/ws/security/src/main/java/org/apache/cxf/ws/security/tokenstore/MemoryTokenStore.java
cxf/sandbox/wss4j-1.6-port/rt/ws/security/src/main/java/org/apache/cxf/ws/security/tokenstore/SecurityToken.java
cxf/sandbox/wss4j-1.6-port/rt/ws/security/src/main/java/org/apache/cxf/ws/security/trust/STSClient.java
cxf/sandbox/wss4j-1.6-port/rt/ws/security/src/main/java/org/apache/cxf/ws/security/wss4j/policyhandlers/SymmetricBindingHandler.java
Modified:
cxf/sandbox/wss4j-1.6-port/rt/ws/security/src/main/java/org/apache/cxf/ws/security/policy/interceptors/IssuedTokenInterceptorProvider.java
URL:
http://svn.apache.org/viewvc/cxf/sandbox/wss4j-1.6-port/rt/ws/security/src/main/java/org/apache/cxf/ws/security/policy/interceptors/IssuedTokenInterceptorProvider.java?rev=1039091&r1=1039090&r2=1039091&view=diff
==============================================================================
---
cxf/sandbox/wss4j-1.6-port/rt/ws/security/src/main/java/org/apache/cxf/ws/security/policy/interceptors/IssuedTokenInterceptorProvider.java
(original)
+++
cxf/sandbox/wss4j-1.6-port/rt/ws/security/src/main/java/org/apache/cxf/ws/security/policy/interceptors/IssuedTokenInterceptorProvider.java
Thu Nov 25 16:45:44 2010
@@ -22,8 +22,6 @@ package org.apache.cxf.ws.security.polic
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
-import java.util.Vector;
-
import org.apache.cxf.Bus;
import org.apache.cxf.endpoint.Endpoint;
@@ -48,6 +46,7 @@ import org.apache.cxf.ws.security.trust.
import org.apache.cxf.ws.security.wss4j.PolicyBasedWSS4JInInterceptor;
import org.apache.cxf.ws.security.wss4j.PolicyBasedWSS4JOutInterceptor;
import org.apache.cxf.ws.security.wss4j.WSS4JInInterceptor;
+import org.apache.ws.security.WSSecurityEngineResult;
import org.apache.ws.security.handler.WSHandlerConstants;
import org.apache.ws.security.handler.WSHandlerResult;
@@ -200,6 +199,7 @@ public class IssuedTokenInterceptorProvi
addAfter(PolicyBasedWSS4JInInterceptor.class.getName());
}
+ @SuppressWarnings("unchecked")
public void handleMessage(Message message) throws Fault {
AssertionInfoMap aim = message.get(AssertionInfoMap.class);
// extract Assertion information
@@ -210,13 +210,12 @@ public class IssuedTokenInterceptorProvi
}
if (!isRequestor(message)) {
boolean found = false;
- Vector results =
(Vector)message.get(WSHandlerConstants.RECV_RESULTS);
+ List<WSHandlerResult> results =
+
(List<WSHandlerResult>)message.get(WSHandlerConstants.RECV_RESULTS);
if (results != null) {
- for (int i = 0; i < results.size(); i++) {
- WSHandlerResult rResult =
- (WSHandlerResult) results.get(i);
-
- List wsSecEngineResults = rResult.getResults();
+ for (WSHandlerResult rResult : results) {
+ List<WSSecurityEngineResult> wsSecEngineResults =
+ rResult.getResults();
for (int j = 0; j < wsSecEngineResults.size();
j++) {
//WSSecurityEngineResult wser =
Modified:
cxf/sandbox/wss4j-1.6-port/rt/ws/security/src/main/java/org/apache/cxf/ws/security/policy/interceptors/SecureConversationInInterceptor.java
URL:
http://svn.apache.org/viewvc/cxf/sandbox/wss4j-1.6-port/rt/ws/security/src/main/java/org/apache/cxf/ws/security/policy/interceptors/SecureConversationInInterceptor.java?rev=1039091&r1=1039090&r2=1039091&view=diff
==============================================================================
---
cxf/sandbox/wss4j-1.6-port/rt/ws/security/src/main/java/org/apache/cxf/ws/security/policy/interceptors/SecureConversationInInterceptor.java
(original)
+++
cxf/sandbox/wss4j-1.6-port/rt/ws/security/src/main/java/org/apache/cxf/ws/security/policy/interceptors/SecureConversationInInterceptor.java
Thu Nov 25 16:45:44 2010
@@ -19,8 +19,8 @@
package org.apache.cxf.ws.security.policy.interceptors;
-import java.util.Calendar;
import java.util.Collection;
+import java.util.Date;
import java.util.List;
import java.util.logging.Logger;
@@ -83,7 +83,7 @@ import org.apache.ws.security.handler.WS
import org.apache.ws.security.message.token.SecurityContextToken;
import org.apache.ws.security.message.token.SecurityTokenReference;
import org.apache.ws.security.util.XmlSchemaDateFormat;
-import org.apache.xml.security.utils.Base64;
+import org.apache.ws.security.util.Base64;
class SecureConversationInInterceptor extends
AbstractPhaseInterceptor<SoapMessage> {
static final Logger LOG =
LogUtils.getL7dLogger(SecureConversationInInterceptor.class);
@@ -376,10 +376,10 @@ class SecureConversationInInterceptor ex
new
SecurityContextToken(SecureConversationTokenInterceptorProvider
.getWSCVersion(tokenType),
writer.getDocument());
- Calendar created = Calendar.getInstance();
- Calendar expires = Calendar.getInstance();
- expires.setTimeInMillis(System.currentTimeMillis() + ttl);
-
+ Date created = new Date();
+ Date expires = new Date();
+ expires.setTime(created.getTime() + (ttl * 1000));
+
SecurityToken token = new SecurityToken(sct.getIdentifier(),
created, expires);
token.setToken(sct.getElement());
token.setTokenType(WSConstants.WSC_SCT);
@@ -445,20 +445,17 @@ class SecureConversationInInterceptor ex
addAfter(WSS4JInInterceptor.class.getName());
}
+ @SuppressWarnings("unchecked")
public void handleMessage(SoapMessage message) throws Fault {
//Find the SC token
boolean found = false;
- List results = (List)message.get(WSHandlerConstants.RECV_RESULTS);
+ List<WSHandlerResult> results =
+
(List<WSHandlerResult>)message.get(WSHandlerConstants.RECV_RESULTS);
if (results != null) {
- for (int i = 0; i < results.size(); i++) {
- WSHandlerResult rResult =
- (WSHandlerResult) results.get(i);
+ for (WSHandlerResult rResult : results) {
+ List<WSSecurityEngineResult> wsSecEngineResults =
rResult.getResults();
- List wsSecEngineResults = rResult.getResults();
-
- for (int j = 0; j < wsSecEngineResults.size(); j++) {
- WSSecurityEngineResult wser =
- (WSSecurityEngineResult)
wsSecEngineResults.get(j);
+ for (WSSecurityEngineResult wser : wsSecEngineResults) {
Integer actInt =
(Integer)wser.get(WSSecurityEngineResult.TAG_ACTION);
if (actInt.intValue() == WSConstants.SCT) {
SecurityContextToken tok
@@ -513,6 +510,7 @@ class SecureConversationInInterceptor ex
doCancel(message, aim, tok);
}
+
private void doCancel(SoapMessage message, AssertionInfoMap aim,
SecureConversationToken itok) {
Message m2 = message.getExchange().getOutMessage();
Modified:
cxf/sandbox/wss4j-1.6-port/rt/ws/security/src/main/java/org/apache/cxf/ws/security/policy/interceptors/SecureConversationTokenInterceptorProvider.java
URL:
http://svn.apache.org/viewvc/cxf/sandbox/wss4j-1.6-port/rt/ws/security/src/main/java/org/apache/cxf/ws/security/policy/interceptors/SecureConversationTokenInterceptorProvider.java?rev=1039091&r1=1039090&r2=1039091&view=diff
==============================================================================
---
cxf/sandbox/wss4j-1.6-port/rt/ws/security/src/main/java/org/apache/cxf/ws/security/policy/interceptors/SecureConversationTokenInterceptorProvider.java
(original)
+++
cxf/sandbox/wss4j-1.6-port/rt/ws/security/src/main/java/org/apache/cxf/ws/security/policy/interceptors/SecureConversationTokenInterceptorProvider.java
Thu Nov 25 16:45:44 2010
@@ -67,7 +67,7 @@ import org.apache.ws.security.conversati
import org.apache.ws.security.message.token.Reference;
import org.apache.ws.security.message.token.SecurityTokenReference;
import org.apache.ws.security.util.WSSecurityUtil;
-import org.apache.xml.security.utils.Base64;
+import org.apache.ws.security.util.Base64;
/**
*
@@ -95,6 +95,7 @@ public class SecureConversationTokenInte
}
return (Trust10)ais.iterator().next().getAssertion();
}
+
static final Trust13 getTrust13(AssertionInfoMap aim) {
Collection<AssertionInfo> ais = aim.get(SP12Constants.TRUST_13);
if (ais == null || ais.isEmpty()) {
@@ -113,6 +114,7 @@ public class SecureConversationTokenInte
}
return tokenStore;
}
+
static PolicyAssertion getAddressingPolicy(AssertionInfoMap aim, boolean
optional) {
Collection<AssertionInfo> lst =
aim.get(MetadataConstants.USING_ADDRESSING_2004_QNAME);
PolicyAssertion assertion = null;
@@ -230,6 +232,7 @@ public class SecureConversationTokenInte
}
return client;
}
+
static byte[] writeProofToken(String prefix,
String namespace,
W3CDOMStreamWriter writer,
Modified:
cxf/sandbox/wss4j-1.6-port/rt/ws/security/src/main/java/org/apache/cxf/ws/security/tokenstore/MemoryTokenStore.java
URL:
http://svn.apache.org/viewvc/cxf/sandbox/wss4j-1.6-port/rt/ws/security/src/main/java/org/apache/cxf/ws/security/tokenstore/MemoryTokenStore.java?rev=1039091&r1=1039090&r2=1039091&view=diff
==============================================================================
---
cxf/sandbox/wss4j-1.6-port/rt/ws/security/src/main/java/org/apache/cxf/ws/security/tokenstore/MemoryTokenStore.java
(original)
+++
cxf/sandbox/wss4j-1.6-port/rt/ws/security/src/main/java/org/apache/cxf/ws/security/tokenstore/MemoryTokenStore.java
Thu Nov 25 16:45:44 2010
@@ -21,6 +21,7 @@ package org.apache.cxf.ws.security.token
import java.util.ArrayList;
import java.util.Collection;
+import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
@@ -108,18 +109,19 @@ public class MemoryTokenStore implements
}
protected void processTokenExpiry() {
- long time = System.currentTimeMillis();
for (SecurityToken token : tokens.values()) {
if (token.getState() == State.EXPIRED
|| token.getState() == State.CANCELLED) {
if (autoRemove) {
remove(token);
}
- } else if (token.getExpires() != null
- && token.getExpires().getTimeInMillis() < time) {
- token.setState(SecurityToken.State.EXPIRED);
- if (autoRemove) {
- remove(token);
+ } else if (token.getExpires() != null) {
+ Date current = new Date();
+ if (token.getExpires().before(current)) {
+ token.setState(SecurityToken.State.EXPIRED);
+ if (autoRemove) {
+ remove(token);
+ }
}
}
}
Modified:
cxf/sandbox/wss4j-1.6-port/rt/ws/security/src/main/java/org/apache/cxf/ws/security/tokenstore/SecurityToken.java
URL:
http://svn.apache.org/viewvc/cxf/sandbox/wss4j-1.6-port/rt/ws/security/src/main/java/org/apache/cxf/ws/security/tokenstore/SecurityToken.java?rev=1039091&r1=1039090&r2=1039091&view=diff
==============================================================================
---
cxf/sandbox/wss4j-1.6-port/rt/ws/security/src/main/java/org/apache/cxf/ws/security/tokenstore/SecurityToken.java
(original)
+++
cxf/sandbox/wss4j-1.6-port/rt/ws/security/src/main/java/org/apache/cxf/ws/security/tokenstore/SecurityToken.java
Thu Nov 25 16:45:44 2010
@@ -20,12 +20,11 @@
package org.apache.cxf.ws.security.tokenstore;
import java.security.cert.X509Certificate;
-import java.util.Calendar;
+import java.util.Date;
+import java.text.DateFormat;
+import java.text.ParseException;
import java.util.Properties;
-import javax.xml.datatype.DatatypeConfigurationException;
-import javax.xml.datatype.DatatypeFactory;
-
import org.w3c.dom.Element;
import org.apache.cxf.helpers.DOMUtils;
@@ -34,6 +33,7 @@ import org.apache.cxf.staxutils.W3CDOMSt
import org.apache.ws.security.WSConstants;
import org.apache.ws.security.components.crypto.Crypto;
import org.apache.ws.security.message.token.Reference;
+import org.apache.ws.security.util.XmlSchemaDateFormat;
/**
@@ -106,12 +106,12 @@ public class SecurityToken {
/**
* Created time
*/
- private Calendar created;
+ private Date created;
/**
* Expiration time
*/
- private Calendar expires;
+ private Date expires;
/**
* Issuer end point address
@@ -136,7 +136,7 @@ public class SecurityToken {
public SecurityToken() {
}
- public SecurityToken(String id, Calendar created, Calendar expires) {
+ public SecurityToken(String id, Date created, Date expires) {
this.id = id;
this.created = created;
this.expires = expires;
@@ -144,8 +144,8 @@ public class SecurityToken {
public SecurityToken(String id,
Element tokenElem,
- Calendar created,
- Calendar expires) {
+ Date created,
+ Date expires) {
this.id = id;
this.token = cloneElement(tokenElem);
this.created = created;
@@ -178,22 +178,20 @@ public class SecurityToken {
*/
private void processLifeTime(Element lifetimeElem) {
try {
- DatatypeFactory factory = DatatypeFactory.newInstance();
-
Element createdElem =
DOMUtils.getFirstChildWithName(lifetimeElem,
WSConstants.WSU_NS,
WSConstants.CREATED_LN);
- this.created =
factory.newXMLGregorianCalendar(DOMUtils.getContent(createdElem))
- .toGregorianCalendar();
+ DateFormat zulu = new XmlSchemaDateFormat();
+
+ this.created = zulu.parse(DOMUtils.getContent(createdElem));
Element expiresElem =
DOMUtils.getFirstChildWithName(lifetimeElem,
WSConstants.WSU_NS,
WSConstants.EXPIRES_LN);
- this.expires =
factory.newXMLGregorianCalendar(DOMUtils.getContent(expiresElem))
- .toGregorianCalendar();
- } catch (DatatypeConfigurationException e) {
+ this.expires = zulu.parse(DOMUtils.getContent(expiresElem));
+ } catch (ParseException e) {
//shouldn't happen
}
}
@@ -324,21 +322,21 @@ public class SecurityToken {
/**
* @return Returns the created.
*/
- public Calendar getCreated() {
+ public Date getCreated() {
return created;
}
/**
* @return Returns the expires.
*/
- public Calendar getExpires() {
+ public Date getExpires() {
return expires;
}
/**
* @param expires The expires to set.
*/
- public void setExpires(Calendar expires) {
+ public void setExpires(Date expires) {
this.expires = expires;
}
@@ -350,7 +348,6 @@ public class SecurityToken {
this.issuerAddress = issuerAddress;
}
-
/**
* @param sha SHA1 of the encrypted key
*/
@@ -407,16 +404,18 @@ public class SecurityToken {
}
return null;
}
+
public void setX509Certificate(X509Certificate cert, Crypto cpt) {
x509cert = cert;
crypto = cpt;
}
+
public X509Certificate getX509Certificate() {
return x509cert;
}
+
public Crypto getCrypto() {
return crypto;
}
-
}
Modified:
cxf/sandbox/wss4j-1.6-port/rt/ws/security/src/main/java/org/apache/cxf/ws/security/trust/STSClient.java
URL:
http://svn.apache.org/viewvc/cxf/sandbox/wss4j-1.6-port/rt/ws/security/src/main/java/org/apache/cxf/ws/security/trust/STSClient.java?rev=1039091&r1=1039090&r2=1039091&view=diff
==============================================================================
---
cxf/sandbox/wss4j-1.6-port/rt/ws/security/src/main/java/org/apache/cxf/ws/security/trust/STSClient.java
(original)
+++
cxf/sandbox/wss4j-1.6-port/rt/ws/security/src/main/java/org/apache/cxf/ws/security/trust/STSClient.java
Thu Nov 25 16:45:44 2010
@@ -289,6 +289,7 @@ public class STSClient implements Config
public void setKeySize(int i) {
keySize = i;
}
+
public int getKeySize() {
return keySize;
}
@@ -574,10 +575,12 @@ public class STSClient implements Config
String ns = "http://schemas.xmlsoap.org/ws/2004/08/addressing/policy";
return new PrimitiveAssertion(new QName(ns, "UsingAddressing"));
}
+
public boolean validateSecurityToken(SecurityToken tok) throws Exception {
return validateSecurityToken(tok,
namespace + "/RSTR/Status");
}
+
private boolean validateSecurityToken(SecurityToken tok, String string)
throws Exception {
createClient();
Modified:
cxf/sandbox/wss4j-1.6-port/rt/ws/security/src/main/java/org/apache/cxf/ws/security/wss4j/policyhandlers/SymmetricBindingHandler.java
URL:
http://svn.apache.org/viewvc/cxf/sandbox/wss4j-1.6-port/rt/ws/security/src/main/java/org/apache/cxf/ws/security/wss4j/policyhandlers/SymmetricBindingHandler.java?rev=1039091&r1=1039090&r2=1039091&view=diff
==============================================================================
---
cxf/sandbox/wss4j-1.6-port/rt/ws/security/src/main/java/org/apache/cxf/ws/security/wss4j/policyhandlers/SymmetricBindingHandler.java
(original)
+++
cxf/sandbox/wss4j-1.6-port/rt/ws/security/src/main/java/org/apache/cxf/ws/security/wss4j/policyhandlers/SymmetricBindingHandler.java
Thu Nov 25 16:45:44 2010
@@ -22,7 +22,7 @@ package org.apache.cxf.ws.security.wss4j
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
-import java.util.Calendar;
+import java.util.Date;
import java.util.List;
import java.util.Vector;
import java.util.logging.Level;
@@ -727,9 +727,9 @@ public class SymmetricBindingHandler ext
String id = encrKey.getId();
byte[] secret = encrKey.getEphemeralKey();
- Calendar created = Calendar.getInstance();
- Calendar expires = Calendar.getInstance();
- expires.setTimeInMillis(System.currentTimeMillis() + 300000);
+ Date created = new Date();
+ Date expires = new Date();
+ expires.setTime(created.getTime() + 300000);
SecurityToken tempTok = new SecurityToken(
id,
encrKey.getEncryptedKeyElement(),
@@ -774,10 +774,10 @@ public class SymmetricBindingHandler ext
&&
((String)wser.get(WSSecurityEngineResult.TAG_ENCRYPTED_KEY_ID)).length() != 0) {
String encryptedKeyID =
(String)wser.get(WSSecurityEngineResult.TAG_ENCRYPTED_KEY_ID);
-
- Calendar created = Calendar.getInstance();
- Calendar expires = Calendar.getInstance();
- expires.setTimeInMillis(System.currentTimeMillis() +
300000);
+
+ Date created = new Date();
+ Date expires = new Date();
+ expires.setTime(created.getTime() + 300000);
SecurityToken tempTok = new SecurityToken(encryptedKeyID,
created, expires);
tempTok.setSecret((byte[])wser.get(WSSecurityEngineResult.TAG_DECRYPTED_KEY));
tempTok.setSHA1(getSHA1((byte[])wser