Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix support for web services that require authentication #26

Closed
okornev opened this issue Jan 28, 2013 · 9 comments
Closed

Fix support for web services that require authentication #26

okornev opened this issue Jan 28, 2013 · 9 comments
Labels
Milestone

Comments

@okornev
Copy link

okornev commented Jan 28, 2013

Right now it fails with
Exception in thread "main" groovy.lang.MissingMethodException: No signature of method: com.predic8.xml.util.BasicAuthenticationResolver.resolve() is applicable for argument types: (java.lang.String, java.lang.String) values: [...?wsdl, ...]
Possible solutions: resolve(java.lang.Object)
at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.unwrap(ScriptBytecodeAdapter.java:55)
at org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.call(PogoMetaClassSite.java:51)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:45)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:108)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:120)
at com.predic8.soamodel.AbstractParser.getResourceToken(AbstractParser.groovy:45)
at com.predic8.soamodel.AbstractParser.this$2$getResourceToken(AbstractParser.groovy)
at com.predic8.soamodel.AbstractParser$this$2$getResourceToken.callCurrent(Unknown Source)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallCurrent(CallSiteArray.java:49)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:133)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:141)
at com.predic8.soamodel.AbstractParser.parse(AbstractParser.groovy:34)
at com.predic8.wsdl.WSDLParser.super$2$parse(WSDLParser.groovy)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:90)
at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:233)
at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1074)
at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.invokeMethodOnSuperN(ScriptBytecodeAdapter.java:128)
at com.predic8.wsdl.WSDLParser.parse(WSDLParser.groovy:29)
at com.predic8.wsdl.WSDLParser$parse.callCurrent(Unknown Source)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallCurrent(CallSiteArray.java:49)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:133)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:141)
at com.predic8.wsdl.WSDLParser.parse(WSDLParser.groovy:25)
at com.xframework.xsoap.impl.Predic8WSDLParserImpl.parse(Predic8WSDLParserImpl.java:72)
at com.xframework.xsoap.impl.Predic8WSDLParserImpl.main(Predic8WSDLParserImpl.java:83)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)

@okornev
Copy link
Author

okornev commented Jan 28, 2013

