I have no database in my laravel application. I am using Soap service for data fetching in this application. I have followed instructions from the solution of this link from stackoverflow to replace the existing laravel's authentication with custom authentication. But when i reached method retrieveByCredentials(), I couldn't return the stdlib class object for user detail. Instead it returned following error.
(1/1) FatalThrowableError Type error: Argument 1 passed to
App\Auth\SoapUserProvider::validateCredentials() must be an instance
of Illuminate\Contracts\Auth\Authenticatable, instance of stdClass
given, called in
C:\xampp\7.1.7\htdocs\gazebo_revamp\vendor\laravel\framework\src\Illuminate\Auth\SessionGuard.php
on line 380
Please shed some light on this.
If you are using a custom User auth provider then in the retrieveByCredentials() method instantiate a new User class and return it. Like so:
if ($api_auth === true )
return new \App\User(['id' => 0]);
Related
I have a multi tenant API and I am trying to RESTIFY it using wso2. I am trying a way to pass the tenant value in the url.
localhost:8290//tenant/api/...
https://tenant.xyz.com/api/...
I tried İntegration studio and i managed to pass a literal tenant value in http endpoint by creating a property named {uri.var.tenant} and setting it to tenant name. However, I don't know how can I take the tenant name from here
localhost:8290//tenant/api
and pass it here.
https://tenant.xyz.com/api/
I also tried using the APIM publisher page with no success.
As I see, there are 2 parts for your question.
How to parameterize the backend URL.
How to read the path parameter from the fronting API that is being called.
For the first one, the method you have followed is correct and an example can be found at https://apim.docs.wso2.com/en/latest/integrate/examples/endpoint_examples/using-http-endpoints/#example-1-populating-an-http-endpoint-during-mediation . What's remaining is to read the path parameter and to populating {uri.var.tenant} which is the second point.
For the second point, you can create and API definition with the URL templated. See the property URI Template at https://apim.docs.wso2.com/en/latest/reference/synapse-properties/rest-api-properties/ you can find an example of the usage at https://apim.docs.wso2.com/en/latest/integrate/examples/rest_api_examples/setting-query-params-outgoing-messages/#reading-a-query-or-path-parameter
I'm trying to follow this documentation - https://developers.google.com/api-client-library/python/guide/aaa_oauth
I use this function to create the auth url step1_get_authorize_url() which works fine. I've written the callback handler successfully and created the credentials object.
How I do I redirect to a continue url to get back to the original page now the credentials have been created.
I don't see how to pass this parameter in step1_get_authorize_url() which would seem to make sense.
Step 1 /url-1 creates login link, /oauth2callbackhandler receives the code and creates the credential object; how do I redirect back to /url-1?
I found it was possible through the state parameter of the Flow object.
state = ''.join(random.choice(string.ascii_uppercase + string.digits)
for x in xrange(32))
flow.params['state'] = 'security_token%3D' + state + '%26url%3D' + urllib.quote_plus(self.request.url)
I store the security token in the session to verify it.
https://developers.google.com/accounts/docs/OAuth2WebServer
step1_get_authorize_url() is a method of a flow object and that flow object holds the redirect URL and gets it passed at creation.
flow = client.flow_from_clientsecrets(
secrets_file,
scope='https://www.googleapis.com/auth/analytics.readonly',
redirect_uri='urn:ietf:wg:oauth:2.0:oob')
auth_uri = flow.step1_get_authorize_url()
A fully working example and explanations you will find here. The tutorial features a console app but the process is analoguous to what you need to do in case of a web application.
How to assign to workers a proxy that requires user name - password and a custom user agent using Selenium, PhantomJS driver with Python bindings.
I've had good success with creating many workers traversing my test website. I can also assign a user agent or a proxy that does not require authorization. But I haven’t figured out how to do both to the same worker at the same time yet.
However the real issue at the moment is assigning a proxy to the workers that require authorization by a user name and password.
The Players:
Selenium 2.33.0 / PhantomJS 1.9.1 / Python 2.7.3 / Ubuntu 12.04
Me:
Nube. Python weeks, Linux days, Selenium hours, PhantomJS -= , SO first post
Searches Yielded:
How do I set a proxy for phantomjs/ghostdriver in python webdriver?
The answers may in fact be there and many other places I have read and re-read, but I can’t connect the dots at my present level.
User Agent solved with this method.
dcap = dict(DesiredCapabilities.PHANTOMJS)
dcap["phantomjs.page.settings.userAgent"] = (
"Any User Agent string here”)
driver = webdriver.PhantomJS(desired_capabilities=dcap)
Proxy without authorization works with this:
service_args = [
'--proxy=127.0.0.1:9999',
'--proxy-type=http,
]
driver = webdriver.PhantomJS('/usr/local/bin/phantomjs,service_args=service_args)
If both above methods are used I’m unsure how to pass both proxy and UA to the PhantomJS driver. ATM I’m only able to do one or the other and not at all with a proxy that requires authorization.
Goal for this SO thread:
Learn how to assign a proxy that requires user name / password
Assign a custom user agent to the same worker.
Using Selenium, PhantomJS driver with Python bindings.
The end game goal is to assign each worker a unique ip and pull from a pool of user agents. Creating the logic for this I remain optimistic but the proxy with authorization is kicking me at the moment.
As you can tell I’m very new to all of this and would appreciate any help and examples to this particular problem.
Thanks!
EDIT: Below accepted answer is incorrect. Unable to reproduce below solution. Only the proxy with authorization is assigned to the driver. Still unable to assign both proxy and a user agent to the same driver.
Any help or direction would be greatly appreciated.
EDIT.02: Issue resolved. It was never a coding issue. A new proxy provider at the server level assigned a default UA that overrode the above script. Once this was removed all was good.
Assign User Agent by Desired Capabilities
dcap = dict(DesiredCapabilities.PHANTOMJS)
dcap["phantomjs.page.settings.userAgent"] = (
"Your User Agent String here . . .")
Found API Reference here for the proxy authorization.
Add "--proxy-auth=username:password" to server_args. Like . . .
service_args = [
'--proxy=xxx.xxx.xx.xxx:xxxx',
'--proxy-auth=username:password',
'--proxy-type=http',
]
Then use both when starting the webdriver
driver = webdriver.PhantomJS(desired_capabilities=dcap,service_args=service_args)
This took care of all my issues.
EDIT: Unable to reproduce solution. Only proxy is changed with above method.
EDIT.02: Issue resolved. It was never a coding issue. A new proxy provider at the server level assigned a default UA that overrode the above script. Once this was removed all was good.
I've read a lot about switching between multiple datasource on runtime, but as far as I understand they're already defined datasources. I'm not quite sure on how can I just asign the datasources properties on runtime from a webservice call.
I don't need to switch between datasources, just need to create only one datasource with conection data coming from a webservice.
Is there a way to retrieve these parameters from the webservice and create the datasource from that?
The policy here is to retrieve the datasource parameters from a webservice for all the projects, that way the connection data is not inside a file nor into the code, and is only manipulated by DBAs from a global security aplication.
I tried to call the web service in the same datasource file, but it didn't work.
Info:
Web service is a Soap Web service
Grails: 1.3.9
Regards.
I think that you can create a BeanPostProcessor that take care of calling your webservice and changing the settings of your dataSource.
Probably you will need to delay the session factory creation, making sure Grails won't try to use your dataSource before you have all setted up correctly.
The BeanPostProcessor will looks like:
class WebserviceDataSourceBeanPostProcessor implements BeanPostProcessor {
Object postProcessBeforeInitialization(Object bean, String beanName) {
return bean
}
Object postProcessAfterInitialization(Object bean, String beanName) {
if (bean instanceof DataSource){
def info = //call webservice here...
bean.username = info.username
bean.password = info.password
bean.url = info.url
//checkout more setters in: http://commons.apache.org/proper/commons-dbcp/apidocs/org/apache/commons/dbcp/BasicDataSource.html
}
return bean
}
}
And make sure you declared this Spring Bean in resources.groovy
beans = {
webserviceDataSourceBeanPostProcessor(WebserviceDataSourceBeanPostProcessor)
}
If you will have more than one project with this same config comming from a webservice you may think in the possibility of a plugin for this, reusing your code.
So I'm having a couple of ANT scripts using Groovy to process complex calculations normal ANT can't do (at least afaik). I'm trying to access an Axis2 web service using a SOAP-envelope via Groovy. The request and response is pretty simple, except for two complexType attributes (one in the request, one in the response).
The first thing I've stumbled across was Groovy Soap. It is quite easy to use, you simply instantiate a SoapClient and call the web service method. Unfortunately it cannot handle complexType attributes in the request, which I need:
Current Limitations:
....
4: Custom data types cannot be processed on client side when using the Groovy SOAP module with the current groovy-1.0 release.
Then I've read a lot about GroovyWS. I created my Grape config file in my user.home, javac and $GROOVY_HOME are available (basically did everything as described on the project quick guide page). Grape somehow retrieved Ivy, when I first started the script (I have no experience with Grape, but I suspect it's very similar to Maven).
Then started my simple script:
#Grab(group='org.codehaus.groovy.modules', module='groovyws',version='0.5.2')
import groovyx.net.ws.WSClient
proxy = new WSClient("http://127.0.0.1/axis2/services/ReleaseService?wsdl", this.class.classLoader)
proxy.initialize()
Unfortunately I couldn't even initialize the web client (without the Groovy Soap library in the classpath):
SEVERE: Could not compile java files for http://127.0.0.1/axis2/services/ReleaseService?wsdl.
Caught: java.lang.IllegalStateException: Unable to create JAXBContext for generated packages: Provider com.sun.xml.bind.v2.ContextFactory could not be instantiated: javax.xml.bind.JAXBException: "com.intershop.qa.tae.ws.xsd" doesnt contain ObjectFactory.class or jaxb.index java.lang.IllegalStateException: Unable to create JAXBContext for generated packages: Provider com.sun.xml.bind.v2.ContextFactory could not be instantiated [...]
With the Groovy Soap library (which seems to overload some of GroovyWS' functionality) in the classpath I've got:
Caught: java.lang.NoSuchMethodError: javax.wsdl.xml.WSDLReader.readWSDL(Ljavax/wsdl/xml/WSDLLocator;Lorg/w3c/dom/Element;)Ljavax/wsdl/Definition; java.lang.NoSuchMethodError:
which looks very similar to the error I've got when I was using Groovy Soap in the first place.
So my question is: How can I communicate with an Axis2 web service using complexType parameters via ANT. I'm not limited to Groovy only, but for deployment reasons (~50 VM snapshots) I want something simple. A Java client worked, but since the deployment is quite some effort (especially if I want to change stuff in the future) I need something which is closer to ANT and easier to deploy.
Thanks in advance for suggestions of other technologies or fix ideas for my GroovyWS implementation.
I finally came up with a solution: groovy-wslight actually solved my problem and was finally able to deploy easily and access the web service without problems/exceptions.
The script:
#Grab(group='com.github.groovy-wslite', module='groovy-wslite', version='0.7.1')
import wslite.soap.*
def client = new SOAPClient("http://127.0.0.1/axis2/services/ReleaseService")
def response = client.send {
body {
myFunction(xmlns:"http://my.namespace.com") {
stringParameter("6.3.0.0")
status() { value("default") }
mode() { value("full") }
}
}
}
Where status and mode are complexTypes which consist of one "value" attribute (as an example).
println(response.myFunctionResponse.return)
gives me the object returned by the web service. Of course the names of the tokens depend on the WSDL. In my case the response of the request is called myFunctionResponse, which has a field name="return" and gives me a complexType object. The fields of the object can be retrieved according to the names given in the WSDL:
println(response.myFunctionResponse.return.location) // gives me the field value of the field "location" for my complexType
I had a similar problem when using JDK 1.7. Switching to JDK 1.6 solved it for me.