日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

shiro的QuickStart

發布時間:2025/4/16 编程问答 14 豆豆
生活随笔 收集整理的這篇文章主要介紹了 shiro的QuickStart 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

RBAC ? role based access control


Shiro QuickStart

Subject currentUser = SecurityUtils.getSubject();
Session session = currentUser.getSession();
//認證
currentUser.login(token);? //通過拋出的異常來判斷用戶登錄結果
//授權
currentUser.hasRole()
currentUser.isPermitted()
currentUser.isAuthenticated()

currentUser.logout();



/** Licensed to the Apache Software Foundation (ASF) under one* or more contributor license agreements. See the NOTICE file* distributed with this work for additional information* regarding copyright ownership. The ASF licenses this file* to you under the Apache License, Version 2.0 (the* "License"); you may not use this file except in compliance* with the License. You may obtain a copy of the License at** http://www.apache.org/licenses/LICENSE-2.0** Unless required by applicable law or agreed to in writing,* software distributed under the License is distributed on an* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY* KIND, either express or implied. See the License for the* specific language governing permissions and limitations* under the License.*/import org.apache.shiro.SecurityUtils; import org.apache.shiro.authc.*; import org.apache.shiro.ini.IniSecurityManagerFactory; import org.apache.shiro.mgt.SecurityManager; import org.apache.shiro.session.Session; import org.apache.shiro.subject.Subject; import org.apache.shiro.lang.util.Factory; import org.slf4j.Logger; import org.slf4j.LoggerFactory;/*** Simple Quickstart application showing how to use Shiro's API.** @since 0.9 RC2*/ public class Quickstart {private static final transient Logger log = LoggerFactory.getLogger(Quickstart.class);public static void main(String[] args) {// 創建 SecurityManagerFactory<SecurityManager> factory = new IniSecurityManagerFactory("classpath:shiro.ini");SecurityManager securityManager = factory.getInstance();SecurityUtils.setSecurityManager(securityManager);// 獲取當前執行的用戶Subject currentUser = SecurityUtils.getSubject();// 使用sessionSession session = currentUser.getSession();session.setAttribute("someKey", "aValue");String value = (String) session.getAttribute("someKey");if (value.equals("aValue")) {log.info("Retrieved the correct value! [" + value + "]");}// 判斷用戶是否登錄if (!currentUser.isAuthenticated()) {UsernamePasswordToken token = new UsernamePasswordToken("lonestarr", "vespa");token.setRememberMe(true);try {currentUser.login(token);} catch (UnknownAccountException uae) {log.info("There is no user with username of " + token.getPrincipal());} catch (IncorrectCredentialsException ice) {log.info("Password for account " + token.getPrincipal() + " was incorrect!");} catch (LockedAccountException lae) {log.info("The account for username " + token.getPrincipal() + " is locked. " +"Please contact your administrator to unlock it.");}// ... catch more exceptions here (maybe custom ones specific to your application?catch (AuthenticationException ae) {//unexpected condition? error?}}//say who they are://print their identifying principal (in this case, a username):log.info("User [" + currentUser.getPrincipal() + "] logged in successfully.");//test a role:if (currentUser.hasRole("schwartz")) {log.info("May the Schwartz be with you!");} else {log.info("Hello, mere mortal.");}//test a typed permission (not instance-level)if (currentUser.isPermitted("lightsaber:wield")) {log.info("You may use a lightsaber ring. Use it wisely.");} else {log.info("Sorry, lightsaber rings are for schwartz masters only.");}//a (very powerful) Instance Level permission:if (currentUser.isPermitted("winnebago:drive:eagle5")) {log.info("You are permitted to 'drive' the winnebago with license plate (id) 'eagle5'. " +"Here are the keys - have fun!");} else {log.info("Sorry, you aren't allowed to drive the 'eagle5' winnebago!");}//all done - log out!currentUser.logout();System.exit(0);} }

?

總結

以上是生活随笔為你收集整理的shiro的QuickStart的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。

主站蜘蛛池模板: 91插插插插插插插插 | 久久久久久99精品 | 久久一区国产 | 视频一区国产精品 | 91精品网| 色欧美片视频在线观看 | 国内视频一区 | 日本不卡视频 | 麻豆伊甸园 | 国产猛男猛女超爽免费视频 | 放几个免费的毛片出来看 | 成人网在线 | 精品福利电影 | japanese在线观看 | 人人妻人人澡人人爽精品 | 亚洲小说图片区 | 久久精品免费一区二区 | www.在线看| www.久久av| 国产第五页 | 日本成人免费在线 | 岛国大片在线观看 | 免费级毛片| 午夜激情影视 | 91区 | 51免费看成人啪啪片 | 亚洲综合婷婷 | 72种无遮挡啪啪的姿势 | 欧美一级黑人 | 亚洲av成人精品毛片 | 91丨九色丨蝌蚪丨对白 | 激情综合小说 | 亚洲国产精选 | 亚洲国产精品久久久久 | 九九免费精品视频 | 日本大尺度激情做爰hd | 国产日韩欧美在线观看 | 国产无套精品 | 青青网站 | 天堂网中文在线 | 国产午夜手机精彩视频 | 亚洲国产精品久久AV | 六月婷婷激情网 | 香蕉视频网站在线 | 狠狠人妻久久久久久综合 | 国产aⅴ爽av久久久久成人 | 乱色专区| 亚洲天堂网一区 | 婷婷亚洲综合 | 97人人艹 | 国产色网址 | 天天干,天天爽 | 欧美日韩国产一区二区在线观看 | 97青青草 | 我爱av好色 | av网页在线 | 久久免费视频3 | 久久欧美| 超碰按摩 | 日韩精品一二三四 | 91婷婷| 人妻少妇偷人精品久久久任期 | 久久久国产免费 | 毛茸茸日本熟妇高潮 | 中文字幕欧美激情 | 福利视频大全 | 美女隐私直播 | 中文字幕免费观看 | 日韩久久精品一区二区 | 欧美一区高清 | 91久久久久久久久久 | 欧美日韩一区二区不卡 | 岛国精品 | 少妇人禽zoz0伦视频 | 热久久中文字幕 | 亚洲一区二区三区在线 | 日韩精品电影一区二区三区 | av中文字幕在线免费观看 | 欧美一区二区不卡视频 | 久久精品国产欧美亚洲人人爽 | 福利二区视频 | 好吊妞在线 | 成人免费小视频 | 91av中文字幕 | 成人免费视屏 | 久久久噜噜噜www成人网 | 五月婷在线观看 | 成人福利av | 人人干人人搞 | 久久最新免费视频 | 国产小视频在线看 | 国产精品白虎 | 亚洲欧美综合一区二区 | 欧美日本在线看 | 国产一区免费看 | 我和我的太阳泰剧在线观看泰剧 | 熟女毛片 | 五月婷婷七月丁香 | 青娱乐在线免费视频 |