国产片侵犯亲女视频播放_亚洲精品二区_在线免费国产视频_欧美精品一区二区三区在线_少妇久久久_在线观看av不卡

服務器之家:專注于服務器技術及軟件下載分享
分類導航

PHP教程|ASP.NET教程|JAVA教程|ASP教程|編程技術|正則表達式|

服務器之家 - 編程語言 - JAVA教程 - springboot 自定義權限標簽(tld),在freemarker引用操作

springboot 自定義權限標簽(tld),在freemarker引用操作

2020-09-19 00:30Kirk_ JAVA教程

這篇文章主要介紹了springboot 自定義權限標簽(tld),在freemarker引用操作,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧

第一步:引入jar包

?
1
2
3
4
5
<dependency>
  <groupId>javax.servlet.jsp</groupId>
  <artifactId>jsp-api</artifactId>
  <version>2.2.1-b03</version>
</dependency>

第二步:自定義標簽類

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import java.util.Map;
import java.util.Set;
import javax.servlet.http.HttpServletRequest;
 
import org.jasig.cas.client.authentication.AttributePrincipal;
import org.springframework.web.servlet.tags.RequestContextAwareTag;
 
import com.goodidea.sso.dto.PrivilegesDto;
import com.goodidea.sso.dto.ResourcesDto;
import com.goodidea.sso.service.PrivilegesService;
 
/**
 *
* @ClassName: PrivilegeTag
* @Description: 權限標簽類
* @author lsg
* @date 2017年9月12日 下午5:36:01
*
 */
public class PrivilegeTag extends RequestContextAwareTag{
 
 
  private static final long serialVersionUID = 534416848523276042L;
 
  private String menuAlias;
 
  private String priAlias;
 
  public String getMenuAlias() {
    return menuAlias;
  }
 
  public void setMenuAlias(String menuAlias) {
    this.menuAlias = menuAlias;
  }
 
 
  public String getPriAlias() {
    return priAlias;
  }
 
  public void setPriAlias(String priAlias) {
    this.priAlias = priAlias;
  }
 
  @Override
  protected int doStartTagInternal() {
    // TODO Auto-generated method stub
    boolean result = false;
     try {
      HttpServletRequest request = (HttpServletRequest) pageContext.getRequest();
       AttributePrincipal principal = (AttributePrincipal)request.getUserPrincipal();
       Map<String, Object> attributes = principal.getAttributes();
      String username=(String) attributes.get("username");
      PrivilegesService privilegesService= (PrivilegesService)this.getRequestContext().getWebApplicationContext().getBean("privilegesServiceImpl");
      Set<ResourcesDto> dto = privilegesService.findResourcesByUsername(username);
      for (ResourcesDto resourcesDto : dto) {
        if(this.menuAlias.equals(resourcesDto.getAlias())){
          for (PrivilegesDto pdto : resourcesDto.getPrivileges()) {
            if(this.priAlias.equals(pdto.getAlias())){
               result = true;
            }
          }
        }
      }
     } catch (Exception e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
      result =false;
    }
    return result? EVAL_BODY_INCLUDE : SKIP_BODY;
  }
}


第三步:創建tld標簽,放入在web-inf下

springboot 自定義權限標簽(tld),在freemarker引用操作

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE taglib PUBLIC "-//Sun Microsystems, Inc.//DTD JSP Tag Library 1.1//EN" "http://java.sun.com/j2ee/dtds/web-jsptaglibrary_1_1.dtd">
<taglib>
  <tlibversion>1.0</tlibversion>
  <jspversion>1.1</jspversion>
  <shortname>privilege</shortname>
  <tag>
    <name>privilege</name>
    <tagclass>com.goodidea.sso.core.PrivilegeTag</tagclass>
    <bodycontent>empty</bodycontent> <!--這里如果設為empty,則無body-->
    <attribute>
      <name>menuAlias</name>
      <required>true</required>
      <rtexprvalue>true</rtexprvalue>
    </attribute>
    <attribute>
      <name>priAlias</name>
      <required>true</required>
      <rtexprvalue>true</rtexprvalue>
    </attribute>
  </tag>
