Grails 3.0.x Interceptor matchAll () excludes for multiple controllers

Following the Grails 3.0.11 Interceptors document , I code my own interceptors as shown below:

class AuthInterceptor {
    int order = HIGHEST_PRECEDENCE;
    AuthInterceptor() {
        println("AuthInterceptor.AuthInterceptor(): Enter..............");
        // ApiController.index() and HomeController.index() don't need authentication.
        // Other controllers need to check authentication

        matchAll().excludes {
            match(controller:'api', action:'index);
            match(controller:'home', action:'index');
        }
    }
    boolean before() {
        println "AuthInterceptor.before():Enter----------------->>>>>>";
        log.debug("AuthInterceptor.before(): params:${params}");
        log.debug("AuthInterceptor.before(): session.id:${session.id}");
        log.debug("AuthInterceptor.before(): session.user:${session.user?.englishDisplayName}");
        if (!session.user) {
            log.debug("AuthInterceptor.before(): display warning msg");
            render "Hi, I am gonna check authentication"
            return false;
        } else {
            return true;
        }
    }

    boolean after() {
        log.debug("AuthInterceptor.after(): Enter ...........");
        true
    }

    void afterView() {
        // no-op
    }
}

class P2mController {
    def index() {
        log.debug("p2m():Enter p2m()..............")
        render "Hi, I am P2M";
    }
}

When I test http: // localhost: 8080 / p2m / index , from the log console I saw that P2mController.index () is running without authentication.

However, when I test http: // localhost: 8080 / api / index or http: // localhost: 8080 / home / index , AuthInterceptor.check () is executed and the browser displays

Hi, I am gonna check authentication

I want P2mController to verify authentication, and HomeController.index () and ApiController.index () do not need authentication. But from the magazine and the answer, the result is the opposite.

Where is the error in my AuthInterceptor?

+4
1

:

matchAll().excludes(controller:'api', action:'index')
          .excludes(controller:'home', action:'index')

"".

+1

Source: https://habr.com/ru/post/1623895/


All Articles