Search in sources :

Example 1 with RequestType

use of com.helger.peppol.wsclient2.RequestType in project mod-oai-pmh by folio-org.

the class ResponseConverterTest method successCase.

@Test
void successCase() {
    OAIPMH oaipmh = new OAIPMH().withResponseDate(Instant.EPOCH).withRequest(new RequestType().withValue("oai")).withErrors(new OAIPMHerrorType().withCode(OAIPMHerrorcodeType.BAD_VERB).withValue("error"));
    String result = ResponseConverter.getInstance().convertToString(oaipmh);
    assertThat(result, not(isEmptyOrNullString()));
    // Unmarshal string to OAIPMH and verify that these objects equals
    OAIPMH oaipmhFromString = ResponseConverter.getInstance().stringToOaiPmh(result);
    assertThat(oaipmh, equalTo(oaipmhFromString));
}
Also used : OAIPMH(org.openarchives.oai._2.OAIPMH) OAIPMHerrorType(org.openarchives.oai._2.OAIPMHerrorType) IsEmptyString.isEmptyOrNullString(org.hamcrest.text.IsEmptyString.isEmptyOrNullString) RequestType(org.openarchives.oai._2.RequestType) Test(org.junit.jupiter.api.Test)

Example 2 with RequestType

use of com.helger.peppol.wsclient2.RequestType in project peppol-practical by phax.

the class WSDVS method validate.

