jfinal-shiro-freemarker实现shiro在freemarker页面的标签过滤

提供一个shiro+freemarker的标签使用,结合jfinal-shiro插件使用博客地址,基于jfinal实现:

https://github.com/Dreampie/jfinal-shiro-freemarker   jfinal-shiro的freemarker标签:

<dependency>      
    <groupId>cn.dreampie</groupId>      
    <artifactId>jfinal-shiro-freemarker</artifactId>      
    <version>${jfinal-shiro-freemarker.version}</version> 
</dependency>

 目前刚刚发布第一个版本0.1:

<jfinal-shiro-freemarker.version>0.1</jfinal-shiro-freemarker.version>

使用起来非常简单:

  1. jfinal config配置

     @Override
        public void afterJFinalStart() {
            super.afterJFinalStart();
            FreeMarkerRender.getConfiguration().setSharedVariable("shiro", new ShiroTags());
        }
  2. 显示登录错误信息

    <@shiro.isLoginFailure name="shiroLoginFailure">
            <div class="alert alert-danger" style="background-image: none;">
                <@shiro.loginException name="shiroLoginFailure"/>
            </div>
        </@shiro.isLoginFailure>
  3.     判断是否有某个角色

    <@shiro.hasRole name="R_ADMIN">
                    //html
     </@shiro.hasRole>
  4. 其他标签使用类似

    //包含任意角色
    <@shiro.hasAnyRoles name="R_USER">
                    //html
     </@shiro.hasAnyRoles>
    //具有权限
     <@shiro.hasPermission name="AUTH_PF">
                    //html
     </@shiro.hasPermission>
    //已经认证
    <@shiro.authenticated>
                    //html
     </@shiro.authenticated>
    //未认证
    <@shiro.notAuthenticated>
                    //html
     </@shiro.notAuthenticated>
    
    //不包含某个角色
    <@shiro.lacksRole name="R_ADMIN">
                    //html
     </@shiro.lacksRole>
    
    //不包含某个权限
    <@shiro.lacksPermission name="AUTH_PF">
                    //html
     </@shiro.lacksPermission>
    
    //是否是已经登录的用户
    <@shiro.user>
                    //html
     </@shiro.user>
    
    //是否是访客
    <@shiro.guest>
                    //html
     </@shiro.guest>
    
    //获取用户名信息
    <@shiro.principal name="用户名属性如,username">
                    //html
     </@shiro.principal>


https://github.com/Dreampie?tab=repositories 目录下有多款插件:

cn.dreampie.jfinal-shiro     https://github.com/Dreampie/jfinal-shiro    shiro插件

cn.dreampie.jfinal-shiro-freemarker   https://github.com/Dreampie/jfinal-shiro-freemarker    shiro插件实现的freemarker标签库

cn.dreampie.jfinal-web     https://github.com/Dreampie/jfinal-web   相关web插件,简洁model实现

cn.dreampie.jfinal-utils        https://github.com/Dreampie/jfinal-utils   部分jfinal工具

cn.dreampie.jfinal-tablebind        https://github.com/Dreampie/jfinal-tablebind   jfinal的table自动绑定插件,支持多数据源

cn.dreampie.jfinal-flyway      https://github.com/Dreampie/jfinal-flyway   数据库脚本升级插件,开发中升级应用时,使用脚本同步升级数据库或者回滚

cn.dreampie.jfinal-captcha      https://github.com/Dreampie/jfinal-captcha   基于jfinal render的超简单验证吗插件

cn.dreampie.jfinal-quartz       https://github.com/Dreampie/jfinal-quartz   基于jfinal 的quartz管理器

cn.dreampie.jfinal-sqlinxml      https://github.com/Dreampie/jfinal-sqlinxml   基于jfinal 的类似ibatis的sql语句管理方案

cn.dreampie.jfinal-lesscss       https://github.com/Dreampie/jfinal-lesscss   java实现的lesscsss实时编译插件,可以由于jfinal

cn.dreampie.jfinal-coffeescript     https://github.com/Dreampie/jfinal-coffeescript   java实现的coffeescript实时编译插件,可以由于jfinal 

cn.dreampie.jfinal-akka    https://github.com/Dreampie/jfinal-akka   java使用akka执行异步任务

cn.dreampie.jfinal-mailer       https://github.com/Dreampie/jfinal-mailer   使用akka发布邮件的jfinal插件

cn.dreampie.jfinal-slf4j     https://github.com/Dreampie/jfinal-slf4j   让jfinal使用slf4j的日志api

部分内容借鉴了网络资料


你可能感兴趣的:(java,freemarker,shiro,jFinal)