Skip to content

Commit

Permalink
various small changes in XACML 2.0 based transactions
Browse files Browse the repository at this point in the history
  • Loading branch information
unixoid committed Feb 16, 2025
1 parent d29f41c commit f4b0db3
Show file tree
Hide file tree
Showing 13 changed files with 86 additions and 60 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,9 @@ private static Consent createConsent(
.addActor(actor)
.setPurpose(purposesOfUse.stream()
.map(pou -> new Coding(
"urn:oid:" + pou.getCode().getCodeSystem(),
pou.getCode().getCode(),
pou.getCode().getDisplayName()))
"urn:oid:" + pou.getCode().codeSystem(),
pou.getCode().code(),
pou.getCode().displayName()))
.collect(Collectors.toList())));

consent.setId(consentId);
Expand All @@ -102,9 +102,9 @@ private static Period createPeriod(Date startDate, Date endDate) {
private static Consent.provisionActorComponent createActor(SubjectRole role) {
return new Consent.provisionActorComponent()
.setRole(new CodeableConcept(new Coding()
.setSystem("urn:oid:" + role.getCode().getCodeSystem())
.setCode(role.getCode().getCode())
.setDisplay(role.getCode().getDisplayName())));
.setSystem("urn:oid:" + role.getCode().codeSystem())
.setCode(role.getCode().code())
.setDisplay(role.getCode().displayName())));
}

private static Consent.provisionActorComponent createInstanceActor(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,12 @@ class Xacml20MessageCreator {
)
}