@Nonnull
public ResponseType validate(@Nonnull final RequestType aValidationRequest) throws ValidateFaultError {
    final HttpServletRequest aHttpRequest = (HttpServletRequest) m_aWSContext.getMessageContext().get(MessageContext.SERVLET_REQUEST);
    final HttpServletResponse aHttpResponse = (HttpServletResponse) m_aWSContext.getMessageContext().get(MessageContext.SERVLET_RESPONSE);
    final String sRateLimitKey = "ip:" + aHttpRequest.getRemoteAddr();
    final boolean bOverRateLimit = m_aRequestRateLimiter != null ? m_aRequestRateLimiter.overLimitWhenIncremented(sRateLimitKey) : false;
    final String sInvocationUniqueID = Integer.toString(INVOCATION_COUNTER.incrementAndGet());
    RW_LOCK.writeLocked(() -> {
        // Just append to file
        try (final CSVWriter w = new CSVWriter(FileHelper.getPrintWriter(WebFileIO.getDataIO().getFile("wsdvs-logs.csv"), EAppend.APPEND, StandardCharsets.ISO_8859_1))) {
            w.setSeparatorChar(';');
            w.writeNext(SESSION_ID, sInvocationUniqueID, PDTFactory.getCurrentLocalDateTime().toString(), aHttpRequest.getRemoteAddr(), Boolean.toString(bOverRateLimit), aValidationRequest.getVESID(), Integer.toString(StringHelper.getLength(aValidationRequest.getXML())), RequestHelper.getHttpUserAgentStringFromRequest(aHttpRequest));
        } catch (final IOException ex) {
            LOGGER.error("Error writing CSV: " + ex.getMessage());
        }
    });
    if (LOGGER.isInfoEnabled())
        LOGGER.info("Start validating business document with SOAP WS; source [" + aHttpRequest.getRemoteAddr() + ":" + aHttpRequest.getRemotePort() + "]; VESID '" + aValidationRequest.getVESID() + "'; Payload: " + StringHelper.getLength(aValidationRequest.getXML()) + " bytes;" + (bOverRateLimit ? " RATE LIMIT EXCEEDED" : ""));
    // Start request scope
    try (final WebScoped aWebScoped = new WebScoped(aHttpRequest, aHttpResponse)) {
        // Track total invocation
        STATS_COUNTER_TOTOAL.increment();
        if (bOverRateLimit) {
            // Too Many Requests
            if (LOGGER.isDebugEnabled())
                LOGGER.debug("REST search rate limit exceeded for " + sRateLimitKey);
            final HttpServletResponse aResponse = (HttpServletResponse) m_aWSContext.getMessageContext().get(MessageContext.SERVLET_RESPONSE);
            try {
                aResponse.sendError(CHttp.HTTP_TOO_MANY_REQUESTS);
            } catch (final IOException ex) {
                throw new UncheckedIOException(ex);
            }
            return null;
        }
        // Interpret parameters
        final String sVESID = aValidationRequest.getVESID();
        final VESID aVESID = VESID.parseIDOrNull(sVESID);
        if (aVESID == null)
            _throw("Syntactically invalid VESID '" + sVESID + "' provided!");
        final IValidationExecutorSet<IValidationSourceXML> aVES = ExtValidationKeyRegistry.getFromIDOrNull(aVESID);
        if (aVES == null)
            _throw("Unsupported VESID " + aVESID.getAsSingleID() + " provided!");
        if (aVES.isDeprecated())
            LOGGER.warn("  VESID '" + aVESID.getAsSingleID() + "' is deprecated");
        Document aXMLDoc = null;
        try {
            aXMLDoc = DOMReader.readXMLDOM(aValidationRequest.getXML());
        } catch (final Exception ex) {
        // fall-through
        }
        if (aXMLDoc == null)
            _throw("Invalid XML provided!");
        final String sDisplayLocale = aValidationRequest.getDisplayLocale();
        final Locale aDisplayLocale = StringHelper.hasText(sDisplayLocale) ? LocaleCache.getInstance().getLocale(sDisplayLocale) : CPPApp.DEFAULT_LOCALE;
        if (aDisplayLocale == null)
            _throw("Invalid display locale '" + sDisplayLocale + "' provided!");
        // All input parameters are valid!
        if (LOGGER.isInfoEnabled())
            LOGGER.info("Validating by SOAP WS using " + aVESID.getAsSingleID());
        final StopWatch aSW = StopWatch.createdStarted();
        // Start validating
        final ValidationResultList aVRL = ValidationExecutionManager.executeValidation(aVES, ValidationSourceXML.create("uploaded-file", aXMLDoc), aDisplayLocale);
        // Result object
        final ResponseType ret = new ResponseType();
        int nWarnings = 0;
        int nErrors = 0;
        boolean bValidationInterrupted = false;
        IErrorLevel aMostSevere = EErrorLevel.LOWEST;
        for (final ValidationResult aVR : aVRL) {
            final ValidationResultType aVRT = new ValidationResultType();
            if (aVR.isIgnored()) {
                bValidationInterrupted = true;
                aVRT.setSuccess(TriStateType.UNDEFINED);
            } else {
                aVRT.setSuccess(aVR.isSuccess() ? TriStateType.TRUE : TriStateType.FALSE);
            }
            aVRT.setArtifactType(aVR.getValidationArtefact().getValidationArtefactType().getID());
            aVRT.setArtifactPath(aVR.getValidationArtefact().getRuleResource().getPath());
            for (final IError aError : aVR.getErrorList()) {
                if (aError.getErrorLevel().isGT(aMostSevere))
                    aMostSevere = aError.getErrorLevel();
                if (aError.getErrorLevel().isGE(EErrorLevel.ERROR))
                    nErrors++;
                else if (aError.getErrorLevel().isGE(EErrorLevel.WARN))
                    nWarnings++;
                final ItemType aItem = new ItemType();
                aItem.setErrorLevel(_convert(aError.getErrorLevel()));
                if (aError.hasErrorID())
                    aItem.setErrorID(aError.getErrorID());
                if (aError.hasErrorFieldName())
                    aItem.setErrorFieldName(aError.getErrorFieldName());
                if (aError.hasErrorLocation())
                    aItem.setErrorLocation(aError.getErrorLocation().getAsString());
                aItem.setErrorText(aError.getErrorText(aDisplayLocale));
                if (aError.hasLinkedException())
                    aItem.setException(StackTraceHelper.getStackAsString(aError.getLinkedException()));
                if (aError instanceof SVRLResourceError) {
                    final String sTest = ((SVRLResourceError) aError).getTest();
                    aItem.setTest(sTest);
                }
                aVRT.addItem(aItem);
            }
            ret.addResult(aVRT);
        }
        // Success if the worst that happened is a warning
        ret.setSuccess(aMostSevere.isLE(EErrorLevel.WARN));
        ret.setInterrupted(bValidationInterrupted);
        ret.setMostSevereErrorLevel(_convert(aMostSevere));
        aSW.stop();
        if (LOGGER.isInfoEnabled())
            LOGGER.info("Finished validation after " + aSW.getMillis() + "ms; " + nWarnings + " warns; " + nErrors + " errors");
        STATS_TIMER.addTime(aSW.getMillis());
        // Track validation result
        if (ret.getMostSevereErrorLevel().equals(ErrorLevelType.ERROR))
            STATS_COUNTER_VALIDATION_ERROR.increment();
        else
            STATS_COUNTER_VALIDATION_SUCCESS.increment();
        // Track API result
        if (ret.isSuccess())
            STATS_COUNTER_API_SUCCESS.increment();
        else
            STATS_COUNTER_API_ERROR.increment();
        final int nFinalWarnings = nWarnings;
        final int nFinalErrors = nErrors;
        RW_LOCK.writeLocked(() -> {
            // Just append to file
            try (final CSVWriter w = new CSVWriter(FileHelper.getPrintWriter(WebFileIO.getDataIO().getFile("wsdvs-results.csv"), EAppend.APPEND, StandardCharsets.ISO_8859_1))) {
                w.setSeparatorChar(';');
                w.writeNext(SESSION_ID, sInvocationUniqueID, PDTFactory.getCurrentLocalDateTime().toString(), Long.toString(aSW.getMillis()), Integer.toString(nFinalWarnings), Integer.toString(nFinalErrors));
            } catch (final IOException ex) {
                LOGGER.error("Error writing CSV2: " + ex.getMessage());
            }
        });
        return ret;
    } finally {
        if (LOGGER.isInfoEnabled())
            LOGGER.info("Finished validating business document with SOAP WS");
    }
}
Also used : WebScoped(com.helger.web.scope.mgr.WebScoped) Locale(java.util.Locale) VESID(com.helger.phive.api.executorset.VESID) ItemType(com.helger.peppol.wsclient2.ItemType) HttpServletResponse(javax.servlet.http.HttpServletResponse) CSVWriter(com.helger.commons.csv.CSVWriter) UncheckedIOException(java.io.UncheckedIOException) IValidationSourceXML(com.helger.phive.engine.source.IValidationSourceXML) UncheckedIOException(java.io.UncheckedIOException) IOException(java.io.IOException) Document(org.w3c.dom.Document) ValidationResult(com.helger.phive.api.result.ValidationResult) IError(com.helger.commons.error.IError) UncheckedIOException(java.io.UncheckedIOException) IOException(java.io.IOException) StopWatch(com.helger.commons.timing.StopWatch) ResponseType(com.helger.peppol.wsclient2.ResponseType) HttpServletRequest(javax.servlet.http.HttpServletRequest) ValidationResultList(com.helger.phive.api.result.ValidationResultList) ValidationResultType(com.helger.peppol.wsclient2.ValidationResultType) IErrorLevel(com.helger.commons.error.level.IErrorLevel) SVRLResourceError(com.helger.schematron.svrl.SVRLResourceError) Nonnull(javax.annotation.Nonnull)

