Skip to content

Commit

Permalink
implementation of IHE SeR and CH:ADR profiles; closes #424
Browse files Browse the repository at this point in the history
  • Loading branch information
unixoid committed Nov 25, 2023
1 parent eab0184 commit ff42542
Show file tree
Hide file tree
Showing 49 changed files with 2,177 additions and 114 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ public void testPpq2To5ResponseTranslation1() {
public void testPpq2To5ResponseTranslation2() {
boolean correct = false;
try {
ResponseType ppq2Response = PPQ_MESSAGE_CREATOR.createNegativePolicyQueryResponse(new Xacml20Exception(Xacml20Status.REQUESTER_ERROR));
ResponseType ppq2Response = PPQ_MESSAGE_CREATOR.createNegativeQueryResponse(new Xacml20Exception(Xacml20Status.REQUESTER_ERROR));
XacmlToFhirTranslator.translatePpq2To5Response(ppq2Response);
} catch (UnclassifiedServerFailureException e) {
assertEquals(400, e.getStatusCode());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,9 @@

package org.openehealth.ipf.commons.ihe.xacml20

import org.apache.commons.lang3.Validate

import org.herasaf.xacml.core.context.impl.*
import org.herasaf.xacml.core.context.impl.ObjectFactory as XacmlContextObjectFactory
import org.herasaf.xacml.core.policy.impl.IdReferenceType
import org.herasaf.xacml.core.policy.impl.ObjectFactory as XacmlPolicyObjectFactory
import org.herasaf.xacml.core.policy.impl.PolicySetType
import org.openehealth.ipf.commons.ihe.xacml20.herasaf.types.IiDataTypeAttribute
import org.openehealth.ipf.commons.ihe.xacml20.model.PpqConstants
Expand All @@ -29,44 +27,15 @@ import org.openehealth.ipf.commons.ihe.xacml20.stub.ehealthswiss.DeletePolicyReq
import org.openehealth.ipf.commons.ihe.xacml20.stub.ehealthswiss.UpdatePolicyRequest
import org.openehealth.ipf.commons.ihe.xacml20.stub.ehealthswiss.XACMLPolicySetIdReferenceStatementType
import org.openehealth.ipf.commons.ihe.xacml20.stub.hl7v3.II
import org.openehealth.ipf.commons.ihe.xacml20.stub.hl7v3.ObjectFactory as Hl7v3ObjectFactory
import org.openehealth.ipf.commons.ihe.xacml20.stub.saml20.assertion.AssertionType
import org.openehealth.ipf.commons.ihe.xacml20.stub.saml20.assertion.NameIDType
import org.openehealth.ipf.commons.ihe.xacml20.stub.saml20.protocol.ResponseType
import org.openehealth.ipf.commons.ihe.xacml20.stub.saml20.protocol.StatusCodeType
import org.openehealth.ipf.commons.ihe.xacml20.stub.saml20.protocol.StatusType
import org.openehealth.ipf.commons.ihe.xacml20.stub.xacml20.saml.assertion.XACMLPolicyStatementType
import org.openehealth.ipf.commons.ihe.xacml20.stub.xacml20.saml.protocol.XACMLPolicyQueryType

import javax.xml.datatype.DatatypeFactory

class ChPpqMessageCreator {

private static final Hl7v3ObjectFactory HL7V3_OBJECT_FACTORY = new Hl7v3ObjectFactory()
private static final XacmlContextObjectFactory XACML_CONTEXT_OBJECT_FACTORY = new XacmlContextObjectFactory()
private static final XacmlPolicyObjectFactory XACML_POLICY_OBJECT_FACTORY = new XacmlPolicyObjectFactory()
private static final DatatypeFactory XML_OBJECT_FACTORY = DatatypeFactory.newInstance()

private final String homeCommunityId
class ChPpqMessageCreator extends Xacml20MessageCreator {

ChPpqMessageCreator(String homeCommunityId) {
this.homeCommunityId = Validate.notEmpty(homeCommunityId as String, 'Home community ID shall be provided')
}

NameIDType createIssuer() {
return new NameIDType(
nameQualifier: PpqConstants.NAME_QUALIFIER_EHEALTH_SUISSSE_COMMUNITY_INDEX,
value: homeCommunityId,
)
}

AssertionType createAssertion() {
return new AssertionType(
ID: '_' + UUID.randomUUID(),
issueInstant: XML_OBJECT_FACTORY.newXMLGregorianCalendar(new GregorianCalendar()),
version: '2.0',
issuer: createIssuer(),
)
super(homeCommunityId)
}

private AssertionType createSubmitAssertion(Collection<PolicySetType> policySets) {
Expand Down Expand Up @@ -144,19 +113,6 @@ class ChPpqMessageCreator {
return query
}

private static ResponseType createResponse(Xacml20Status status, String statusMessage, AssertionType assertion) {
return new ResponseType(
ID: '_' + UUID.randomUUID(),
issueInstant: XML_OBJECT_FACTORY.newXMLGregorianCalendar(new GregorianCalendar()),
version: '2.0',
status: new StatusType(
statusCode: new StatusCodeType(value: status.code),
statusMessage: statusMessage,
),
assertionOrEncryptedAssertion: [assertion],
)
}

ResponseType createPositivePolicyQueryResponse(List<PolicySetType> policySets) {
def assertion = createAssertion()
assertion.statementOrAuthnStatementOrAuthzDecisionStatement << new XACMLPolicyStatementType(
Expand All @@ -165,14 +121,4 @@ class ChPpqMessageCreator {
return createResponse(Xacml20Status.SUCCESS, null, assertion)
}

ResponseType createNegativePolicyQueryResponse(Xacml20Status status, String statusMessage) {
return createResponse(status, statusMessage, createAssertion())
}

ResponseType createNegativePolicyQueryResponse(Exception exception) {
return (exception instanceof Xacml20Exception)
? createNegativePolicyQueryResponse(exception.status, exception.message)
: createNegativePolicyQueryResponse(Xacml20Status.RESPONDER_ERROR, exception.message)
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
/*
* Copyright 2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.openehealth.ipf.commons.ihe.xacml20

import org.apache.commons.lang3.Validate
import org.openehealth.ipf.commons.ihe.xacml20.model.PpqConstants
import org.openehealth.ipf.commons.ihe.xacml20.stub.hl7v3.ObjectFactory
import org.openehealth.ipf.commons.ihe.xacml20.stub.saml20.assertion.AssertionType
import org.openehealth.ipf.commons.ihe.xacml20.stub.saml20.assertion.NameIDType
import org.openehealth.ipf.commons.ihe.xacml20.stub.saml20.protocol.ResponseType
import org.openehealth.ipf.commons.ihe.xacml20.stub.saml20.protocol.StatusCodeType
import org.openehealth.ipf.commons.ihe.xacml20.stub.saml20.protocol.StatusType

import javax.xml.datatype.DatatypeFactory

/**
* @author Dmytro Rud
* @since 4.8.0
*/
class Xacml20MessageCreator {

protected static final ObjectFactory HL7V3_OBJECT_FACTORY = new ObjectFactory()
protected static final org.herasaf.xacml.core.context.impl.ObjectFactory XACML_CONTEXT_OBJECT_FACTORY = new org.herasaf.xacml.core.context.impl.ObjectFactory()
protected static final org.herasaf.xacml.core.policy.impl.ObjectFactory XACML_POLICY_OBJECT_FACTORY = new org.herasaf.xacml.core.policy.impl.ObjectFactory()
protected static final DatatypeFactory XML_OBJECT_FACTORY = DatatypeFactory.newInstance()

private final String homeCommunityId

Xacml20MessageCreator(String homeCommunityId) {
this.homeCommunityId = Validate.notEmpty(homeCommunityId as String, 'Home community ID shall be provided')
}

NameIDType createIssuer() {
return new NameIDType(
nameQualifier: PpqConstants.NAME_QUALIFIER_EHEALTH_SUISSSE_COMMUNITY_INDEX,
value: homeCommunityId,
)
}

AssertionType createAssertion() {
return new AssertionType(
ID: '_' + UUID.randomUUID(),
issueInstant: XML_OBJECT_FACTORY.newXMLGregorianCalendar(new GregorianCalendar()),
version: '2.0',
issuer: createIssuer(),
)
}

protected static ResponseType createResponse(Xacml20Status status, String statusMessage, AssertionType assertion) {
return new ResponseType(
ID: '_' + UUID.randomUUID(),
issueInstant: XML_OBJECT_FACTORY.newXMLGregorianCalendar(new GregorianCalendar()),
version: '2.0',
status: new StatusType(
statusCode: new StatusCodeType(value: status.code),
statusMessage: statusMessage,
),
assertionOrEncryptedAssertion: [assertion],
)
}

ResponseType createNegativeQueryResponse(Xacml20Status status, String statusMessage) {
return createResponse(status, statusMessage, createAssertion())
}

ResponseType createNegativeQueryResponse(Exception exception) {
return (exception instanceof Xacml20Exception)
? createNegativeQueryResponse(exception.status, exception.message)
: createNegativeQueryResponse(Xacml20Status.RESPONDER_ERROR, exception.message)
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/*
* Copyright 2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.openehealth.ipf.commons.ihe.xacml20;

import lombok.AllArgsConstructor;
import lombok.Getter;
import org.openehealth.ipf.commons.ihe.core.IntegrationProfile;
import org.openehealth.ipf.commons.ihe.core.InteractionId;
import org.openehealth.ipf.commons.ihe.ws.WsInteractionId;
import org.openehealth.ipf.commons.ihe.ws.WsTransactionConfiguration;
import org.openehealth.ipf.commons.ihe.xacml20.chadr.ChAdrAuditDataset;
import org.openehealth.ipf.commons.ihe.xacml20.chadr.ChAdrAuditStrategy;
import org.openehealth.ipf.commons.ihe.xacml20.chadr.ChAdrPortType;

import javax.xml.namespace.QName;
import java.util.Arrays;
import java.util.List;

/**
* Definitions for the Swiss national profile "Authorization Decision Request" (CH:ADR).
*
* @author Dmytro Rud
* @since 4.8.0
*/
public class CH_ADR implements IntegrationProfile {

@AllArgsConstructor
public enum Interactions implements WsInteractionId<WsTransactionConfiguration<ChAdrAuditDataset>> {
CH_ADR(CH_ADR_WS_CONFIG);

@Getter
private final WsTransactionConfiguration<ChAdrAuditDataset> wsTransactionConfiguration;
}

@Override
public List<InteractionId> getInteractionIds() {
return Arrays.asList(Interactions.values());
}

private final static WsTransactionConfiguration<ChAdrAuditDataset> CH_ADR_WS_CONFIG = new WsTransactionConfiguration<>(
"ch-adr",
"Authorization Decisions Query",
true,
new ChAdrAuditStrategy(false),
new ChAdrAuditStrategy(true),
new QName("urn:ihe:iti:2014:ser", "AuthorizationDecisionsManager_Service"),
ChAdrPortType.class,
new QName("urn:ihe:iti:2014:ser", "AuthorizationDecisionsManager_Port_Soap12"),
false,
"wsdl/ch-adr.wsdl",
true,
false,
false,
false);


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/*
* Copyright 2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.openehealth.ipf.commons.ihe.xacml20;

import lombok.AllArgsConstructor;
import lombok.Getter;
import org.openehealth.ipf.commons.ihe.core.IntegrationProfile;
import org.openehealth.ipf.commons.ihe.core.InteractionId;
import org.openehealth.ipf.commons.ihe.ws.WsInteractionId;
import org.openehealth.ipf.commons.ihe.ws.WsTransactionConfiguration;
import org.openehealth.ipf.commons.ihe.xacml20.iti79.Iti79AuditDataset;
import org.openehealth.ipf.commons.ihe.xacml20.iti79.Iti79AuditStrategy;
import org.openehealth.ipf.commons.ihe.xacml20.iti79.Iti79PortType;

import javax.xml.namespace.QName;
import java.util.Arrays;
import java.util.List;

/**
* Definitions for the IHE integration profile "Secure Retrieve" (SeR).
*
* @author Dmytro Rud
* @since 4.8.0
*/
public class SER implements IntegrationProfile {

@AllArgsConstructor
public enum Interactions implements WsInteractionId<WsTransactionConfiguration<Iti79AuditDataset>> {
ITI_79(ITI_79_WS_CONFIG);

@Getter
private final WsTransactionConfiguration<Iti79AuditDataset> wsTransactionConfiguration;
}

@Override
public List<InteractionId> getInteractionIds() {
return Arrays.asList(Interactions.values());
}

private final static WsTransactionConfiguration<Iti79AuditDataset> ITI_79_WS_CONFIG = new WsTransactionConfiguration<>(
"ser-iti79",
"Authorization Decisions Query",
true,
new Iti79AuditStrategy(false),
new Iti79AuditStrategy(true),
new QName("urn:ihe:iti:2014:ser", "AuthorizationDecisionsManager_Service"),
Iti79PortType.class,
new QName("urn:ihe:iti:2014:ser", "AuthorizationDecisionsManager_Port_Soap12"),
false,
"wsdl/iti79.wsdl",
true,
false,
true,
false);

}
Loading

0 comments on commit ff42542

Please sign in to comment.