我解決了它的工作。但是這有問題。
我寫了一個吊帶過濾器並將其映射到我想限制訪問的文件夾,所以如果有人呼籲該文件夾或子文件夾/文件的請求通過我的過濾器。
在我的過濾器中,我檢查用戶是否已登錄。 但是,現在出現的問題是,任何想訪問此文件夾的人都必須登錄到我的應用程序中,使用該應用程序設置會話。而Admin(CQ主作者無法訪問文件夾本身。)
管理員已停止我束(具有上面提到的過濾器),然後訪問DAM文件夾作爲束中過濾器防止了CQ管理員訪問DAM。任何快速解決方案
代碼:
package com.xxx.hiresite.filters;
import java.io.IOException;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import org.apache.felix.scr.annotations.Properties;
import org.apache.felix.scr.annotations.Property;
import org.apache.felix.scr.annotations.Reference;
import org.apache.felix.scr.annotations.sling.SlingFilter;
import org.apache.jackrabbit.api.security.user.Authorizable;
import org.apache.sling.api.resource.ResourceResolver;
import org.apache.sling.api.resource.ResourceResolverFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@SlingFilter(order = -1000)
@Properties({
@Property(name="service.pid", value="com.xxx.hiresite.filters.DAMAccessFilter",propertyPrivate=false),
@Property(name="service.description",value="DAM Documents Authentication Filter", propertyPrivate=false),
@Property(name="service.vendor",value="Zensar Tech", propertyPrivate=false),
@Property(name="pattern",value="/content/dam/xxxdocuments/.*", propertyPrivate=false)
})
public class DAMAccessFilter implements Filter{
private final Logger log = LoggerFactory.getLogger(this.getClass());
@Reference
protected ResourceResolverFactory resolverFactory;
public void destroy() {
}
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
// Authentication Filter for the whole application
log.info("DAMAccessFilter Invoked***************************");
HttpServletRequest httpServletRequest = (HttpServletRequest)request;
String path =httpServletRequest.getRequestURI();
log.info("Request URI ::"+path);
HttpSession session = httpServletRequest.getSession(false);
if(session ==null || session.getAttribute("userId")==null)
{
log.info("DAMAccessFilter :: Not Logged in");
HttpServletResponse httpResponse = (HttpServletResponse)response;
httpResponse.sendError(HttpServletResponse.SC_FORBIDDEN);
}
else
{
log.info("DAMAccessFilter :: Logged in");
chain.doFilter(request, response);
log.info("DAMAccessFilter Done");
}
}
public void init(FilterConfig config) throws ServletException {
}
}
最終用戶不是組的最終用戶嗎? –
不是。他們是普通用戶, Facebook或任何社交網站任何輸入? – Oliver
你有什麼樣的用戶差異?servlet過濾器可能是提供插件授權機制的一個很好的選擇,特別是如果它只是一個邊緣案例 –