phpajaxgrailsspring-securitygrails-2.0.4

how to bypass spring security login check in grails


I have controller method, Which returns json data and does not have security check logic.

def getJsonData(){
 // return json

}

I am doing ajax request from a php page from another server(cross domain).

      $.ajax({
             type: "GET",
             url: "http://localhost:8080/training/getJsonData",
             data: { ListID: '1'},
              dataType: "jsonp",
              success: function(data) {
               alert('Hi'+data);
                $("#success").html(data);

            }
         });

Data is not coming from the server, It only works when the user is logged in to the app server. How to serve these requests without checking for login in grails.


Solution

  • Add IS_AUTHENTICATED_ANONYMOUSLY above your grails action, like

    @Secured('IS_AUTHENTICATED_ANONYMOUSLY')
    def getJsonData() {
        ....
    }
    

    EDIT...................................................................................

    OK then may be you are using url mapping in config file(Simple Map in Config.groovy). Change there like

    grails.plugins.springsecurity.interceptUrlMap = [
        ...
        '/training/getJsonData/**': ['IS_AUTHENTICATED_ANONYMOUSLY'],
        ...
    ]