Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit ddffd6c

Browse files
自定义权限
1 parent ee81751 commit ddffd6c

File tree

13 files changed

+411
-30
lines changed

13 files changed

+411
-30
lines changed

‎src/main/java/com/study/config/shiro/ShiroConfig.java

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,23 @@
11
package com.study.config.shiro;
22

3+
import com.github.pagehelper.PageInfo;
34
import com.github.pagehelper.util.StringUtil;
45
import com.study.model.Resources;
6+
import com.study.model.User;
57
import com.study.service.ResourcesService;
8+
import com.study.service.UserService;
69
import org.apache.shiro.authc.credential.HashedCredentialsMatcher;
710
import org.apache.shiro.spring.LifecycleBeanPostProcessor;
811
import org.apache.shiro.spring.security.interceptor.AuthorizationAttributeSourceAdvisor;
912
import org.apache.shiro.spring.web.ShiroFilterFactoryBean;
13+
import org.springframework.beans.factory.BeanFactory;
1014
import org.springframework.beans.factory.annotation.Autowired;
1115
import org.springframework.context.annotation.Bean;
1216
import org.springframework.context.annotation.Configuration;
1317
import org.apache.shiro.web.mgt.DefaultWebSecurityManager;
1418
import org.apache.shiro.mgt.SecurityManager;
19+
import org.springframework.web.context.support.WebApplicationContextUtils;
20+
import tk.mybatis.mapper.entity.Example;
1521

