diff --git a/TODO.txt b/TODO.txt index 733d802a..5826c89b 100644 --- a/TODO.txt +++ b/TODO.txt @@ -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 diff --git a/examples/mini-service/src/main/java/org/springside/examples/miniservice/webservice/rs/server/UserResouceService.java b/examples/mini-service/src/main/java/org/springside/examples/miniservice/webservice/rs/server/UserResouceService.java index 7485b034..40c4a1d2 100644 --- a/examples/mini-service/src/main/java/org/springside/examples/miniservice/webservice/rs/server/UserResouceService.java +++ b/examples/mini-service/src/main/java/org/springside/examples/miniservice/webservice/rs/server/UserResouceService.java @@ -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 searchUser(@QueryParam("loginName") String loginName, @QueryParam("name") String name) { try { List 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); } diff --git a/examples/mini-web/src/main/java/org/springside/examples/miniweb/service/account/ShiroDbRealm.java b/examples/mini-web/src/main/java/org/springside/examples/miniweb/service/account/ShiroDbRealm.java index 4771f530..4b8c8f1f 100644 --- a/examples/mini-web/src/main/java/org/springside/examples/miniweb/service/account/ShiroDbRealm.java +++ b/examples/mini-web/src/main/java/org/springside/examples/miniweb/service/account/ShiroDbRealm.java @@ -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; } + /** + * 本函数输出将作为默认的输出. + */ @Override public String toString() { return loginName; diff --git a/examples/mini-web/src/main/resources/applicationContext-shiro.xml b/examples/mini-web/src/main/resources/applicationContext-shiro.xml index b0c08402..927c44fb 100644 --- a/examples/mini-web/src/main/resources/applicationContext-shiro.xml +++ b/examples/mini-web/src/main/resources/applicationContext-shiro.xml @@ -15,17 +15,21 @@ - + - + /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"] diff --git a/examples/mini-web/src/main/webapp/WEB-INF/sitemesh3.xml b/examples/mini-web/src/main/webapp/WEB-INF/sitemesh3.xml index d0d30e2c..1919fbfa 100644 --- a/examples/mini-web/src/main/webapp/WEB-INF/sitemesh3.xml +++ b/examples/mini-web/src/main/webapp/WEB-INF/sitemesh3.xml @@ -1,5 +1,5 @@ - - + + \ No newline at end of file diff --git a/examples/mini-web/src/main/webapp/WEB-INF/views/login.jsp b/examples/mini-web/src/main/webapp/WEB-INF/views/login.jsp index 15e1079c..ac3f4661 100644 --- a/examples/mini-web/src/main/webapp/WEB-INF/views/login.jsp +++ b/examples/mini-web/src/main/webapp/WEB-INF/views/login.jsp @@ -17,14 +17,21 @@ -<% - String error = (String) request.getAttribute(FormAuthenticationFilter.DEFAULT_ERROR_KEY_ATTRIBUTE_NAME); - if(error != null){ - %> -
登录失败,请重试.
- <% - } - %> + <% + String error = (String) request.getAttribute(FormAuthenticationFilter.DEFAULT_ERROR_KEY_ATTRIBUTE_NAME); + if(error != null){ + %> +
登录失败,请重试.
+ <% + } + %> + <% + if(request.getParameter("unauthorized")!=null){ + %> +
用户无权限,请登录其他用户或返回上一页
+ <% + } + %>
登录 diff --git a/examples/showcase/src/main/java/org/springside/examples/showcase/security/ShiroDbRealm.java b/examples/showcase/src/main/java/org/springside/examples/showcase/security/ShiroDbRealm.java index 87fadc17..556e1b58 100644 --- a/examples/showcase/src/main/java/org/springside/examples/showcase/security/ShiroDbRealm.java +++ b/examples/showcase/src/main/java/org/springside/examples/showcase/security/ShiroDbRealm.java @@ -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; } + /** + * 本函数输出将作为默认的输出. + */ @Override public String toString() { return loginName; diff --git a/examples/showcase/src/main/resources/security/applicationContext-shiro.xml b/examples/showcase/src/main/resources/security/applicationContext-shiro.xml index f32bd3f0..f9061ae0 100644 --- a/examples/showcase/src/main/resources/security/applicationContext-shiro.xml +++ b/examples/showcase/src/main/resources/security/applicationContext-shiro.xml @@ -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"> - Shiro安全配置 - @@ -17,7 +15,7 @@ - + /login = authc diff --git a/examples/showcase/src/main/webapp/WEB-INF/sitemesh3.xml b/examples/showcase/src/main/webapp/WEB-INF/sitemesh3.xml index ef8132f1..57351c93 100644 --- a/examples/showcase/src/main/webapp/WEB-INF/sitemesh3.xml +++ b/examples/showcase/src/main/webapp/WEB-INF/sitemesh3.xml @@ -1,6 +1,6 @@ - - - + + + \ No newline at end of file diff --git a/examples/showcase/src/main/webapp/WEB-INF/views/security/login.jsp b/examples/showcase/src/main/webapp/WEB-INF/views/security/login.jsp index a3cd7dab..a88f170d 100644 --- a/examples/showcase/src/main/webapp/WEB-INF/views/security/login.jsp +++ b/examples/showcase/src/main/webapp/WEB-INF/views/security/login.jsp @@ -20,15 +20,15 @@ <% String error = (String) request.getAttribute(FormAuthenticationFilter.DEFAULT_ERROR_KEY_ATTRIBUTE_NAME); if(error != null){ - if(error.equals(LockedAccountException.class.getName())) { %>
登录失败,请重试.
<% - }else{ - } %> -
登录失败,请重试.
+ <% + if(request.getParameter("unauthorized")!=null){ + %> +
用户无权限,请登录其他用户或返回上一页
<% } %>