/// <summary> /// Gets a parameter for the unmanaged signature that represents the provided <paramref name="info"/>. /// </summary> /// <param name="generator">The marshalling generator for this <paramref name="info"/></param> /// <param name="info">Object to marshal</param> public static ParameterSyntax AsParameter(this IMarshallingGenerator generator, TypePositionInfo info) { SignatureBehavior behavior = generator.GetNativeSignatureBehavior(info); if (behavior == SignatureBehavior.ManagedTypeAndAttributes) { return GenerateForwardingParameter(info); } return Parameter(Identifier(info.InstanceIdentifier)) .WithType(behavior switch { SignatureBehavior.NativeType => generator.AsNativeType(info), SignatureBehavior.PointerToNativeType => PointerType(generator.AsNativeType(info)), _ => throw new InvalidOperationException() });
public static bindingTemplate start(UDDIClient client, String cfg_node_name) { bool reg = client.getClientConfig().getConfiguration().client.subscriptionCallbacks.autoRegisterBindingTemplate; String endpoint = client.getClientConfig().getConfiguration().client.subscriptionCallbacks.listenUrl; String kd = client.getClientConfig().getConfiguration().client.subscriptionCallbacks.keyDomain; String key = client.getClientConfig().getConfiguration().client.subscriptionCallbacks.autoRegisterBusinessServiceKey; String sbs = client.getClientConfig().getConfiguration().client.subscriptionCallbacks.signatureBehavior; SignatureBehavior sb = SignatureBehavior.DoNothing; try { sb = (SignatureBehavior)Enum.Parse(typeof(SignatureBehavior), sbs); } catch (Exception ex) { log.warn("Unable to parse config setting for SignatureBehavior, defaulting to DoNothing", ex); } return(start(client, cfg_node_name, endpoint, kd, reg, key, sb)); }
/** * return true if and only if the binding exists and is signed * * @param bindingKey * @param uddiInquiryService * @param token * @param behavior * @return */ private static bool CheckExistingBindingForSignature(String bindingKey, UDDI_Inquiry_SoapBinding uddiInquiryService, String token, SignatureBehavior behavior) { get_bindingDetail gbd = new get_bindingDetail(); gbd.authInfo = (token); gbd.bindingKey = new string[] { bindingKey }; try { bindingDetail bindingDetail = uddiInquiryService.get_bindingDetail(gbd); if (bindingDetail != null && bindingDetail.bindingTemplate != null && bindingDetail.bindingTemplate.Length > 0 && bindingDetail.bindingTemplate[0].Signature != null && bindingDetail.bindingTemplate[0].Signature.Length > 0) { log.info("the binding template with key=" + bindingKey + " exists and is digitally signed"); } return(true); } catch (Exception ex) { log.debug("Error caught checking for the existence of and if a signature is present for binding key " + bindingKey + " this may be ignorable", ex); } return(false); }
/** * Registers a UDDI binding template that represents the subscription * callback endpoint * * @param client * @param cfg_node_name * @param bt - Binding Template * @param behavior * @return * @throws ServiceAlreadyStartedException * @throws SecurityException * @throws ConfigurationException * @throws TransportException * @throws DispositionReportFaultMessage * @throws RemoteException * @throws UnexpectedException * @throws RegistrationAbortedException * @throws UnableToSignException */ public static bindingTemplate registerBinding(UDDIClient client, String cfg_node_name, bindingTemplate bt, SignatureBehavior behavior) { log.info("Attempting to register binding " + bt.bindingKey); UDDIClerk clerk = client.getClerk(cfg_node_name); Transport tp = client.getTransport(cfg_node_name); UDDI_Inquiry_SoapBinding uddiInquiryService = tp.getUDDIInquiryService(); UDDI_Publication_SoapBinding uddiPublishService = tp.getUDDIPublishService(); String token = clerk.getAuthToken(clerk.getUDDINode().getSecurityUrl()); switch (behavior) { case SignatureBehavior.AbortIfSigned: if (CheckExistingBindingForSignature(bt.bindingKey, uddiInquiryService, token, behavior)) { throw new RegistrationAbortedException("Aborting, Either the item exists and is signed"); } if (CheckServiceAndParentForSignature(bt.serviceKey, uddiInquiryService, token)) { throw new RegistrationAbortedException("Aborting, Either the service or busness is signed"); } break; case SignatureBehavior.DoNothing: break; case SignatureBehavior.SignAlways: try { DigSigUtil ds = new DigSigUtil(client.getClientConfig().getDigitalSignatureConfiguration()); bt = (bindingTemplate)ds.signUddiEntity(bt); } catch (Exception ex) { log.error("Unable to sign", ex); throw new UnableToSignException("Unable to sign", ex); } break; case SignatureBehavior.SignOnlyIfParentIsntSigned: if (!CheckServiceAndParentForSignature(bt.serviceKey, uddiInquiryService, token)) { try { DigSigUtil ds = new DigSigUtil(client.getClientConfig().getDigitalSignatureConfiguration()); bt = (bindingTemplate)ds.signUddiEntity(bt); } catch (Exception ex) { log.error("Unable to sign", ex); throw new UnableToSignException("Unable to sign", ex); } } break; } save_binding sb = new save_binding(); sb.authInfo = (token); sb.bindingTemplate = new bindingTemplate[] { bt }; bindingDetail saveBinding = uddiPublishService.save_binding(sb); log.info("Binding registered successfully"); if (saveBinding.bindingTemplate == null || saveBinding.bindingTemplate.Length > 1) { throw new UnexpectedResponseException("The number of binding templates returned was unexpected, count=" + (saveBinding.bindingTemplate == null ? "none" : saveBinding.bindingTemplate.Length.ToString())); } return(saveBinding.bindingTemplate[0]); }
public static bindingTemplate start(UDDIClient client, String cfg_node_name, String endpoint, String keydomain, bool autoregister, String serviceKey, SignatureBehavior behavior) { if (instance == null) { instance = new SubscriptionCallbackListener(); } if (ep != null && ep.State == CommunicationState.Opened) { throw new ServiceAlreadyStartedException(); } Uri url = null; try { url = new Uri(endpoint); } catch (Exception ex) { log.warn("Callback endpoint couldn't be parsed, generating a random one: " + ex.Message); url = new Uri("http://" + GetHostname() + ":" + GetRandomPort(4000) + "/" + Guid.NewGuid().ToString()); } endpoint = url.ToString(); //if (endpoint == null || endpoint.equals("")) { // endpoint = "http://" + GetHostname() + ":" + GetRandomPort(url.getPort()) + "/" + UUID.randomUUID().toString(); int attempts = 5; if (ep == null) { while ((ep == null || ep.State != CommunicationState.Opened) && attempts > 0) { try { if (endpoint.Contains("localhost")) { endpoint = endpoint.Replace("localhost", GetHostname()); } ep = new ServiceHost(instance, new Uri[] { new Uri(endpoint) }); //ep = Endpoint.publish(endpoint, instance); ep.Open(); callback = endpoint; } catch (Exception be) { log.info("trouble starting callback at " + endpoint + ", trying again with a random port: " + be.Message); log.debug(be); attempts--; //if (be instanceof java.net.BindException) { url = new Uri("http://" + url.Host + ":" + GetRandomPort(url.Port) + "/" + url.PathAndQuery); endpoint = url.ToString(); } } } if (ep == null || ep.State != CommunicationState.Opened) { log.warn("Unable to start callback endpoint, aborting"); throw new SecurityException("unable to start endpoint, view previous errors for reason"); } log.info("Endpoint started at " + callback); bindingTemplate bt = new bindingTemplate(); bt.Item = (new accessPoint(callback, "endPoint")); tModelInstanceInfo instanceInfo = new tModelInstanceInfo(); instanceInfo.tModelKey = ("uddi:uddi.org:transport:http"); bt.tModelInstanceDetails = new tModelInstanceInfo[] { instanceInfo }; bt.serviceKey = (serviceKey); if (keydomain.EndsWith(":")) { bt.bindingKey = (keydomain + GetHostname() + "_Subscription_Callback"); } else { bt.bindingKey = (keydomain + ":" + GetHostname() + "_Subscription_Callback"); } if (autoregister) { bt = registerBinding(client, cfg_node_name, bt, behavior); } return(bt); }
/** * return true if and only if the binding exists and is signed * * @param bindingKey * @param uddiInquiryService * @param token * @param behavior * @return */ private static bool CheckExistingBindingForSignature(String bindingKey, UDDI_Inquiry_SoapBinding uddiInquiryService, String token, SignatureBehavior behavior) { get_bindingDetail gbd = new get_bindingDetail(); gbd.authInfo = (token); gbd.bindingKey = new string[] { bindingKey }; try { bindingDetail bindingDetail = uddiInquiryService.get_bindingDetail(gbd); if (bindingDetail != null && bindingDetail.bindingTemplate != null && bindingDetail.bindingTemplate.Length > 0 && bindingDetail.bindingTemplate[0].Signature != null && bindingDetail.bindingTemplate[0].Signature.Length > 0) { log.info("the binding template with key=" + bindingKey + " exists and is digitally signed"); } return true; } catch (Exception ex) { log.debug("Error caught checking for the existence of and if a signature is present for binding key " + bindingKey + " this may be ignorable", ex); } return false; }
public static bindingTemplate start(UDDIClient client, String cfg_node_name, String endpoint, String keydomain, bool autoregister, String serviceKey, SignatureBehavior behavior) { if (instance == null) { instance = new SubscriptionCallbackListener(); } if (ep != null && ep.State == CommunicationState.Opened) { throw new ServiceAlreadyStartedException(); } Uri url = null; try { url = new Uri(endpoint); } catch (Exception ex) { log.warn("Callback endpoint couldn't be parsed, generating a random one: " + ex.Message); url = new Uri("http://" + GetHostname() + ":" + GetRandomPort(4000) + "/" + Guid.NewGuid().ToString()); } endpoint = url.ToString(); //if (endpoint == null || endpoint.equals("")) { // endpoint = "http://" + GetHostname() + ":" + GetRandomPort(url.getPort()) + "/" + UUID.randomUUID().toString(); int attempts = 5; if (ep == null) { while ((ep == null || ep.State != CommunicationState.Opened) && attempts > 0) { try { if (endpoint.Contains("localhost")) endpoint = endpoint.Replace("localhost", GetHostname()); ep = new ServiceHost(instance, new Uri[] { new Uri(endpoint) }); //ep = Endpoint.publish(endpoint, instance); ep.Open(); callback = endpoint; } catch (Exception be) { log.info("trouble starting callback at " + endpoint + ", trying again with a random port: " + be.Message); log.debug(be); attempts--; //if (be instanceof java.net.BindException) { url = new Uri("http://" + url.Host + ":" + GetRandomPort(url.Port) + "/" + url.PathAndQuery); endpoint = url.ToString(); } } } if (ep == null || ep.State != CommunicationState.Opened) { log.warn("Unable to start callback endpoint, aborting"); throw new SecurityException("unable to start endpoint, view previous errors for reason"); } log.info("Endpoint started at " + callback); bindingTemplate bt = new bindingTemplate(); bt.Item = (new accessPoint(callback, "endPoint")); tModelInstanceInfo instanceInfo = new tModelInstanceInfo(); instanceInfo.tModelKey = ("uddi:uddi.org:transport:http"); bt.tModelInstanceDetails = new tModelInstanceInfo[] { instanceInfo }; bt.serviceKey = (serviceKey); if (keydomain.EndsWith(":")) { bt.bindingKey = (keydomain + GetHostname() + "_Subscription_Callback"); } else { bt.bindingKey = (keydomain + ":" + GetHostname() + "_Subscription_Callback"); } if (autoregister) { bt = registerBinding(client, cfg_node_name, bt, behavior); } return bt; }
/** * Registers a UDDI binding template that represents the subscription * callback endpoint * * @param client * @param cfg_node_name * @param bt - Binding Template * @param behavior * @return * @throws ServiceAlreadyStartedException * @throws SecurityException * @throws ConfigurationException * @throws TransportException * @throws DispositionReportFaultMessage * @throws RemoteException * @throws UnexpectedException * @throws RegistrationAbortedException * @throws UnableToSignException */ public static bindingTemplate registerBinding(UDDIClient client, String cfg_node_name, bindingTemplate bt, SignatureBehavior behavior) { log.info("Attempting to register binding " + bt.bindingKey); UDDIClerk clerk = client.getClerk(cfg_node_name); Transport tp = client.getTransport(cfg_node_name); UDDI_Inquiry_SoapBinding uddiInquiryService = tp.getUDDIInquiryService(); UDDI_Publication_SoapBinding uddiPublishService = tp.getUDDIPublishService(); String token = clerk.getAuthToken(clerk.getUDDINode().getSecurityUrl()); switch (behavior) { case SignatureBehavior.AbortIfSigned: if (CheckExistingBindingForSignature(bt.bindingKey, uddiInquiryService, token, behavior)) { throw new RegistrationAbortedException("Aborting, Either the item exists and is signed"); } if (CheckServiceAndParentForSignature(bt.serviceKey, uddiInquiryService, token)) { throw new RegistrationAbortedException("Aborting, Either the service or busness is signed"); } break; case SignatureBehavior.DoNothing: break; case SignatureBehavior.SignAlways: try { DigSigUtil ds = new DigSigUtil(client.getClientConfig().getDigitalSignatureConfiguration()); bt = (bindingTemplate)ds.signUddiEntity(bt); } catch (Exception ex) { log.error("Unable to sign", ex); throw new UnableToSignException("Unable to sign", ex); } break; case SignatureBehavior.SignOnlyIfParentIsntSigned: if (!CheckServiceAndParentForSignature(bt.serviceKey, uddiInquiryService, token)) { try { DigSigUtil ds = new DigSigUtil(client.getClientConfig().getDigitalSignatureConfiguration()); bt = (bindingTemplate)ds.signUddiEntity(bt); } catch (Exception ex) { log.error("Unable to sign", ex); throw new UnableToSignException("Unable to sign", ex); } } break; } save_binding sb = new save_binding(); sb.authInfo = (token); sb.bindingTemplate = new bindingTemplate[] { bt }; bindingDetail saveBinding = uddiPublishService.save_binding(sb); log.info("Binding registered successfully"); if (saveBinding.bindingTemplate == null || saveBinding.bindingTemplate.Length > 1) { throw new UnexpectedResponseException("The number of binding templates returned was unexpected, count=" + (saveBinding.bindingTemplate == null ? "none" : saveBinding.bindingTemplate.Length.ToString())); } return saveBinding.bindingTemplate[0]; }