Skip to content

Commit

Permalink
More webservice fixes (mostly fault handling). More webserice tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
semancik committed Apr 2, 2015
1 parent c9806d5 commit 9116f6c
Show file tree
Hide file tree
Showing 27 changed files with 976 additions and 103 deletions.
Expand Up @@ -58,4 +58,5 @@
<!-- </limit> -->
</limitations>
</stringPolicy>
<minOccurs>0</minOccurs>
</valuePolicy>
Expand Up @@ -22,6 +22,7 @@
import org.apache.commons.lang.Validate;

import com.evolveum.midpoint.prism.PrismObject;
import com.evolveum.midpoint.prism.xml.XsdTypeMapper;
import com.evolveum.midpoint.schema.result.OperationResult;
import com.evolveum.midpoint.schema.result.OperationResultStatus;
import com.evolveum.midpoint.util.logging.Trace;
Expand Down Expand Up @@ -159,21 +160,23 @@ public static boolean validatePassword(String password, ValuePolicyType pp, Oper
* @return - Operation result of this validation
*/
public static OperationResult validatePassword(String password, ValuePolicyType pp) {
// check input params
// if (null == pp) {
// throw new IllegalArgumentException("No policy provided: NULL");
// }
//
// if (null == password) {
// throw new IllegalArgumentException("Password for validaiton is null.");
// }

Validate.notNull(pp, "Password policy must not be null.");
Validate.notNull(password, "Password to validate must not be null.");

Validate.notNull(pp, "Password policy must not be null.");

OperationResult ret = new OperationResult(OPERATION_PASSWORD_VALIDATION);
ret.addParam("policyName", pp.getName());
normalize(pp);

if (password == null && pp.getMinOccurs() != null && XsdTypeMapper.multiplicityToInteger(pp.getMinOccurs()) == 0) {
// No password is allowed
ret.recordSuccess();
return ret;
}

if (password == null) {
password = "";
}

LimitationsType lims = pp.getStringPolicy().getLimitations();

StringBuilder message = new StringBuilder();
Expand Down
Expand Up @@ -420,6 +420,18 @@ public String serializeToString(RootXNode xnode) throws SchemaException {
Element element = serializer.serialize(xnode);
return DOMUtil.serializeDOMToString(element);
}

public Element serializeUnderElement(XNode xnode, QName rootElementName, Element parentElement) throws SchemaException {
DomSerializer serializer = new DomSerializer(this, schemaRegistry);
RootXNode xroot;
if (xnode instanceof RootXNode) {
xroot = (RootXNode) xnode;
} else {
xroot = new RootXNode(rootElementName);
xroot.setSubnode(xnode);
}
return serializer.serializeUnderElement(xroot, parentElement);
}

public Element serializeXMapToElement(MapXNode xmap, QName elementName) throws SchemaException {
DomSerializer serializer = new DomSerializer(this, schemaRegistry);
Expand Down
Expand Up @@ -86,19 +86,27 @@ private void initializeWithExistingDocument(Document document) {

public Element serialize(RootXNode rootxnode) throws SchemaException {
initialize();
return serializeInternal(rootxnode);
return serializeInternal(rootxnode, null);
}

// this one is used only from within JaxbDomHack.toAny(..) - hopefully it will disappear soon
@Deprecated
public Element serialize(RootXNode rootxnode, Document document) throws SchemaException {
initializeWithExistingDocument(document);
return serializeInternal(rootxnode);
return serializeInternal(rootxnode, null);
}

public Element serializeUnderElement(RootXNode rootxnode, Element parentElement) throws SchemaException {
initializeWithExistingDocument(parentElement.getOwnerDocument());
return serializeInternal(rootxnode, parentElement);
}

private Element serializeInternal(RootXNode rootxnode) throws SchemaException {
private Element serializeInternal(RootXNode rootxnode, Element parentElement) throws SchemaException {
QName rootElementName = rootxnode.getRootElementName();
Element topElement = createElement(rootElementName, null);
Element topElement = createElement(rootElementName, parentElement);
if (parentElement != null) {
parentElement.appendChild(topElement);
}
QName typeQName = rootxnode.getTypeQName();
if (typeQName == null && rootxnode.getSubnode().getTypeQName() != null) {
typeQName = rootxnode.getSubnode().getTypeQName();
Expand Down
Expand Up @@ -110,6 +110,10 @@ public boolean canProcess(Class<?> clazz) {
return RawType.class.equals(clazz) || clazz.getAnnotation(XmlType.class) != null;
}

public QName determineTypeForClass(Class<?> clazz) {
return inspector.determineTypeForClass(clazz);
}

public <T> T unmarshall(MapXNode xnode, QName typeQName) throws SchemaException {
Class<T> classType = getSchemaRegistry().determineCompileTimeClass(typeQName);
return unmarshall(xnode, classType);
Expand Down
Expand Up @@ -58,6 +58,7 @@ public abstract class SchemaConstants {
public static final String NS_MATCHING_RULE = NS_MIDPOINT_PUBLIC + "/common/matching-rule-3";
public static final String NS_WFCF = "http://midpoint.evolveum.com/xml/ns/model/workflow/common-forms-3";
public static final String NS_WFPIS = "http://midpoint.evolveum.com/xml/ns/model/workflow/process-instance-state-3";
public static final String NS_FAULT = "http://midpoint.evolveum.com/xml/ns/public/common/fault-3";

// COMMON NAMESPACE

Expand Down Expand Up @@ -230,4 +231,6 @@ public abstract class SchemaConstants {
public static final QName C_ASSIGNMENT = new QName(SchemaConstants.NS_C, "assignment");

public static final QName C_NAME = new QName(SchemaConstants.NS_C, "name");

public static final QName FAULT_MESSAGE_ELEMENT_NAME = new QName(NS_FAULT, "fault");
}
Expand Up @@ -7667,6 +7667,24 @@
<xsd:sequence>
<xsd:element name="lifetime" type="c:PasswordLifeTimeType" minOccurs="1" maxOccurs="1"/>
<xsd:element name="stringPolicy" type="c:StringPolicyType" minOccurs="1" maxOccurs="1"/>
<xsd:element name="minOccurs" type="xsd:string" minOccurs="0">
<xsd:annotation>
<xsd:documentation>
Minimal number of value occurences. minOccurs set to zero means that the value
is optional.
E.g. when applied to passwords the minOccurs=0 means that the policy will
accept no password at all. But it will still validate the password using
stringPolicy if a password is present.
</xsd:documentation>
</xsd:annotation>
</xsd:element>
<xsd:element name="maxOccurs" type="xsd:string" minOccurs="0">
<xsd:annotation>
<xsd:documentation>
Maximal number of value occurences.
</xsd:documentation>
</xsd:annotation>
</xsd:element>
</xsd:sequence>
</xsd:extension>
</xsd:complexContent>
Expand Down Expand Up @@ -8020,7 +8038,7 @@
TODO: better documentation
</xsd:documentation>
<xsd:appinfo>
<a:objectReferenceTargetType>tns:ValuePolicyType</a:objectReferenceTargetType>
<a:objectReferenceTargetType>tns:SecurityPolicyType</a:objectReferenceTargetType>
</xsd:appinfo>
</xsd:annotation>
</xsd:element>
Expand Down
80 changes: 74 additions & 6 deletions infra/schema/src/main/resources/xml/ns/public/common/fault-3.wsdl
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Copyright (c) 2010-2014 Evolveum
~ Copyright (c) 2010-2015 Evolveum
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
Expand All @@ -25,18 +25,23 @@
xmlns:tns="http://midpoint.evolveum.com/xml/ns/public/common/fault-3">

<types>
<xsd:schema targetNamespace="http://midpoint.evolveum.com/xml/ns/public/common/fault-3">
<xsd:schema targetNamespace="http://midpoint.evolveum.com/xml/ns/public/common/fault-3"
elementFormDefault="qualified">

<xsd:import namespace="http://midpoint.evolveum.com/xml/ns/public/common/common-3"
schemaLocation="http://midpoint.evolveum.com/xml/ns/public/common/common-3"/>

<xsd:complexType name="FaultType" abstract="true">
<xsd:sequence>
<xsd:element name="message" type="xsd:string" />
<xsd:element name="operationResult" type="c:OperationResultType" />
<xsd:element ref="tns:message" />
<xsd:element ref="tns:operationResult" />
</xsd:sequence>
</xsd:complexType>

<xsd:element name="fault" type="tns:FaultType" />
<xsd:element name="fault" type="tns:FaultType" />

<xsd:element name="message" type="xsd:string" />
<xsd:element name="operationResult" type="c:OperationResultType" />

<xsd:complexType name="SystemFaultType">
<xsd:annotation>
Expand Down Expand Up @@ -128,7 +133,38 @@
</xsd:complexContent>
</xsd:complexType>

<xsd:element name="schemaViolationFaul" type="tns:SchemaViolationFaultType" />
<xsd:element name="schemaViolationFault" type="tns:SchemaViolationFaultType" />

<xsd:complexType name="PolicyViolationFaultType">
<xsd:annotation>
<xsd:documentation>
Provided object does not conform to the policies (such as password policy).
</xsd:documentation>
</xsd:annotation>
<xsd:complexContent>
<xsd:extension base="tns:ObjectAccessFaultType">
</xsd:extension>
</xsd:complexContent>
</xsd:complexType>

<xsd:element name="policyViolationFault" type="tns:PolicyViolationFaultType" />

<xsd:complexType name="ConcurrencyFaultType">
<xsd:annotation>
<xsd:documentation>
Exceptional concurrency state or operation invocation.

This fault is thrown in case of race conditions and similar conflicting concurrency conditions.
It is also thrown in an attempt to acquire already acquired locks and similar cases.
</xsd:documentation>
</xsd:annotation>
<xsd:complexContent>
<xsd:extension base="tns:ObjectAccessFaultType">
</xsd:extension>
</xsd:complexContent>
</xsd:complexType>

<xsd:element name="concurrencyFault" type="tns:ConcurrencyFaultType" />

<xsd:complexType name="ReferentialIntegrityFaultType">
<xsd:annotation>
Expand Down Expand Up @@ -198,6 +234,38 @@
</xsd:complexType>

<xsd:element name="unsupportedOperationFault" type="tns:UnsupportedOperationFaultType" />

<xsd:complexType name="CommunicationFaultType">
<xsd:annotation>
<xsd:documentation>
Generic communication error. May happen in case of various network communication errors, including
(but not limited to) connection refused and timeouts.
</xsd:documentation>
</xsd:annotation>
<xsd:complexContent>
<xsd:extension base="tns:FaultType">
</xsd:extension>
</xsd:complexContent>
</xsd:complexType>

<xsd:element name="communicationFault" type="tns:CommunicationFaultType" />

<xsd:complexType name="ConfigurationFaultType">
<xsd:annotation>
<xsd:documentation>
Configuration exception indicates that something is mis-configured.

The system or its part is misconfigured and therefore the intended operation
cannot be executed.
</xsd:documentation>
</xsd:annotation>
<xsd:complexContent>
<xsd:extension base="tns:FaultType">
</xsd:extension>
</xsd:complexContent>
</xsd:complexType>

<xsd:element name="configurationFault" type="tns:ConfigurationFaultType" />

</xsd:schema>
</types>
Expand Down
Expand Up @@ -34,6 +34,7 @@
* @author Radovan Semancik
*
*/
@Deprecated
public class ConsistencyViolationException extends CommonException {
private static final long serialVersionUID = -4194650066561884619L;

Expand Down

0 comments on commit 9116f6c

Please sign in to comment.