Forum Discussion

Dobly's avatar
Dobly
New Contributor
10 years ago

Set authentication at REST service level

I have a project with a REST service added. Any and every call to this service needs authentication.

So far I have added around 8 resources to this service. A few GETS, a POST and a DELETE. In each case I had to click the Auth tab and add in the authentication info. Copy paste / copy paste. Tedious. There are around 60 calls in this web service.

How do I set the authentication info at the REST service level so that every resource within has the authentication info automatically.

This seems like a basic thing. I mean, does anyone have a web service where only some of the calls have authentication requirements? So I just must be missing something. Where do I set this in SoapUI?

3 Replies

  • PaulDonny's avatar
    PaulDonny
    Regular Contributor
    def password = "password1"
    def username = "username1"

    for (testSuite in testRunner.testCase.testSuite.project.getTestSuiteList()) {
    for (testCase in testSuite.getTestCaseList()) {
    for (testStep in testCase.getTestStepList()) {
    testStep.setPropertyValue("Password",password)
    testStep.setPropertyValue("Username",username)
    log.info testStep.name +" password has been set to "+testStep.getPropertyValue("Password")
    log.info testStep.name +" username has been set to "+ testStep.getPropertyValue("Username")
    }
    }
    }



    This will set the username and password for all requests within a project. Is there a better way? Probably. But this will at least get you going plus give you some simple for loops in groovy to use in the future.
  • Dobly's avatar
    Dobly
    New Contributor
    Thanks Paul.

    I'm quite new at SoapUI. Where do I put that script?
  • PaulDonny's avatar
    PaulDonny
    Regular Contributor
    That is a groovy script so you would just build a groovy script step and it will process through all of the requests for it.