当前位置:网站首页>Permission management with binary
Permission management with binary
2022-04-23 18:08:00 【dawnsun001】
Just give an example ! Examples will be explained 1. Permission means 2. Authority judgment 3. Add permissions 4. Cancellation of authority
- public class Test {
- /**
- * @param args
- */
- public static void main(String[] args) {
- /**
- * Four permissions , Currently defined as int, The following binary representation takes only the last four digits for explanation
- */
- // add to
- int c = 1;// ...0001
- // Inquire about
- int r = 2;// ...0010
- // modify
- int u = 4;// ...0100
- // Delete
- int d = 8;// ...1000
- /**
- *
- * You can observe the rules of binary representation of four permissions , All are 2 Of N Power ,
- * It means itself , The last bit of add permission is... Others 0, The penultimate digit of the query is 1 Everything else is 0, Change the penultimate to 1 Everything else is 0, Delete the penultimate as 1 Everything else is 0
- *
- */
- /**
- *1111---- This indicates what kind of permission you have. You can use |( Press bit or ) operation
- *
- */
- // user A Have the right to add and modify
- int usera = c | r | u;
- // user B Have the right to add and delete
- int userb = c | d;
- /**
- * 2222---- To judge whether a user has certain permissions, use the user permissions and the permissions to be judged &( Bitwise AND ) operation , When the result is the permission value to be judged, it means that the user has this permission , Otherwise, you don't have this permission
- */
- if ((usera & u) == u) {
- System.out.println(" user a Have update permission ");
- } else {
- System.out.println(" user a No update permission ");
- }
- /**
- * 3333---- Add permissions to users. Use user permissions and permissions to be added |( Press bit or ) The operation overwrites the previous permission value
- */
- if ((userb & u) == u) {
- System.out.println(" user b Have update permission ");
- } else {
- System.out.println(" user b No update permission ");
- }
- // To the user b Add update permissions
- userb = userb | u;
- if ((userb & u) == u) {
- System.out.println(" user b Have update permission ");
- } else {
- System.out.println(" user b No update permission ");
- }
- /**
- * 4444---- Cancel a user's permission , Use the user authority and the authority to be cancelled to reverse by bit, and then carry out by bit operation , Overwrite the previous permission value
- */
- if ((usera & r) == r) {
- System.out.println(" user a Have query authority ");
- } else {
- System.out.println(" user a No query permission ");
- }
- // Cancel user a The query authority of
- usera = usera & (~r);
- if ((usera & r) == r) {
- System.out.println(" user a Have query authority ");
- } else {
- System.out.println(" user a No query permission ");
- }
- }
- }
版权声明
本文为[dawnsun001]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204230544289337.html
边栏推荐
- 纳米技术+AI赋能蛋白质组学|珞米生命科技完成近千万美元融资
- Nanotechnology + AI enabled proteomics | Luomi life technology completed nearly ten million US dollars of financing
- Go语言JSON包使用
- MySQL_ 01_ Simple data retrieval
- How to ensure the security of futures accounts online?
- powerdesigner各种字体设置;preview字体设置;sql字体设置
- SSD硬盘SATA接口和M.2接口区别(详细)总结
- Qt读写XML文件(含源码+注释)
- Crawler for querying nicknames and avatars based on qqwebapi
- Rewrite four functions such as StrCmp in C language
猜你喜欢

C#的随机数生成

A few lines of code teach you to crawl lol skin pictures

cv_ Solution of mismatch between bridge and opencv

JD-FreeFuck 京東薅羊毛控制面板 後臺命令執行漏洞

Gobang game based on pyGame Library

Implementation of k8s redis one master multi slave dynamic capacity expansion

Batch export ArcGIS attribute table

Nodejs安装

Robocode Tutorial 4 - robocode's game physics

Go file operation
随机推荐
Auto. JS custom dialog box
Go language JSON package usage
[UDS unified diagnostic service] IV. typical diagnostic service (6) - input / output control unit (0x2F)
Crawl the product data of cicada mother data platform
C medium? This form of
Robocode Tutorial 4 - robocode's game physics
MySQL_01_简单数据检索
Robocode tutorial 3 - Robo machine analysis
2022 Jiangxi Photovoltaic Exhibition, China Distributed Photovoltaic Exhibition, Nanchang Solar Energy Utilization Exhibition
[UDS unified diagnostic service] IV. typical diagnostic service (4) - online programming function unit (0x34-0x38)
.104History
Installation du docker redis
2022江西光伏展,中國分布式光伏展會,南昌太陽能利用展
2022江西储能技术展会,中国电池展,动力电池展,燃料电池展
Secure credit
Notes on common basic usage of eigen Library
Classes and objects
cartographer_ There is no problem compiling node, but running the bug that hangs directly
Realsense selection comparison d455 d435i d415 t265 3D hardware comparison
.105Location