AEM Dispatcher Settings with CUG Permission Check

Permission-sensitive caching enables you to cache secured pages. Dispatcher checks users' access permissions for a page before delivering the cached page.

Dispatcher includes the AuthChecker module that implements permission-sensitive caching. When the module is activated, the render calls an AEM servlet to perform user authentication and authorization for the requested content. The servlet response determines whether the content is delivered to the web browser.

Because the methods of authentication and authorization are specific to the AEM deployment, you are required to create the servlet.

The servlet recieves only HEAD requests from the render, so you only need to implement the doHead method.

The render includes the URI of the requested resource as a parameter of the HTTP request. For example, an authorization servlet is accessed via /bin/permissioncheck. To perform a security check on the /content/geometrixx-outdoors/en.html page, the render includes the following URL in the HTTP request:

/bin/permissioncheck?uri=/content/geometrixx-outdoors/en.html

The servlet response message must contain the following HTTP status codes:

  • 200: Authentication and authorization passed.

package com.adobe.example;

 

import org.apache.felix.scr.annotations.Component;

import org.apache.felix.scr.annotations.Service;

import org.apache.felix.scr.annotations.Property;

 

import org.apache.sling.api.SlingHttpServletRequest;

import org.apache.sling.api.SlingHttpServletResponse;

import org.apache.sling.api.servlets.SlingSafeMethodsServlet;

 

import org.slf4j.Logger;

import org.slf4j.LoggerFactory;

 

import javax.jcr.Session;

 

@Component(metatype=false)

@Service

public class AuthcheckerServlet extends SlingSafeMethodsServlet {

     

    @Property(value="/bin/permissioncheck")

    static final String SERVLET_PATH="sling.servlet.paths";

     

    private Logger logger = LoggerFactory.getLogger(this.getClass());

     

    public void doHead(SlingHttpServletRequest request, SlingHttpServletResponse response) {

        try{

            //retrieve the requested URL

            String uri = request.getParameter("uri");

            //obtain the session from the request

            Session session = request.getResourceResolver().adaptTo(javax.jcr.Session.class);       

            //perform the permissions check

            try {

                session.checkPermission(uri, Session.ACTION_READ);

                logger.info("authchecker says OK");

                response.setStatus(SlingHttpServletResponse.SC_OK);

            } catch(Exception e) {

                logger.info("authchecker says READ access DENIED!");

                response.setStatus(SlingHttpServletResponse.SC_FORBIDDEN);

            }

        }catch(Exception e){

            logger.error("authchecker servlet exception: " + e.getMessage());

        }

    }

}

 

Configure Dispatcher for permission-sensitive caching

 

The auth_checker section of the dispatcher.any file controls the behavior of permission-sensitive caching. The auth_checker section includes the following subsections:

  • url: The value of the sling.servlet.paths property of the servlet that performs the security check.
  • filter: Filters that specify the folders to which permission-sensitive caching is applied. Typically, a deny filter is applied to all folders, and allow filters are applied to secured folders.  
  • headers: Specifies the HTTP headers that the authorization servlet includes in the response.

When Dispatcher starts, the Dispatcher log file includes the following debug-level message:

AuthChecker: initialized with URL 'configured_url'.

The following example auth_checker section configures Dispatcher to use the servlet of the prevoius topic. The filter section causes permission checks to be performed only on secure HTML resources.

 

Example configuration

/auth_checker

  {

  # request is sent to this URL with '?uri=<page>' appended

  /url "/bin/permissioncheck"

       

  # only the requested pages matching the filter section below are checked,

  # all other pages get delivered unchecked

  /filter

    {

    /0000

      {

      /glob "*"

      /type "deny"

      }

    /0001

      {

      /glob "/content/secure/*.html"

      /type "allow"

      }

    }

  # any header line returned from the auth_checker's HEAD request matching

  # the section below will be returned as well

  /headers

    {

    /0000

      {

      /glob "*"

      /type "deny"

      }

    /0001

      {

      /glob "Set-Cookie:*"

      /type "allow"

      }

    }

  }

转载于:https://my.oschina.net/slightScenery/blog/1919799

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值