Example 3 with RequestType

use of com.helger.peppol.wsclient2.RequestType in project peppol-practical by phax.

the class MainWSDVSClient method main.

public static void main(final String[] args) throws ValidateFaultError {
    WSHelper.enableSoapLogging(true);
    LOGGER.info("Starting the engines");
    final String sXML = StreamHelper.getAllBytesAsString(new ClassPathResource("ws/invoice1.xml"), StandardCharsets.UTF_8);
    final WSDVSService aService = new WSDVSService(new FileSystemResource("src/main/webapp/WEB-INF/wsdl/pp-dvs.wsdl").getAsURL());
    final WSDVSPort aPort = aService.getWSDVSPort();
    final WSClientConfig aWsClientConfig = new WSClientConfig(URLHelper.getAsURL(true ? "https://peppol.helger.com/wsdvs" : "http://localhost:8080/wsdvs"));
    aWsClientConfig.applyWSSettingsToBindingProvider((BindingProvider) aPort);
    LOGGER.info("Starting validation process");
    final RequestType aRequest = new RequestType();
    aRequest.setVESID(PeppolValidation3_13_0.VID_OPENPEPPOL_INVOICE_V3.getAsSingleID());
    aRequest.setXML(sXML);
    aRequest.setDisplayLocale("en");
    final ResponseType aResponse = aPort.validate(aRequest);
    if (false)
        LOGGER.info("Result:\n" + new GenericJAXBMarshaller<>(ResponseType.class, com.helger.peppol.wsclient2.ObjectFactory._ValidateResponseOutput_QNAME).getAsString(aResponse));
    LOGGER.info("Success: " + aResponse.isSuccess());
    LOGGER.info("Interrupted: " + aResponse.isInterrupted());
    LOGGER.info("Most severe error level: " + aResponse.getMostSevereErrorLevel());
    int nPos = 1;
    final int nMaxPos = aResponse.getResultCount();
    for (final ValidationResultType aResult : aResponse.getResult()) {
        LOGGER.info("  [" + nPos + "/" + nMaxPos + "] " + aResult.getArtifactType() + " - " + aResult.getArtifactPath());
        ++nPos;
        LOGGER.info("  Success: " + aResult.getSuccess());
        for (final ItemType aItem : aResult.getItem()) {
            LOGGER.info("    Error Level: " + aItem.getErrorLevel());
            if (aItem.getErrorID() != null)
                LOGGER.info("    Error ID: " + aItem.getErrorID());
            if (aItem.getErrorFieldName() != null)
                LOGGER.info("    Error Field: " + aItem.getErrorFieldName());
            LOGGER.info("    Error Text: " + aItem.getErrorText());
            if (aItem.getErrorLocation() != null)
                LOGGER.info("    Location: " + aItem.getErrorLocation());
            if (aItem.getTest() != null)
                LOGGER.info("    Test: " + aItem.getTest());
            LOGGER.info("--");
        }
    }
    LOGGER.info("Done");
}
Also used : WSDVSService(com.helger.peppol.wsclient2.WSDVSService) WSDVSPort(com.helger.peppol.wsclient2.WSDVSPort) WSClientConfig(com.helger.wsclient.WSClientConfig) ValidationResultType(com.helger.peppol.wsclient2.ValidationResultType) ItemType(com.helger.peppol.wsclient2.ItemType) FileSystemResource(com.helger.commons.io.resource.FileSystemResource) GenericJAXBMarshaller(com.helger.jaxb.GenericJAXBMarshaller) ClassPathResource(com.helger.commons.io.resource.ClassPathResource) RequestType(com.helger.peppol.wsclient2.RequestType) ResponseType(com.helger.peppol.wsclient2.ResponseType)