1622
import javax.annotation.Resource;
1723
import java.util.LinkedHashMap;
@@ -23,9 +29,12 @@
2329
*/
2430
@Configuration
2531
public class ShiroConfig {
26-
@Autowired(required = false)
32+
@Resource
2733
private ResourcesService resourcesService;
2834

35+
@Resource
36+
private UserService userService;
37+
2938
/**
3039
* ShiroFilterFactoryBean 处理拦截资源文件问题。
3140
* 注意:单独一个ShiroFilterFactoryBean配置是或报错的,因为在
@@ -47,7 +56,7 @@ public ShiroFilterFactoryBean shirFilter(SecurityManager securityManager){
4756
// 如果不设置默认会自动寻找Web工程根目录下的"/login.jsp"页面
4857
shiroFilterFactoryBean.setLoginUrl("/login");
4958
// 登录成功后要跳转的链接
50-
shiroFilterFactoryBean.setSuccessUrl("/user");
59+
shiroFilterFactoryBean.setSuccessUrl("/usersPage");
5160
//未授权界面;
5261
shiroFilterFactoryBean.setUnauthorizedUrl("/403");
5362
//拦截器.
@@ -63,15 +72,18 @@ public ShiroFilterFactoryBean shirFilter(SecurityManager securityManager){
6372
//<!-- authc:所有url都必须认证通过才可以访问; anon:所有url都都可以匿名访问-->
6473
filterChainDefinitionMap.put("/user", "authc");
6574
//自定义加载权限资源关系
66-
List<Resources> resourcesList = resourcesService.selectByExample(new Resources());
67-
for(Resources resources:resourcesList){
75+
/* List<Resources> resourcesList = resourcesService.selectByExample(new Example(Resources.class));*/
76+
/* PageInfo<Resources> pageInfo = resourcesService.selectByPage(new Resources(), 1, 20);*/
77+
User user = userService.selectByUsername("admin");
78+
System.out.println(user.getUsername()+"======");
79+
/* for(Resources resources:resourcesList){
6880
6981
if (StringUtil.isNotEmpty(resources.getResurl())&& StringUtil.isNotEmpty(resources.getReskey())) {
7082
String permission = "perms[" + resources.getReskey()+ "]";
7183
System.out.println(resources.getResurl()+"---"+permission);
7284
filterChainDefinitionMap.put(resources.getResurl(),permission);
7385
}
74-
}
86+
}*/
7587
filterChainDefinitionMap.put("/**", "authc");
7688

7789

@@ -91,7 +103,7 @@ public SecurityManager securityManager(){
91103
@Bean
92104
public MyShiroRealm myShiroRealm(){
93105
MyShiroRealm myShiroRealm = new MyShiroRealm();
94-
myShiroRealm.setCredentialsMatcher(hashedCredentialsMatcher());;
106+
myShiroRealm.setCredentialsMatcher(hashedCredentialsMatcher());
95107
return myShiroRealm;
96108
}
97109

‎src/main/java/com/study/controller/HomeController.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public String login(HttpServletRequest request, User user, Model model){
3636
UsernamePasswordToken token=new UsernamePasswordToken(user.getUsername(),user.getPassword());
3737
try {
3838
subject.login(token);
39-
return "redirect:user";
39+
return "redirect:usersPage";
4040
}catch (LockedAccountException lae) {
4141
token.clear();
4242
request.setAttribute("msg", "用户已经被锁定不能登录,请与管理员联系!");
@@ -47,9 +47,14 @@ public String login(HttpServletRequest request, User user, Model model){
4747
return "login";
4848
}
4949
}
50-
@RequestMapping("/user")
51-
public String user(){
50+
@RequestMapping("/usersPage")
51+
public String usersPage(){
5252
return "user/users";
5353
}
5454

55+
@RequestMapping("/resourcesPage")
56+
public String resourcesPage(){
57+
return "resources/resources";
58+
}
59+
5560
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
package com.study.controller;
2+
3+
import com.github.pagehelper.PageInfo;
4+
import com.study.model.Resources;
5+
import com.study.service.ResourcesService;
6+
import org.springframework.web.bind.annotation.RequestMapping;
7+
import org.springframework.web.bind.annotation.RequestParam;
8+
import org.springframework.web.bind.annotation.RestController;
9+
import tk.mybatis.mapper.entity.Example;
10+
11+
import javax.annotation.Resource;
12+
import java.util.HashMap;
13+
import java.util.List;
14+
import java.util.Map;
15+
16+
/**
17+
* Created by yangqj on 2017年4月25日.
18+
*/
19+
@RestController
20+
@RequestMapping("/resources")
21+
public class ResourcesController {
22+
23+
@Resource
24+
private ResourcesService resourcesService;
25+
26+
@RequestMapping
27+
public Map<String,Object> getAll(Resources resources, String draw,
28+
@RequestParam(required = false, defaultValue = "1") int start,
29+
@RequestParam(required = false, defaultValue = "10") int length){
30+
Map<String,Object> map = new HashMap<>();
31+
PageInfo<Resources> pageInfo = resourcesService.selectByPage(resources, start, length);
32+
System.out.println("pageInfo.getTotal():"+pageInfo.getTotal());
33+
map.put("draw",draw);
34+
map.put("recordsTotal",pageInfo.getTotal());
35+
map.put("recordsFiltered",pageInfo.getTotal());
36+
map.put("data", pageInfo.getList());
37+
return map;
38+
}
39+
40+
@RequestMapping("/test")
41+
public List<Resources> test(){
42+
List<Resources> resourcesList = resourcesService.selectByExample(new Example(Resources.class));
43+
System.out.println(resourcesList+"=========");
44+
return resourcesList;
45+
}
46+
47+
}

‎src/main/java/com/study/model/Resources.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package com.study.model;
22

33
import javax.persistence.*;
4-
54
public class Resources {
65
@Id
76
@GeneratedValue(strategy = GenerationType.IDENTITY)
@@ -161,4 +160,17 @@ public Integer getSort() {
161160
public void setSort(Integer sort) {
162161
this.sort = sort;
163162
}
163+
164+
@Override
165+
public String toString() {
166+
return "Resources{" +
167+
"id=" + id +
168+
", name='" + name + '\'' +
169+
", reskey='" + reskey + '\'' +
170+
", resurl='" + resurl + '\'' +
171+
", type=" + type +
172+
", parentid=" + parentid +
173+
", sort=" + sort +
174+
'}';
175+
}
164176
}
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
package com.study.service;
22

3+
import com.github.pagehelper.PageInfo;
34
import com.study.model.Resources;
4-
import org.springframework.stereotype.Service;
55

66
/**
77
* Created by yangqj on 2017年4月25日.
88
*/
99
public interface ResourcesService extends IService<Resources> {
10+
PageInfo<Resources> selectByPage(Resources resources, int start, int length);
11+
1012
}

‎src/main/java/com/study/service/UserService.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Created by yangqj on 2017年4月21日.
88
*/
99
public interface UserService extends IService<User>{
10-
publicPageInfo<User> selectByPage(User user, int start, int length);
10+
PageInfo<User> selectByPage(User user, int start, int length);
1111

12-
publicUser selectByUsername(String username);
12+
User selectByUsername(String username);
1313
}
Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,28 @@
11
package com.study.service.impl;
22

3+
import com.github.pagehelper.PageHelper;
4+
import com.github.pagehelper.PageInfo;
5+
import com.github.pagehelper.util.StringUtil;
36
import com.study.model.Resources;
7+
import com.study.model.User;
48
import com.study.service.ResourcesService;
59
import org.springframework.stereotype.Service;
10+
import tk.mybatis.mapper.entity.Example;
11+
12+
import java.util.List;
613

714
/**
815
* Created by yangqj on 2017年4月25日.
916
*/
10-
@Service
17+
@Service("resourcesService")
1118
public class ResourcesServiceImpl extends BaseService<Resources> implements ResourcesService {
19+
@Override
20+
public PageInfo<Resources> selectByPage(Resources resources, int start, int length) {
21+
int page = start/length+1;
22+
Example example = new Example(Resources.class);
23+
//分页查询
24+
PageHelper.startPage(page, length);
25+
List<Resources> userList = selectByExample(example);
26+
return new PageInfo<>(userList);
27+
}
1228
}

‎src/main/java/com/study/service/impl/UserServiceImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
/**
1414
* Created by yangqj on 2017年4月21日.
1515
*/
16-
@Service
16+
@Service("userService")
1717
public class UserServiceImpl extends BaseService<User> implements UserService{
1818

1919
@Override

‎src/main/resources/static/js/jquery.ztree.core.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1632,7 +1632,7 @@
16321632
} else if (setting.async.enable) {
16331633
if (!view.asyncNode(setting, node)) {
16341634
view.expandCollapseNode(setting, node, !node.open);
1635-
return;
1635+
16361636
}
16371637
} else if (node) {
16381638
view.expandCollapseNode(setting, node, !node.open);
@@ -1832,9 +1832,9 @@
18321832
refresh: function () {
18331833
this.setting.treeObj.empty();
18341834
var root = data.getRoot(setting),
1835-
nodes = root[setting.data.key.children]
1835+
nodes = root[setting.data.key.children];
18361836
data.initRoot(setting);
1837-
root[setting.data.key.children] = nodes
1837+
root[setting.data.key.children] = nodes;
18381838
data.initCache(setting);
18391839
view.createNodes(setting, 0, root[setting.data.key.children], null, -1);
18401840
},
@@ -1894,7 +1894,7 @@
18941894
view.setNodeFontCss(setting, node);
18951895
}
18961896
}
1897-
}
1897+
};
18981898
root.treeTools = zTreeTools;
18991899
data.setZTreeTools(setting, zTreeTools);
19001900

‎src/main/resources/static/js/jquery.ztree.excheck.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -183,30 +183,30 @@
183183
this.setting.treeObj.trigger(consts.event.CHECK, [null, this.setting.treeId, node]);
184184
}
185185
}
186-
}
186+
};
187187

