在web專案pom.xml檔案中匯入jar包
>
>
commons-logginggroupid
>
>
commons-loggingartifactid
>
>
1.1.1version
>
dependency
>
>
>
org.apache.shirogroupid
>
>
shiro-coreartifactid
>
>
1.2.3version
>
dependency
>
>
>
org.apache.shirogroupid
>
>
shiro-springartifactid
>
>
1.3.2version
>
dependency
>
>
>
org.apache.shirogroupid
>
>
shiro-webartifactid
>
>
1.3.2version
>
dependency
>
2.在web.xml檔案中宣告shiro攔截許可權的過濾器
>
>
shirofilterfilter-name
>
>
org.springframework.web.filter.delegatingfilterproxyfilter-class
>
>
>
targetfilterlifecycleparam-name
>
>
trueparam-value
>
init-param
>
>
>
targetbeannameparam-name
>
>
shirofilterparam-value
>
init-param
>
filter
>
>
>
shirofilterfilter-name
>
>
/*url-pattern
>
>
在spring中自定義域物件
在realm中建立authrealm類
package com.chang.shiro.realm;
import com.chang.shiro.entity.users;
import com.chang.shiro.service.userservice;
import org.apache.shiro.authc.*;
import org.apache.shiro.authz.authorizationinfo;
import org.apache.shiro.realm.authorizingrealm;
import org.apache.shiro.subject.principalcollection;
import org.springframework.beans.factory.annotation.autowired;
/** *
* */
public
class
authrealm
extends
authorizingrealm
//獲取認證資訊
protected authenticationinfo dogetauthenticationinfo
(authenticationtoken token)
throws authenticationexception
//封裝使用者的身份對子那個 返回這個身份物件
******authenticationinfo info =
new******authenticationinfo
(user, user.
getpassword()
,"authrealm");
return info;
}}
建立spring-shiro.xml中配置
<?xml version="1.0" encoding="utf-8"?>
xmlns
=""xmlns:xsi
=""xsi:schemalocation
=" /spring-beans.xsd"
>
"authrealm"
class
="com.chang.shiro.realm.authrealm"
>
bean
>
"securitymanager"
class
="org.apache.shiro.web.mgt.defaultwebsecuritymanager"
>
name
="realm"
ref="authrealm"
>
property
>
bean
>
"shirofilter"
class
="org.apache.shiro.spring.web.shirofilte***ctorybean"
>
name
="securitymanager"
ref="securitymanager"
>
property
>
name
="loginurl"
value
="/user/login.do"
>
property
>
name
="filterchaindefinitions"
>
>
/static/*=anon
/user/login.do=anon
/login.jsp=anon
/*=authc
/*/*=authc
value
>
property
>
bean
>
beans
>
resource
="classpath:spring-shiro.xml"
>
import
>
在控制器中使用shiro去做登入認證
//使用者登入
JSON在web專案中的使用
1.jquery的ajax方式傳遞json到後台 1 示例一 ajax datatype text json headers cache false,success function msg error function 2 示例二 var form vals form1 serializearra...
web專案中修改密碼的實現
專案以springboot,springsecurity等技術為後端,vue elementui為前端。需求,增加密碼的修改。開啟修改密碼dialog對話方塊,原密碼中要輸入並驗證是否正確,新密碼和確認新密碼是驗證是否一致和正則匹配,然後修改按鈕提交到後端進行資料庫中user表的密碼更新。respo...
在Seam專案中快速實現Web Service
以前寫web service一直是用axis來做,用了seam來開發web後,這次為了專案的簡潔,決定採用 在seam專案中寫jbossws 的方案來實現webservice。寫基於pojo的web service實現 webservice public class testservice 如果在w...