当前位置:网站首页>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
边栏推荐
- proxy server
- Go对文件操作
- Build openstack platform
- Selenium + phantom JS crack sliding verification 2
- Crawl lottery data
- .105Location
- How to install jsonpath package
- Cells in rust share variable pointers
- [UDS unified diagnostic service] (Supplement) v. detailed explanation of ECU bootloader development points (2)
- Nat commun | current progress and open challenges of applied deep learning in Bioscience
猜你喜欢
A few lines of code teach you to crawl lol skin pictures
Nat commun | current progress and open challenges of applied deep learning in Bioscience
Closure type of rust (difference between FN, fnmut and fnone)
Robocode tutorial 5 - enemy class
Re regular expression
Docker installation MySQL
ArcGIS license error -15 solution
Laser slam theory and practice of dark blue College Chapter 3 laser radar distortion removal exercise
Operators in C language
Auto. JS custom dialog box
随机推荐
How to read literature
[UDS unified diagnostic service] IV. typical diagnostic service (4) - online programming function unit (0x34-0x38)
proxy server
Deep learning classic network analysis and target detection (I): r-cnn
YOLOv4剪枝【附代码】
Tensorflow tensor introduction
Implementation of k8s redis one master multi slave dynamic capacity expansion
A few lines of code teach you to crawl lol skin pictures
2022江西光伏展,中國分布式光伏展會,南昌太陽能利用展
Docker 安裝 Redis
MySQL 中的字符串函数
解决允许在postman中写入注释请求接口方法
Random number generation of C #
C medium? This form of
Generate verification code
_ FindText error
I / O multiplexing and its related details
Rewrite four functions such as StrCmp in C language
C [file operation] read TXT text by line
C language input and output (printf and scanf functions, putchar and getchar functions)