1. 程式人生 > >Shiro自定義密碼匹配認證

Shiro自定義密碼匹配認證

() global throws equals urn authent assert cred color

項目集成shiro的時候,有寫某個自定義類然後繼承自AuthorizingRealm

並且重寫實現了他的2個方法:

1、其中一個:認證回調 驗證賬戶密碼的

doGetAuthenticationInfo

2、另外一個:授權查詢 驗證權限的

doGetAuthorizationInfo

ok,上面沒什麽用,只是講述一下,正真用到的是下面的代碼

  /**
     * 認證密碼匹配調用方法
     * @param authcToken
     * @param info
     * @throws AuthenticationException
     */
    @Override
    
protected void assertCredentialsMatch(AuthenticationToken authcToken, AuthenticationInfo info) throws AuthenticationException { UsernamePasswordToken token = (UsernamePasswordToken) authcToken; // 若單點登錄,則使用單點登錄授權方法。 if (!token.getUsername().equals("thinkgem")) { Map
<String,Object> map = Maps.newConcurrentMap(); map.put("name",token.getUsername()); map.put("pwd",String.valueOf(token.getPassword())); // 調用sso連接認證 String result = HttpClientUtils.doGet(Global.getConfig("ssoLoginUrl"), map); if
(result.equals("true")){ return; } } // 否則還是繼續匹配(兜底方案) super.assertCredentialsMatch(token, info); }

使用上述代碼就能通過自定義密碼匹配認證




Shiro自定義密碼匹配認證