This works:
com.predic8.xml.util.BasicAuthenticationResolver.groovy:41
def resolve(input) {
-->
def resolve(input, baseDir) {

@predic8
Copy link
Member

predic8 commented Jan 29, 2013

Hi,
thanks for the report and the fix. We will incorporate the fix into the code.

@keshavarzi
Copy link

Won't fix! A WSDL should be public.

@michbeck100
Copy link

Not all WSDLs are public. If they are used for communication between internal systems, that should not be visible to the outside.

@predic8
Copy link
Member

predic8 commented Mar 20, 2015

If they are used internal then the communication could be visible inside the organization.

In case you need more security you could fork SOA Model and implement it. Just extend the external resolver class around line 113:

https://github.com/membrane/soa-model/blob/master/core/src/main/groovy/com/predic8/xml/util/ExternalResolver.groovy

I think to implement it you need to provide the HTTP client with a configuration.

@ssneha345
Copy link

ssneha345 commented Aug 5, 2020

What is the Fix Predic8 .. I am still getting same error . I am using 1.6.1 version maven dependency .How To add authenticationDetails to the wsdlParser

@predic8
Copy link
Member

predic8 commented Aug 5, 2020

We do not plan to support authentication for WSDL download. You can place an Membrane Service Proxy infront os the Model and do the authentication there.

@arashghafori
Copy link

arashghafori commented Jun 10, 2022

base on okornevs answer, this worked for me:

  • create your own BasicAuthenticationResolver groovy class, just like this BasicAuthenticationResolver

  • remove "baseDir" variable from the class and add it to resolve method.

  • add "commons-httpclient" dependency with version 3.1 to your build tool (maven/gradel)

  • change the request method to this:

private request(url) {
        HttpClient client = new HttpClient();
        if ( username ) {
            Credentials defaultcreds = new UsernamePasswordCredentials(username, password)
            client.state.setCredentials(AuthScope.ANY, defaultcreds)
        }
        if ( proxyHost )
            client.getHostConfiguration().setProxy(proxyHost, proxyPort)

        HttpMethod method = new GetMethod(url)
        method.params.setParameter(HttpMethodParams.USER_AGENT,"SOA Model (see http://membrane-soa.org)")
        int status = client.executeMethod(method);
        if(status != 200) {
            def rde = new ResourceDownloadException("could not get resource $url by HTTP")
            rde.status = status
            rde.url = url
            method.releaseConnection()
            throw rde
        }
        method
    }

  • finally use this class instead of predic8 BasicAuthenticationResolver.

in the end, your BasicAuthenticationResolver class should look like this:

import com.predic8.xml.util.ResourceDownloadException
import com.predic8.xml.util.ResourceResolver
import org.apache.commons.httpclient.Credentials
import org.apache.commons.httpclient.HttpClient
import org.apache.commons.httpclient.HttpMethod
import org.apache.commons.httpclient.UsernamePasswordCredentials
import org.apache.commons.httpclient.auth.AuthScope
import org.apache.commons.httpclient.methods.GetMethod
import org.apache.commons.httpclient.params.HttpMethodParams;

import com.predic8.schema.Import as SchemaImport
import com.predic8.wsdl.Import as WsdlImport

class BasicAuth extends ResourceResolver{

    def username = ''
    def password = ''
    def proxyHost
    def proxyPort

    def resolve(input, baseDir) {
        if ( input instanceof SchemaImport ) {
            if ( !input.schemaLocation ) return
            input = input.schemaLocation
        }

        if ( input instanceof WsdlImport ) {
            if ( !input.location ) return
            input = input.location
        }

        if ( input instanceof InputStream )  {
            return input;
        }

        if(input instanceof Reader) {
            throw new RuntimeException("Please use an InputStream instead of Reader!")
        }


        if(input instanceof File){
            return new FileInputStream(input)
        }
        if (! input instanceof String)
            throw new RuntimeException("Do not know how to resolve $input")

        if(input.startsWith('file')){
            def url = new URL(input)
            return new FileInputStream(url.getPath())
        } else if(input.startsWith('http') || input.startsWith('https')) {
            return resolveViaHttp(input)
        } else {
            if(baseDir && (baseDir.startsWith('http') || baseDir.startsWith('https'))){
                return resolveViaHttp(baseDir + input)
            } else if(baseDir) {
                return new FileInputStream(baseDir+input)
            }
            else {
                def file = new File(input)
                return new FileInputStream(file.getAbsolutePath())
            }
        }
    }

    private request(url) {
        HttpClient client = new HttpClient();
        if ( username ) {
            Credentials defaultcreds = new UsernamePasswordCredentials(username, password)
            client.state.setCredentials(AuthScope.ANY, defaultcreds)
        }
        if ( proxyHost )
            client.getHostConfiguration().setProxy(proxyHost, proxyPort)

        HttpMethod method = new GetMethod(url)
        method.params.setParameter(HttpMethodParams.USER_AGENT,"SOA Model (see http://membrane-soa.org)")
        int status = client.executeMethod(method);
        if(status != 200) {
            def rde = new ResourceDownloadException("could not get resource $url by HTTP")
            rde.status = status
            rde.url = url
            method.releaseConnection()
            throw rde
        }
        method
    }

    protected resolveViaHttp(url) {
        new StringReader(resolveAsString(url))
    }

    protected resolveAsString(url) {
        def con = request(url)
        def res = con.getResponseBodyAsString()
        con.releaseConnection()
        res
    }
}

@ali-mahdavi
Copy link

  • commons-httpclie

thanks dear arash,
it's work for me

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

7 participants