Spring Security的基本使用

2021-08-28 23:42:44 字數 1373 閱讀 2884

這個**會把過濾到請求自動轉到 springsecurityfilterchain 這個類裡面,這個是spring security的乙個處理類

這個過濾器要配置 springsecurityfilterchain 這裡的name固定要是springsecurityfilterchain,因為他是security內建好的過濾器名稱

a).在spring-security.xml中配置spring security的頁面攔截規則:		

b).在spring-security.xml中配置認證管理器

如果不登入,直接訪問index.html,會跳轉到這個登陸頁面,如果不使用 admin 123456登陸,也會提示登陸失敗,只有使用admin 123456登陸後,才能跳轉到index.html頁面

csrf(cross-site request forgery)跨站請求偽造,也被稱為「one click attack」或者session riding,通常縮寫為csrf或者xsrf,是一種對**的惡意利用,如果是jsp頁面,那每個頁面都會自帶csrf

在html頁面中,也可以在js**中,給請求新增csrf頭資訊,適用於傳送ajax請求

a). pom.xml,web.xml,login.html中的form表單裡面的寫法都同上面一樣

b). 寫乙個userdetailsserviceimpl 繼承 userdetailsservice,這是security認證介面的實現類,userdetailsservice是security自己定義的乙個認證類,

這裡要實現裡面乙個方法,loaduserbyusername(string username),當使用者在頁面登入後,通過security的配置,請求會自動進入到這個方法裡面

c). public userdetails loaduserbyusername(string username)

throws usernamenotfoundexception

d). 當用呼叫服務層的應用訪問資料庫時,需要乙個sellerservice物件:

/**呼叫服務層訪問資料庫,來查詢使用者*/

private sellerservice sellerservice;

/**因為當前類所在的包不在controller裡面,所以不能dubbo的@reference來注入物件,這裡採用spring配置檔案的形式注入物件,所以這裡要提供乙個set方法*/

public void setsellerservice(sellerservice sellerservice)

e).

Spring Security結合CAS的配置

在我的幾個專案裡需要用到單點登入,我選用了cas,下面給出乙個一般性的spring security結合cas的配置檔案 附加說明 drop table if exists uc users create table uc users username varchar 32 not null,pas...

Spring Security的基本使用

是乙個能夠為基於 spring 的企業應用系統提供宣告式的安全訪問控制解決方案的安全框架。它提供了一組可以在 spring 應用上下文中配置的 bean,充分利用了 spring ioc,di 控制反轉 inversion of control di dependencyinjection 依賴注入...

springsecurity的URL過濾和全域性過濾

springsecurity的url過濾和全域性過濾 最近有個需求,需要配置乙個登陸使用者才能訪問專案的資源,也就是說要配置乙個 形式的鏈結,保護專案中所有的資源,要登入了的使用者才能訪問,當然是要除開登陸頁面之外。springsecurity對url過濾是採用的正規表示式,其實一直就在使用spri...