From 3073b0642fe88f8c05601a40811cbeed35c7b1fb Mon Sep 17 00:00:00 2001 From: lishengzhao Date: Thu, 20 Mar 2014 13:44:20 +0800 Subject: [PATCH] Change to wdcy --- .../cc/wdcy/domain/shared/BeanProvider.java | 44 ----- .../shared/paginated/DefaultPaginated.java | 179 ------------------ .../domain/shared/paginated/Paginated.java | 35 ---- .../shared/paginated/PaginatedLoader.java | 26 --- .../shared/paginated/PaginatedSort.java | 30 --- .../shared/security/SecurityHolder.java | 22 --- .../domain/shared/security/SecurityUtils.java | 31 --- src/main/java/cc/wdcy/domain/user/User.java | 10 - .../context/BeanContextLoaderListener.java | 33 ---- .../web/context/SpringSecurityHolder.java | 36 ---- .../wdcy/web/controller/UserController.java | 11 -- .../controller/mobile/MobileController.java | 11 -- .../web/controller/unity/UnityController.java | 11 -- .../web/oauth/OauthUserApprovalHandler.java | 12 -- src/main/resources/spring/security.xml | 6 - src/main/webapp/WEB-INF/web.xml | 2 +- src/test/java/cc/wdcy/ContextTest.java | 13 +- 17 files changed, 2 insertions(+), 510 deletions(-) delete mode 100644 src/main/java/cc/wdcy/domain/shared/BeanProvider.java delete mode 100644 src/main/java/cc/wdcy/domain/shared/paginated/DefaultPaginated.java delete mode 100644 src/main/java/cc/wdcy/domain/shared/paginated/Paginated.java delete mode 100644 src/main/java/cc/wdcy/domain/shared/paginated/PaginatedLoader.java delete mode 100644 src/main/java/cc/wdcy/domain/shared/paginated/PaginatedSort.java delete mode 100644 src/main/java/cc/wdcy/domain/shared/security/SecurityHolder.java delete mode 100644 src/main/java/cc/wdcy/domain/shared/security/SecurityUtils.java delete mode 100644 src/main/java/cc/wdcy/web/context/BeanContextLoaderListener.java delete mode 100644 src/main/java/cc/wdcy/web/context/SpringSecurityHolder.java diff --git a/src/main/java/cc/wdcy/domain/shared/BeanProvider.java b/src/main/java/cc/wdcy/domain/shared/BeanProvider.java deleted file mode 100644 index 2f9dff3..0000000 --- a/src/main/java/cc/wdcy/domain/shared/BeanProvider.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright (c) 2013 Honyee Industry Group Co., Ltd - * www.honyee.biz - * All rights reserved. - * - * This software is the confidential and proprietary information of - * Honyee Industry Group Co., Ltd ("Confidential Information"). - * You shall not disclose such Confidential Information and shall use - * it only in accordance with the terms of the license agreement you - * entered into with Honyee Industry Group Co., Ltd. - */ -package cc.wdcy.domain.shared; - -import org.springframework.context.ApplicationContext; - -/** - * @author Shengzhao Li - */ -public abstract class BeanProvider { - - private static ApplicationContext applicationContext; - - - public static void initialize(ApplicationContext applicationContext) { - BeanProvider.applicationContext = applicationContext; - } - - /** - * Get Bean by clazz. - * - * @param clazz Class - * @param class type - * @return Bean instance - */ - public static T getBean(Class clazz) { - return applicationContext.getBean(clazz); - } - - @SuppressWarnings("unchecked") - public static T getBean(String beanId) { - return (T) applicationContext.getBean(beanId); - } - -} \ No newline at end of file diff --git a/src/main/java/cc/wdcy/domain/shared/paginated/DefaultPaginated.java b/src/main/java/cc/wdcy/domain/shared/paginated/DefaultPaginated.java deleted file mode 100644 index 5f26f5e..0000000 --- a/src/main/java/cc/wdcy/domain/shared/paginated/DefaultPaginated.java +++ /dev/null @@ -1,179 +0,0 @@ -/* - * Copyright (c) 2013 Honyee Industry Group Co., Ltd - * www.honyee.biz - * All rights reserved. - * - * This software is the confidential and proprietary information of - * Honyee Industry Group Co., Ltd ("Confidential Information"). - * You shall not disclose such Confidential Information and shall use - * it only in accordance with the terms of the license agreement you - * entered into with Honyee Industry Group Co., Ltd. - */ -package cc.wdcy.domain.shared.paginated; - -import cc.wdcy.domain.shared.security.SecurityUtils; -import org.displaytag.pagination.PaginatedList; -import org.displaytag.properties.SortOrderEnum; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -/** - * @author Shengzhao Li - */ -public class DefaultPaginated implements Paginated, PaginatedList { - - public static final int DEFAULT_PER_PAGE_SIZE = 20; - - protected List list = new ArrayList(); - protected int perPageSize; - protected int totalSize = 0; - protected int pageNumber = 1; - - protected String sortName; - protected PaginatedSort sort; - - protected String sortCriterion; - private SortOrderEnum sortOrderEnum; - private String searchId; - - - public DefaultPaginated() { - this(DEFAULT_PER_PAGE_SIZE); - } - - public DefaultPaginated(int perPageSize) { - this.perPageSize = perPageSize; - } - - @Override - public List getList() { - return list; - } - - public Map defaultQueryMap() { - Map map = new HashMap<>(); - map.put("user", SecurityUtils.currentUser()); - map.put("perPageSize", getPerPageSize()); - map.put("startIndex", getStartIndex()); - return map; - } - - public int getTotalPages() { - if (totalSize % perPageSize == 0) { - return (totalSize / perPageSize); - } else { - return (totalSize / perPageSize) + 1; - } - } - - @Override - public int getPageNumber() { - return pageNumber; - } - - @Override - public int getObjectsPerPage() { - return perPageSize; - } - - @Override - public int getFullListSize() { - return totalSize; - } - - @Override - public String getSortCriterion() { - return sortCriterion; - } - - public void setSortCriterion(String sortCriterion) { - this.sortCriterion = sortCriterion; - } - - @Override - public SortOrderEnum getSortDirection() { - return sortOrderEnum; - } - - @Override - public String getSearchId() { - return searchId; - } - - @Override - public int getPerPageSize() { - return perPageSize; - } - - @Override - public int getTotalSize() { - return totalSize; - } - - @Override - public String getSortName() { - return sortName; - } - - @Override - public PaginatedSort getSort() { - return sort; - } - - public int getStartIndex() { - return (getPageNumber() - 1) * getPerPageSize(); - } - - @SuppressWarnings("unchecked") - public K load(PaginatedLoader paginatedLoader) { - if (this.totalSize == 0) { - this.totalSize = paginatedLoader.loadTotalSize(); - } - this.list = paginatedLoader.loadList(); - afterLoad(); - return (K) this; - } - - public void afterLoad() { - // Callback after load data. - } - - public void setPerPageSize(int perPageSize) { - this.perPageSize = perPageSize; - } - - public void setTotalSize(int totalSize) { - this.totalSize = totalSize; - } - - public void setPageNumber(int pageNumber) { - this.pageNumber = pageNumber; - } - - public void setSortName(String sortName) { - this.sortName = sortName; - } - - public void setSort(PaginatedSort sort) { - this.sort = sort; - } - - public boolean isHasNext() { - return (getStartIndex() + this.perPageSize < totalSize); - } - - public boolean isHasPrevious() { - return getStartIndex() != 0; - } - - public void setSortOrderEnum(SortOrderEnum sortOrderEnum) { - this.sortOrderEnum = sortOrderEnum; - } - - public void setSearchId(String searchId) { - this.searchId = searchId; - } -} \ No newline at end of file diff --git a/src/main/java/cc/wdcy/domain/shared/paginated/Paginated.java b/src/main/java/cc/wdcy/domain/shared/paginated/Paginated.java deleted file mode 100644 index 7b15165..0000000 --- a/src/main/java/cc/wdcy/domain/shared/paginated/Paginated.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright (c) 2013 Honyee Industry Group Co., Ltd - * www.honyee.biz - * All rights reserved. - * - * This software is the confidential and proprietary information of - * Honyee Industry Group Co., Ltd ("Confidential Information"). - * You shall not disclose such Confidential Information and shall use - * it only in accordance with the terms of the license agreement you - * entered into with Honyee Industry Group Co., Ltd. - */ -package cc.wdcy.domain.shared.paginated; - -import java.util.List; - -/** - * @author Shengzhao Li - */ - -public interface Paginated { - - List getList(); - - int getPageNumber(); - - int getPerPageSize(); - - int getTotalSize(); - - String getSortName(); - - PaginatedSort getSort(); - - int getTotalPages(); -} \ No newline at end of file diff --git a/src/main/java/cc/wdcy/domain/shared/paginated/PaginatedLoader.java b/src/main/java/cc/wdcy/domain/shared/paginated/PaginatedLoader.java deleted file mode 100644 index 2a452a4..0000000 --- a/src/main/java/cc/wdcy/domain/shared/paginated/PaginatedLoader.java +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (c) 2013 Honyee Industry Group Co., Ltd - * www.honyee.biz - * All rights reserved. - * - * This software is the confidential and proprietary information of - * Honyee Industry Group Co., Ltd ("Confidential Information"). - * You shall not disclose such Confidential Information and shall use - * it only in accordance with the terms of the license agreement you - * entered into with Honyee Industry Group Co., Ltd. - */ -package cc.wdcy.domain.shared.paginated; - -import java.util.List; - -/** - * @author Shengzhao Li - */ - -public interface PaginatedLoader { - - List loadList(); - - int loadTotalSize(); - -} \ No newline at end of file diff --git a/src/main/java/cc/wdcy/domain/shared/paginated/PaginatedSort.java b/src/main/java/cc/wdcy/domain/shared/paginated/PaginatedSort.java deleted file mode 100644 index 13c4867..0000000 --- a/src/main/java/cc/wdcy/domain/shared/paginated/PaginatedSort.java +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Copyright (c) 2013 Honyee Industry Group Co., Ltd - * www.honyee.biz - * All rights reserved. - * - * This software is the confidential and proprietary information of - * Honyee Industry Group Co., Ltd ("Confidential Information"). - * You shall not disclose such Confidential Information and shall use - * it only in accordance with the terms of the license agreement you - * entered into with Honyee Industry Group Co., Ltd. - */ -package cc.wdcy.domain.shared.paginated; - -/** - * @author Shengzhao Li - */ -public enum PaginatedSort { - ASC("asc"), - DESC("desc"); - - private String label; - - PaginatedSort(String label) { - this.label = label; - } - - public String getLabel() { - return label; - } -} \ No newline at end of file diff --git a/src/main/java/cc/wdcy/domain/shared/security/SecurityHolder.java b/src/main/java/cc/wdcy/domain/shared/security/SecurityHolder.java deleted file mode 100644 index c4127c3..0000000 --- a/src/main/java/cc/wdcy/domain/shared/security/SecurityHolder.java +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Copyright (c) 2013 Honyee Industry Group Co., Ltd - * www.honyee.biz - * All rights reserved. - * - * This software is the confidential and proprietary information of - * Honyee Industry Group Co., Ltd ("Confidential Information"). - * You shall not disclose such Confidential Information and shall use - * it only in accordance with the terms of the license agreement you - * entered into with Honyee Industry Group Co., Ltd. - */ -package cc.wdcy.domain.shared.security; - -/** - * @author Shengzhao Li - */ - -public interface SecurityHolder { - - WdcyUserDetails userDetails(); - -} \ No newline at end of file diff --git a/src/main/java/cc/wdcy/domain/shared/security/SecurityUtils.java b/src/main/java/cc/wdcy/domain/shared/security/SecurityUtils.java deleted file mode 100644 index c96dc6e..0000000 --- a/src/main/java/cc/wdcy/domain/shared/security/SecurityUtils.java +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright (c) 2013 Honyee Industry Group Co., Ltd - * www.honyee.biz - * All rights reserved. - * - * This software is the confidential and proprietary information of - * Honyee Industry Group Co., Ltd ("Confidential Information"). - * You shall not disclose such Confidential Information and shall use - * it only in accordance with the terms of the license agreement you - * entered into with Honyee Industry Group Co., Ltd. - */ -package cc.wdcy.domain.shared.security; - -import cc.wdcy.domain.user.User; - -/** - * @author Shengzhao Li - */ -public class SecurityUtils { - - private static SecurityHolder securityHolder; - - public void setSecurityHolder(SecurityHolder securityHolder) { - SecurityUtils.securityHolder = securityHolder; - } - - public static User currentUser() { - WdcyUserDetails userDetails = securityHolder.userDetails(); - return (userDetails != null ? userDetails.user() : null); - } -} \ No newline at end of file diff --git a/src/main/java/cc/wdcy/domain/user/User.java b/src/main/java/cc/wdcy/domain/user/User.java index d5d7ac9..378deba 100644 --- a/src/main/java/cc/wdcy/domain/user/User.java +++ b/src/main/java/cc/wdcy/domain/user/User.java @@ -12,7 +12,6 @@ package cc.wdcy.domain.user; import cc.wdcy.domain.AbstractDomain; -import cc.wdcy.domain.shared.BeanProvider; import java.util.Date; @@ -21,7 +20,6 @@ import java.util.Date; */ public class User extends AbstractDomain { - private transient UserRepository userRepository = BeanProvider.getBean(UserRepository.class); private String username; private String password; @@ -86,14 +84,6 @@ public class User extends AbstractDomain { return this; } - @Override - public void saveOrUpdate() { - if (isNewly()) { - userRepository.saveUser(this); - } else { - userRepository.updateUser(this); - } - } public User username(String username) { this.username = username; diff --git a/src/main/java/cc/wdcy/web/context/BeanContextLoaderListener.java b/src/main/java/cc/wdcy/web/context/BeanContextLoaderListener.java deleted file mode 100644 index 4f3c1d0..0000000 --- a/src/main/java/cc/wdcy/web/context/BeanContextLoaderListener.java +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2013 Honyee Industry Group Co., Ltd - * www.honyee.biz - * All rights reserved. - * - * This software is the confidential and proprietary information of - * Honyee Industry Group Co., Ltd ("Confidential Information"). - * You shall not disclose such Confidential Information and shall use - * it only in accordance with the terms of the license agreement you - * entered into with Honyee Industry Group Co., Ltd. - */ -package cc.wdcy.web.context; - -import cc.wdcy.domain.shared.BeanProvider; -import org.springframework.web.context.ContextLoaderListener; -import org.springframework.web.context.WebApplicationContext; -import org.springframework.web.context.support.WebApplicationContextUtils; - -import javax.servlet.ServletContextEvent; - -/** - * @author Shengzhao Li - */ -public class BeanContextLoaderListener extends ContextLoaderListener { - - - @Override - public void contextInitialized(ServletContextEvent event) { - super.contextInitialized(event); - WebApplicationContext applicationContext = WebApplicationContextUtils.getRequiredWebApplicationContext(event.getServletContext()); - BeanProvider.initialize(applicationContext); - } -} \ No newline at end of file diff --git a/src/main/java/cc/wdcy/web/context/SpringSecurityHolder.java b/src/main/java/cc/wdcy/web/context/SpringSecurityHolder.java deleted file mode 100644 index fa47f6b..0000000 --- a/src/main/java/cc/wdcy/web/context/SpringSecurityHolder.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright (c) 2013 Honyee Industry Group Co., Ltd - * www.honyee.biz - * All rights reserved. - * - * This software is the confidential and proprietary information of - * Honyee Industry Group Co., Ltd ("Confidential Information"). - * You shall not disclose such Confidential Information and shall use - * it only in accordance with the terms of the license agreement you - * entered into with Honyee Industry Group Co., Ltd. - */ -package cc.wdcy.web.context; - -import cc.wdcy.domain.shared.security.WdcyUserDetails; -import cc.wdcy.domain.shared.security.SecurityHolder; -import org.springframework.security.core.Authentication; -import org.springframework.security.core.context.SecurityContextHolder; - -/** - * @author Shengzhao Li - */ -public class SpringSecurityHolder implements SecurityHolder { - - @Override - public WdcyUserDetails userDetails() { - Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); - if (authentication == null) { - return null; - } - Object principal = authentication.getPrincipal(); - if (principal instanceof WdcyUserDetails) { - return (WdcyUserDetails) principal; - } - return null; - } -} \ No newline at end of file diff --git a/src/main/java/cc/wdcy/web/controller/UserController.java b/src/main/java/cc/wdcy/web/controller/UserController.java index 706dc07..8966e42 100644 --- a/src/main/java/cc/wdcy/web/controller/UserController.java +++ b/src/main/java/cc/wdcy/web/controller/UserController.java @@ -1,14 +1,3 @@ -/* - * Copyright (c) 2013 Honyee Industry Group Co., Ltd - * www.honyee.biz - * All rights reserved. - * - * This software is the confidential and proprietary information of - * Honyee Industry Group Co., Ltd ("Confidential Information"). - * You shall not disclose such Confidential Information and shall use - * it only in accordance with the terms of the license agreement you - * entered into with Honyee Industry Group Co., Ltd. - */ package cc.wdcy.web.controller; import cc.wdcy.service.UserService; diff --git a/src/main/java/cc/wdcy/web/controller/mobile/MobileController.java b/src/main/java/cc/wdcy/web/controller/mobile/MobileController.java index 66e3442..118ec18 100644 --- a/src/main/java/cc/wdcy/web/controller/mobile/MobileController.java +++ b/src/main/java/cc/wdcy/web/controller/mobile/MobileController.java @@ -1,14 +1,3 @@ -/* - * Copyright (c) 2013 Honyee Industry Group Co., Ltd - * www.honyee.biz - * All rights reserved. - * - * This software is the confidential and proprietary information of - * Honyee Industry Group Co., Ltd ("Confidential Information"). - * You shall not disclose such Confidential Information and shall use - * it only in accordance with the terms of the license agreement you - * entered into with Honyee Industry Group Co., Ltd. - */ package cc.wdcy.web.controller.mobile; import org.springframework.stereotype.Controller; diff --git a/src/main/java/cc/wdcy/web/controller/unity/UnityController.java b/src/main/java/cc/wdcy/web/controller/unity/UnityController.java index e9bea07..e536fbb 100644 --- a/src/main/java/cc/wdcy/web/controller/unity/UnityController.java +++ b/src/main/java/cc/wdcy/web/controller/unity/UnityController.java @@ -1,14 +1,3 @@ -/* - * Copyright (c) 2013 Honyee Industry Group Co., Ltd - * www.honyee.biz - * All rights reserved. - * - * This software is the confidential and proprietary information of - * Honyee Industry Group Co., Ltd ("Confidential Information"). - * You shall not disclose such Confidential Information and shall use - * it only in accordance with the terms of the license agreement you - * entered into with Honyee Industry Group Co., Ltd. - */ package cc.wdcy.web.controller.unity; import org.springframework.stereotype.Controller; diff --git a/src/main/java/cc/wdcy/web/oauth/OauthUserApprovalHandler.java b/src/main/java/cc/wdcy/web/oauth/OauthUserApprovalHandler.java index 1ba17d5..f77e567 100644 --- a/src/main/java/cc/wdcy/web/oauth/OauthUserApprovalHandler.java +++ b/src/main/java/cc/wdcy/web/oauth/OauthUserApprovalHandler.java @@ -1,15 +1,3 @@ -/* - * Copyright (c) 2013 Honyee Industry Group Co., Ltd - * www.honyee.biz - * All rights reserved. - * - * This software is the confidential and proprietary information of - * Honyee Industry Group Co., Ltd ("Confidential Information"). - * You shall not disclose such Confidential Information and shall use - * it only in accordance with the terms of the license agreement you - * entered into with Honyee Industry Group Co., Ltd. - */ - package cc.wdcy.web.oauth; import cc.wdcy.domain.oauth.OauthClientDetails; diff --git a/src/main/resources/spring/security.xml b/src/main/resources/spring/security.xml index 499322e..cb3a3de 100644 --- a/src/main/resources/spring/security.xml +++ b/src/main/resources/spring/security.xml @@ -171,11 +171,5 @@ Oauth server end............. --> - - - - - - \ No newline at end of file diff --git a/src/main/webapp/WEB-INF/web.xml b/src/main/webapp/WEB-INF/web.xml index 5f55f00..a089ccb 100644 --- a/src/main/webapp/WEB-INF/web.xml +++ b/src/main/webapp/WEB-INF/web.xml @@ -72,7 +72,7 @@ - cc.wdcy.web.context.BeanContextLoaderListener + org.springframework.web.context.ContextLoaderListener diff --git a/src/test/java/cc/wdcy/ContextTest.java b/src/test/java/cc/wdcy/ContextTest.java index 3eaa667..b9ea46d 100644 --- a/src/test/java/cc/wdcy/ContextTest.java +++ b/src/test/java/cc/wdcy/ContextTest.java @@ -1,9 +1,5 @@ package cc.wdcy; -import cc.wdcy.domain.shared.BeanProvider; -import cc.wdcy.domain.shared.security.WdcyUserDetails; -import cc.wdcy.domain.shared.security.SecurityUtils; -import cc.wdcy.web.context.SpringSecurityHolder; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.testng.AbstractTransactionalTestNGSpringContextTests; import org.springframework.test.context.transaction.BeforeTransaction; @@ -16,13 +12,6 @@ public abstract class ContextTest extends AbstractTransactionalTestNGSpringConte @BeforeTransaction public void beforeTest() { - BeanProvider.initialize(applicationContext); - SecurityUtils securityUtils = new SecurityUtils(); - securityUtils.setSecurityHolder(new SpringSecurityHolder() { - @Override - public WdcyUserDetails userDetails() { - return null; - } - }); + } } \ No newline at end of file