Topic
3 replies Latest Post - ‏2012-11-07T15:07:58Z by SystemAdmin
SystemAdmin
SystemAdmin
300 Posts
ACCEPTED ANSWER

Pinned topic How to protect static resources by using adapter based authentication?

‏2012-11-05T11:04:40Z |
Hi,
I'm a beginner in Worklight... I'd like to protect static resources using adapter based authentication...

I added customSecurityTest, realm in authenticationConfig.xml and code of the adapter according the tutorial: http://public.dhe.ibm.com/ibmdl/export/pub/software/mobile-solutions/worklight/docs/Module_21_-_Adapter_Based_Authentication.pdf

Then I apply the security test to the folder which I'd like to protect from unauthenticated users.
<staticResources>
<resource id="testAuth" securityTest="TestAuthAdapter-securityTest">
<urlPatterns>/foo/bar/*</urlPatterns>
</resource>
</staticResources>

The onAuthRequired method does get invoked when I try to access the protected resources without login... But it just reports an error in the console:
An error occurred while invoking procedure TestAuthAdapter/onAuthRequired parameters:{
"arr": [
{
"Accept-Charset": [
"ISO-8859-1,utf-8;q=0.7,*;q=0.3"
],
"Accept-Encoding": [
"gzip,deflate,sdch"
],
"Accept-Language": [
"q=0.8,en-US;q=0.6,en;q=0.4"
],
"Connection": [
"keep-alive"
],
"Cookie": [
"JSESSIONID=zx11oortq77t1ncb1wke0nfpi; testcookie=oreo"
],
"Host": [
"localhost:8080"
],
"User-Agent": [
"Mozilla\/5.0 (Windows NT 6.1; WOW64) AppleWebKit\/537.4 (KHTML, like Gecko) Chrome\/22.0.1229.94 Safari\/537.4"
]
}
]
}
null
Caused by: null

I totally have no idea on what else I can do to fix the problem...
Any help will be appreciated...
  • SystemAdmin
    SystemAdmin
    300 Posts
    ACCEPTED ANSWER

    Re: How to protect static resources by using adapter based authentication?

    ‏2012-11-05T21:33:26Z  in response to SystemAdmin
    Have you tried installing our code samples and seeing if they work?
    https://www.ibm.com/developerworks/mobile/worklight/getting-started/index.html
    You may find it helpful to install them and then to attempt to code the solution yourself, comparing the two when you encounter errors.
    Thanks,
    -Dave
    • SystemAdmin
      SystemAdmin
      300 Posts
      ACCEPTED ANSWER

      Re: How to protect static resources by using adapter based authentication?

      ‏2012-11-06T01:41:50Z  in response to SystemAdmin
      Thanks Dave. I have tried the samples you provided... But there seems no sample showing how to config the <staticResources>
      </staticResources> section in authenticationConfig.xml to protect resources... It is only used to protect the console in the sampmles... Any materials/samples on details of <staticResources> would be helpful...
      • SystemAdmin
        SystemAdmin
        300 Posts
        ACCEPTED ANSWER

        Re: How to protect static resources by using adapter based authentication?

        ‏2012-11-07T15:07:58Z  in response to SystemAdmin
        Hi,
        Thanks for the response. You would not want to put any static resources into the same war as the worklight app. Rather, you should package them into another WAR and use adapters to allow the application to access them. In that way you can control the access to the war containing the static resources. Alternately you could package it as part of the hybrid application and deploy it as part of the client side application.
        Thanks!
        -Dave