---
title: "JEECMS 系统权限设计"
author: "q474818917"
date: "2013-07-08T14:44:20Z"
tags: []
categories: ["企业架构"]
slug: "jeecms"
draft: false
lastmod: "2013-07-08T14:45:25Z"
id: 1901374
url: "https://chinajweb.iteye.com/blog/1901374"
---

![](http://dl2.iteye.com/upload/attachment/0086/6658/d4db0cc4-44e2-3e01-864d-8432fd50e5e1.jpg)  
 

1、用户校验.

             登录校验主要围绕着用户后台登陆的url拦截

             a.围绕着用户登录过程中设计到两张用户表

             jc\_user:存储着用户的基本信息

             jo\_user:存储着用户登录、注册、更新时间及用户密码信息

 

             b.后台用户登录负责处理的servlet是CmsLoginAct类，该类包含两个方法:

             input:根据浏览器的请求指向用户登录页面。

                 submit:用户输入账号信息登录处理method。

 

```
@RequestMapping(value = "/login.do", method = RequestMethod.GET)
	public String input(HttpServletRequest request,
			HttpServletResponse response, ModelMap model) {
```

 

```
@RequestMapping(value = "/login.do", method = RequestMethod.POST)
	public String submit(String username, String password, String captcha,String processUrl, String returnUrl, String message,
			HttpServletRequest request, HttpServletResponse response,
			ModelMap model) {
```

                    这里从submit展开，该方法中主要包含3个操作：

          第一个就是用户的username、password的校验。

```
public UnifiedUser login(String username, String password, String ip)
			throws UsernameNotFoundException, BadCredentialsException {
		UnifiedUser user = getByUsername(username);//根据用户取得jo_user
		if (user == null) {
			throw new UsernameNotFoundException("该用户未注册: " + username);
		}
		//无需加密后比较
		//TODO DavidfINCH
		//if (!pwdEncoder.isPasswordValid(user.getPassword(), password) && !user.getPassword().equals(password)){
		//不再启用暗文！
		if (!user.getPassword().equals(password)) {//将取来的用户的密码和request获取的密码进行比较，如果成功则返回jo_user
			updateLoginError(user.getId(), ip);
			throw new BadCredentialsException("密码错误！");
		}
		if (!user.getActivation()) {
			throw new BadCredentialsException("该用户信息需激活！");
		}
		updateLoginSuccess(user.getId(), ip);
		return user;
	}
```

 获取到用户信息后将用户的认证信息保存到数据库中，同时产生一个认证key，放入到session

 

```
UnifiedUser user = unifiedUserMng.login(username, password, ip);
Authentication auth = new Authentication();
auth.setUid(user.getId());
auth.setUsername(user.getUsername());
auth.setEmail(user.getEmail());
auth.setLoginIp(ip);
save(auth);
session.setAttribute(request, response, AUTH_KEY, auth.getId());
```

 第二个是从认证表中的取得的user\_id ,再获取jc\_user

  最后根据传入的returnurl将direct到index.do去处理。

 

2、url校验

 在整个过程中AdminContextInterceptor都对url进行拦截处理。

主要步骤：

从session中取得cmsUser也就是jc\_user的信息。

比较url和user.getPerms

```
private boolean permistionPass(String uri, Set<String> perms,
			boolean viewOnly) {
		String u = null;
		int i;
		for (String perm : perms) {
			if (uri.startsWith(perm)) {
				// 只读管理员
				if (viewOnly) {
					// 获得最后一个 '/' 的URI地址。
					i = uri.lastIndexOf("/");
					if (i == -1) {
						throw new RuntimeException("uri must start width '/':"
								+ uri);
					}
					u = uri.substring(i + 1);
					// 操作型地址被禁止
					if (u.startsWith("o_")) {
						return false;
					}
				}
				return true;
			}
		}
		return false;
	}
```