Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
后端镜像
java镜像
Springside4
提交
83fe10ae
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,发现更多精彩内容 >>
提交
83fe10ae
编写于
3月 01, 2012
作者:
C
Calvin
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
一边写文档一边小清理代码
上级
025f17c8
变更
10
隐藏空白更改
内联
并排
Showing
10 changed file
with
52 addition
and
32 deletion
+52
-32
TODO.txt
TODO.txt
+3
-4
examples/mini-service/src/main/java/org/springside/examples/miniservice/webservice/rs/server/UserResouceService.java
.../miniservice/webservice/rs/server/UserResouceService.java
+6
-6
examples/mini-web/src/main/java/org/springside/examples/miniweb/service/account/ShiroDbRealm.java
...ngside/examples/miniweb/service/account/ShiroDbRealm.java
+6
-0
examples/mini-web/src/main/resources/applicationContext-shiro.xml
.../mini-web/src/main/resources/applicationContext-shiro.xml
+6
-2
examples/mini-web/src/main/webapp/WEB-INF/sitemesh3.xml
examples/mini-web/src/main/webapp/WEB-INF/sitemesh3.xml
+2
-2
examples/mini-web/src/main/webapp/WEB-INF/views/login.jsp
examples/mini-web/src/main/webapp/WEB-INF/views/login.jsp
+15
-8
examples/showcase/src/main/java/org/springside/examples/showcase/security/ShiroDbRealm.java
...g/springside/examples/showcase/security/ShiroDbRealm.java
+6
-0
examples/showcase/src/main/resources/security/applicationContext-shiro.xml
.../src/main/resources/security/applicationContext-shiro.xml
+1
-3
examples/showcase/src/main/webapp/WEB-INF/sitemesh3.xml
examples/showcase/src/main/webapp/WEB-INF/sitemesh3.xml
+3
-3
examples/showcase/src/main/webapp/WEB-INF/views/security/login.jsp
...showcase/src/main/webapp/WEB-INF/views/security/login.jsp
+4
-4
未找到文件。
TODO.txt
浏览文件 @
83fe10ae
...
...
@@ -2,10 +2,9 @@
目标:体现Spring4.0的主体框架与选型.
TODO部分:
文档:
Shiro,Spring Profile, Mybatis提一下组合对象, blueprint,sitemesh3,hibernate validator,Selenium2, Mockito+PowerMock
已完成,计划2012.03.05发布
Jersey文档-Jersey json client,Jersey Multipart演示取消返回值multi-part
---------------------------------------------------------------------------------
已完成部分:
...
...
@@ -60,7 +59,6 @@ Shiro,Spring Profile, Mybatis提一下组合对象, blueprint,sitemesh3,hibern
* 包括Guava的Cache Builder做的简单缓存
* Review HttpClient的使用
* Review perf4j的使用
* Jersey的Jackson JSON绑定看有没有简化,并升级其他用法。
* 升级Jquery-validation用法??
* Ehcache2.x新功能演示
* JPA2.0特征
...
...
@@ -73,6 +71,7 @@ Shiro,Spring Profile, Mybatis提一下组合对象, blueprint,sitemesh3,hibern
* 参考springfuse改进404.jsp,500.jsp
* 第三方repository也移到github,依赖包次要版本升级:JSW 3.5.7, Log4jdbc,Spymemcached(需自行打包),在pom.xml中标注自己提供的包
* 在Jenkins上运行覆盖率,Checkstyle,PMD,Findbugs检查
* No Content Error
...
...
examples/mini-service/src/main/java/org/springside/examples/miniservice/webservice/rs/server/UserResouceService.java
浏览文件 @
83fe10ae
...
...
@@ -14,8 +14,8 @@ import javax.ws.rs.QueryParam;
import
javax.ws.rs.core.Context
;
import
javax.ws.rs.core.MediaType
;
import
javax.ws.rs.core.Response
;
import
javax.ws.rs.core.UriInfo
;
import
javax.ws.rs.core.Response.Status
;
import
javax.ws.rs.core.UriInfo
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
...
...
@@ -49,7 +49,7 @@ public class UserResouceService {
*/
@GET
@Path
(
"{id}"
)
@Produces
(
{
MediaType
.
APPLICATION_JSON
,
MediaType
.
APPLICATION_XML
+
WsConstants
.
CHARSET
})
@Produces
({
MediaType
.
APPLICATION_JSON
,
MediaType
.
APPLICATION_XML
+
WsConstants
.
CHARSET
})
public
UserDTO
getUser
(
@PathParam
(
"id"
)
Long
id
)
{
try
{
User
entity
=
accountManager
.
getUser
(
id
);
...
...
@@ -70,7 +70,7 @@ public class UserResouceService {
*/
@GET
@Path
(
"search"
)
@Produces
(
{
MediaType
.
APPLICATION_JSON
,
MediaType
.
APPLICATION_XML
+
WsConstants
.
CHARSET
})
@Produces
({
MediaType
.
APPLICATION_JSON
,
MediaType
.
APPLICATION_XML
+
WsConstants
.
CHARSET
})
public
List
<
UserDTO
>
searchUser
(
@QueryParam
(
"loginName"
)
String
loginName
,
@QueryParam
(
"name"
)
String
name
)
{
try
{
List
<
User
>
entityList
=
accountManager
.
searchUser
(
loginName
,
name
);
...
...
@@ -85,7 +85,7 @@ public class UserResouceService {
* 创建用户, 请求数据为POST过来的JSON/XML格式编码的DTO, 返回表示所创建用户的URI.
*/
@POST
@Consumes
(
{
MediaType
.
APPLICATION_JSON
,
MediaType
.
APPLICATION_XML
+
WsConstants
.
CHARSET
})
@Consumes
({
MediaType
.
APPLICATION_JSON
,
MediaType
.
APPLICATION_XML
+
WsConstants
.
CHARSET
})
public
Response
createUser
(
UserDTO
user
)
{
//转换并创建用户
try
{
...
...
@@ -97,10 +97,10 @@ public class UserResouceService {
return
Response
.
created
(
createdUri
).
build
();
}
catch
(
ConstraintViolationException
e
)
{
String
message
=
Validators
.
convertMessage
(
e
,
"\n"
);
throw
WebExceptionFactory
.
buildException
(
Status
.
BAD_REQUEST
.
getStatusCode
()
,
message
,
logger
);
throw
WebExceptionFactory
.
buildException
(
Status
.
BAD_REQUEST
,
message
,
logger
);
}
catch
(
DataIntegrityViolationException
e
)
{
String
message
=
"新建用户参数存在唯一性冲突(用户:"
+
user
+
")"
;
throw
WebExceptionFactory
.
buildException
(
Status
.
BAD_REQUEST
.
getStatusCode
()
,
message
,
logger
);
throw
WebExceptionFactory
.
buildException
(
Status
.
BAD_REQUEST
,
message
,
logger
);
}
catch
(
RuntimeException
e
)
{
throw
WebExceptionFactory
.
buildDefaultException
(
e
,
logger
);
}
...
...
examples/mini-web/src/main/java/org/springside/examples/miniweb/service/account/ShiroDbRealm.java
浏览文件 @
83fe10ae
...
...
@@ -77,6 +77,9 @@ public class ShiroDbRealm extends AuthorizingRealm {
this
.
accountManager
=
accountManager
;
}
/**
* 自定义Authentication对象,使得Subject除了携带用户的登录名外还可以携带更多信息.
*/
public
static
class
ShiroUser
implements
Serializable
{
private
static
final
long
serialVersionUID
=
-
1748602382963711884L
;
...
...
@@ -92,6 +95,9 @@ public class ShiroDbRealm extends AuthorizingRealm {
return
loginName
;
}
/**
* 本函数输出将作为默认的<shiro:principal/>输出.
*/
@Override
public
String
toString
()
{
return
loginName
;
...
...
examples/mini-web/src/main/resources/applicationContext-shiro.xml
浏览文件 @
83fe10ae
...
...
@@ -15,17 +15,21 @@
<bean
id=
"shiroDbRealm"
class=
"org.springside.examples.miniweb.service.account.ShiroDbRealm"
/>
<!-- Shiro Filter -->
<bean
id=
"shiroFilter"
class=
"org.springside.modules.shiro.ShiroFilterFactoryBean"
>
<bean
id=
"shiroFilter"
class=
"org.springside.modules.shiro.ShiroFilterFactoryBean"
>
<property
name=
"securityManager"
ref=
"securityManager"
/>
<property
name=
"loginUrl"
value=
"/login"
/>
<property
name=
"successUrl"
value=
"/account/user/"
/>
<property
name=
"unauthorizedUrl"
value=
"/login"
/>
<property
name=
"unauthorizedUrl"
value=
"/login
?unauthorized=true
"
/>
<property
name=
"filterChainDefinitions"
>
<value>
/login = authc
/logout = logout
/static/** = anon
/account/user/save/** = perms["user:edit"]
/account/user/delete/** = perms["user:edit"]
/account/user/** = perms["user:view"]
/account/group/save/** = perms["group:edit"]
/account/group/delete/** = perms["group:edit"]
/account/group/** = perms["group:view"]
</value>
</property>
...
...
examples/mini-web/src/main/webapp/WEB-INF/sitemesh3.xml
浏览文件 @
83fe10ae
<?xml version="1.0" encoding="UTF-8"?>
<sitemesh>
<mapping
path=
"/"
decorator=
"/WEB-INF/layouts/default.jsp"
/>
<mapping
path=
"/static"
exclude=
"true"
/>
<mapping
path=
"/
*
"
decorator=
"/WEB-INF/layouts/default.jsp"
/>
<mapping
path=
"/static
/*
"
exclude=
"true"
/>
</sitemesh>
\ No newline at end of file
examples/mini-web/src/main/webapp/WEB-INF/views/login.jsp
浏览文件 @
83fe10ae
...
...
@@ -17,14 +17,21 @@
</head>
<body>
<%
String
error
=
(
String
)
request
.
getAttribute
(
FormAuthenticationFilter
.
DEFAULT_ERROR_KEY_ATTRIBUTE_NAME
);
if
(
error
!=
null
){
%>
<div
class=
"error prepend-top"
>
登录失败,请重试.
</div>
<%
}
%>
<%
String
error
=
(
String
)
request
.
getAttribute
(
FormAuthenticationFilter
.
DEFAULT_ERROR_KEY_ATTRIBUTE_NAME
);
if
(
error
!=
null
){
%>
<div
class=
"error prepend-top"
>
登录失败,请重试.
</div>
<%
}
%>
<%
if
(
request
.
getParameter
(
"unauthorized"
)!=
null
){
%>
<div
class=
"error prepend-top"
>
用户无权限,请登录其他用户或
<a
href=
"javascript:history.back()"
>
返回上一页
</a></div>
<%
}
%>
<form:form
id=
"loginForm"
action=
"
${
ctx
}
/login"
method=
"post"
>
<fieldset
class=
"prepend-top"
>
<legend>
登录
</legend>
...
...
examples/showcase/src/main/java/org/springside/examples/showcase/security/ShiroDbRealm.java
浏览文件 @
83fe10ae
...
...
@@ -90,6 +90,9 @@ public class ShiroDbRealm extends AuthorizingRealm {
this
.
accountManager
=
accountManager
;
}
/**
* 自定义Authentication对象,使得Subject除了携带用户的登录名外还可以携带更多信息.
*/
public
static
class
ShiroUser
implements
Serializable
{
private
static
final
long
serialVersionUID
=
-
1373760761780840081L
;
private
String
loginName
;
...
...
@@ -104,6 +107,9 @@ public class ShiroDbRealm extends AuthorizingRealm {
return
loginName
;
}
/**
* 本函数输出将作为默认的<shiro:principal/>输出.
*/
@Override
public
String
toString
()
{
return
loginName
;
...
...
examples/showcase/src/main/resources/security/applicationContext-shiro.xml
浏览文件 @
83fe10ae
...
...
@@ -3,10 +3,8 @@
xsi:schemaLocation=
"http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd"
default-lazy-init=
"true"
>
<description>
Shiro安全配置
</description>
<bean
id=
"securityManager"
class=
"org.apache.shiro.web.mgt.DefaultWebSecurityManager"
>
<property
name=
"realm"
ref=
"shiroDbRealm"
/>
</bean>
...
...
@@ -17,7 +15,7 @@
<property
name=
"securityManager"
ref=
"securityManager"
/>
<property
name=
"loginUrl"
value=
"/login"
/>
<property
name=
"successUrl"
value=
"/"
/>
<property
name=
"unauthorizedUrl"
value=
"/"
/>
<property
name=
"unauthorizedUrl"
value=
"/
login?unauthorized=true
"
/>
<property
name=
"filterChainDefinitions"
>
<value>
/login = authc
...
...
examples/showcase/src/main/webapp/WEB-INF/sitemesh3.xml
浏览文件 @
83fe10ae
<?xml version="1.0" encoding="UTF-8"?>
<sitemesh>
<mapping
path=
"/"
decorator=
"/WEB-INF/layouts/default.jsp"
/>
<mapping
path=
"/static"
exclude=
"true"
/>
<mapping
path=
"/rs"
exclude=
"true"
/>
<mapping
path=
"/
*
"
decorator=
"/WEB-INF/layouts/default.jsp"
/>
<mapping
path=
"/static
/*
"
exclude=
"true"
/>
<mapping
path=
"/rs
/*
"
exclude=
"true"
/>
</sitemesh>
\ No newline at end of file
examples/showcase/src/main/webapp/WEB-INF/views/security/login.jsp
浏览文件 @
83fe10ae
...
...
@@ -20,15 +20,15 @@
<%
String
error
=
(
String
)
request
.
getAttribute
(
FormAuthenticationFilter
.
DEFAULT_ERROR_KEY_ATTRIBUTE_NAME
);
if
(
error
!=
null
){
if
(
error
.
equals
(
LockedAccountException
.
class
.
getName
()))
{
%>
<div
class=
"error prepend-top"
>
登录失败,请重试.
</div>
<%
}
else
{
}
%>
<div
class=
"error prepend-top"
>
登录失败,请重试.
</div>
<%
if
(
request
.
getParameter
(
"unauthorized"
)!=
null
){
%>
<div
class=
"error prepend-top"
>
用户无权限,请登录其他用户或
<a
href=
"javascript:history.back()"
>
返回上一页
</a></div>
<%
}
%>
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录