</taglib>


第四:頁面引用

<#assign p=JspTaglibs["/WEB-INF/tld/privilege.tld"] />

注意tld,如果不在web.xml上進行引入的話,就放在web-inf下,要不然會報找不到tld資源異常

補充知識:Springboot項目 freemarker 引入shiro 標簽

springboot集成shiro權限過程略過

一、添加maven 依賴

?
1
2
3
4
5
<dependency>
 <groupId>net.mingsoft</groupId>
 <artifactId>shiro-freemarker-tags</artifactId>
 <version>0.1</version>
</dependency>

二、注入FreeMarkerConfigurer,未指定templateLoaderPath時遇到過跳轉到頁面404問題

?
1
2
3
4
5
6
7
8
9
10
11
@Bean
public FreeMarkerConfigurer freeMarkerConfigurer() throws IOException, TemplateException {
  FreeMarkerConfigurer freeMarkerConfigurer = new FreeMarkerConfigurer();
  freeMarkerConfigurer.setTemplateLoaderPath("classpath:templates/");
  freemarker.template.Configuration configuration = freeMarkerConfigurer.createConfiguration();
  configuration.setDefaultEncoding("UTF-8");
  //這里可以添加其他共享變量 比如sso登錄地址
  configuration.setSharedVariable("shiro", new ShiroTags());
  freeMarkerConfigurer.setConfiguration(configuration);
  return freeMarkerConfigurer;
}

三、shiro標簽

1、session中讀取登錄人信息

<@shiro.principal/>

2、帶有loginName屬性的對象轉換為Prinipal后保存在session

<shiro:principal property="loginName" />

3、帶有loginName屬性的Json(個人使用的是FashJson對象)轉換為Prinipal后保存在session,使用freemarker標簽處理Json

<#assign loginInfo><@shiro.principal/></#assign>

<#assign data=loginInfo?eval>

用戶:${data.loginName!""}

4、其他shiro標簽使用

<@shiro.hasPermission name="權限編碼">
...
</@shiro.hasPermission>

以上這篇springboot 自定義權限標簽(tld),在freemarker引用操作就是小編分享給大家的全部內容了,希望能給大家一個參考,也希望大家多多支持服務器之家。

原文鏈接:https://blog.csdn.net/cutterwolf/article/details/78085808

延伸 · 閱讀

精彩推薦
主站蜘蛛池模板: 黄视频在线免费看 | 久久aⅴ乱码一区二区三区 一区二区精品视频 | 北条麻妃99精品青青久久主播 | 黄色一级毛片在线观看 | 91欧美激情一区二区三区成人 | 操网| 欧美精品国产精品 | 成人在线精品视频 | 亚洲男女视频在线观看 | 免费看国产视频 | 欧美在线小视频 | 午夜影院a| 日本综合色 | 91免费视频网站 | 国产精品久久av | 视频一区二区在线观看 | 国产免费一区二区三区 | 天堂精品一区二区三区 | 日韩一区二区三区在线观看 | 色欧美日韩 | 情一色一乱一欲一区二区 | 精品第一页 | 999这里只有是极品 最新中文字幕在线 | 成人网在线观看 | 性高湖久久久久久久久aaaaa | 中文字幕一区二区在线观看 | 国产午夜一区二区三区 | 久久综合av | 视频三区 | 欧美精品成人一区二区三区四区 | 国产欧美日韩 | 一区视频 | 中文字幕在线免费视频 | 日韩国产精品一区二区三区 | 亚洲国产一区二区a毛片 | 欧美激情精品久久久久久变态 | 亚洲三级在线免费观看 | 欧美日韩免费看 | 日韩欧美一区二区三区在线观看 | a网站在线观看 | 99在线精品视频 |