Example 4 with RequestType

use of com.helger.peppol.wsclient2.RequestType in project UVMS-Docker by UnionVMS.

the class FluxMessageReceiverBeanIT method postRequestTypeRequestSuccessTest.

/**
 * Post request type request success test.
 *
 * @throws Exception the exception
 */
@Test
@Ignore
public void postRequestTypeRequestSuccessTest() throws Exception {
    Asset testAsset = AssetTestHelper.createTestAsset();
    MobileTerminalType mobileTerminalType = MobileTerminalTestHelper.createMobileTerminalType();
    MobileTerminalTestHelper.assignMobileTerminal(testAsset, mobileTerminalType);
    GregorianCalendar calendar = new GregorianCalendar();
    calendar.setTime(new Date());
    BridgeConnectorPortType bridgeConnectorPortType = createBridgeConnector();
    RequestType requestType = new RequestType();
    FLUXVesselPositionMessage fLUXVesselPositionMessage = new FLUXVesselPositionMessage();
    VesselTransportMeansType vesselTransportMeansType = new VesselTransportMeansType();
    IDType cfrId = new IDType();
    cfrId.setSchemeID("CFR");
    cfrId.setValue(testAsset.getCfr());
    vesselTransportMeansType.getIDS().add(cfrId);
    IDType ircsId = new IDType();
    ircsId.setSchemeID("IRCS");
    ircsId.setValue(testAsset.getIrcs());
    vesselTransportMeansType.getIDS().add(ircsId);
    // IDType extMarkingId = new IDType();
    // extMarkingId.setSchemeID("EXT_MARKING");
    // extMarkingId.setValue(testAsset.getExternalMarking());
    // vesselTransportMeansType.getIDS().add(extMarkingId);
    VesselCountryType vesselCountry = new VesselCountryType();
    IDType countryId = new IDType();
    countryId.setValue("SWE");
    vesselCountry.setID(countryId);
    vesselTransportMeansType.setRegistrationVesselCountry(vesselCountry);
    VesselPositionEventType vesselPositionEventType = new VesselPositionEventType();
    MeasureType measureType = new MeasureType();
    measureType.setValue(new BigDecimal(282));
    vesselPositionEventType.setCourseValueMeasure(measureType);
    DateTimeType posDateTime = new DateTimeType();
    posDateTime.setDateTime(DatatypeFactory.newInstance().newXMLGregorianCalendar(calendar));
    vesselPositionEventType.setObtainedOccurrenceDateTime(posDateTime);
    VesselGeographicalCoordinateType cordinates = new VesselGeographicalCoordinateType();
    MeasureType longitude = new MeasureType();
    longitude.setValue(new BigDecimal(21.5740000000));
    cordinates.setLongitudeMeasure(longitude);
    MeasureType latitude = new MeasureType();
    latitude.setValue(new BigDecimal(59.6480000000));
    cordinates.setLatitudeMeasure(latitude);
    vesselPositionEventType.setSpecifiedVesselGeographicalCoordinate(cordinates);
    MeasureType speedValue = new MeasureType();
    speedValue.setValue(new BigDecimal(7.5));
    vesselPositionEventType.setSpeedValueMeasure(speedValue);
    CodeType typeCodeValue = new CodeType();
    typeCodeValue.setValue("POS");
    vesselPositionEventType.setTypeCode(typeCodeValue);
    vesselTransportMeansType.getSpecifiedVesselPositionEvents().add(vesselPositionEventType);
    fLUXVesselPositionMessage.setVesselTransportMeans(vesselTransportMeansType);
    FLUXReportDocumentType fluxReportDocumentType = new FLUXReportDocumentType();
    DateTimeType dateTimeType = new DateTimeType();
    dateTimeType.setDateTime(DatatypeFactory.newInstance().newXMLGregorianCalendar(calendar));
    fluxReportDocumentType.setCreationDateTime(dateTimeType);
    FLUXPartyType fLUXPartyType = new FLUXPartyType();
    fLUXPartyType.getIDS().add(countryId);
    fluxReportDocumentType.setOwnerFLUXParty(fLUXPartyType);
    TextType textType = new TextType();
    fluxReportDocumentType.setPurpose(textType);
    CodeType purposeCode = new CodeType();
    purposeCode.setValue("9");
    fluxReportDocumentType.setPurposeCode(purposeCode);
    IDType idType = new IDType();
    fluxReportDocumentType.setReferencedID(idType);
    CodeType typeCode = new CodeType();
    fluxReportDocumentType.setTypeCode(typeCode);
    fLUXVesselPositionMessage.setFLUXReportDocument(fluxReportDocumentType);
    requestType.setAny(createAnyElement(fLUXVesselPositionMessage));
    requestType.setAD("SWE");
    requestType.setAR(true);
    requestType.setDF("df");
    requestType.setON("on");
    requestType.setTO(1234);
    requestType.setTODT(DatatypeFactory.newInstance().newXMLGregorianCalendar(calendar));
    ResponseType responseType = bridgeConnectorPortType.post(requestType);
    assertNotNull(responseType);
    assertEquals("OK", responseType.getStatus());
    Thread.sleep(7500);
    List<String> connectIds = new ArrayList<>();
    connectIds.add(testAsset.getEventHistory().getEventId());
    final HttpResponse response = Request.Post(getBaseUrl() + "movement/rest/movement/latest").setHeader("Content-Type", "application/json").setHeader("Authorization", getValidJwtToken()).bodyByteArray(writeValueAsString(connectIds).getBytes()).execute().returnResponse();
    List dataList = checkSuccessResponseReturnType(response, List.class);
    assertEquals("Expect one position in movement db", 1, dataList.size());
}
Also used : ArrayList(java.util.ArrayList) MeasureType(un.unece.uncefact.data.standard.unqualifieddatatype._18.MeasureType) FLUXReportDocumentType(un.unece.uncefact.data.standard.reusableaggregatebusinessinformationentity._18.FLUXReportDocumentType) IDType(un.unece.uncefact.data.standard.unqualifieddatatype._18.IDType) BridgeConnectorPortType(xeu.bridge_connector.wsdl.v1.BridgeConnectorPortType) Asset(eu.europa.ec.fisheries.wsdl.asset.types.Asset) ArrayList(java.util.ArrayList) List(java.util.List) MobileTerminalType(eu.europa.ec.fisheries.schema.mobileterminal.types.v1.MobileTerminalType) VesselCountryType(un.unece.uncefact.data.standard.reusableaggregatebusinessinformationentity._18.VesselCountryType) FLUXVesselPositionMessage(un.unece.uncefact.data.standard.fluxvesselpositionmessage._4.FLUXVesselPositionMessage) VesselGeographicalCoordinateType(un.unece.uncefact.data.standard.reusableaggregatebusinessinformationentity._18.VesselGeographicalCoordinateType) GregorianCalendar(java.util.GregorianCalendar) VesselPositionEventType(un.unece.uncefact.data.standard.reusableaggregatebusinessinformationentity._18.VesselPositionEventType) HttpResponse(org.apache.http.HttpResponse) VesselTransportMeansType(un.unece.uncefact.data.standard.reusableaggregatebusinessinformationentity._18.VesselTransportMeansType) FLUXPartyType(un.unece.uncefact.data.standard.reusableaggregatebusinessinformationentity._18.FLUXPartyType) Date(java.util.Date) BigDecimal(java.math.BigDecimal) TextType(un.unece.uncefact.data.standard.unqualifieddatatype._18.TextType) ResponseType(xeu.bridge_connector.v1.ResponseType) DateTimeType(un.unece.uncefact.data.standard.unqualifieddatatype._18.DateTimeType) CodeType(un.unece.uncefact.data.standard.unqualifieddatatype._18.CodeType) RequestType(xeu.bridge_connector.v1.RequestType) Ignore(org.junit.Ignore) Test(org.junit.Test) AbstractRestServiceTest(eu.europa.ec.fisheries.uvms.docker.validation.common.AbstractRestServiceTest)

Example 5 with RequestType

use of com.helger.peppol.wsclient2.RequestType in project ddf by codice.

the class XacmlPdp method createXACMLRequest.

protected RequestType createXACMLRequest(String subject, AuthorizationInfo info, CollectionPermission permission) {
    LOGGER.debug("Creating XACML request for subject: {} and metacard permissions {}", subject, permission);
    RequestType xacmlRequestType = new RequestType();
    xacmlRequestType.setCombinedDecision(false);
    xacmlRequestType.setReturnPolicyIdList(false);
    // Adding filter action
    AttributesType actionAttributes = new AttributesType();
    actionAttributes.setCategory(ACTION_CATEGORY);
    AttributeType actionAttribute = new AttributeType();
    actionAttribute.setAttributeId(ACTION_ID);
    actionAttribute.setIncludeInResult(false);
    AttributeValueType actionValue = new AttributeValueType();
    actionValue.setDataType(STRING_DATA_TYPE);
    LOGGER.trace("Adding action: {} for subject: {}", FILTER_ACTION, subject);
    actionValue.getContent().add(permission.getAction());
    actionAttribute.getAttributeValue().add(actionValue);
    actionAttributes.getAttribute().add(actionAttribute);
    xacmlRequestType.getAttributes().add(actionAttributes);
    // Adding permissions for the calling subject
    AttributesType subjectAttributes = createSubjectAttributes(subject, info);
    xacmlRequestType.getAttributes().add(subjectAttributes);
    // Adding permissions for the resource
    AttributesType metadataAttributes = new AttributesType();
    metadataAttributes.setCategory(RESOURCE_CATEGORY);
    AttributesType environmentAttributesType = new AttributesType();
    environmentAttributesType.setCategory(ENVIRONMENT_CATEGORY);
    if (!CollectionUtils.isEmpty(environmentAttributes)) {
        for (String envAttr : environmentAttributes) {
            String[] attr = envAttr.split("=");
            if (attr.length == 2) {
                AttributeType attributeType = new AttributeType();
                attributeType.setAttributeId(attr[0].trim());
                String[] attrVals = attr[1].split(",");
                for (String attrVal : attrVals) {
                    AttributeValueType attributeValueType = new AttributeValueType();
                    attributeValueType.setDataType(STRING_DATA_TYPE);
                    attributeValueType.getContent().add(attrVal.trim());
                    attributeType.getAttributeValue().add(attributeValueType);
                }
                environmentAttributesType.getAttribute().add(attributeType);
            }
        }
    }
    if (permission instanceof KeyValueCollectionPermission) {
        List<KeyValuePermission> tmpList = ((KeyValueCollectionPermission) permission).getKeyValuePermissionList();
        for (KeyValuePermission curPermission : tmpList) {
            AttributeType resourceAttribute = new AttributeType();
            resourceAttribute.setAttributeId(curPermission.getKey());
            resourceAttribute.setIncludeInResult(false);
            if (!curPermission.getValues().isEmpty()) {
                for (String curPermValue : curPermission.getValues()) {
                    AttributeValueType resourceAttributeValue = new AttributeValueType();
                    resourceAttributeValue.setDataType(getXacmlDataType(curPermValue));
                    LOGGER.trace("Adding permission: {}:{} for incoming resource", new Object[] { curPermission.getKey(), curPermValue });
                    resourceAttributeValue.getContent().add(curPermValue);
                    resourceAttribute.getAttributeValue().add(resourceAttributeValue);
                }
                metadataAttributes.getAttribute().add(resourceAttribute);
            }
        }
        xacmlRequestType.getAttributes().add(metadataAttributes);
        if (!CollectionUtils.isEmpty(environmentAttributes)) {
            xacmlRequestType.getAttributes().add(environmentAttributesType);
        }
    } else {
        LOGGER.warn("Permission on the resource need to be of type KeyValueCollectionPermission, cannot process this resource.");
    }
    return xacmlRequestType;
}
Also used : KeyValueCollectionPermission(ddf.security.permission.KeyValueCollectionPermission) AttributeValueType(oasis.names.tc.xacml._3_0.core.schema.wd_17.AttributeValueType) AttributeType(oasis.names.tc.xacml._3_0.core.schema.wd_17.AttributeType) AttributesType(oasis.names.tc.xacml._3_0.core.schema.wd_17.AttributesType) KeyValuePermission(ddf.security.permission.KeyValuePermission) RequestType(oasis.names.tc.xacml._3_0.core.schema.wd_17.RequestType)

Aggregations

RequestType (oasis.names.tc.xacml._3_0.core.schema.wd_17.RequestType)14 Test (org.junit.Test)14 KeyValueCollectionPermissionImpl (ddf.security.permission.impl.KeyValueCollectionPermissionImpl)8 AttributesType (oasis.names.tc.xacml._3_0.core.schema.wd_17.AttributesType)6 KeyValueCollectionPermission (ddf.security.permission.KeyValueCollectionPermission)5 AttributeType (oasis.names.tc.xacml._3_0.core.schema.wd_17.AttributeType)5 AttributeValueType (oasis.names.tc.xacml._3_0.core.schema.wd_17.AttributeValueType)5 SecurityLogger (ddf.security.audit.SecurityLogger)4 ArrayList (java.util.ArrayList)4 List (java.util.List)4 File (java.io.File)3 StringWriter (java.io.StringWriter)3 Writer (java.io.Writer)3 ItemType (com.helger.peppol.wsclient2.ItemType)2 ResponseType (com.helger.peppol.wsclient2.ResponseType)2 ValidationResultType (com.helger.peppol.wsclient2.ValidationResultType)2 KeyValuePermission (ddf.security.permission.KeyValuePermission)2 AbstractRestServiceTest (eu.europa.ec.fisheries.uvms.docker.validation.common.AbstractRestServiceTest)2 HashMap (java.util.HashMap)2 JAXBContext (javax.xml.bind.JAXBContext)2