我想知道使用spring进行基于角色的访问控制的最佳实践。
我的要求是,
我将为用户分配一组角色,例如
user1 = admin,user2 = expert
user1将具有类似
的访问权限/管理/部件的管理
/管理/项目管理
...
for user2 ....
/ myproject1 / *
所以如果user2尝试访问网址
/管理/部件的管理
将重定向到授权失败页面。
答案 0 :(得分:6)
与Spring MVC一起使用的标准框架是Spring Security。虽然它可能非常复杂,但这里是您需要的最小版本:4.2.2 A Minimal Configuration
在您的情况下,配置将是这样的:
<http auto-config='true'>
<intercept-url pattern="/admin/**" access="ROLE_ADMIN" />
</http>
答案 1 :(得分:4)
Spring Security具有角色的概念,但开箱即用它没有权限概念。它确实有ACLs的概念,但是这个ACL比权限要复杂得多,并且它们与特定对象相关联,而不是通常授权操作。
看看Apache Shiro。它的角色和permissions看起来非常类似于您提供的示例(使用通配符)。它也是easy to use with Spring。
答案 2 :(得分:0)
img = cv2.imread(img_path)
rows = img.shape[0]
cols = img.shape[1]
#print rows , cols
img = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
# Apply dilation and erosion to remove some noise
#kernel = np.ones((5,5), np.uint64)
#img = cv2.dilate(img, kernel, iterations=1)
#img = cv2.erode(img, kernel, iterations=1)
# Write image after removed noise
cv2.imwrite(src_path + "removed_noise1.png", img)
# Apply threshold to get image with only black and white
#img = cv2.adaptiveThreshold(img, 255, cv2.ADAPTIVE_THRESH_GAUSSIAN_C, cv2.THRESH_BINARY,225,95)
img = cv2.adaptiveThreshold(img, 255, cv2.ADAPTIVE_THRESH_GAUSSIAN_C , cv2.THRESH_BINARY ,251,95)
#print cv2.getGaussianKernel(ksize=221,sigma=41)
# Write the image after apply opencv to do some ...
cv2.imwrite(src_path + "thres1.png", img)
# Recognize text with tesseract for python
result = pytesseract.image_to_string(Image.open(src_path + "thres1.png"))
}