Search in sources :

Example 21 with Signature

use of org.hl7.fhir.r5.model.Signature in project dpc-app by CMSgov.

the class KeyUpload method run.

@Override
public void run(Bootstrap<?> bootstrap, Namespace namespace) throws Exception {
    final IdType orgID = new IdType(namespace.getString("org-reference"));
    final String apiService = namespace.getString(API_HOSTNAME);
    System.out.println(String.format("Connecting to API service at: %s", apiService));
    // Read the file and parse it
    final Path keyFilePath = FileSystems.getDefault().getPath(namespace.getString(KEY_FILE));
    final String publicKey = Files.readString(keyFilePath);
    final Path signaturePath = FileSystems.getDefault().getPath(namespace.getString(SIGNATURE_FILE));
    final String signature = Files.readString(signaturePath);
    KeyResource.KeySignature keySignature = new KeyResource.KeySignature(publicKey, signature);
    final Optional<String> label = Optional.ofNullable(namespace.getString("key-label"));
    uploadKey(apiService, orgID.getIdPart(), label, keySignature);
}
Also used : Path(java.nio.file.Path) KeyResource(gov.cms.dpc.api.resources.v1.KeyResource) IdType(org.hl7.fhir.dstu3.model.IdType)

Example 22 with Signature

use of org.hl7.fhir.r5.model.Signature in project clinical_quality_language by cqframework.

the class ElmRequirementsContext method reportFunctionRef.

public void reportFunctionRef(FunctionRef functionRef) {
    CompiledLibrary targetLibrary = prepareLibraryVisit(getCurrentLibraryIdentifier(), functionRef.getLibraryName());
    try {
        List<DataType> signature;
        signature = new ArrayList<DataType>();
        for (TypeSpecifier ts : functionRef.getSignature()) {
            signature.add(typeResolver.resolveTypeSpecifier(ts));
        }
        // Signature sizes will only be different in the case that the signature is not present in the ELM, so needs to be constructed
        if (signature.size() != functionRef.getOperand().size()) {
            for (Expression e : functionRef.getOperand()) {
                if (e.getResultType() != null) {
                    signature.add(e.getResultType());
                } else if (e.getResultTypeName() != null) {
                    signature.add(typeResolver.resolveTypeName(e.getResultTypeName()));
                } else if (e.getResultTypeSpecifier() != null) {
                    signature.add(typeResolver.resolveTypeSpecifier(e.getResultTypeSpecifier()));
                } else {
                    // Signature could not be constructed, fall back to reporting all function defs
                    signature = null;
                    break;
                }
            }
        }
        Iterable<FunctionDef> fds = targetLibrary.resolveFunctionRef(functionRef.getName(), signature);
        for (FunctionDef fd : fds) {
            if (!visited.contains(fd)) {
                visitor.visitElement(fd, this);
            }
        }
    } finally {
        unprepareLibraryVisit(functionRef.getLibraryName());
    }
}
Also used : CompiledLibrary(org.cqframework.cql.cql2elm.model.CompiledLibrary) DataType(org.hl7.cql.model.DataType)

Example 23 with Signature

use of org.hl7.fhir.r5.model.Signature in project clinical_quality_language by cqframework.

the class GenericOperator method instantiate.

public InstantiationResult instantiate(Signature callSignature, Map<TypeParameter, DataType> parameters, OperatorMap operatorMap, ConversionMap conversionMap, boolean allowPromotionAndDemotion) {
    Map<TypeParameter, DataType> typeMap = new HashMap<>();
    for (TypeParameter p : typeParameters) {
        typeMap.put(p, null);
    }
    if (parameters != null) {
        for (Map.Entry<TypeParameter, DataType> entry : parameters.entrySet()) {
            typeMap.put(entry.getKey(), entry.getValue());
        }
    }
    InstantiationContextImpl context = new InstantiationContextImpl(typeMap, operatorMap, conversionMap, allowPromotionAndDemotion);
    Boolean instantiable = getSignature().isInstantiable(callSignature, context);
    if (instantiable) {
        Operator result = new Operator(getName(), getSignature().instantiate(context), getResultType().instantiate(context));
        result.setAccessLevel(getAccessLevel());
        result.setLibraryName(getLibraryName());
        return new InstantiationResult(this, result, context.getConversionScore());
    }
    return new InstantiationResult(this, null, context.getConversionScore());
}
Also used : TypeParameter(org.hl7.cql.model.TypeParameter) HashMap(java.util.HashMap) DataType(org.hl7.cql.model.DataType) Map(java.util.Map) HashMap(java.util.HashMap)

Example 24 with Signature

use of org.hl7.fhir.r5.model.Signature in project clinical_quality_language by cqframework.

the class OperatorEntry method expandChoices.

