小男孩‘自慰网亚洲一区二区,亚洲一级在线播放毛片,亚洲中文字幕av每天更新,黄aⅴ永久免费无码,91成人午夜在线精品,色网站免费在线观看,亚洲欧洲wwwww在线观看

分享

jfinal-shiro的shiro注解結(jié)合數(shù)據(jù)庫url路徑過濾,動(dòng)態(tài)維護(hù)你的權(quán)限系統(tǒng),支持ajax

 飛鷹飛龍飛天 2014-11-19

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

1
2
3
4
5
<dependency>
      <groupId>cn.dreampie</groupId>
      <artifactId>jfinal-shiro</artifactId>
      <version>${jfinal-shiro.version}</version>
 </dependency>

目前剛剛發(fā)布第一個(gè)版本0.1:

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

首先感謝jfinal-ext中原作者,該插件主要是針對(duì)ext插件的部分改進(jìn)。

下面主要介紹兩種使用方式:

    在web.xml里添加

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
    <!--權(quán)限過濾器 start-->
    <listener>
        <listener-class>org.apache.shiro.web.env.EnvironmentLoaderListener</listener-class>
    </listener>
     
    <filter>
        <filter-name>shiroFilter</filter-name>
        <filter-class>org.apache.shiro.web.servlet.ShiroFilter</filter-class>
    </filter>
    <filter-mapping>
        <filter-name>shiroFilter</filter-name>
        <url-pattern>/*</url-pattern>
        <dispatcher>REQUEST</dispatcher>
        <dispatcher>FORWARD</dispatcher>
        <dispatcher>INCLUDE</dispatcher>
        <dispatcher>ERROR</dispatcher>
    </filter-mapping>
    <!--權(quán)限過濾器 end-->

    啟用shiro   在jfinal config里configPlugin方法添加

1
2
3
  
 //shiro權(quán)限框架   在jfinal  plugins里添加shiro  plugin
        plugins.add(new ShiroPlugin(routes, new MyJdbcAuthzService()));

    添加shiro的過濾器  在jfinal config里configInterceptor方法添加

1
2
3
interceptors.add(new ShiroInterceptor());
public class User extends cn.dreampie.shiro.model.User<User> //user的model需要繼承User
  1. 在方法上使用注解

    1. Shiro共有5個(gè)注解,分別如下:

      1. RequiresAuthentication:使用該注解標(biāo)注的類,實(shí)例,方法在訪問或調(diào)用時(shí),當(dāng)前Subject必須在當(dāng)前session中已經(jīng)過認(rèn)證。

      2. RequiresGuest:使用該注解標(biāo)注的類,實(shí)例,方法在訪問或調(diào)用時(shí),當(dāng)前Subject可以是“gust”身份,不需要經(jīng)過認(rèn)證或者在原先的session中存在記錄。

      3. RequiresPermissions:當(dāng)前Subject需要擁有某些特定的權(quán)限時(shí),才能執(zhí)行被該注解標(biāo)注的方法。如果當(dāng)前Subject不具有這樣的權(quán)限,則方法不會(huì)被執(zhí)行。

      4. RequiresRoles:當(dāng)前Subject必須擁有所有指定的角色時(shí),才能訪問被該注解標(biāo)注的方法。如果當(dāng)天Subject不同時(shí)擁有所有指定角色,則方法不會(huì)執(zhí)行還會(huì)拋出AuthorizationException異常。

      5. RequiresUser:當(dāng)前Subject必須是應(yīng)用的用戶,才能訪問或調(diào)用被該注解標(biāo)注的類,實(shí)例,方法。

    2. Shiro的認(rèn)證注解處理是有內(nèi)定的處理順序的,如果有個(gè)多個(gè)注解的話,前面的通過了會(huì)繼續(xù)檢查后面的,若不通過則直接返回,處理順序依次為(與實(shí)際聲明順序無關(guān)):
      RequiresRoles
      RequiresPermissions
      RequiresAuthentication
      RequiresUser
      RequiresGuest
      例如:你同時(shí)生命了RequiresRoles和RequiresPermissions,那就要求擁有此角色的同時(shí)還得擁有相應(yīng)的權(quán)限。

    3. RequiresRoles可以用在Controller或者方法上??梢远鄠€(gè)roles,默認(rèn)邏輯為 AND也就是所有具備所有role才能訪問。

            示例:

    1
    2
    3
    4
    5
    6
    7
    8
    //屬于user角色
    @RequiresRoles("user")
      
    //必須同時(shí)屬于user和admin角色
    @RequiresRoles({"user","admin"})
      
    //屬于user或者admin之一。
    @RequiresRoles(value={"user","admin"},logical=Logical.OR)
  2. 其他使用方法類似。

  3. 1
    2
    3
    4
    @RequiresPermissions
    @RequiresAuthentication
    @RequiresUser
    @RequiresGusst
  4. 詳細(xì)可以參考瑪雅牛的shiro注解使用,http://my.oschina.net/myaniu/blog/137205

  5. 基于數(shù)據(jù)庫的權(quán)限設(shè)計(jì)與維護(hù)

    數(shù)據(jù)庫的基本權(quán)限結(jié)構(gòu)主要:用戶->角色->權(quán)限

    表結(jié)構(gòu)設(shè)計(jì)如下(h2數(shù)據(jù)庫,使用其他數(shù)據(jù)修改部分sql語句之后使用):

    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
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    DROP TABLE IF EXISTS sec_user;
    DROP SEQUENCE IF EXISTS sec_user_id_seq;
    CREATE SEQUENCE sec_user_id_seq START WITH 1;
    CREATE TABLE sec_user (  --用戶表
      id            BIGINT       NOT NULL DEFAULT NEXTVAL('sec_user_id_seq'PRIMARY KEY,
      username      VARCHAR(50)  NOT NULL COMMENT '登錄名',
      providername  VARCHAR(50)  NOT NULL COMMENT '提供者',
      email         VARCHAR(200) COMMENT '郵箱',
      mobile        VARCHAR(50) COMMENT '手機(jī)',
      password      VARCHAR(200) NOT NULL COMMENT '密碼',
      hasher   VARCHAR(200) NOT NULL COMMENT '加密類型',
      salt VARCHAR(200) NOT NULL COMMENT '加密鹽',
      avatar_url    VARCHAR(255) COMMENT '頭像',
      first_name    VARCHAR(10) COMMENT '名字',
      last_name     VARCHAR(10) COMMENT '姓氏',
      full_name     VARCHAR(20) COMMENT '全名',
      department_id BIGINT NOT NULL COMMENT '部門id',
      created_at    TIMESTAMP    NOT NULL,
      updated_at    TIMESTAMP,
      deleted_at    TIMESTAMP
    );
    DROP TABLE IF EXISTS sec_user_info;
    DROP SEQUENCE IF EXISTS sec_user_info_id_seq;
    CREATE SEQUENCE sec_user_info_id_seq START WITH 1;
    CREATE TABLE sec_user_info (-- 用戶詳細(xì)信息表
      id          BIGINT    NOT NULL DEFAULT NEXTVAL('sec_user_info_id_seq'PRIMARY KEY,
      user_id     BIGINT    NOT NULL COMMENT '用戶id',
      creator_id  BIGINT COMMENT '創(chuàng)建者id',
      gender      INT DEFAULT 0 COMMENT '性別0男,1女',
      province_id BIGINT COMMENT '省id',
      city_id     BIGINT COMMENT '市id',
      county_id   BIGINT COMMENT '縣id',
      street      VARCHAR(500) COMMENT '街道',
      zip_code    VARCHAR(50) COMMENT '郵編',
      created_at  TIMESTAMP NOT NULL,
      updated_at  TIMESTAMP,
      deleted_at  TIMESTAMP
    );
    DROP TABLE IF EXISTS sec_role;
    DROP SEQUENCE IF EXISTS sec_role_id_seq;
    CREATE SEQUENCE sec_role_id_seq START WITH 1;
    CREATE TABLE sec_role (--角色表
      id         BIGINT      NOT NULL DEFAULT NEXTVAL('sec_role_id_seq'PRIMARY KEY,
      name       VARCHAR(50) NOT NULL COMMENT '名稱',
      value      VARCHAR(50) NOT NULL COMMENT '值',
      intro      VARCHAR(255) COMMENT '簡介',
      pid        BIGINT DEFAULT 0 COMMENT '父級(jí)id',
      left_code  BIGINT DEFAULT 0 COMMENT '數(shù)據(jù)左邊碼',
      right_code BIGINT DEFAULT 0 COMMENT '數(shù)據(jù)右邊碼',
      created_at TIMESTAMP   NOT NULL,
      updated_at TIMESTAMP,
      deleted_at TIMESTAMP
    );
    DROP TABLE IF EXISTS sec_user_role;
    DROP SEQUENCE IF EXISTS sec_user_role_id_seq;
    CREATE SEQUENCE sec_user_role_id_seq START WITH 1;
    CREATE TABLE sec_user_role (--用戶角色關(guān)系表
      id      BIGINT NOT NULL DEFAULT NEXTVAL('sec_user_role_id_seq'PRIMARY KEY,
      user_id BIGINT NOT NULL,
      role_id BIGINT NOT NULL
    );
    DROP TABLE IF EXISTS sec_permission;
    DROP SEQUENCE IF EXISTS sec_permission_id_seq;
    CREATE SEQUENCE sec_permission_id_seq START WITH 1;
    CREATE TABLE sec_permission (--權(quán)限表
      id         BIGINT      NOT NULL DEFAULT NEXTVAL('sec_permission_id_seq'PRIMARY KEY,
      name       VARCHAR(50) NOT NULL COMMENT '名稱',
      value      VARCHAR(50) NOT NULL COMMENT '值',
      url        VARCHAR(255) COMMENT 'url地址',
      intro      VARCHAR(255) COMMENT '簡介',
      pid        BIGINT DEFAULT 0 COMMENT '父級(jí)id',
      left_code  BIGINT DEFAULT 0 COMMENT '數(shù)據(jù)左邊碼',
      right_code BIGINT DEFAULT 0 COMMENT '數(shù)據(jù)右邊碼',
      created_at TIMESTAMP   NOT NULL,
      updated_at TIMESTAMP,
      deleted_at TIMESTAMP
    );
    DROP TABLE IF EXISTS sec_role_permission;
    DROP SEQUENCE IF EXISTS sec_role_permission_id_seq;
    CREATE SEQUENCE sec_role_permission_id_seq START WITH 1;
    CREATE TABLE sec_role_permission (--角色權(quán)限關(guān)系表
      id            BIGINT NOT NULL DEFAULT NEXTVAL('sec_role_permission_id_seq'PRIMARY KEY,
      role_id       BIGINT NOT NULL,
      permission_id BIGINT NOT NULL
    );

            數(shù)據(jù)結(jié)構(gòu)基本完成,提示:pid,left_code,right_code是數(shù)據(jù)的樹形結(jié)構(gòu)設(shè)計(jì)和權(quán)限無關(guān)

            測試數(shù)據(jù):

    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
    --create role--
    INSERT INTO sec_role(id,name, value, intro, pid,left_code,right_code,created_at)
    VALUES (sec_role_id_seq.nextval,'超級(jí)管理員','R_ADMIN','',0,1,8, current_timestamp),
           (sec_role_id_seq.nextval,'系統(tǒng)管理員','R_MANAGER','',1,2,7,current_timestamp),
           (sec_role_id_seq.nextval,'會(huì)員','R_MEMBER','',2,3,4,current_timestamp),
           (sec_role_id_seq.nextval,'普通用戶','R_USER','',2,5,6,current_timestamp);
    --create permission--
    INSERT INTO sec_permission(id, name, value, url, intro,pid,left_code,right_code, created_at)
    VALUES (sec_permission_id_seq.nextval,'管理員目錄','P_D_ADMIN','/admin/**','',0,1,6,current_timestamp),
           (sec_permission_id_seq.nextval,'角色權(quán)限管理','P_ROLE','/admin/role/**','',1,2,3,current_timestamp),
           (sec_permission_id_seq.nextval,'用戶管理','P_USER','/admin/user/**','',1,4,5,current_timestamp),
           (sec_permission_id_seq.nextval,'會(huì)員目錄','P_D_MEMBER','/member/**','',0,9,10,current_timestamp),
           (sec_permission_id_seq.nextval,'普通用戶目錄','P_D_USER','/user/**','',0,11,12,current_timestamp);
    INSERT INTO sec_role_permission(id,role_id, permission_id)
    VALUES (sec_role_permission_id_seq.nextval,1,1),(sec_role_permission_id_seq.nextval,1,2),
           (sec_role_permission_id_seq.nextval,1,3),(sec_role_permission_id_seq.nextval,1,4),
           (sec_role_permission_id_seq.nextval,1,5),
           (sec_role_permission_id_seq.nextval,2,1),(sec_role_permission_id_seq.nextval,2,3),
           (sec_role_permission_id_seq.nextval,2,4),(sec_role_permission_id_seq.nextval,2,5),
           (sec_role_permission_id_seq.nextval,3,4),(sec_role_permission_id_seq.nextval,3,5),
           (sec_role_permission_id_seq.nextval,4,5);
      --user data--
    --create  admin--
    INSERT INTO sec_user(id, username, providername, email, mobile, password, hasher, salt, avatar_url, first_name, last_name, full_name,department_id, created_at)
    VALUES (sec_user_id_seq.nextval,'admin','dreampie','wangrenhui1990@gmail.com','18611434500','$shiro1$SHA-256$500000$ZMhNGAcL3HbpTbNXzxxT1Q==$wRi5AF6BK/1FsQdvISIY1lJ9Rm/aekBoChjunVsqkUU=','default_hasher','','','仁輝','王','仁輝&middot;王',1,current_timestamp),
           (sec_user_id_seq.nextval,'aaaaa','dreampie','aaaaa@gmail.com','18511400000','$shiro1$SHA-256$500000$ZMhNGAcL3HbpTbNXzxxT1Q==$wRi5AF6BK/1FsQdvISIY1lJ9Rm/aekBoChjunVsqkUU=','default_hasher','','','金彤','劉','金彤&middot;劉',2,current_timestamp);
    --create user_info--
    INSERT INTO sec_user_info(id, user_id, creator_id, gender,province_id,city_id,county_id,street,created_at)
    VALUES (sec_user_info_id_seq.nextval,1,0,0,1,2,3,'人民大學(xué)',current_timestamp),
           (sec_user_info_id_seq.nextval,2,0,0,1,2,3,'人民大學(xué)',current_timestamp);
    --create user_role--
    INSERT INTO sec_user_role(id, user_id, role_id)
    VALUES (sec_user_role_id_seq.nextval,1,1),
           (sec_user_role_id_seq.nextval,2,2);

            接下來實(shí)現(xiàn)兩個(gè)關(guān)鍵接口,一個(gè)是shiro的JdbcRealm:        

    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
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    public class MyJdbcRealm extends AuthorizingRealm {
      /**
       * 登錄認(rèn)證
       *
       * @param token
       * @return
       * @throws org.apache.shiro.authc.AuthenticationException
       */
      protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) throws AuthenticationException {
        UsernamePasswordToken userToken = (UsernamePasswordToken) token;
        User user = null;
        String username = userToken.getUsername();
        if (ValidateKit.isEmail(username)) {
          user = User.dao.findFirstBy(" `user`.email =? AND `user`.deleted_at is null", username);
        else if (ValidateKit.isMobile(username)) {
          user = User.dao.findFirstBy(" `user`.mobile =? AND `user`.deleted_at is null", username);
        else {
          user = User.dao.findFirstBy(" `user`.username =? AND `user`.deleted_at is null", username);
        }
        if (user != null) {
          SimpleAuthenticationInfo info = new SimpleAuthenticationInfo(user, user.getStr("password"), getName());
          return info;
        else {
          return null;
        }
      }
      /**
       * 授權(quán)查詢回調(diào)函數(shù), 進(jìn)行鑒權(quán)但緩存中無用戶的授權(quán)信息時(shí)調(diào)用.
       *
       * @param principals
       * @return
       */
      protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principals) {
        String loginName = ((User) principals.fromRealm(getName()).iterator().next()).get("username");
        SimpleAuthorizationInfo info = new SimpleAuthorizationInfo();
        Set<String> roleSet = new LinkedHashSet<String>(); // 角色集合
        Set<String> permissionSet = new LinkedHashSet<String>();  // 權(quán)限集合
        List<Role> roles = null;
        User user = User.dao.findFirstBy(" `user`.username =? AND `user`.deleted_at is null", loginName);
        if (user != null) {
          //遍歷角色
          roles = Role.dao.findUserBy("", user.getLong("id"));
        else {
          SubjectKit.getSubject().logout();
        }
        loadRole(roleSet, permissionSet, roles);
        info.setRoles(roleSet); // 設(shè)置角色
        info.setStringPermissions(permissionSet); // 設(shè)置權(quán)限
        return info;
      }
      /**
       * @param roleSet
       * @param permissionSet
       * @param roles
       */
      private void loadRole(Set<String> roleSet, Set<String> permissionSet, List<Role> roles) {
        List<Permission> permissions;
        for (Role role : roles) {
          //角色可用
          if (role.getDate("deleted_at") == null) {
            roleSet.add(role.getStr("value"));
            permissions = Permission.dao.findByRole("", role.getLong("id"));
            loadAuth(permissionSet, permissions);
          }
        }
      }
      /**
       * @param permissionSet
       * @param permissions
       */
      private void loadAuth(Set<String> permissionSet, List<Permission> permissions) {
        //遍歷權(quán)限
        for (Permission permission : permissions) {
          //權(quán)限可用
          if (permission.getDate("deleted_at") == null) {
            permissionSet.add(permission.getStr("value"));
          }
        }
      }
      /**
       * 更新用戶授權(quán)信息緩存.
       */
      public void clearCachedAuthorizationInfo(Object principal) {
        SimplePrincipalCollection principals = new SimplePrincipalCollection(principal, getName());
        clearCachedAuthorizationInfo(principals);
      }
      /**
       * 清除所有用戶授權(quán)信息緩存.
       */
      public void clearAllCachedAuthorizationInfo() {
        Cache<Object, AuthorizationInfo> cache = getAuthorizationCache();
        if (cache != null) {
          for (Object key : cache.keys()) {
            cache.remove(key);
          }
        }
      }
    }

         實(shí)現(xiàn)數(shù)據(jù)庫權(quán)限的初始化加載:

    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
    public class MyJdbcAuthzService implements JdbcAuthzService {
      @Override
      public Map<String, AuthzHandler> getJdbcAuthz() {
        //加載數(shù)據(jù)庫的url配置
        Map<String, AuthzHandler> authzJdbcMaps = new HashMap<String, AuthzHandler>();
        //遍歷角色
        List<Role> roles = Role.dao.findAll();
        List<Permission> permissions = null;
        for (Role role : roles) {
          //角色可用
          if (role.getDate("daleted_at") == null) {
            permissions = Permission.dao.findByRole("", role.get("id"));
            //遍歷權(quán)限
            for (Permission permission : permissions) {
              //權(quán)限可用
              if (permission.getDate("daleted_at") == null) {
                if (permission.getStr("url") != null && !permission.getStr("url").isEmpty()) {
                  authzJdbcMaps.put(permission.getStr("url"), new JdbcPermissionAuthzHandler(permission.getStr("value")));
                }
              }
            }
          }
        }
        return authzJdbcMaps;
      }
    }

前臺(tái)使用驗(yàn)證碼時(shí)傳入username,password,captcha  三個(gè)參數(shù),第三個(gè)是驗(yàn)證碼參數(shù)名,提前把驗(yàn)證碼內(nèi)容存入session,shiro會(huì)自動(dòng)進(jìn)行驗(yàn)證,注意名稱為captcha

主要結(jié)構(gòu)是權(quán)限表里的url-value,如果需要訪問

1
url:  /admin/**   需要value:P_D_ADMIN

把這些權(quán)限綁定到角色之后,角色綁定給用戶就相當(dāng)于,用戶下面有很多這些  url-value

    1.系統(tǒng)啟動(dòng)的時(shí)候把這個(gè)對(duì)應(yīng)關(guān)系加載到內(nèi)存或者緩存  //cn.dreampie.shiro.core.ShiroKit

    2. 用戶登錄的時(shí)候把用戶對(duì)應(yīng)的角色所有的權(quán)限加載到緩存,這一步是shiro自己實(shí)現(xiàn)

    3.當(dāng)用戶訪問某個(gè)url的時(shí)候 如訪問/admin/index,過濾器會(huì)匹配到/admin/**,這個(gè)url需要擁有P_D_ADMIN的權(quán)限

    4.然后使用shiro的接口hasPremission(value),判斷用戶是否擁有這個(gè)權(quán)限//cn.dreampie.shiro.core.ShiroInterceptor

    5.放行或者拒絕訪問返回403狀態(tài)

jfinal-shiro支持Ajax登陸/退出,使用json數(shù)據(jù)

如果你使用freemarker作為模板,推薦使用jfinal-shiro-freemarker標(biāo)簽庫 http://my.oschina.net/wangrenhui1990/blog/312741

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插件實(shí)現(xiàn)的freemarker標(biāo)簽庫

cn.dreampie.jfinal-web     https://github.com/Dreampie/jfinal-web   相關(guān)web插件,簡潔model實(shí)現(xiàn)

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

cn.dreampie.jfinal-tablebind        https://github.com/Dreampie/jfinal-tablebind   jfinal的table自動(dòng)綁定插件,支持多數(shù)據(jù)源

cn.dreampie.jfinal-flyway      https://github.com/Dreampie/jfinal-flyway   數(shù)據(jù)庫腳本升級(jí)插件,開發(fā)中升級(jí)應(yīng)用時(shí),使用腳本同步升級(jí)數(shù)據(jù)庫或者回滾

cn.dreampie.jfinal-captcha      https://github.com/Dreampie/jfinal-captcha   基于jfinal render的超簡單驗(yàn)證嗎插件

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實(shí)現(xiàn)的lesscsss實(shí)時(shí)編譯插件,可以由于jfinal

cn.dreampie.jfinal-coffeescript     https://github.com/Dreampie/jfinal-coffeescript   java實(shí)現(xiàn)的coffeescript實(shí)時(shí)編譯插件,可以由于jfinal 

cn.dreampie.jfinal-akka    https://github.com/Dreampie/jfinal-akka   java使用akka執(zhí)行異步任務(wù)

cn.dreampie.jfinal-mailer       https://github.com/Dreampie/jfinal-mailer   使用akka發(fā)布郵件的jfinal插件

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

部分內(nèi)容借鑒了網(wǎng)絡(luò)資料

評(píng)論7

  • 1樓:liuxuehua12 發(fā)表于 2014-10-17 15:38 回復(fù)此評(píng)論
    你好,我用了你的這個(gè)權(quán)限插件,發(fā)現(xiàn)授權(quán)不對(duì),/login頁面都攔截了
    我參考了你示例的shiro.ini配置,麻煩看下對(duì)不?
    [users]
    guest = guest,guest

    [main]
    authc = cn.dreampie.shiro.ShiroFormAuthenticationFilter //這里為什么用自己的?不明白
    authc.loginUrl = /login

    authc.successUrl = /
    authc.failureUrl = /login

    signout = cn.dreampie.shiro.ShiroLogoutFilter //這里為什么用自己的?不明白
    signout.redirectUrl = /login

    #anon = cn.dreampie.shiro.ShiroAnonymousFilter

    #realm
    jdbcRealm = com.sxtaxi.common.shiro.MyJdbcRealm
    securityManager.realm = $jdbcRealm


  • 2樓:liuxuehua12 發(fā)表于 2014-10-17 15:39 回復(fù)此評(píng)論
    passwordService = org.apache.shiro.authc.credential.DefaultPasswordService
    passwordMatcher = cn.dreampie.shiro.ShiroPasswordMatcher
    passwordMatcher.passwordService = $passwordService
    jdbcRealm.credentialsMatcher = $passwordMatcher

    #cache
    shiroCacheManager = org.apache.shiro.cache.ehcache.EhCacheManager
    shiroCacheManager.cacheManagerConfigFile = classpath:ehcache.xml
    securityManager.cacheManager = $shiroCacheManager

    #session
    sessionDAO = org.apache.shiro.session.mgt.eis.EnterpriseCacheSessionDAO
    sessionManager = org.apache.shiro.web.session.mgt.DefaultWebSessionManager
    sessionDAO.activeSessionsCacheName = shiro-activeSessionCache
    sessionManager.sessionDAO = $sessionDAO
    securityManager.sessionManager = $sessionManager
    sessionListener = cn.dreampie.shiro.listeners.ShiroSessionListener
    securityManager.sessionManager.sessionListeners = $sessionListener

  • 3樓:liuxuehua12 發(fā)表于 2014-10-17 15:39 回復(fù)此評(píng)論
    securityManager.sessionManager.globalSessionTimeout = 1200000
    ;sessionValidationScheduler = org.apache.shiro.session.mgt.ExecutorServiceSessionValidationScheduler
    ;sessionValidationScheduler.interval = 1200000
    ;securityManager.sessionManager.sessionValidationScheduler = $sessionValidationScheduler
    securityManager.sessionManager.sessionValidationSchedulerEnabled = false
    securityManager.sessionManager.deleteInvalidSessions = false
    ;securityManager.subjectDAO.sessionStorageEvaluator.sessionStorageEnabled = false

    [urls]
    /login = anon
    /checklogin = anon
    /logout = signout
    /** = authc
  • 4樓:liuxuehua12 發(fā)表于 2014-10-17 16:20 回復(fù)此評(píng)論
    我在ShiroInterceptor中添加對(duì)上面幾個(gè)的過濾就沒問題了
    private String[] noans = {"/login","/login/","/checklogin"};
    @Override
    public void intercept(ActionInvocation ai) {
       String actionKey = ai.getActionKey();
    //路徑權(quán)限 //注解權(quán)限
       //過濾不需要權(quán)限控制的
       boolean need = true;
       for(String p : noans){
         if(p.equalsIgnoreCase(actionKey)){
           need = false;
           break;
         }
       }
      if(need){
       List<AuthzHandler> ahs = ShiroKit.getAuthzHandler(ai.getController().getRequest(), actionKey);
       //權(quán)限驗(yàn)證
       if (assertNoAuthorized(ai, ahs)) return;
      }
    // 執(zhí)行正常邏輯
    ai.invoke();
    }
  • 5樓:王仁輝(java) 發(fā)表于 2014-10-17 18:41 回復(fù)此評(píng)論

    引用來自“l(fā)iuxuehua12”的評(píng)論

    securityManager.sessionManager.globalSessionTimeout = 1200000
    ;sessionValidationScheduler = org.apache.shiro.session.mgt.ExecutorServiceSessionValidationScheduler
    ;sessionValidationScheduler.interval = 1200000
    ;securityManager.sessionManager.sessionValidationScheduler = $sessionValidationScheduler
    securityManager.sessionManager.sessionValidationSchedulerEnabled = false
    securityManager.sessionManager.deleteInvalidSessions = false
    ;securityManager.subjectDAO.sessionStorageEvaluator.sessionStorageEnabled = false

    [urls]
    /login = anon
    /checklogin = anon
    /logout = signout
    /** = authc
    /login 如果是你的登陸url 配置為 /login=authc #authc 指的是上面配置的filter ShiroFormAuthenticationFilter /logout 退出登陸url 配置為 /logout = signout # signout 指的是上面配置的filter ShiroLogoutFilter 您的配置 應(yīng)該是 /login = authc /logout = signout /** = anon /checklogin 不用配 它被 /**=anon包含了 anon表示不會(huì)經(jīng)過登錄和退出相關(guān)的filter,除了登陸和退出的權(quán)限 其他權(quán)限都存在數(shù)據(jù)庫里 如果還有問題 qq:173956022 聯(lián)系我
  • 6樓:delicate 發(fā)表于 2014-10-21 11:12 回復(fù)此評(píng)論
    博主 有沒有獨(dú)立的jfinal+shiro的demo啊
  • 7樓:王仁輝(java) iPhone 發(fā)表于 2014-10-21 20:48 回復(fù)此評(píng)論

    引用來自“王仁輝(java)”的評(píng)論

    引用來自“delicate”的評(píng)論

    博主 有沒有獨(dú)立的jfinal+shiro的demo啊

    點(diǎn)擊此處輸入評(píng)論
    暫時(shí)沒有,你可以把前端換成freemarker,完全不影響使用,現(xiàn)在有些同學(xué)已經(jīng)在用了,你也可以試試

    本站是提供個(gè)人知識(shí)管理的網(wǎng)絡(luò)存儲(chǔ)空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點(diǎn)。請(qǐng)注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購買等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊一鍵舉報(bào)。
    轉(zhuǎn)藏 分享 獻(xiàn)花(0

    0條評(píng)論

    發(fā)表

    請(qǐng)遵守用戶 評(píng)論公約

    類似文章 更多