You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ws.apache.org by co...@apache.org on 2015/05/18 12:40:49 UTC
svn commit: r1679979 - in /webservices/wss4j/branches/2_0_x-fixes:
ws-security-dom/src/main/java/org/apache/wss4j/dom/message/token/
ws-security-policy-stax/src/main/java/org/apache/wss4j/policy/stax/
ws-security-stax/src/main/java/org/apache/wss4j/sta...
Author: coheigea
Date: Mon May 18 10:40:48 2015
New Revision: 1679979
URL: http://svn.apache.org/r1679979
Log:
Some code cleanup
Conflicts:
ws-security-dom/src/main/java/org/apache/wss4j/dom/message/token/DerivedKeyToken.java
ws-security-dom/src/main/java/org/apache/wss4j/dom/message/token/SecurityTokenReference.java
Modified:
webservices/wss4j/branches/2_0_x-fixes/ws-security-dom/src/main/java/org/apache/wss4j/dom/message/token/DerivedKeyToken.java
webservices/wss4j/branches/2_0_x-fixes/ws-security-dom/src/main/java/org/apache/wss4j/dom/message/token/SecurityTokenReference.java
webservices/wss4j/branches/2_0_x-fixes/ws-security-policy-stax/src/main/java/org/apache/wss4j/policy/stax/PolicyEnforcer.java
webservices/wss4j/branches/2_0_x-fixes/ws-security-stax/src/main/java/org/apache/wss4j/stax/ConfigurationConverter.java
webservices/wss4j/branches/2_0_x-fixes/ws-security-stax/src/main/java/org/apache/wss4j/stax/impl/processor/output/EncryptOutputProcessor.java
webservices/wss4j/branches/2_0_x-fixes/ws-security-stax/src/main/java/org/apache/wss4j/stax/impl/processor/output/WSSSignatureOutputProcessor.java
Modified: webservices/wss4j/branches/2_0_x-fixes/ws-security-dom/src/main/java/org/apache/wss4j/dom/message/token/DerivedKeyToken.java
URL: http://svn.apache.org/viewvc/webservices/wss4j/branches/2_0_x-fixes/ws-security-dom/src/main/java/org/apache/wss4j/dom/message/token/DerivedKeyToken.java?rev=1679979&r1=1679978&r2=1679979&view=diff
==============================================================================
--- webservices/wss4j/branches/2_0_x-fixes/ws-security-dom/src/main/java/org/apache/wss4j/dom/message/token/DerivedKeyToken.java (original)
+++ webservices/wss4j/branches/2_0_x-fixes/ws-security-dom/src/main/java/org/apache/wss4j/dom/message/token/DerivedKeyToken.java Mon May 18 10:40:48 2015
@@ -22,6 +22,7 @@ package org.apache.wss4j.dom.message.tok
import java.security.Principal;
import java.util.HashMap;
import java.util.Map;
+import java.util.Map.Entry;
import javax.xml.namespace.QName;
@@ -90,7 +91,8 @@ public class DerivedKeyToken {
ns = ConversationConstants.getWSCNs(version);
element =
- doc.createElementNS(ns, "wsc:" + ConversationConstants.DERIVED_KEY_TOKEN_LN);
+ doc.createElementNS(ns, ConversationConstants.WSC_PREFIX + ":"
+ + ConversationConstants.DERIVED_KEY_TOKEN_LN);
WSSecurityUtil.setNamespace(element, ns, ConversationConstants.WSC_PREFIX);
bspEnforcer = new BSPEnforcer();
}
@@ -206,12 +208,13 @@ public class DerivedKeyToken {
if (elementProperties == null) { //Create the properties element if it is not there
elementProperties =
element.getOwnerDocument().createElementNS(
- ns, "wsc:" + ConversationConstants.PROPERTIES_LN
+ ns, ConversationConstants.WSC_PREFIX + ":" + ConversationConstants.PROPERTIES_LN
);
element.appendChild(elementProperties);
}
Element tempElement =
- element.getOwnerDocument().createElementNS(ns, "wsc:" + propName);
+ element.getOwnerDocument().createElementNS(ns, ConversationConstants.WSC_PREFIX + ":"
+ + propName);
tempElement.appendChild(element.getOwnerDocument().createTextNode(propValue));
elementProperties.appendChild(tempElement);
@@ -243,17 +246,19 @@ public class DerivedKeyToken {
* @param properties The properties and values in a Map
*/
public void setProperties(Map<String, String> properties) {
- for (String key : properties.keySet()) {
- String propertyName = properties.get(key); //Get the property name
- //Check whether this property is already there
- //If so change the value
- Element node =
- WSSecurityUtil.findElement(elementProperties, propertyName, ns);
- if (node != null) { //If the node is not null
- Text node1 = getFirstNode(node);
- node1.setData(properties.get(propertyName));
- } else {
- addProperty(propertyName, properties.get(propertyName));
+ if (properties != null && !properties.isEmpty()) {
+ for (Entry<String, String> entry : properties.entrySet()) {
+ String propertyName = entry.getValue();
+ //Check whether this property is already there
+ //If so change the value
+ Element node =
+ WSSecurityUtil.findElement(elementProperties, propertyName, ns);
+ if (node != null) { //If the node is not null
+ Text node1 = getFirstNode(node);
+ node1.setData(properties.get(propertyName));
+ } else {
+ addProperty(propertyName, properties.get(propertyName));
+ }
}
}
}
@@ -282,7 +287,7 @@ public class DerivedKeyToken {
public void setLength(int length) {
elementLength =
element.getOwnerDocument().createElementNS(
- ns, "wsc:" + ConversationConstants.LENGTH_LN
+ ns, ConversationConstants.WSC_PREFIX + ":" + ConversationConstants.LENGTH_LN
);
elementLength.appendChild(
element.getOwnerDocument().createTextNode(Long.toString(length))
@@ -307,7 +312,7 @@ public class DerivedKeyToken {
if (elementGeneration == null) {
elementOffset =
element.getOwnerDocument().createElementNS(
- ns, "wsc:" + ConversationConstants.OFFSET_LN
+ ns, ConversationConstants.WSC_PREFIX + ":" + ConversationConstants.OFFSET_LN
);
elementOffset.appendChild(
element.getOwnerDocument().createTextNode(Integer.toString(offset))
@@ -336,7 +341,7 @@ public class DerivedKeyToken {
if (elementOffset == null) {
elementGeneration =
element.getOwnerDocument().createElementNS(
- ns, "wsc:" + ConversationConstants.GENERATION_LN
+ ns, ConversationConstants.WSC_PREFIX + ":" + ConversationConstants.GENERATION_LN
);
elementGeneration.appendChild(
element.getOwnerDocument().createTextNode(Integer.toString(generation))
@@ -362,7 +367,7 @@ public class DerivedKeyToken {
public void setLabel(String label) {
elementLabel =
element.getOwnerDocument().createElementNS(
- ns, "wsc:" + ConversationConstants.LABEL_LN
+ ns, ConversationConstants.WSC_PREFIX + ":" + ConversationConstants.LABEL_LN
);
elementLabel.appendChild(element.getOwnerDocument().createTextNode(label));
element.appendChild(elementLabel);
@@ -376,7 +381,7 @@ public class DerivedKeyToken {
public void setNonce(String nonce) {
elementNonce =
element.getOwnerDocument().createElementNS(
- ns, "wsc:" + ConversationConstants.NONCE_LN
+ ns, ConversationConstants.WSC_PREFIX + ":" + ConversationConstants.NONCE_LN
);
elementNonce.appendChild(element.getOwnerDocument().createTextNode(nonce));
element.appendChild(elementNonce);
@@ -534,10 +539,11 @@ public class DerivedKeyToken {
System.arraycopy(labelBytes, 0, seed, 0, labelBytes.length);
System.arraycopy(nonce, 0, seed, labelBytes.length, nonce.length);
- if (length <= 0) {
- length = getLength();
+ int keyLength = length;
+ if (keyLength <= 0) {
+ keyLength = getLength();
}
- return algo.createKey(secret, seed, getOffset(), length);
+ return algo.createKey(secret, seed, getOffset(), keyLength);
} catch (Exception e) {
throw new WSSecurityException(
Modified: webservices/wss4j/branches/2_0_x-fixes/ws-security-dom/src/main/java/org/apache/wss4j/dom/message/token/SecurityTokenReference.java
URL: http://svn.apache.org/viewvc/webservices/wss4j/branches/2_0_x-fixes/ws-security-dom/src/main/java/org/apache/wss4j/dom/message/token/SecurityTokenReference.java?rev=1679979&r1=1679978&r2=1679979&view=diff
==============================================================================
--- webservices/wss4j/branches/2_0_x-fixes/ws-security-dom/src/main/java/org/apache/wss4j/dom/message/token/SecurityTokenReference.java (original)
+++ webservices/wss4j/branches/2_0_x-fixes/ws-security-dom/src/main/java/org/apache/wss4j/dom/message/token/SecurityTokenReference.java Mon May 18 10:40:48 2015
@@ -828,7 +828,7 @@ public class SecurityTokenReference {
if (!WSConstants.WSS_SAML_KI_VALUE_TYPE.equals(valueType)
&& !WSConstants.WSS_SAML2_KI_VALUE_TYPE.equals(valueType)
- && (encodingType == null || "".equals(encodingType))) {
+ && "".equals(encodingType)) {
bspEnforcer.handleBSPRule(BSPRule.R3070);
}
} else if ("Embedded".equals(child.getLocalName())) {
Modified: webservices/wss4j/branches/2_0_x-fixes/ws-security-policy-stax/src/main/java/org/apache/wss4j/policy/stax/PolicyEnforcer.java
URL: http://svn.apache.org/viewvc/webservices/wss4j/branches/2_0_x-fixes/ws-security-policy-stax/src/main/java/org/apache/wss4j/policy/stax/PolicyEnforcer.java?rev=1679979&r1=1679978&r2=1679979&view=diff
==============================================================================
--- webservices/wss4j/branches/2_0_x-fixes/ws-security-policy-stax/src/main/java/org/apache/wss4j/policy/stax/PolicyEnforcer.java (original)
+++ webservices/wss4j/branches/2_0_x-fixes/ws-security-policy-stax/src/main/java/org/apache/wss4j/policy/stax/PolicyEnforcer.java Mon May 18 10:40:48 2015
@@ -119,7 +119,7 @@ public class PolicyEnforcer implements S
// HttpsToken Algorithms
//unused tokens must be checked (algorithms etc)
- protected static final transient org.slf4j.Logger log =
+ private static final transient org.slf4j.Logger LOG =
org.slf4j.LoggerFactory.getLogger(PolicyEnforcer.class);
private static final QName SOAP11_FAULT = new QName(WSSConstants.NS_SOAP11, "Fault");
@@ -659,7 +659,7 @@ public class PolicyEnforcer implements S
while (assertableIterator.hasNext()) {
Assertable assertable = assertableIterator.next();
if (!assertable.isAsserted() && !assertable.isLogged()) {
- log.error(entry.getKey().getName() + " not satisfied: " + assertable.getErrorMessage());
+ LOG.error(entry.getKey().getName() + " not satisfied: " + assertable.getErrorMessage());
assertable.setLogged(true);
}
}
@@ -672,7 +672,7 @@ public class PolicyEnforcer implements S
@Override
public synchronized void registerSecurityEvent(SecurityEvent securityEvent) throws WSSecurityException {
- if (securityEvent instanceof NoSecuritySecurityEvent) {
+ if (!noSecurityHeader && securityEvent instanceof NoSecuritySecurityEvent) {
noSecurityHeader = true;
}
@@ -689,8 +689,8 @@ public class PolicyEnforcer implements S
if (WSSecurityEventConstants.Operation.equals(securityEvent.getSecurityEventType())) {
operationSecurityEventOccured = true;
final OperationSecurityEvent operationSecurityEvent = (OperationSecurityEvent) securityEvent;
- if (SOAP11_FAULT.equals(operationSecurityEvent.getOperation())
- || SOAP12_FAULT.equals(operationSecurityEvent.getOperation())) {
+ if (!faultOccurred && (SOAP11_FAULT.equals(operationSecurityEvent.getOperation())
+ || SOAP12_FAULT.equals(operationSecurityEvent.getOperation()))) {
faultOccurred = true;
}
Modified: webservices/wss4j/branches/2_0_x-fixes/ws-security-stax/src/main/java/org/apache/wss4j/stax/ConfigurationConverter.java
URL: http://svn.apache.org/viewvc/webservices/wss4j/branches/2_0_x-fixes/ws-security-stax/src/main/java/org/apache/wss4j/stax/ConfigurationConverter.java?rev=1679979&r1=1679978&r2=1679979&view=diff
==============================================================================
--- webservices/wss4j/branches/2_0_x-fixes/ws-security-stax/src/main/java/org/apache/wss4j/stax/ConfigurationConverter.java (original)
+++ webservices/wss4j/branches/2_0_x-fixes/ws-security-stax/src/main/java/org/apache/wss4j/stax/ConfigurationConverter.java Mon May 18 10:40:48 2015
@@ -644,8 +644,8 @@ public final class ConfigurationConverte
final Map<QName, Validator> validatorMap =
(Map<QName, Validator>)config.get(ConfigurationConstants.VALIDATOR_MAP);
if (validatorMap != null) {
- for (QName key : validatorMap.keySet()) {
- properties.addValidator(key, validatorMap.get(key));
+ for (Map.Entry<QName, Validator> entry : validatorMap.entrySet()) {
+ properties.addValidator(entry.getKey(), entry.getValue());
}
}
Modified: webservices/wss4j/branches/2_0_x-fixes/ws-security-stax/src/main/java/org/apache/wss4j/stax/impl/processor/output/EncryptOutputProcessor.java
URL: http://svn.apache.org/viewvc/webservices/wss4j/branches/2_0_x-fixes/ws-security-stax/src/main/java/org/apache/wss4j/stax/impl/processor/output/EncryptOutputProcessor.java?rev=1679979&r1=1679978&r2=1679979&view=diff
==============================================================================
--- webservices/wss4j/branches/2_0_x-fixes/ws-security-stax/src/main/java/org/apache/wss4j/stax/impl/processor/output/EncryptOutputProcessor.java (original)
+++ webservices/wss4j/branches/2_0_x-fixes/ws-security-stax/src/main/java/org/apache/wss4j/stax/impl/processor/output/EncryptOutputProcessor.java Mon May 18 10:40:48 2015
@@ -196,7 +196,7 @@ public class EncryptOutputProcessor exte
final String externalReference = securePart.getExternalReference();
if (externalReference != null && externalReference.startsWith("cid:")) {
attachmentSecurePart = securePart;
- externalId = externalReference.substring(4);
+ externalId = externalReference.substring("cid:".length());
break;
}
}
@@ -459,7 +459,7 @@ public class EncryptOutputProcessor exte
if (use200512Namespace) {
attributes.add(createAttribute(WSSConstants.ATT_NULL_ValueType, WSSConstants.NS_WSC_05_12 + "/sct"));
} else {
- attributes.add(createAttribute(WSSConstants.ATT_NULL_ValueType, WSSConstants.NS_WSC_05_12 + "/sct"));
+ attributes.add(createAttribute(WSSConstants.ATT_NULL_ValueType, WSSConstants.NS_WSC_05_02 + "/sct"));
}
} else if (WSSecurityTokenConstants.EncryptedKeyToken.equals(securityToken.getTokenType())) {
attributes.add(createAttribute(WSSConstants.ATT_NULL_ValueType, WSSConstants.NS_WSS_ENC_KEY_VALUE_TYPE));
Modified: webservices/wss4j/branches/2_0_x-fixes/ws-security-stax/src/main/java/org/apache/wss4j/stax/impl/processor/output/WSSSignatureOutputProcessor.java
URL: http://svn.apache.org/viewvc/webservices/wss4j/branches/2_0_x-fixes/ws-security-stax/src/main/java/org/apache/wss4j/stax/impl/processor/output/WSSSignatureOutputProcessor.java?rev=1679979&r1=1679978&r2=1679979&view=diff
==============================================================================
--- webservices/wss4j/branches/2_0_x-fixes/ws-security-stax/src/main/java/org/apache/wss4j/stax/impl/processor/output/WSSSignatureOutputProcessor.java (original)
+++ webservices/wss4j/branches/2_0_x-fixes/ws-security-stax/src/main/java/org/apache/wss4j/stax/impl/processor/output/WSSSignatureOutputProcessor.java Mon May 18 10:40:48 2015
@@ -161,7 +161,7 @@ public class WSSSignatureOutputProcessor
}
AttachmentRequestCallback attachmentRequestCallback = new AttachmentRequestCallback();
- String id = securePart.getExternalReference().substring(4);
+ String id = securePart.getExternalReference().substring("cid:".length());
attachmentRequestCallback.setAttachmentId(id);
try {
attachmentCallbackHandler.handle(new Callback[]{attachmentRequestCallback});