提交 83fe10ae 编写于 作者: C Calvin

一边写文档一边小清理代码

上级 025f17c8
......@@ -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
......
......@@ -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);
}
......
......@@ -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;
......
......@@ -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>
......
<?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
......@@ -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>
......
......@@ -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;
......
......@@ -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
......
<?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
......@@ -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.
先完成此消息的编辑!
想要评论请 注册