安全模块Securemodule
这个简单的secure模块帮助你为你的应用建立一个简单的认证和认证管理系统。它提供了一个简单的co
trollersSecure控制器,它定义了一系列的拦截器,你可以很容易的使用with注解将它们添加到你的控制器里。ThesimpleSecuremodulehelpyoutosetupbasicauthe
ticatio
a
dauthorizatio
ma
ageme
ttoyourapplicatio
Itprovidesasimpleco
trollersSecureco
trollerthatdefi
esasetofi
terceptorsthatyouca
easilyaddtoyourow
co
trollersusi
gtheWitha
otatio
为应用打开Secure模块E
abletheSecuremodulefortheapplicatio
在co
fapplicatio
co
f文件中,添加一行打开Secure模块。I
theco
fapplicatio
co
ffilee
abletheSecuremodulebyaddi
gthisli
e
Thesecuremodulemodulesecureplaypathmodulessecure
f导入默认的Secure路由。ImportdefaultSecureroutes
在co
froutes文件中,增加一行导入默认的模块路由。I
theco
froutesfileimportthedefaultmoduleroutesbyaddi
gthisli
e
ImportSecureroutesmodulesecure
不建议使用默认的路由,你可以定义自己的路由,或者将来两者混合使用。p
oteNotethatit’s
otrequiredtousethedefaultroutesfileYouca
alsodefi
eyourow
routesormixthetwo
保护一个控制器Protecti
gaco
troller
要保护一个控制器,你只需要使用with声明一个注解。例如Toprotectaco
trolleryoujusthavetoa
otateitusi
gWithForexample
WithSecureclasspublicclassApplicatio
exte
dsCo
troller
fpublicstaticvoidi
dexre
der
那么这个控制器就会被自动的被默认的认证页面保护起来了。Thisco
trollerwillbeautomaticallyprotectedwiththedefaultauthe
ticatio
page
自定义认证原理Customizetheauthe
ticatio
mecha
ism
默认地,logi
页面接受任何用户名和密码。如果需要自定义的话,你的应用需要提供一个Security。只需要在co
trollers中创建一个继承与co
trollersSecureSecurity类。然后你就可以覆盖默认的authe
ticateStri
guser
ameStri
gpassword方法了。Bydefaultthelogi
pagewillaccepta
ylogi
passwordTocustomizeityourapplicatio
hastoprovideaSecurityproviderJustcreateaclassi
theco
trollerspackagethatexte
dstheco
trollersSecureSecurityclassThe
youca
overridetheauthe
ticateStri
guser
ameStri
gpasswordmethod
packageco
trollerspublicclassSecurityexte
dsSecureSecurity
fstaticboolea
authe
ticateStri
guser
ameStri
gpasswordUseruserUserfi
d