protected static ResponseType createResponse(Xacml20Status status, String statusMessage, AssertionType assertion) {
protected static ResponseType createResponse(Xacml20Status status, String statusMessage, AssertionType assertion, String requestId) {
return new ResponseType(
ID: '_' + UUID.randomUUID(),
issueInstant: XML_OBJECT_FACTORY.newXMLGregorianCalendar(new GregorianCalendar()),
version: '2.0',
inResponseTo: requestId,
status: new StatusType(
statusCode: new StatusCodeType(value: status.code),
statusMessage: statusMessage,
Expand All @@ -74,14 +75,14 @@ class Xacml20MessageCreator {
)
}

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

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

}
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,13 @@ public enum Xacml20Status {
@Getter
private final String code;

public static Xacml20Status fromCode(String code) {
for (Xacml20Status status : values()) {
if (status.code.equals(code)) {
return status;
}
}
return null;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,12 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
@jakarta.xml.bind.annotation.XmlSchema(namespace = "urn:e-health-suisse:2015:policy-administration", elementFormDefault = jakarta.xml.bind.annotation.XmlNsForm.QUALIFIED)
@XmlSchema(
namespace = "urn:e-health-suisse:2015:policy-administration",
elementFormDefault = jakarta.xml.bind.annotation.XmlNsForm.QUALIFIED,
xmlns = {@XmlNs(namespaceURI = "urn:e-health-suisse:2015:policy-administration", prefix = "ppq")}
)
package org.openehealth.ipf.commons.ihe.xacml20.stub.ehealthswiss;

import jakarta.xml.bind.annotation.XmlNs;
import jakarta.xml.bind.annotation.XmlSchema;
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,12 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
@jakarta.xml.bind.annotation.XmlSchema(namespace = "urn:hl7-org:v3", elementFormDefault = jakarta.xml.bind.annotation.XmlNsForm.QUALIFIED)
@XmlSchema(
namespace = "urn:hl7-org:v3",
elementFormDefault = jakarta.xml.bind.annotation.XmlNsForm.QUALIFIED,
xmlns = {@XmlNs(namespaceURI = "urn:hl7-org:v3", prefix = "hl7")}
)
package org.openehealth.ipf.commons.ihe.xacml20.stub.hl7v3;

import jakarta.xml.bind.annotation.XmlNs;
import jakarta.xml.bind.annotation.XmlSchema;
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,12 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
@jakarta.xml.bind.annotation.XmlSchema(namespace = "urn:oasis:names:tc:SAML:2.0:assertion", elementFormDefault = jakarta.xml.bind.annotation.XmlNsForm.QUALIFIED)
@XmlSchema(
namespace = "urn:oasis:names:tc:SAML:2.0:assertion",
elementFormDefault = jakarta.xml.bind.annotation.XmlNsForm.QUALIFIED,
xmlns = {@XmlNs(namespaceURI = "urn:oasis:names:tc:SAML:2.0:assertion", prefix = "saml")}
)
package org.openehealth.ipf.commons.ihe.xacml20.stub.saml20.assertion;

import jakarta.xml.bind.annotation.XmlNs;
import jakarta.xml.bind.annotation.XmlSchema;
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,12 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
@jakarta.xml.bind.annotation.XmlSchema(namespace = "urn:oasis:names:tc:SAML:2.0:conditions:delegation", elementFormDefault = jakarta.xml.bind.annotation.XmlNsForm.QUALIFIED)
@XmlSchema(
namespace = "urn:oasis:names:tc:SAML:2.0:conditions:delegation",
elementFormDefault = jakarta.xml.bind.annotation.XmlNsForm.QUALIFIED,
xmlns = {@XmlNs(namespaceURI = "urn:oasis:names:tc:SAML:2.0:conditions:delegation", prefix = "del")}
)
package org.openehealth.ipf.commons.ihe.xacml20.stub.saml20.delegation;

import jakarta.xml.bind.annotation.XmlNs;
import jakarta.xml.bind.annotation.XmlSchema;
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,12 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
@jakarta.xml.bind.annotation.XmlSchema(namespace = "urn:oasis:names:tc:SAML:2.0:protocol", elementFormDefault = jakarta.xml.bind.annotation.XmlNsForm.QUALIFIED)
@XmlSchema(
namespace = "urn:oasis:names:tc:SAML:2.0:protocol",
elementFormDefault = jakarta.xml.bind.annotation.XmlNsForm.QUALIFIED,
xmlns = {@XmlNs(namespaceURI = "urn:oasis:names:tc:SAML:2.0:protocol", prefix = "samlp")}
)
package org.openehealth.ipf.commons.ihe.xacml20.stub.saml20.protocol;

import jakarta.xml.bind.annotation.XmlNs;
import jakarta.xml.bind.annotation.XmlSchema;
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,12 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
@jakarta.xml.bind.annotation.XmlSchema(namespace = "urn:oasis:names:tc:xacml:2.0:profile:saml2.0:v2:schema:assertion", elementFormDefault = jakarta.xml.bind.annotation.XmlNsForm.QUALIFIED)
@XmlSchema(
namespace = "urn:oasis:names:tc:xacml:2.0:profile:saml2.0:v2:schema:assertion",
elementFormDefault = jakarta.xml.bind.annotation.XmlNsForm.QUALIFIED,
xmlns = {@XmlNs(namespaceURI = "urn:oasis:names:tc:xacml:2.0:profile:saml2.0:v2:schema:assertion", prefix = "xacml-saml")}
)
package org.openehealth.ipf.commons.ihe.xacml20.stub.xacml20.saml.assertion;

import jakarta.xml.bind.annotation.XmlNs;
import jakarta.xml.bind.annotation.XmlSchema;
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,12 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
@jakarta.xml.bind.annotation.XmlSchema(namespace = "urn:oasis:names:tc:xacml:2.0:profile:saml2.0:v2:schema:protocol", elementFormDefault = jakarta.xml.bind.annotation.XmlNsForm.QUALIFIED)
@XmlSchema(
namespace = "urn:oasis:names:tc:xacml:2.0:profile:saml2.0:v2:schema:protocol",
elementFormDefault = jakarta.xml.bind.annotation.XmlNsForm.QUALIFIED,
xmlns = {@XmlNs(namespaceURI = "urn:oasis:names:tc:xacml:2.0:profile:saml2.0:v2:schema:protocol", prefix = "xacml-samlp")}
)
package org.openehealth.ipf.commons.ihe.xacml20.stub.xacml20.saml.protocol;

import jakarta.xml.bind.annotation.XmlNs;
import jakarta.xml.bind.annotation.XmlSchema;
Original file line number Diff line number Diff line change
Expand Up @@ -15,28 +15,8 @@
*/
package org.openehealth.ipf.commons.ihe.xacml20.model;

import lombok.AllArgsConstructor;
import lombok.EqualsAndHashCode;
import lombok.Getter;

/**
* @author Dmytro Rud
*/
@AllArgsConstructor
@EqualsAndHashCode
public class CE {
@Getter private final String code;
@Getter private final String codeSystem;
@Getter private final String codeSystemName;
@Getter private final String displayName;

@Override
public String toString() {
return "CE{" +
"code='" + code + '\'' +
", codeSystem='" + codeSystem + '\'' +
", codeSystemName='" + codeSystemName + '\'' +
", displayName='" + displayName + '\'' +
'}';
}
public record CE(String code, String codeSystem, String codeSystemName, String displayName) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,29 +15,13 @@
*/
package org.openehealth.ipf.commons.ihe.xacml20.model;

import lombok.AllArgsConstructor;
import lombok.EqualsAndHashCode;
import lombok.Getter;

/**
* @author Dmytro Rud
*/
@AllArgsConstructor
@EqualsAndHashCode
public class CX {

@Getter private final String id;
@Getter private final String assigningAuthorityId;
public record CX(String id, String assigningAuthorityId) {

public String toHl7String() {
return id + "^^^&" + assigningAuthorityId + "&ISO";
}

@Override
public String toString() {
return "CX{" +
"id='" + id + '\'' +
", assigningAuthorityId='" + assigningAuthorityId + '\'' +
'}';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import lombok.extern.slf4j.Slf4j;
import org.openehealth.ipf.commons.ihe.xacml20.Xacml20MessageCreator;
import org.openehealth.ipf.commons.ihe.xacml20.stub.saml20.protocol.RequestAbstractType;
import org.openehealth.ipf.commons.ihe.xacml20.stub.saml20.protocol.ResponseType;
import org.openehealth.ipf.platform.camel.core.util.Exchanges;
import org.openehealth.ipf.platform.camel.ihe.core.HomeCommunityUtils;
Expand All @@ -35,16 +36,18 @@ public Xacml20QueryService(String homeCommunityId) {
this.homeCommunityId = homeCommunityId;
}

public ResponseType doProcessRequest(Object request) {
public ResponseType doProcessRequest(RequestAbstractType request) {
var exchange = process(request);
var exception = Exchanges.extractException(exchange);
if (exception != null) {
log.debug("{} service failed", getClass().getSimpleName(), exception);
var homeCommunityId = HomeCommunityUtils.getHomeCommunityId(exchange, this.homeCommunityId);
var messageCreator = new Xacml20MessageCreator(homeCommunityId);
return messageCreator.createNegativeQueryResponse(exception);
return messageCreator.createNegativeQueryResponse(exception, request.getID());
}
return exchange.getMessage().getBody(ResponseType.class);
var response = exchange.getMessage().getBody(ResponseType.class);
response.setInResponseTo(request.getID());
return response;
}

}

0 comments on commit f4b0db3

Please sign in to comment.