Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
后端镜像
java镜像
Springside4
提交
d83e4bad
S
Springside4
项目概览
后端镜像
/
java镜像
/
Springside4
通知
0
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
S
Springside4
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
d83e4bad
编写于
9月 01, 2012
作者:
C
Calvin
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
#85 showcase中补充用户的角色管理(checkBox提交)的演示,比旧版有改进。
上级
13a8efec
变更
8
隐藏空白更改
内联
并排
Showing
8 changed file
with
72 addition
and
8 deletion
+72
-8
examples/showcase/src/main/java/org/springside/examples/showcase/entity/Role.java
...in/java/org/springside/examples/showcase/entity/Role.java
+7
-0
examples/showcase/src/main/java/org/springside/examples/showcase/repository/jpa/RoleDao.java
.../springside/examples/showcase/repository/jpa/RoleDao.java
+8
-0
examples/showcase/src/main/java/org/springside/examples/showcase/service/AccountService.java
.../springside/examples/showcase/service/AccountService.java
+22
-1
examples/showcase/src/main/java/org/springside/examples/showcase/web/UserController.java
.../org/springside/examples/showcase/web/UserController.java
+24
-2
examples/showcase/src/main/resources/security/applicationContext-shiro.xml
.../src/main/resources/security/applicationContext-shiro.xml
+1
-1
examples/showcase/src/main/webapp/WEB-INF/views/account/userForm.jsp
...owcase/src/main/webapp/WEB-INF/views/account/userForm.jsp
+6
-0
examples/showcase/src/main/webapp/WEB-INF/views/account/userList.jsp
...owcase/src/main/webapp/WEB-INF/views/account/userList.jsp
+1
-1
examples/showcase/src/test/functional/org/springside/examples/showcase/functional/account/UserManagerFT.java
...e/examples/showcase/functional/account/UserManagerFT.java
+3
-3
未找到文件。
examples/showcase/src/main/java/org/springside/examples/showcase/entity/Role.java
浏览文件 @
d83e4bad
...
...
@@ -27,6 +27,13 @@ public class Role extends IdEntity {
private
String
permissions
;
public
Role
()
{
}
public
Role
(
Long
id
)
{
this
.
id
=
id
;
}
@Column
(
nullable
=
false
,
unique
=
true
)
public
String
getName
()
{
return
name
;
...
...
examples/showcase/src/main/java/org/springside/examples/showcase/repository/jpa/RoleDao.java
0 → 100644
浏览文件 @
d83e4bad
package
org.springside.examples.showcase.repository.jpa
;
import
org.springframework.data.repository.PagingAndSortingRepository
;
import
org.springside.examples.showcase.entity.Role
;
public
interface
RoleDao
extends
PagingAndSortingRepository
<
Role
,
Long
>
{
}
examples/showcase/src/main/java/org/springside/examples/showcase/service/AccountService.java
浏览文件 @
d83e4bad
...
...
@@ -11,7 +11,9 @@ import org.springframework.stereotype.Component;
import
org.springframework.transaction.annotation.Transactional
;
import
org.springside.examples.showcase.demos.jms.simple.NotifyMessageProducer
;
import
org.springside.examples.showcase.demos.jmx.ApplicationStatistics
;
import
org.springside.examples.showcase.entity.Role
;
import
org.springside.examples.showcase.entity.User
;
import
org.springside.examples.showcase.repository.jpa.RoleDao
;
import
org.springside.examples.showcase.repository.jpa.UserDao
;
import
org.springside.modules.persistence.Hibernates
;
import
org.springside.modules.security.utils.Digests
;
...
...
@@ -34,6 +36,8 @@ public class AccountService {
private
UserDao
userDao
;
private
RoleDao
roleDao
;
private
NotifyMessageProducer
notifyProducer
;
//JMS消息发送
private
ApplicationStatistics
applicationStatistics
;
...
...
@@ -77,7 +81,7 @@ public class AccountService {
user
.
setPassword
(
Encodes
.
encodeHex
(
hashPassword
));
}
public
List
<
User
>
getAllUser
()
{
public
List
<
User
>
getAllUser
s
()
{
if
(
applicationStatistics
!=
null
)
{
applicationStatistics
.
incrListUserTimes
();
...
...
@@ -142,11 +146,28 @@ public class AccountService {
}
}
//--------------------//
// Role Management //
//--------------------//
public
List
<
Role
>
getAllRoles
()
{
return
(
List
<
Role
>)
roleDao
.
findAll
();
}
//-----------------//
// Setter methods //
//-----------------//
@Autowired
public
void
setUserDao
(
UserDao
userDao
)
{
this
.
userDao
=
userDao
;
}
@Autowired
public
void
setRoleDao
(
RoleDao
roleDao
)
{
this
.
roleDao
=
roleDao
;
}
@Autowired
(
required
=
false
)
public
void
setNotifyProducer
(
NotifyMessageProducer
notifyProducer
)
{
this
.
notifyProducer
=
notifyProducer
;
...
...
examples/showcase/src/main/java/org/springside/examples/showcase/web/UserController.java
浏览文件 @
d83e4bad
...
...
@@ -11,12 +11,15 @@ import org.apache.shiro.authz.annotation.RequiresRoles;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Controller
;
import
org.springframework.ui.Model
;
import
org.springframework.web.bind.WebDataBinder
;
import
org.springframework.web.bind.annotation.InitBinder
;
import
org.springframework.web.bind.annotation.ModelAttribute
;
import
org.springframework.web.bind.annotation.PathVariable
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RequestParam
;
import
org.springframework.web.bind.annotation.ResponseBody
;
import
org.springframework.web.servlet.mvc.support.RedirectAttributes
;
import
org.springside.examples.showcase.entity.Role
;
import
org.springside.examples.showcase.entity.User
;
import
org.springside.examples.showcase.service.AccountService
;
...
...
@@ -40,7 +43,7 @@ public class UserController {
@RequiresRoles
(
value
=
{
"Admin"
,
"User"
},
logical
=
Logical
.
OR
)
@RequestMapping
(
value
=
""
)
public
String
list
(
Model
model
)
{
List
<
User
>
users
=
accountService
.
getAllUser
();
List
<
User
>
users
=
accountService
.
getAllUser
s
();
model
.
addAttribute
(
"users"
,
users
);
model
.
addAttribute
(
"allStatus"
,
allStatus
);
return
"account/userList"
;
...
...
@@ -51,13 +54,24 @@ public class UserController {
public
String
updateForm
(
@PathVariable
(
"id"
)
Long
id
,
Model
model
)
{
model
.
addAttribute
(
"user"
,
accountService
.
getUser
(
id
));
model
.
addAttribute
(
"allStatus"
,
allStatus
);
model
.
addAttribute
(
"allRoles"
,
accountService
.
getAllRoles
());
return
"account/userForm"
;
}
@RequiresPermissions
(
"user:edit"
)
@RequestMapping
(
value
=
"save/{userId}"
)
public
String
update
(
@Valid
@ModelAttribute
(
"user"
)
User
user
,
RedirectAttributes
redirectAttributes
)
{
public
String
update
(
@Valid
@ModelAttribute
(
"user"
)
User
user
,
@RequestParam
(
value
=
"roleList"
)
List
<
Long
>
checkedRoleList
,
RedirectAttributes
redirectAttributes
)
{
//bind roleList
user
.
getRoleList
().
clear
();
for
(
Long
roleId
:
checkedRoleList
)
{
Role
role
=
new
Role
(
roleId
);
user
.
getRoleList
().
add
(
role
);
}
accountService
.
saveUser
(
user
);
redirectAttributes
.
addFlashAttribute
(
"message"
,
"保存用户成功"
);
return
"redirect:/account/user"
;
}
...
...
@@ -86,4 +100,12 @@ public class UserController {
}
return
null
;
}
/**
* 不自动绑定对象中的roleList属性,另行处理
*/
@InitBinder
protected
void
initBinder
(
WebDataBinder
binder
)
{
binder
.
setDisallowedFields
(
"roleList"
);
}
}
examples/showcase/src/main/resources/security/applicationContext-shiro.xml
浏览文件 @
d83e4bad
...
...
@@ -12,7 +12,7 @@
</bean>
<!-- 項目自定义的Realm -->
<bean
id=
"shiroDbRealm"
class=
"org.springside.examples.showcase.service.ShiroDbRealm"
depends-on=
"userDao"
>
<bean
id=
"shiroDbRealm"
class=
"org.springside.examples.showcase.service.ShiroDbRealm"
depends-on=
"userDao
,roleDao
"
>
<property
name=
"accountService"
ref=
"accountService"
/>
</bean>
...
...
examples/showcase/src/main/webapp/WEB-INF/views/account/userForm.jsp
浏览文件 @
d83e4bad
...
...
@@ -56,6 +56,12 @@
<input
type=
"password"
id=
"plainPassword"
name=
"plainPassword"
class=
"input-large"
placeholder=
"...Leave it blank if no change"
/>
</div>
</div>
<div
class=
"control-group"
>
<label
for=
"groupList"
class=
"control-label"
>
角色:
</label>
<div
class=
"controls"
>
<form:bscheckboxes
path=
"roleList"
items=
"
${
allRoles
}
"
itemLabel=
"name"
itemValue=
"id"
/>
</div>
</div>
<div
class=
"control-group"
>
<label
for=
"status"
class=
"control-label"
>
状态:
</label>
<div
class=
"controls"
>
...
...
examples/showcase/src/main/webapp/WEB-INF/views/account/userList.jsp
浏览文件 @
d83e4bad
...
...
@@ -15,7 +15,7 @@
<body>
<h1>
帐号管理
</h1>
<c:if
test=
"
${
not
empty
message
}
"
>
<div
id=
"message"
class=
"
success"
>
${message}
</div>
<div
id=
"message"
class=
"
alert alert-success"
><button
data-dismiss=
"alert"
class=
"close"
>
×
</button>
${message}
</div>
</c:if>
<table
class=
"table table-striped table-bordered table-condensed"
>
...
...
examples/showcase/src/test/functional/org/springside/examples/showcase/functional/account/UserManagerFT.java
浏览文件 @
d83e4bad
...
...
@@ -35,17 +35,17 @@ public class UserManagerFT extends BaseSeleniumTestCase {
//点击提交按钮
s
.
type
(
By
.
name
(
"name"
),
"user_foo"
);
s
.
getSelect
(
By
.
name
(
"status"
)).
selectByValue
(
"disabled"
);
s
.
check
(
By
.
id
(
"status2"
)
);
s
.
click
(
By
.
id
(
"submit_btn"
));
//重新进入用户修改页面, 检查最后修改者
s
.
click
(
By
.
id
(
"editLink-user"
));
assertEquals
(
"user_foo"
,
s
.
getValue
(
By
.
name
(
"name"
)));
assert
Equals
(
"disabled"
,
s
.
getSelect
(
By
.
name
(
"status"
)).
getFirstSelectedOption
().
getText
(
));
assert
True
(
s
.
isChecked
(
By
.
id
(
"status2"
)
));
//恢复原有值
s
.
type
(
By
.
name
(
"name"
),
"user"
);
s
.
getSelect
(
By
.
name
(
"status"
)).
selectByValue
(
"enabled"
);
s
.
check
(
By
.
id
(
"status1"
)
);
s
.
click
(
By
.
id
(
"submit_btn"
));
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录