Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
后端镜像
java镜像
Smart Sample
提交
0e7670e7
S
Smart Sample
项目概览
后端镜像
/
java镜像
/
Smart Sample
通知
0
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
S
Smart Sample
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
0e7670e7
编写于
6月 02, 2014
作者:
黄
黄勇
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
【I】将 Smart Security 模块转换为 Smart Security 插件,并提供基于注解的授权特性
上级
7b09202e
变更
19
隐藏空白更改
内联
并排
Showing
19 changed file
with
140 addition
and
30 deletion
+140
-30
doc/sample.sql
doc/sample.sql
+43
-1
pom.xml
pom.xml
+5
-5
src/main/java/org/smart4j/sample/CustomSmartSecurity.java
src/main/java/org/smart4j/sample/CustomSmartSecurity.java
+2
-2
src/main/java/org/smart4j/sample/action/ProductAction.java
src/main/java/org/smart4j/sample/action/ProductAction.java
+2
-0
src/main/java/org/smart4j/sample/action/SystemAction.java
src/main/java/org/smart4j/sample/action/SystemAction.java
+4
-4
src/main/java/org/smart4j/sample/service/impl/UserServiceImpl.java
...java/org/smart4j/sample/service/impl/UserServiceImpl.java
+2
-2
src/main/resources/i18n/i18n_en_US.properties
src/main/resources/i18n/i18n_en_US.properties
+2
-0
src/main/resources/i18n/i18n_zh_CN.properties
src/main/resources/i18n/i18n_zh_CN.properties
+2
-0
src/main/resources/shiro.ini
src/main/resources/shiro.ini
+3
-3
src/main/resources/smart.properties
src/main/resources/smart.properties
+1
-1
src/main/webapp/WEB-INF/jsp/common/header.jsp
src/main/webapp/WEB-INF/jsp/common/header.jsp
+5
-3
src/main/webapp/WEB-INF/jsp/error/403.jsp
src/main/webapp/WEB-INF/jsp/error/403.jsp
+31
-0
src/main/webapp/WEB-INF/jsp/error/404.jsp
src/main/webapp/WEB-INF/jsp/error/404.jsp
+1
-1
src/main/webapp/WEB-INF/jsp/error/500.jsp
src/main/webapp/WEB-INF/jsp/error/500.jsp
+1
-1
src/main/webapp/WEB-INF/jsp/login.jsp
src/main/webapp/WEB-INF/jsp/login.jsp
+1
-1
src/main/webapp/WEB-INF/jsp/product.jsp
src/main/webapp/WEB-INF/jsp/product.jsp
+4
-1
src/main/webapp/WEB-INF/web.xml
src/main/webapp/WEB-INF/web.xml
+4
-0
src/main/webapp/www/css/global.css
src/main/webapp/www/css/global.css
+9
-5
src/test/java/org/smart4j/sample/test/ShiroTest.java
src/test/java/org/smart4j/sample/test/ShiroTest.java
+18
-0
未找到文件。
doc/sample.sql
浏览文件 @
0e7670e7
...
...
@@ -65,7 +65,7 @@ INSERT INTO `product_type` VALUES ('2', 'Tablet Computer', '平板电脑');
-- ----------------------------
-- Table structure for log
-- ----------------------------
DROP
TABLE
IF
EXISTS
`log`
;
CREATE
TABLE
`log`
(
`id`
bigint
(
20
)
NOT
NULL
AUTO_INCREMENT
,
`date`
char
(
10
)
DEFAULT
NULL
,
...
...
@@ -73,3 +73,45 @@ CREATE TABLE `log` (
`description`
text
,
PRIMARY
KEY
(
`id`
)
)
ENGINE
=
InnoDB
AUTO_INCREMENT
=
1
DEFAULT
CHARSET
=
utf8
;
-- ----------------------------
-- Table structure for role
-- ----------------------------
DROP
TABLE
IF
EXISTS
`role`
;
CREATE
TABLE
`role`
(
`id`
bigint
(
20
)
NOT
NULL
AUTO_INCREMENT
,
`role_name`
varchar
(
255
)
DEFAULT
NULL
,
PRIMARY
KEY
(
`id`
)
)
ENGINE
=
InnoDB
AUTO_INCREMENT
=
1
DEFAULT
CHARSET
=
utf8
;
-- ----------------------------
-- Table structure for permission
-- ----------------------------
DROP
TABLE
IF
EXISTS
`permission`
;
CREATE
TABLE
`permission`
(
`id`
bigint
(
20
)
NOT
NULL
AUTO_INCREMENT
,
`permission_name`
varchar
(
255
)
DEFAULT
NULL
,
PRIMARY
KEY
(
`id`
)
)
ENGINE
=
InnoDB
AUTO_INCREMENT
=
1
DEFAULT
CHARSET
=
utf8
;
-- ----------------------------
-- Table structure for user_role
-- ----------------------------
DROP
TABLE
IF
EXISTS
`user_role`
;
CREATE
TABLE
`user_role`
(
`id`
bigint
(
20
)
NOT
NULL
AUTO_INCREMENT
,
`user_id`
bigint
(
20
)
DEFAULT
NULL
,
`role_id`
bigint
(
20
)
DEFAULT
NULL
,
PRIMARY
KEY
(
`id`
)
)
ENGINE
=
InnoDB
AUTO_INCREMENT
=
1
DEFAULT
CHARSET
=
utf8
;
-- ----------------------------
-- Table structure for role_permission
-- ----------------------------
DROP
TABLE
IF
EXISTS
`role_permission`
;
CREATE
TABLE
`role_permission`
(
`id`
bigint
(
20
)
NOT
NULL
AUTO_INCREMENT
,
`role_id`
bigint
(
20
)
DEFAULT
NULL
,
`permission_id`
bigint
(
20
)
DEFAULT
NULL
,
PRIMARY
KEY
(
`id`
)
)
ENGINE
=
InnoDB
AUTO_INCREMENT
=
1
DEFAULT
CHARSET
=
utf8
;
pom.xml
浏览文件 @
0e7670e7
...
...
@@ -56,11 +56,6 @@
<groupId>
org.smart4j
</groupId>
<artifactId>
smart-framework
</artifactId>
<version>
${smart.version}
</version>
</dependency>
<dependency>
<groupId>
org.smart4j
</groupId>
<artifactId>
smart-security
</artifactId>
<version>
${smart.version}
</version>
</dependency>
<dependency>
<groupId>
org.smart4j
</groupId>
...
...
@@ -92,6 +87,11 @@
<artifactId>
smart-plugin-druid
</artifactId>
<version>
${smart.version}
</version>
</dependency>
<dependency>
<groupId>
org.smart4j
</groupId>
<artifactId>
smart-plugin-security
</artifactId>
<version>
${smart.version}
</version>
</dependency>
</dependencies>
<build>
...
...
src/main/java/org/smart4j/sample/CustomSmartSecurity.java
浏览文件 @
0e7670e7
...
...
@@ -4,7 +4,7 @@ import java.util.LinkedHashSet;
import
java.util.List
;
import
java.util.Set
;
import
org.smart4j.framework.dao.DatabaseHelper
;
import
org.smart4j.security.SmartSecurity
;
import
org.smart4j.
plugin.
security.SmartSecurity
;
public
class
CustomSmartSecurity
implements
SmartSecurity
{
...
...
@@ -22,7 +22,7 @@ public class CustomSmartSecurity implements SmartSecurity {
}
@Override
public
Set
<
String
>
getPermNameSet
(
String
roleName
)
{
public
Set
<
String
>
getPerm
ission
NameSet
(
String
roleName
)
{
String
sql
=
"select distinct p.permission_name from role r, role_permission rp, permission p where r.id = rp.role_id and p.id = rp.permission_id and r.role_name = ?"
;
List
<
String
>
list
=
DatabaseHelper
.
queryColumnList
(
sql
,
roleName
);
return
new
LinkedHashSet
<
String
>(
list
);
...
...
src/main/java/org/smart4j/sample/action/ProductAction.java
浏览文件 @
0e7670e7
...
...
@@ -13,6 +13,7 @@ import org.smart4j.framework.mvc.bean.Params;
import
org.smart4j.framework.mvc.bean.Result
;
import
org.smart4j.framework.mvc.bean.View
;
import
org.smart4j.framework.util.WebUtil
;
import
org.smart4j.plugin.security.annotation.HasPermissions
;
import
org.smart4j.sample.Constant
;
import
org.smart4j.sample.Tool
;
import
org.smart4j.sample.bean.ProductBean
;
...
...
@@ -48,6 +49,7 @@ public class ProductAction {
.
data
(
"productBeanPager"
,
productBeanPager
);
}
@HasPermissions
(
"product.create"
)
@Request
.
Get
(
"/product/create"
)
public
View
create
()
{
List
<
ProductType
>
productTypeList
=
productService
.
getProductTypeList
();
...
...
src/main/java/org/smart4j/sample/action/SystemAction.java
浏览文件 @
0e7670e7
...
...
@@ -8,9 +8,9 @@ import org.smart4j.framework.mvc.bean.Result;
import
org.smart4j.framework.mvc.bean.View
;
import
org.smart4j.framework.util.StringUtil
;
import
org.smart4j.framework.util.WebUtil
;
import
org.smart4j.plugin.security.SecurityHelper
;
import
org.smart4j.plugin.security.fault.LoginException
;
import
org.smart4j.sample.Constant
;
import
org.smart4j.security.SmartSecurityHelper
;
import
org.smart4j.security.exception.LoginException
;
@Action
public
class
SystemAction
{
...
...
@@ -38,7 +38,7 @@ public class SystemAction {
}
try
{
S
martS
ecurityHelper
.
login
(
username
,
password
,
false
);
SecurityHelper
.
login
(
username
,
password
,
false
);
}
catch
(
LoginException
e
)
{
return
new
Result
(
false
);
}
...
...
@@ -48,7 +48,7 @@ public class SystemAction {
@Request
.
Get
(
"/logout"
)
public
Result
logout
()
{
S
martS
ecurityHelper
.
logout
();
SecurityHelper
.
logout
();
return
new
Result
(
true
);
}
}
src/main/java/org/smart4j/sample/service/impl/UserServiceImpl.java
浏览文件 @
0e7670e7
package
org.smart4j.sample.service.impl
;
import
org.smart4j.framework.tx.annotation.Service
;
import
org.smart4j.plugin.security.SecurityHelper
;
import
org.smart4j.sample.service.UserService
;
import
org.smart4j.security.SmartSecurityHelper
;
@Service
public
class
UserServiceImpl
implements
UserService
{
@Override
public
void
login
(
String
username
,
String
password
)
{
S
martS
ecurityHelper
.
login
(
username
,
password
,
false
);
SecurityHelper
.
login
(
username
,
password
,
false
);
}
}
src/main/resources/i18n/i18n_en_US.properties
浏览文件 @
0e7670e7
common.title
=
Smart Sample
common.copyright
=
Copyright
\u
00A9 2013
common.user
=
User
common.logout
=
Logout
common.logout_confirm
=
Do you want to logout system?
common.action
=
Action
...
...
@@ -23,6 +24,7 @@ common.captcha.change=Change a new Captcha
common.captcha.error
=
Captcha error!
error.page
=
Error Page
error.page.403
=
Access to the specified resource has been forbidden!
error.page.404
=
The requested resource is not available!
error.page.500
=
Internal server error!
...
...
src/main/resources/i18n/i18n_zh_CN.properties
浏览文件 @
0e7670e7
common.title
=
Smart
\u
793A
\u
4F8B
common.copyright
=
\u7248\u6743\u6240\u6709
\u
00A9 2013
common.user
=
\u7528\u6237
common.logout
=
\u
6CE8
\u9500
common.logout_confirm
=
\u
4F60
\u
60F3
\u
6CE8
\u9500\u
7CFB
\u
7EDF
\u5417\u
FF1F
common.action
=
\u
64CD
\u
4F5C
...
...
@@ -23,6 +24,7 @@ common.captcha.change=\u6362\u4E00\u4E2A\u65B0\u7684\u9A8C\u8BC1\u7801
common.captcha.error
=
\u
9A8C
\u
8BC1
\u7801\u9519\u
8BEF
\u
FF01
error.page
=
\u9519\u
8BEF
\u9875\u9762
error.page.403
=
\u7981\u
6B62
\u
8BBF
\u
95EE
\u6307\u
5B9A
\u7684\u
8D44
\u
6E90
\u
FF01
error.page.404
=
\u
8BF7
\u
6C42
\u7684\u
8D44
\u
6E90
\u
4E0D
\u
53EF
\u7528\u
FF01
error.page.500
=
\u5185\u
90E8
\u
670D
\u
52A1
\u5668\u9519\u
8BEF
\u
FF01
...
...
src/main/resources/shiro.ini
浏览文件 @
0e7670e7
[main]
authc.loginUrl
=
/login
authc.loginUrl
=
/login
[urls]
/
=
anon
/product/**
=
authc
\ No newline at end of file
/=anon
/product/**=authc
\ No newline at end of file
src/main/resources/smart.properties
浏览文件 @
0e7670e7
...
...
@@ -16,4 +16,4 @@ smart.security.realms=custom
smart.security.custom.class
=
org.smart4j.sample.CustomSmartSecurity
smart.security.cache
=
true
sample.upload_path
=
/www/upload/
sample.upload_path
=
/www/upload/
\ No newline at end of file
src/main/webapp/WEB-INF/jsp/common/header.jsp
浏览文件 @
0e7670e7
<%@ page
pageEncoding=
"UTF-8"
%>
<%@ taglib
prefix=
"security"
uri=
"/security"
%>
<div
id=
"header"
>
<div
id
=
"logo"
>
<div
class
=
"logo"
>
<a
href=
"${BASE}/"
><f:message
key=
"common.title"
/></a>
</div>
<div
id
=
"menu"
>
<div
class
=
"menu"
>
<a
href=
"${BASE}/product"
><f:message
key=
"product"
/></a>
</div>
<div
id=
"oper"
>
<div
class=
"oper"
>
<span><f:message
key=
"common.user"
/>
:
<security:principal/></span>
<button
type=
"button"
id=
"logout"
><f:message
key=
"common.logout"
/></button>
</div>
</div>
\ No newline at end of file
src/main/webapp/WEB-INF/jsp/error/403.jsp
0 → 100644
浏览文件 @
0e7670e7
<%@ page
pageEncoding=
"UTF-8"
%>
<%@ include
file=
"../common/global.jsp"
%>
<!DOCTYPE html>
<html>
<head>
<%@ include
file=
"../common/meta.jsp"
%>
<title><f:message
key=
"common.title"
/>
-
<f:message
key=
"error.page"
/></title>
<%@ include
file=
"../common/style.jsp"
%>
</head>
<body>
<div
id=
"header"
>
<div
class=
"logo"
>
<a
href=
"${BASE}/"
><f:message
key=
"common.title"
/></a>
</div>
</div>
<div
id=
"content"
>
<div
id=
"main"
>
<h3>
403 -
<f:message
key=
"error.page.403"
/></h3>
<a
href=
"javascript:history.back();"
><f:message
key=
"common.back"
/></a>
</div>
</div>
<%@ include
file=
"../common/footer.jsp"
%>
<%@ include
file=
"../common/script.jsp"
%>
</body>
</html>
\ No newline at end of file
src/main/webapp/WEB-INF/jsp/error/404.jsp
浏览文件 @
0e7670e7
...
...
@@ -11,7 +11,7 @@
<body>
<div
id=
"header"
>
<div
id
=
"logo"
>
<div
class
=
"logo"
>
<a
href=
"${BASE}/"
><f:message
key=
"common.title"
/></a>
</div>
</div>
...
...
src/main/webapp/WEB-INF/jsp/error/500.jsp
浏览文件 @
0e7670e7
...
...
@@ -11,7 +11,7 @@
<body>
<div
id=
"header"
>
<div
id
=
"logo"
>
<div
class
=
"logo"
>
<a
href=
"${BASE}/"
><f:message
key=
"common.title"
/></a>
</div>
</div>
...
...
src/main/webapp/WEB-INF/jsp/login.jsp
浏览文件 @
0e7670e7
...
...
@@ -11,7 +11,7 @@
<body>
<div
id=
"header"
>
<div
id
=
"logo"
>
<div
class
=
"logo"
>
<a
href=
"${BASE}/"
><f:message
key=
"common.title"
/></a>
</div>
</div>
...
...
src/main/webapp/WEB-INF/jsp/product.jsp
浏览文件 @
0e7670e7
<%@ page
pageEncoding=
"UTF-8"
%>
<%@ include
file=
"common/global.jsp"
%>
<%@ taglib
prefix=
"security"
uri=
"/security"
%>
<!DOCTYPE html>
<html>
...
...
@@ -31,7 +32,9 @@
</form>
</div>
<div
class=
"css-right"
>
<a
href=
"${BASE}/product/create"
><f:message
key=
"product.new_product"
/></a>
<security:hasPermission
name=
"product.create"
>
<a
href=
"${BASE}/product/create"
><f:message
key=
"product.new_product"
/></a>
</security:hasPermission>
</div>
</div>
<div
id=
"product_list"
>
...
...
src/main/webapp/WEB-INF/web.xml
浏览文件 @
0e7670e7
...
...
@@ -5,6 +5,10 @@
http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
version=
"3.0"
>
<error-page>
<error-code>
403
</error-code>
<location>
/WEB-INF/jsp/error/403.jsp
</location>
</error-page>
<error-page>
<error-code>
404
</error-code>
<location>
/WEB-INF/jsp/error/404.jsp
</location>
...
...
src/main/webapp/www/css/global.css
浏览文件 @
0e7670e7
...
...
@@ -113,24 +113,28 @@ img {
#header
a
{
color
:
#FFF
;
}
#header
#
logo
{
#header
.
logo
{
float
:
left
;
font-size
:
16px
;
font-weight
:
bold
;
margin
:
10px
;
}
#header
#
menu
{
#header
.
menu
{
float
:
left
;
margin
:
10px
;
}
#header
#
menu
a
{
#header
.
menu
a
{
margin
:
10px
;
}
#header
#
oper
{
#header
.
oper
{
float
:
right
;
margin
:
10px
;
}
#header
#oper
button
{
#header
.oper
span
{
height
:
20px
;
padding
:
0
5px
;
}
#header
.oper
button
{
height
:
20px
;
padding
:
0
5px
;
}
...
...
src/test/java/org/smart4j/sample/test/ShiroTest.java
0 → 100644
浏览文件 @
0e7670e7
package
org.smart4j.sample.test
;
import
org.apache.shiro.authc.credential.DefaultPasswordService
;
import
org.apache.shiro.authc.credential.PasswordService
;
import
org.junit.Assert
;
import
org.junit.Test
;
public
class
ShiroTest
{
@Test
public
void
passwordTest
()
{
String
plaintextPassword
=
"admin"
;
PasswordService
passwordService
=
new
DefaultPasswordService
();
String
encryptPassword
=
passwordService
.
encryptPassword
(
plaintextPassword
);
System
.
out
.
println
(
"encryptPassword: "
+
encryptPassword
);
Assert
.
assertTrue
(
passwordService
.
passwordsMatch
(
plaintextPassword
,
encryptPassword
));
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录