188188
zTreeTools.checkAllNodes = function(checked) {
189189
view.repairAllChk(this.setting, !!checked);
190-
}
190+
};
191191

192192
zTreeTools.getCheckedNodes = function(checked) {
193193
var childKey = this.setting.data.key.children;
194194
checked = (checked !== false);
195195
return data.getTreeCheckedNodes(this.setting, data.getRoot(this.setting)[childKey], checked);
196-
}
196+
};
197197

198198
zTreeTools.getChangeCheckedNodes = function() {
199199
var childKey = this.setting.data.key.children;
200200
return data.getTreeChangeCheckedNodes(this.setting, data.getRoot(this.setting)[childKey]);
201-
}
201+
};
202202

203203
zTreeTools.setChkDisabled = function(node, disabled, inheritParent, inheritChildren) {
204204
disabled = !!disabled;
205205
inheritParent = !!inheritParent;
206206
inheritChildren = !!inheritChildren;
207207
view.repairSonChkDisabled(this.setting, node, disabled, inheritChildren);
208208
view.repairParentChkDisabled(this.setting, node.getParentNode(), disabled, inheritParent);
209-
}
209+
};
210210

211211
var _updateNode = zTreeTools.updateNode;
212212
zTreeTools.updateNode = function(node, checkTypeFlag) {
@@ -604,15 +604,15 @@
604604
if (_createNodes) _createNodes.apply(view, arguments);
605605
if (!nodes) return;
606606
view.repairParentChkClassWithSelf(setting, parentNode);
607-
}
607+
};
608608
var _removeNode = view.removeNode;
609609
view.removeNode = function(setting, node) {
610610
var parentNode = node.getParentNode();
611611
if (_removeNode) _removeNode.apply(view, arguments);
612612
if (!node || !parentNode) return;
613613
view.repairChkClass(setting, parentNode);
614614
view.repairParentChkClass(setting, parentNode);
615-
}
615+
};
616616

617617
var _appendNodes = view.appendNodes;
618618
view.appendNodes = function(setting, level, nodes, parentNode, index, initFlag, openFlag) {

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /