当前位置:网站首页>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
边栏推荐
- ArcGIS table to excel exceeds the upper limit, conversion failed
- How to read literature
- Qtablewidget usage explanation
- Rust: how to implement a thread pool?
- Docker installation MySQL
- Svn simple operation command
- String function in MySQL
- Pointers in rust: box, RC, cell, refcell
- [UDS unified diagnostic service] v. diagnostic application example: Flash bootloader
- 由tcl脚本生成板子对应的vivado工程
猜你喜欢

Batch export ArcGIS attribute table

Nodejs安装

Go's gin framework learning

Robocode tutorial 5 - enemy class

Install pyshp Library

SSD硬盘SATA接口和M.2接口区别(详细)总结

Docker installation MySQL

2022 Jiangxi energy storage technology exhibition, China Battery exhibition, power battery exhibition and fuel cell Exhibition

7-21 wrong questions involve knowledge points.

A few lines of code teach you to crawl lol skin pictures
随机推荐
2022 Jiangxi Photovoltaic Exhibition, China distributed Photovoltaic Exhibition, Nanchang solar energy utilization Exhibition
Gobang game based on pyGame Library
Go's gin framework learning
NVIDIA Jetson: GStreamer and openmax (GST OMX) plug-ins
登录和发布文章功能测试
Calculation of fishing net road density
由tcl脚本生成板子对应的vivado工程
Implementation of image recognition code based on VGg convolutional neural network
Rust: shared variable in thread pool
Climbing watermelon video URL
C byte array (byte []) and string are converted to each other
Qtablewidget usage explanation
C# 网络相关操作
解决允许在postman中写入注释请求接口方法
YOLOv4剪枝【附代码】
【ACM】455. 分发饼干(1. 大饼干优先喂给大胃口;2. 遍历两个数组可以只用一个for循环(用下标索引--来遍历另一个数组))
C language to achieve 2048 small game direction merging logic
GDAL + ogr learning
Identification verification code
Serialization scheme of serde - trust