You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
45 lines
1.3 KiB
45 lines
1.3 KiB
package com.tptj.course.hg.auth.template; |
|
|
|
import javax.servlet.http.HttpServletRequest; |
|
import java.util.HashMap; |
|
import java.util.Map; |
|
import java.util.Set; |
|
|
|
/** |
|
* @author 秃破天际 |
|
* @version 10.0 |
|
* Created by 秃破天际 on 2021/6/23 |
|
* HyperlinkTokenSaveHelper |
|
* ReportletHyperlink |
|
**/ |
|
public abstract class TemplateAuth { |
|
|
|
/** |
|
* |
|
* @param request 当前的请求 |
|
* @param templateId 当前要访问的模板路径 |
|
* @param username 当前已登录的用户名(如果没有登录就是空) |
|
* @return 是否授权访问 |
|
*/ |
|
public abstract boolean auth(HttpServletRequest request,String templateId, String username ); |
|
|
|
private String getType() { |
|
return this.getClass().getName(); |
|
} |
|
|
|
private static Map<String,TemplateAuth> map = new HashMap<String,TemplateAuth>(); |
|
|
|
public static void register( TemplateAuth auth ){ |
|
map.put(auth.getType(), auth); |
|
} |
|
|
|
public static boolean check(HttpServletRequest request,String templateId, String username){ |
|
Set<Map.Entry<String, TemplateAuth>> entries = map.entrySet(); |
|
for( Map.Entry<String, TemplateAuth> entry : entries ){ |
|
if(entry.getValue().auth(request,templateId,username)){ |
|
return true; |
|
} |
|
} |
|
return false; |
|
} |
|
}
|
|
|