public List<Signature> expandChoices(Signature callSignature) {
    ArrayList<Signature> signatures = new ArrayList<Signature>();
    if (callSignature.containsChoices()) {
        ArrayList<ArrayList<DataType>> operandList = new ArrayList<ArrayList<DataType>>();
        for (DataType operand : callSignature.getOperandTypes()) {
            ArrayList<DataType> list = new ArrayList<DataType>();
            if (operand instanceof ChoiceType) {
                for (DataType type : ((ChoiceType) operand).getTypes()) {
                    list.add(type);
                }
            } else {
                list.add(operand);
            }
            operandList.add(list);
        }
        DataType[] result = new DataType[callSignature.getSize()];
        collectSignatures(operandList, result, 0, signatures);
    } else {
        signatures.add(callSignature);
    }
    return signatures;
}
Also used : ChoiceType(org.hl7.cql.model.ChoiceType) DataType(org.hl7.cql.model.DataType)

Example 25 with Signature

use of org.hl7.fhir.r5.model.Signature in project drug-formulary-ri by HL7-DaVinci.

the class PatientAuthorizationInterceptor method buildRuleList.

@Override
public List<IAuthRule> buildRuleList(RequestDetails theRequestDetails) {
    String authHeader = theRequestDetails.getHeader("Authorization");
    if (authHeader != null) {
        // Retrieve the JWT token from the Authorization header
        Pattern pattern = Pattern.compile("Bearer (.*)");
        Matcher matcher = pattern.matcher(authHeader);
        if (matcher.find() && matcher.groupCount() == 1) {
            String token = matcher.group(1);
            logger.fine("AuthorizationInterceptor::Token retrieved is " + token);
            String adminToken = HapiProperties.getAdminToken();
            if (adminToken != null && token.equals(adminToken)) {
                logger.info("AuthorizationInterceptor::JWT token is admin token");
                return adminAuthorizedRule();
            }
            try {
                IIdType patientId = verify(token, theRequestDetails.getFhirServerBase());
                if (patientId != null)
                    return authorizedRule(patientId);
            } catch (SignatureVerificationException e) {
                String msg = "Authorization failed: invalid signature";
                throw new AuthenticationException(msg, e.getCause());
            } catch (TokenExpiredException e) {
                String msg = "Authorization failed: access token expired";
                throw new AuthenticationException(msg, e.getCause());
            } catch (Exception e) {
                throw new AuthenticationException(e.getMessage(), e.getCause());
            }
        } else {
            throw new AuthenticationException("Authorization header is not in the form 'Bearer <token>'");
        }
    }
    return unauthorizedRule();
}
Also used : Pattern(java.util.regex.Pattern) TokenExpiredException(com.auth0.jwt.exceptions.TokenExpiredException) Matcher(java.util.regex.Matcher) AuthenticationException(ca.uhn.fhir.rest.server.exceptions.AuthenticationException) SignatureVerificationException(com.auth0.jwt.exceptions.SignatureVerificationException) AuthenticationException(ca.uhn.fhir.rest.server.exceptions.AuthenticationException) TokenExpiredException(com.auth0.jwt.exceptions.TokenExpiredException) SignatureVerificationException(com.auth0.jwt.exceptions.SignatureVerificationException) JWTVerificationException(com.auth0.jwt.exceptions.JWTVerificationException) IIdType(org.hl7.fhir.instance.model.api.IIdType)

Aggregations

ByteArrayInputStream (java.io.ByteArrayInputStream)6 OutputStream (java.io.OutputStream)6 Reference (javax.xml.crypto.dsig.Reference)6 SignedInfo (javax.xml.crypto.dsig.SignedInfo)6 XMLSignature (javax.xml.crypto.dsig.XMLSignature)6 XMLSignatureFactory (javax.xml.crypto.dsig.XMLSignatureFactory)6 DOMSignContext (javax.xml.crypto.dsig.dom.DOMSignContext)6 KeyInfo (javax.xml.crypto.dsig.keyinfo.KeyInfo)6 KeyInfoFactory (javax.xml.crypto.dsig.keyinfo.KeyInfoFactory)6 KeyValue (javax.xml.crypto.dsig.keyinfo.KeyValue)6 C14NMethodParameterSpec (javax.xml.crypto.dsig.spec.C14NMethodParameterSpec)6 DocumentBuilder (javax.xml.parsers.DocumentBuilder)6 DocumentBuilderFactory (javax.xml.parsers.DocumentBuilderFactory)6 NotImplementedException (org.apache.commons.lang3.NotImplementedException)6 XmlGenerator (org.hl7.fhir.utilities.xml.XmlGenerator)6 Document (org.w3c.dom.Document)6 Complex (org.hl7.fhir.dstu2016may.formats.RdfGenerator.Complex)4 Complex (org.hl7.fhir.r4.utils.formats.Turtle.Complex)4 FileOutputStream (java.io.FileOutputStream)3 IOException (java.io.IOException)3