diff --git a/lib/org/logback-extensions/logback-ext-parent/0.1.2-SNAPSHOT/_remote.repositories b/lib/org/logback-extensions/logback-ext-parent/0.1.2-SNAPSHOT/_remote.repositories new file mode 100644 index 0000000..01bcd62 --- /dev/null +++ b/lib/org/logback-extensions/logback-ext-parent/0.1.2-SNAPSHOT/_remote.repositories @@ -0,0 +1,3 @@ +#NOTE: This is an Aether internal implementation file, its format can be changed without prior notice. +#Thu Nov 07 15:05:54 CST 2013 +logback-ext-parent-0.1.2-SNAPSHOT.pom>= diff --git a/lib/org/logback-extensions/logback-ext-parent/0.1.2-SNAPSHOT/logback-ext-parent-0.1.2-SNAPSHOT.pom b/lib/org/logback-extensions/logback-ext-parent/0.1.2-SNAPSHOT/logback-ext-parent-0.1.2-SNAPSHOT.pom new file mode 100644 index 0000000..4544713 --- /dev/null +++ b/lib/org/logback-extensions/logback-ext-parent/0.1.2-SNAPSHOT/logback-ext-parent-0.1.2-SNAPSHOT.pom @@ -0,0 +1,414 @@ + + + + 4.0.0 + + + org.sonatype.oss + oss-parent + 7 + + + org.logback-extensions + logback-ext-parent + pom + 0.1.2-SNAPSHOT + + Logback Extensions + https://github.com/qos-ch/logback-extensions/wiki + + Logback Extensions provides community-driven and supported extensions to the Logback logging framework. + + 2012 + + + + Apache License, Version 2.0 + http://www.apache.org/licenses/LICENSE-2.0 + repo + + + + + scm:git:git://github.com/qos-ch/logback-extensions.git + scm:git:git@github.com:qos-ch/logback-extensions.git + https://github.com/qos-ch/logback-extensions + + + GitHub + https://github.com/qos-ch/logback-extensions/issues + + + + + lhazlewood + Les Hazlewood + les@hazlewood.com + http://www.leshazlewood.com + -8 + + + belaso + Christian Trutz + christian.trutz@belaso.de + http://www.belaso.de + +2 + + + tony19 + Tony Trinh + tony19@gmail.com + http://tony19.github.com + -5 + + + + + + spring + + + + UTF-8 + + + 1.0.9 + 1.9.5 + 3.1.1.RELEASE + 2.7.3 + + + 3.1 + 1.8.6 + 0.999.15 + 4.8.2 + + + + + + + org.codehaus.groovy + groovy-all + ${groovy.version} + test + + + org.easymock + easymock + ${easymock.version} + test + + + com.googlecode.jmockit + jmockit + ${jmockit.version} + test + + + junit + junit + ${junit.version} + test + + + + + + + + + + + + + + ch.qos.logback + logback-access + ${logback.version} + + + + ch.qos.logback + logback-classic + ${logback.version} + + + + ch.qos.logback + logback-core + ${logback.version} + + + + + ch.qos.logback.extensions + logback-ext-jackson + + ${project.version} + + + + ch.qos.logback.extensions + logback-ext-json-classic + + ${project.version} + + + ch.qos.logback.extensions + logback-ext-json-core + + ${project.version} + + + + + javax.servlet + servlet-api + 2.5 + provided + true + + + org.codehaus.jackson + jackson-mapper-asl + ${jackson.version} + provided + + + + org.springframework + spring-context + ${spring.version} + provided + true + + + commons-logging + commons-logging + + + + + org.springframework + spring-web + ${spring.version} + provided + true + + + commons-logging + commons-logging + + + + + + org.mongodb + mongo-java-driver + ${mongo-java-driver.version} + provided + + + + + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 2.3.2 + + 1.6 + 1.6 + UTF-8 + + + + + org.codehaus.gmaven + gmaven-plugin + 1.4 + + 1.7 + src/main/groovy + + + + org.codehaus.gmaven.runtime + gmaven-runtime-1.7 + 1.3 + + + org.codehaus.groovy + groovy-all + + + + + org.codehaus.groovy + groovy-all + ${groovy.version} + + + + + org.eclipse.m2e + lifecycle-mapping + 1.0.0 + + + + + + org.codehaus.gmaven + gmaven-plugin + [1.0.0,) + + testCompile + + + + + + + + + + + + + + + + + org.codehaus.gmaven + gmaven-plugin + + + + + testCompile + + + + + + + org.apache.maven.plugins + maven-release-plugin + 2.2.2 + + clean install + true + false + + deploy + -Prelease + forked-path + + + + + + + + release + + + + org.apache.maven.plugins + maven-javadoc-plugin + 2.8.1 + + + attach-api-docs + + + jar + + + + true + + + org.apache.maven.plugins + maven-source-plugin + 2.1.2 + + + attach-sources + + jar + + + + true + + + + + + + release-sign-artifacts + + + performRelease + true + + + + + + org.apache.maven.plugins + maven-gpg-plugin + 1.4 + + + sign-artifacts + verify + + sign + + + + + + + + + + diff --git a/lib/org/logback-extensions/logback-ext-parent/0.1.2-SNAPSHOT/maven-metadata-basedir.xml b/lib/org/logback-extensions/logback-ext-parent/0.1.2-SNAPSHOT/maven-metadata-basedir.xml new file mode 100644 index 0000000..57f2852 --- /dev/null +++ b/lib/org/logback-extensions/logback-ext-parent/0.1.2-SNAPSHOT/maven-metadata-basedir.xml @@ -0,0 +1,6 @@ + + + org.logback-extensions + logback-ext-parent + 0.1.2-SNAPSHOT + diff --git a/lib/org/logback-extensions/logback-ext-parent/0.1.2-SNAPSHOT/maven-metadata-local.xml b/lib/org/logback-extensions/logback-ext-parent/0.1.2-SNAPSHOT/maven-metadata-local.xml new file mode 100644 index 0000000..01794d9 --- /dev/null +++ b/lib/org/logback-extensions/logback-ext-parent/0.1.2-SNAPSHOT/maven-metadata-local.xml @@ -0,0 +1,19 @@ + + + org.logback-extensions + logback-ext-parent + 0.1.2-SNAPSHOT + + + true + + 20131107070554 + + + pom + 0.1.2-SNAPSHOT + 20131107070554 + + + + diff --git a/lib/org/logback-extensions/logback-ext-parent/maven-metadata-local.xml b/lib/org/logback-extensions/logback-ext-parent/maven-metadata-local.xml new file mode 100644 index 0000000..6203676 --- /dev/null +++ b/lib/org/logback-extensions/logback-ext-parent/maven-metadata-local.xml @@ -0,0 +1,11 @@ + + + org.logback-extensions + logback-ext-parent + + + 0.1.2-SNAPSHOT + + 20131107070554 + + diff --git a/lib/org/logback-extensions/logback-ext-spring/0.1.2-SNAPSHOT/_remote.repositories b/lib/org/logback-extensions/logback-ext-spring/0.1.2-SNAPSHOT/_remote.repositories new file mode 100644 index 0000000..029cd3d --- /dev/null +++ b/lib/org/logback-extensions/logback-ext-spring/0.1.2-SNAPSHOT/_remote.repositories @@ -0,0 +1,4 @@ +#NOTE: This is an Aether internal implementation file, its format can be changed without prior notice. +#Thu Nov 07 12:01:52 CST 2013 +logback-ext-spring-0.1.2-SNAPSHOT.jar>= +logback-ext-spring-0.1.2-SNAPSHOT.pom>= diff --git a/lib/org/logback-extensions/logback-ext-spring/0.1.2-SNAPSHOT/logback-ext-spring-0.1.2-SNAPSHOT.pom b/lib/org/logback-extensions/logback-ext-spring/0.1.2-SNAPSHOT/logback-ext-spring-0.1.2-SNAPSHOT.pom new file mode 100644 index 0000000..8fd692c --- /dev/null +++ b/lib/org/logback-extensions/logback-ext-spring/0.1.2-SNAPSHOT/logback-ext-spring-0.1.2-SNAPSHOT.pom @@ -0,0 +1,51 @@ + + + + + org.logback-extensions + logback-ext-parent + 0.1.2-SNAPSHOT + + + 4.0.0 + logback-ext-spring + Logback Extensions :: Spring + jar + + + + ch.qos.logback + logback-classic + + + + org.springframework + spring-context + + + + org.springframework + spring-web + + + javax.servlet + servlet-api + + + + + diff --git a/lib/org/logback-extensions/logback-ext-spring/0.1.2-SNAPSHOT/maven-metadata-local.xml b/lib/org/logback-extensions/logback-ext-spring/0.1.2-SNAPSHOT/maven-metadata-local.xml new file mode 100644 index 0000000..b720bcc --- /dev/null +++ b/lib/org/logback-extensions/logback-ext-spring/0.1.2-SNAPSHOT/maven-metadata-local.xml @@ -0,0 +1,24 @@ + + + org.logback-extensions + logback-ext-spring + 0.1.2-SNAPSHOT + + + true + + 20131107040152 + + + jar + 0.1.2-SNAPSHOT + 20131107040152 + + + pom + 0.1.2-SNAPSHOT + 20131107040152 + + + + diff --git a/lib/org/logback-extensions/logback-ext-spring/maven-metadata-local.xml b/lib/org/logback-extensions/logback-ext-spring/maven-metadata-local.xml new file mode 100644 index 0000000..89e1ddf --- /dev/null +++ b/lib/org/logback-extensions/logback-ext-spring/maven-metadata-local.xml @@ -0,0 +1,11 @@ + + + org.logback-extensions + logback-ext-spring + + + 0.1.2-SNAPSHOT + + 20131107040152 + + diff --git a/others/database/initial_data.ddl b/others/database/initial_data.ddl new file mode 100644 index 0000000..d7ffe61 --- /dev/null +++ b/others/database/initial_data.ddl @@ -0,0 +1,20 @@ +-- Initial database pre data +-- admin, password is honyee2013 +insert into user_(id,guid,create_time,email,password,phone,username,default_user) +values +(21,'29f6004fb1b0466f9572b02bf2ac1be8',now(),'admin@honyee.cc','69f71fbb5b41bd481d5d3b28a02a0b7e','028-65536867','admin',true); + + +-- initial oauth client details test data +truncate oauth_client_details; +insert into oauth_client_details +(client_id, resource_ids, client_secret, scope, authorized_grant_types, +web_server_redirect_uri,authorities, access_token_validity, +refresh_token_validity, additional_information, create_time, archived, trusted) +values +('unity-client','unity-resource', 'unity', 'read,write','password,authorization_code,refresh_token,implicit', +null,'ROLE_UNITY',null, +null,null, now(), 0, 0), +('mobile-client','mobile-resource', 'mobile', 'read,write','password,authorization_code,refresh_token,implicit', +null,'ROLE_MOBILE',null, +null,null, now(), 0, 0); diff --git a/others/database/initial_db.ddl b/others/database/initial_db.ddl new file mode 100644 index 0000000..4a470fc --- /dev/null +++ b/others/database/initial_db.ddl @@ -0,0 +1,29 @@ +-- ############### +-- create database , if need create, cancel the comment +-- ############### +-- create database if not exists jiuzhai default character set utf8; +-- use jiuzhai set default character = utf8; + +-- ############### +-- grant privileges to jiuzhai/jiuzhai +-- ############### +-- GRANT ALL PRIVILEGES ON jiuzhai.* TO jiuzhai@localhost IDENTIFIED BY "jiuzhai"; + +-- ############### +-- Domain: User +-- ############### +Drop table if exists user_; +CREATE TABLE `user_` ( + `id` int(11) NOT NULL auto_increment, + `guid` varchar(255) not null unique, + `create_time` datetime , + `archived` tinyint(1) default '0', + `email` varchar(255), + `password` varchar(255) not null, + `phone` varchar(255), + `username` varchar(255) not null unique, + `default_user` tinyint(1) default '0', + `last_login_time` datetime , + PRIMARY KEY (`id`) +) ENGINE=InnoDB AUTO_INCREMENT=20 DEFAULT CHARSET=utf8; + diff --git a/others/database/oauth.ddl b/others/database/oauth.ddl new file mode 100644 index 0000000..08eeeac --- /dev/null +++ b/others/database/oauth.ddl @@ -0,0 +1,56 @@ +-- +-- Oauth sql -- MYSQL +-- + +Drop table if exists oauth_client_details; +create table oauth_client_details ( + client_id VARCHAR(256) PRIMARY KEY, + resource_ids VARCHAR(256), + client_secret VARCHAR(256), + scope VARCHAR(256), + authorized_grant_types VARCHAR(256), + web_server_redirect_uri VARCHAR(256), + authorities VARCHAR(256), + access_token_validity INTEGER, + refresh_token_validity INTEGER, + additional_information VARCHAR(4096), + create_time datetime, + archived tinyint(1) default '0', + trusted tinyint(1) default '0' +); + +Drop table if exists oauth_client_token; +create table oauth_client_token ( + token_id VARCHAR(256), + token BLOB, + authentication_id VARCHAR(256), + user_name VARCHAR(256), + client_id VARCHAR(256) +); + +Drop table if exists oauth_access_token; +create table oauth_access_token ( + token_id VARCHAR(256), + token BLOB, + authentication_id VARCHAR(256), + user_name VARCHAR(256), + client_id VARCHAR(256), + authentication BLOB, + refresh_token VARCHAR(256) +); + +Drop table if exists oauth_refresh_token; +create table oauth_refresh_token ( + token_id VARCHAR(256), + token BLOB, + authentication BLOB +); + +Drop table if exists oauth_code; +create table oauth_code ( + code VARCHAR(256), authentication BLOB +); + + + + diff --git a/others/intellij_templates.txt b/others/intellij_templates.txt new file mode 100644 index 0000000..74ee6f1 --- /dev/null +++ b/others/intellij_templates.txt @@ -0,0 +1,124 @@ +-------------------IN 'TEMPLATES'------------- +Class: + +/* + * 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 ${PACKAGE_NAME}; + +#parse("File Header.java") +public class ${NAME} { +} + + + +Interface: + +/* + * 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 ${PACKAGE_NAME}; + +#parse("File Header.java") + +public interface ${NAME} { +} + + +Enum: + +/* + * 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 ${PACKAGE_NAME}; + +#parse("File Header.java") + +public enum ${NAME} { +} + + +AnnotationType: + +/* + * 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 ${PACKAGE_NAME}; + +#parse("File Header.java") + +public @interface ${NAME} { +} + +------------------IN 'CODE'------------- +Implemented, New & Overridden method body: +throw new UnsupportedOperationException("Not yet implemented"); + +Catch Statement Body +${EXCEPTION}.printStackTrace(); + + + +-----------------IN 'INCLUDES'-------------------- +ActionScript File Header , File Header: please replace the author. + +/** + * + * @author Shengzhao Li + */ + + +-----------------IN 'Java EE'-------------------- +Web -> Jsp files -> Jsp File.jsp +Change the comment content as follow, change the author to self name. + +<%-- + * 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. +--%> +<%-- + * + * @author Shengzhao Li +--%> + + + diff --git a/others/oauth_test.txt b/others/oauth_test.txt new file mode 100644 index 0000000..80c4fc8 --- /dev/null +++ b/others/oauth_test.txt @@ -0,0 +1,10 @@ + +方式1:基于浏览器 +http://localhost:8080/oauth/authorize?client_id=unity-client&redirect_uri=http%3a%2f%2flocalhost%3a8080%2funity%2fdashboard.htm&response_type=code&scope=read + +方式2:基于客户端 +http://localhost:8080/oauth/token?client_id=unity-client&client_secret=unity&grant_type=password&scope=read,write&username=admin&password=honyee2013 + + + +{"access_token":"3420d0e0-ed77-45e1-8370-2b55af0a62e8","token_type":"bearer","refresh_token":"b36f4978-a172-4aa8-af89-60f58abe3ba1","expires_in":43199,"scope":"read write"} diff --git a/others/项目开发规范.txt b/others/项目开发规范.txt new file mode 100644 index 0000000..80d3109 --- /dev/null +++ b/others/项目开发规范.txt @@ -0,0 +1,99 @@ + + + +ĿһЩ淶Ծء + + +>> 1.ʹ汾Ϣ + + * JDK 1.7.0_40 + * Maven 3.1.0 + * IDEA 11.1.3 + * Tomcat 6.0.33 + * MySQL 5.5 + * TortoiseSVN 1.7.7 + * Git 1.7.10 + + +(࿪汾ڵһʹõʱָ) +[ʹͬ汾] + + + + +>> 2.Ҫ + + + * ӢлݼCtrl+Shift+Home + * IDEAпݼ + + ݿ⿪ + *(table)ֶ(column)ȫСд»߷ָuser; user_detail; color_def + *SQLűдʹùߵ + *κֶΣȷҪ⣬ҪκԼǿԼ + *ݿipoݿipo_test + + Hibernate + *ӳļֹʹmany-to-manyone-to-many 滻 + *ӳļͳһinfrastructureģpersistence.hibernate.mappingĿ¼ + *DomainԽӳ䣬ӳļʹ + + + IDEA + *Զ(ݼCtrl+Alt+L) + *μintellij_templates.txt + + SVNʹҪ + *ÿύǰȸ + *ύʱдע(Comment)ǹύĵĹܵ + *ȷڱرͨһܣͨreviewύ + + +>> 3.ĿҪ + + *֧֣IE7-9 Safari + *DTOܴ뵽Domain + *ServiceIJ뷵ֵǻDTODomain + *service㲻κҵ + *IJƵ4 + + *壬JSPļ(package)ҪȫСд磺companyform.jspcom.achievo.ipo + շ磺CompanyController + *ҵ񷽷DomainݿдԪԣʹTestNG + *Serviceapplication.xmlļУRepositoryinfrastructure.xmlļУControlleripo-servlet.xmlļ + *Ŀӵservice(com.achievo.ipo.serviceӰ)Serviceloadͷķֻֻ֧д + *URLҪ + 1.URLðģ黮Ŀ¼CompanyģĶĿ¼Ϊ/companyCompanyURLڸĿ¼£CompanyURLΪ/company/add + ༭CompanyURLΪ/company/editɾURLΪ/company/deleteOverviewURLΪ/company/overview + URL书絼Ϊ/company/export вURL磺/company/edit?guid=1223-soed-dȡ + 2). URLʱģҽṹ. + 3). ҳϵURLʹ··(contextPath) + 4). URLþһ书 + + *ڻȡSpringеʵʱʹBeanProvider.getBean(Class clazz)ȡDomainлȡRepositoryķ£ + + private transient BacklogRepository backlogRepository = BeanProvider.getBean(BacklogRepository.class); + + ʹʱ£ + public void saveOrUpdate() { + getRepository().saveOrUpdate(this); + } + + *ǰ̨ʹJQUERYز + * + *κ½Repository̳RepositoryӿڣHibernateʵ̳AbstractRepository(û)һʾ£ + + public interface DoctorQualificationRepository extends Repository { + //codes + } + + public class DoctorQualificationRepositoryHibernate extends AbstractRepository implements DoctorQualificationRepository { + //codes + } + + + +4. + + + diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..96f865c --- /dev/null +++ b/pom.xml @@ -0,0 +1,443 @@ + + + 4.0.0 + + honyee.cc + spring-oauth-server + 1.0 + spring-oauth-server + war + Spring Oauth Server + + + UTF-8 + 3.1.1.RELEASE + 3.1.0.RELEASE + 1.6.10 + 3.2.1 + + + com.mysql.jdbc.Driver + jdbc:mysql://ec2-23-21-211-172.compute-1.amazonaws.com:3306/jiuzhai_test?autoReconnect=true&useUnicode=true&characterEncoding=utf8 + honyee + honyee + + false + false + + + + Jenkins + https://honyee.ci.cloudbees.com/ + + + + + shengzhao + shengzhao@honyee.cc + + + + + + + spring-oauth-server + + + + org.apache.maven.plugins + maven-compiler-plugin + 2.3.2 + + utf-8 + 1.7 + 1.7 + + + + + maven-war-plugin + 2.0.2 + + + + + ${project.version} + + + honyee.cc + + + honyee.cc + + + ${project.name} + + + ${project.version} + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + maven-surefire-plugin + 2.4 + + ${test.skip} + none + + **/*Test.java + + + + jdbc.url + ${jdbc.url} + + + jdbc.username + ${jdbc.user} + + + jdbc.password + ${jdbc.pass} + + + + + + + + + src/main/resources + + **/* + + + + database.properties + mail.properties + + + + + + src/test/resources + + **/* + + + + + + + + + javax.servlet + servlet-api + 2.4 + provided + + + javax.servlet.jsp + jsp-api + 2.1 + provided + + + + + net.sf.ehcache + ehcache-web + 2.0.4 + + + javax.mail + mail + 1.4 + compile + + + opensymphony + sitemesh + 2.4 + + + org.aspectj + aspectjrt + ${aspectj.version} + compile + + + org.aspectj + aspectjweaver + ${aspectj.version} + compile + + + commons-dbcp + commons-dbcp + 1.4 + + + commons-fileupload + commons-fileupload + 1.2.2 + + + commons-io + commons-io + 2.4 + + + + org.springframework + spring-aop + ${spring.version} + + + org.springframework + spring-beans + ${spring.version} + + + org.springframework + spring-context + ${spring.version} + + + org.springframework + spring-core + ${spring.version} + + + org.springframework + spring-orm + ${spring.version} + + + org.springframework + spring-tx + ${spring.version} + + + org.springframework + spring-expression + ${spring.version} + + + org.springframework + spring-web + ${spring.version} + + + org.springframework + spring-webmvc + ${spring.version} + + + org.springframework + spring-context-support + ${spring.version} + + + + org.springframework.security + spring-security-core + ${spring.security.version} + + + org.springframework.security + spring-security-web + ${spring.security.version} + + + org.springframework.security + spring-security-taglibs + ${spring.security.version} + + + org.springframework.security + spring-security-acl + ${spring.security.version} + + + org.springframework.security + spring-security-crypto + ${spring.security.version} + + + org.springframework.security + spring-security-config + ${spring.security.version} + + + + org.springframework.security.oauth + spring-security-oauth2 + 1.0.5.RELEASE + + + + mysql + mysql-connector-java + 5.1.6 + compile + + + + + + + + + + org.antlr + antlr-runtime + 3.3 + compile + + + org.antlr + stringtemplate + 3.2.1 + + + + ch.qos.logback + logback-classic + 1.0.13 + + + org.logback-extensions + logback-ext-spring + 0.1.2-SNAPSHOT + + + org.slf4j + jul-to-slf4j + 1.7.5 + + + + com.google.zxing + javase + 2.2 + + + + + org.mybatis + mybatis + ${mybatis.version} + + + org.mybatis + mybatis-spring + 1.1.1 + + + javax.servlet + jstl + 1.1.2 + + + taglibs + standard + 1.1.2 + compile + + + + net.sf.json-lib + json-lib + 2.4 + jdk15 + + + displaytag + displaytag + 1.2 + + + org.slf4j + slf4j-log4j12 + + + org.slf4j + jcl104-over-slf4j + + + + + + + org.springframework + spring-test + ${spring.version} + test + + + org.easymock + easymock + 3.0 + test + + + org.testng + testng + 6.1.1 + test + + + + + + basedir + file://${project.basedir}/lib/ + + + + \ No newline at end of file diff --git a/src/main/java/cc/honyee/domain/AbstractDomain.java b/src/main/java/cc/honyee/domain/AbstractDomain.java new file mode 100644 index 0000000..acd53cc --- /dev/null +++ b/src/main/java/cc/honyee/domain/AbstractDomain.java @@ -0,0 +1,108 @@ +/* + * 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.honyee.domain; + +import cc.honyee.infrastructure.DateUtils; +import cc.honyee.domain.shared.GuidGenerator; + +import java.io.Serializable; +import java.util.Date; + +/** + * @author Shengzhao Li + */ +public abstract class AbstractDomain implements Serializable { + + /** + * Database id + */ + protected int id; + + protected boolean archived; + /** + * Domain business guid. + */ + protected String guid = GuidGenerator.generate(); + + /** + * The domain create time. + */ + protected Date createTime = DateUtils.now(); + + public AbstractDomain() { + } + + public int id() { + return id; + } + + public void id(int id) { + this.id = id; + } + + public boolean archived() { + return archived; + } + + public AbstractDomain archived(boolean archived) { + this.archived = archived; + return this; + } + + public String guid() { + return guid; + } + + public void guid(String guid) { + this.guid = guid; + } + + public Date createTime() { + return createTime; + } + + public boolean isNewly() { + return id == 0; + } + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (!(o instanceof AbstractDomain)) { + return false; + } + AbstractDomain that = (AbstractDomain) o; + return guid.equals(that.guid); + } + + @Override + public int hashCode() { + return guid.hashCode(); + } + + //For subclass override it + public void saveOrUpdate() { + } + + @Override + public String toString() { + final StringBuilder sb = new StringBuilder(); + sb.append("{id=").append(id); + sb.append(", archived=").append(archived); + sb.append(", guid='").append(guid).append('\''); + sb.append(", createTime=").append(createTime); + sb.append('}'); + return sb.toString(); + } +} \ No newline at end of file diff --git a/src/main/java/cc/honyee/domain/dto/AbstractDto.java b/src/main/java/cc/honyee/domain/dto/AbstractDto.java new file mode 100644 index 0000000..d0ab41f --- /dev/null +++ b/src/main/java/cc/honyee/domain/dto/AbstractDto.java @@ -0,0 +1,43 @@ +/* + * 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.honyee.domain.dto; + +import org.apache.commons.lang.StringUtils; + +import java.io.Serializable; + +/** + * @author Shengzhao Li + */ +public abstract class AbstractDto implements Serializable { + + protected String guid; + + protected AbstractDto() { + } + + protected AbstractDto(String guid) { + this.guid = guid; + } + + public boolean isNewly() { + return StringUtils.isEmpty(guid); + } + + public String getGuid() { + return guid; + } + + public void setGuid(String guid) { + this.guid = guid; + } +} \ No newline at end of file diff --git a/src/main/java/cc/honyee/domain/dto/user/UserDto.java b/src/main/java/cc/honyee/domain/dto/user/UserDto.java new file mode 100644 index 0000000..f1c7d55 --- /dev/null +++ b/src/main/java/cc/honyee/domain/dto/user/UserDto.java @@ -0,0 +1,94 @@ +/* + * 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.honyee.domain.dto.user; + +import cc.honyee.domain.dto.AbstractDto; +import cc.honyee.domain.user.User; +import cc.honyee.infrastructure.DateUtils; + +import java.util.ArrayList; +import java.util.List; + +/** + * @author Shengzhao Li + */ +public class UserDto extends AbstractDto { + + protected String username; + protected String createDate; + + protected String phone; + protected String email; + protected boolean defaultUser; + + + public UserDto() { + } + + public UserDto(User user) { + super(user.guid()); + this.username = user.username(); + this.createDate = DateUtils.toDateText(user.createTime()); + + this.phone = user.phone(); + this.email = user.email(); + this.defaultUser = user.defaultUser(); + } + + public boolean isDefaultUser() { + return defaultUser; + } + + public void setDefaultUser(boolean defaultUser) { + this.defaultUser = defaultUser; + } + + public String getUsername() { + return username; + } + + public void setUsername(String username) { + this.username = username; + } + + public String getCreateDate() { + return createDate; + } + + public void setCreateDate(String createDate) { + this.createDate = createDate; + } + + public String getPhone() { + return phone; + } + + public void setPhone(String phone) { + this.phone = phone; + } + + public String getEmail() { + return email; + } + + public void setEmail(String email) { + this.email = email; + } + + public static List toDtos(List users) { + List dtoList = new ArrayList<>(users.size()); + for (User user : users) { + dtoList.add(new UserDto(user)); + } + return dtoList; + } +} \ No newline at end of file diff --git a/src/main/java/cc/honyee/domain/dto/user/UserFormDto.java b/src/main/java/cc/honyee/domain/dto/user/UserFormDto.java new file mode 100644 index 0000000..8285714 --- /dev/null +++ b/src/main/java/cc/honyee/domain/dto/user/UserFormDto.java @@ -0,0 +1,73 @@ +/* + * 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.honyee.domain.dto.user; + +import cc.honyee.domain.user.User; +import cc.honyee.infrastructure.PasswordHandler; + +/** + * @author Shengzhao Li + */ +public class UserFormDto extends UserDto { + + private String password; + private String rePassword; + + private String existUsername; + + public UserFormDto() { + } + + public UserFormDto(User user) { + super(user); + this.existUsername = user.username(); + } + + public UserFormDto(String guid) { + this.guid = guid; + } + + @Override + public boolean isNewly() { + return super.isNewly() || "create".equalsIgnoreCase(guid); + } + + public User toDomain() { + String encryptPass = PasswordHandler.encryptPassword(password); + return new User(username, encryptPass, phone, email); + } + + + public String getPassword() { + return password; + } + + public void setPassword(String password) { + this.password = password; + } + + public String getRePassword() { + return rePassword; + } + + public void setRePassword(String rePassword) { + this.rePassword = rePassword; + } + + public String getExistUsername() { + return existUsername; + } + + public void setExistUsername(String existUsername) { + this.existUsername = existUsername; + } +} \ No newline at end of file diff --git a/src/main/java/cc/honyee/domain/oauth/CustomJdbcClientDetailsService.java b/src/main/java/cc/honyee/domain/oauth/CustomJdbcClientDetailsService.java new file mode 100644 index 0000000..16f836c --- /dev/null +++ b/src/main/java/cc/honyee/domain/oauth/CustomJdbcClientDetailsService.java @@ -0,0 +1,36 @@ +/* + * 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.honyee.domain.oauth; + +import org.springframework.security.oauth2.provider.JdbcClientDetailsService; + +import javax.sql.DataSource; + +/** + * Add archived = 0 condition + * + * @author Shengzhao Li + */ +public class CustomJdbcClientDetailsService extends JdbcClientDetailsService { + + private static final String SELECT_CLIENT_DETAILS_SQL = "select client_id, client_secret, resource_ids, scope, authorized_grant_types, " + + "web_server_redirect_uri, authorities, access_token_validity, refresh_token_validity, additional_information " + + "from oauth_client_details where client_id = ? and archived = 0 "; + + + public CustomJdbcClientDetailsService(DataSource dataSource) { + super(dataSource); + setSelectClientDetailsSql(SELECT_CLIENT_DETAILS_SQL); + } + + +} \ No newline at end of file diff --git a/src/main/java/cc/honyee/domain/oauth/OauthClientDetails.java b/src/main/java/cc/honyee/domain/oauth/OauthClientDetails.java new file mode 100644 index 0000000..920ba98 --- /dev/null +++ b/src/main/java/cc/honyee/domain/oauth/OauthClientDetails.java @@ -0,0 +1,85 @@ +/* + * 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.honyee.domain.oauth; + +import cc.honyee.infrastructure.DateUtils; + +import java.io.Serializable; +import java.util.Date; + +/** + * @author Shengzhao Li + */ +public class OauthClientDetails implements Serializable { + + + private Date createTime = DateUtils.now(); + private boolean archived = false; + + private String clientId; + private String resourceIds; + + private String clientSecret; + /** + * Available values: read,write + */ + private String scope; + + /** + * grant types include + * "authorization_code", "password", "assertion", and "refresh_token". + * Default value is "authorization_code,refresh_token". + */ + private String authorizedGrantTypes = "authorization_code,refresh_token"; + + /** + * The re-direct URI(s) established during registration (optional, comma separated). + */ + private String webServerRedirectUri; + + /** + * Authorities that are granted to the client (comma-separated). Distinct from the authorities + * granted to the user on behalf of whom the client is acting. + *

+ * For example: ROLE_USER + */ + private String authorities; + + /** + * The access token validity period in seconds (optional). + * If unspecified a global default will be applied by the token services. + */ + private Integer accessTokenValidity; + + /** + * The refresh token validity period in seconds (optional). + * If unspecified a global default will be applied by the token services. + */ + private Integer refreshTokenValidity; + + // optional + private String additionalInformation; + + /** + * The client is trusted or not. If it is trust, will skip approve step + * default false. + */ + private boolean trusted = false; + + public OauthClientDetails() { + } + + + public boolean trusted() { + return trusted; + } +} \ No newline at end of file diff --git a/src/main/java/cc/honyee/domain/oauth/OauthRepository.java b/src/main/java/cc/honyee/domain/oauth/OauthRepository.java new file mode 100644 index 0000000..db49ff3 --- /dev/null +++ b/src/main/java/cc/honyee/domain/oauth/OauthRepository.java @@ -0,0 +1,22 @@ +/* + * 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.honyee.domain.oauth; + +import cc.honyee.domain.shared.Repository; + +/** + * @author Shengzhao Li + */ +public interface OauthRepository extends Repository { + + OauthClientDetails findOauthClientDetails(String clientId); +} \ No newline at end of file diff --git a/src/main/java/cc/honyee/domain/shared/BeanProvider.java b/src/main/java/cc/honyee/domain/shared/BeanProvider.java new file mode 100644 index 0000000..3a66360 --- /dev/null +++ b/src/main/java/cc/honyee/domain/shared/BeanProvider.java @@ -0,0 +1,44 @@ +/* + * 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.honyee.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/honyee/domain/shared/GuidGenerator.java b/src/main/java/cc/honyee/domain/shared/GuidGenerator.java new file mode 100644 index 0000000..abac230 --- /dev/null +++ b/src/main/java/cc/honyee/domain/shared/GuidGenerator.java @@ -0,0 +1,24 @@ +/* + * 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.honyee.domain.shared; + +import java.util.UUID; + +/** + * @author Shengzhao Li + */ +public abstract class GuidGenerator { + + public static String generate() { + return UUID.randomUUID().toString().replaceAll("-", ""); + } +} \ No newline at end of file diff --git a/src/main/java/cc/honyee/domain/shared/Repository.java b/src/main/java/cc/honyee/domain/shared/Repository.java new file mode 100644 index 0000000..6196ead --- /dev/null +++ b/src/main/java/cc/honyee/domain/shared/Repository.java @@ -0,0 +1,19 @@ +/* + * 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.honyee.domain.shared; + +/** + * @author Shengzhao Li + */ + +public interface Repository { +} \ No newline at end of file diff --git a/src/main/java/cc/honyee/domain/shared/paginated/DefaultPaginated.java b/src/main/java/cc/honyee/domain/shared/paginated/DefaultPaginated.java new file mode 100644 index 0000000..8d0dd48 --- /dev/null +++ b/src/main/java/cc/honyee/domain/shared/paginated/DefaultPaginated.java @@ -0,0 +1,179 @@ +/* + * 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.honyee.domain.shared.paginated; + +import cc.honyee.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/honyee/domain/shared/paginated/Paginated.java b/src/main/java/cc/honyee/domain/shared/paginated/Paginated.java new file mode 100644 index 0000000..6f0f095 --- /dev/null +++ b/src/main/java/cc/honyee/domain/shared/paginated/Paginated.java @@ -0,0 +1,35 @@ +/* + * 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.honyee.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/honyee/domain/shared/paginated/PaginatedLoader.java b/src/main/java/cc/honyee/domain/shared/paginated/PaginatedLoader.java new file mode 100644 index 0000000..1fbe3b3 --- /dev/null +++ b/src/main/java/cc/honyee/domain/shared/paginated/PaginatedLoader.java @@ -0,0 +1,26 @@ +/* + * 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.honyee.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/honyee/domain/shared/paginated/PaginatedSort.java b/src/main/java/cc/honyee/domain/shared/paginated/PaginatedSort.java new file mode 100644 index 0000000..591f303 --- /dev/null +++ b/src/main/java/cc/honyee/domain/shared/paginated/PaginatedSort.java @@ -0,0 +1,30 @@ +/* + * 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.honyee.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/honyee/domain/shared/security/HonyeeUserDetails.java b/src/main/java/cc/honyee/domain/shared/security/HonyeeUserDetails.java new file mode 100644 index 0000000..8e2c509 --- /dev/null +++ b/src/main/java/cc/honyee/domain/shared/security/HonyeeUserDetails.java @@ -0,0 +1,98 @@ +/* + * 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.honyee.domain.shared.security; + +import cc.honyee.infrastructure.DateUtils; +import cc.honyee.domain.user.User; +import org.springframework.security.core.GrantedAuthority; +import org.springframework.security.core.authority.SimpleGrantedAuthority; +import org.springframework.security.core.userdetails.UserDetails; + +import java.util.Arrays; +import java.util.Collection; + +/** + * @author Shengzhao Li + */ +public class HonyeeUserDetails implements UserDetails { + + protected static final String ROLE_PREFIX = "ROLE_"; + protected static final GrantedAuthority DEFAULT_USER_ROLE = new SimpleGrantedAuthority(ROLE_PREFIX + "USER"); + protected static final GrantedAuthority ADMIN_USER_ROLE = new SimpleGrantedAuthority(ROLE_PREFIX + "ADMIN"); + + protected User user; + + + public HonyeeUserDetails() { + } + + public HonyeeUserDetails(User user) { + this.user = user; + } + + @Override + public Collection getAuthorities() { +// if (user.defaultUser()) { +// return Arrays.asList(ADMIN_USER_ROLE, DEFAULT_USER_ROLE); +// } + return Arrays.asList(DEFAULT_USER_ROLE, new SimpleGrantedAuthority(ROLE_PREFIX + "UNITY"), new SimpleGrantedAuthority(ROLE_PREFIX + "MOBILE")); + } + + @Override + public String getPassword() { + return user.password(); + } + + @Override + public String getUsername() { + return user.username(); + } + + @Override + public boolean isAccountNonExpired() { + return true; + } + + @Override + public boolean isAccountNonLocked() { + return true; + } + + @Override + public boolean isCredentialsNonExpired() { + return true; + } + + @Override + public boolean isEnabled() { + return true; + } + + public User user() { + return user; + } + + public String getLastLoginTime() { + if (user != null && user.lastLoginTime() != null) { + return DateUtils.toDateText(user.lastLoginTime(), DateUtils.DEFAULT_DATE_TIME_FORMAT); + } + return "---"; + } + + @Override + public String toString() { + final StringBuilder sb = new StringBuilder(); + sb.append("{user=").append(user); + sb.append('}'); + return sb.toString(); + } +} \ No newline at end of file diff --git a/src/main/java/cc/honyee/domain/shared/security/SecurityHolder.java b/src/main/java/cc/honyee/domain/shared/security/SecurityHolder.java new file mode 100644 index 0000000..544a804 --- /dev/null +++ b/src/main/java/cc/honyee/domain/shared/security/SecurityHolder.java @@ -0,0 +1,22 @@ +/* + * 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.honyee.domain.shared.security; + +/** + * @author Shengzhao Li + */ + +public interface SecurityHolder { + + HonyeeUserDetails userDetails(); + +} \ No newline at end of file diff --git a/src/main/java/cc/honyee/domain/shared/security/SecurityUtils.java b/src/main/java/cc/honyee/domain/shared/security/SecurityUtils.java new file mode 100644 index 0000000..203d842 --- /dev/null +++ b/src/main/java/cc/honyee/domain/shared/security/SecurityUtils.java @@ -0,0 +1,31 @@ +/* + * 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.honyee.domain.shared.security; + +import cc.honyee.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() { + HonyeeUserDetails userDetails = securityHolder.userDetails(); + return (userDetails != null ? userDetails.user() : null); + } +} \ No newline at end of file diff --git a/src/main/java/cc/honyee/domain/user/User.java b/src/main/java/cc/honyee/domain/user/User.java new file mode 100644 index 0000000..a5f5720 --- /dev/null +++ b/src/main/java/cc/honyee/domain/user/User.java @@ -0,0 +1,119 @@ +/* + * 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.honyee.domain.user; + +import cc.honyee.domain.AbstractDomain; +import cc.honyee.domain.shared.BeanProvider; +import cc.honyee.infrastructure.PasswordHandler; + +import java.util.Date; + +/** + * @author Shengzhao Li + */ +public class User extends AbstractDomain { + + private transient UserRepository userRepository = BeanProvider.getBean(UserRepository.class); + + private String username; + private String password; + + private String phone; + private String email; + //Default user is initial when create database, do not delete + private boolean defaultUser = false; + + private Date lastLoginTime; + + public User() { + } + + public User(String username, String password, String phone, String email) { + this.username = username; + this.password = password; + this.phone = phone; + this.email = email; + } + + public boolean defaultUser() { + return defaultUser; + } + + public String username() { + return username; + } + + public String password() { + return password; + } + + public String phone() { + return phone; + } + + public String email() { + return email; + } + + @Override + public String toString() { + final StringBuilder sb = new StringBuilder(); + sb.append("{username='").append(username).append('\''); + sb.append(", phone='").append(phone).append('\''); + sb.append(", id='").append(id).append('\''); + sb.append(", guid='").append(guid).append('\''); + sb.append(", defaultUser='").append(defaultUser).append('\''); + sb.append(", email='").append(email).append('\''); + sb.append('}'); + return sb.toString(); + } + + public User email(String email) { + this.email = email; + return this; + } + + public User phone(String phone) { + this.phone = phone; + return this; + } + + @Override + public void saveOrUpdate() { + if (isNewly()) { + userRepository.saveUser(this); + } else { + userRepository.updateUser(this); + } + } + + public User username(String username) { + this.username = username; + return this; + } + + public String resetPassword() { + String newOriginalPass = PasswordHandler.randomPassword(); + this.password = PasswordHandler.encryptPassword(newOriginalPass); + this.saveOrUpdate(); + return newOriginalPass; + } + + + public Date lastLoginTime() { + return lastLoginTime; + } + + public void lastLoginTime(Date lastLoginTime) { + this.lastLoginTime = lastLoginTime; + } +} \ No newline at end of file diff --git a/src/main/java/cc/honyee/domain/user/UserRepository.java b/src/main/java/cc/honyee/domain/user/UserRepository.java new file mode 100644 index 0000000..5757e56 --- /dev/null +++ b/src/main/java/cc/honyee/domain/user/UserRepository.java @@ -0,0 +1,30 @@ +/* + * 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.honyee.domain.user; + +import cc.honyee.domain.shared.Repository; + +/** + * @author Shengzhao Li + */ + +public interface UserRepository extends Repository { + + User findByGuid(String guid); + + void saveUser(User user); + + void updateUser(User user); + + User findByUsername(String username); + +} \ No newline at end of file diff --git a/src/main/java/cc/honyee/infrastructure/DateUtils.java b/src/main/java/cc/honyee/infrastructure/DateUtils.java new file mode 100644 index 0000000..e343477 --- /dev/null +++ b/src/main/java/cc/honyee/infrastructure/DateUtils.java @@ -0,0 +1,135 @@ +/* + * 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.honyee.infrastructure; + +import org.apache.commons.lang.StringUtils; + +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.Calendar; +import java.util.Date; + +/** + * @author Shengzhao Li + */ +public abstract class DateUtils { + + /** + * Default time format : yyyy-MM-dd HH:mm:ss + */ + public static final String DEFAULT_DATE_TIME_FORMAT = "yyyy-MM-dd HH:mm:ss"; + + /** + * Time format : yyyy-MM-dd HH:mm + */ + public static final String DATE_TIME_FORMAT = "yyyy-MM-dd HH:mm"; + public static final String TIME_FORMAT = "HH:mm"; + + /** + * Default date format + */ + public static final String DATE_FORMAT = "yyyy-MM-dd"; + /** + * Default month format + */ + public static final String MONTH_FORMAT = "yyyy-MM"; + /** + * Default day format + */ + public static final String DAY_FORMAT = "dd"; + + public static final long DAY_MILLISECONDS = (1000l * 60 * 60 * 24); + + //Date pattern, demo: 2013-09-11 + public static final String DATE_PATTERN = "^[0-9]{4}\\-[0-9]{2}\\-[0-9]{2}$"; + + + public static boolean isDate(String dateAsText) { + return StringUtils.isNotEmpty(dateAsText) && dateAsText.matches(DATE_PATTERN); + } + + public static Date now() { + return new Date(); + } + + public static String toDateText(Date date) { + return toDateText(date, DATE_FORMAT); + } + + public static String toDateText(Date date, String pattern) { + if (date == null || pattern == null) { + return null; + } + SimpleDateFormat dateFormat = new SimpleDateFormat(pattern); + return dateFormat.format(date); + } + + public static Date getDate(String dateText) { + return getDate(dateText, DATE_FORMAT); + } + + + public static Date getDate(String dateText, String pattern) { + SimpleDateFormat dateFormat = new SimpleDateFormat(pattern); + try { + return dateFormat.parse(dateText); + } catch (ParseException e) { + throw new IllegalStateException("Parse date from [" + dateText + "," + pattern + "] failed", e); + } + } + + public static String toDateTime(Date date) { + return toDateText(date, DATE_TIME_FORMAT); + } + + + /** + * Return current year. + * + * @return Current year + */ + public static int currentYear() { + return calendar().get(Calendar.YEAR); + } + + public static Calendar calendar() { + return Calendar.getInstance(); + } + + public static boolean isToday(Date date) { + if (date == null) { + return false; + } + String dateAsText = toDateText(date); + String todayAsText = toDateText(now()); + return dateAsText.equals(todayAsText); + } + + /** + * Get tow dates period as days, + * return -1 if the start or end is null + * + * @param start Start date + * @param end End date + * @return Period as days or -1 + */ + public static long periodAsDays(Date start, Date end) { + if (start == null || end == null) { + return -1; + } + start = org.apache.commons.lang.time.DateUtils.truncate(start, Calendar.DAY_OF_MONTH); + end = org.apache.commons.lang.time.DateUtils.truncate(end, Calendar.DAY_OF_MONTH); + + long periodAsMilliSeconds = end.getTime() - start.getTime(); + return (periodAsMilliSeconds / (DAY_MILLISECONDS)); + } +} \ No newline at end of file diff --git a/src/main/java/cc/honyee/infrastructure/DimensionalCodeHelper.java b/src/main/java/cc/honyee/infrastructure/DimensionalCodeHelper.java new file mode 100644 index 0000000..2928b57 --- /dev/null +++ b/src/main/java/cc/honyee/infrastructure/DimensionalCodeHelper.java @@ -0,0 +1,59 @@ +/* + * 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.honyee.infrastructure; + +import com.google.zxing.BarcodeFormat; +import com.google.zxing.EncodeHintType; +import com.google.zxing.WriterException; +import com.google.zxing.client.j2se.MatrixToImageWriter; +import com.google.zxing.common.BitMatrix; +import com.google.zxing.qrcode.QRCodeWriter; + +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.util.HashMap; +import java.util.Map; + +/** + * @author Shengzhao Li + */ +public abstract class DimensionalCodeHelper { + + + //Default size: 200 * 200 + public static byte[] encode(String content) { + return encode(content, 200, 200); + } + + + public static byte[] encode(String content, int width, int height) { + Map hints = new HashMap<>(); + hints.put(EncodeHintType.CHARACTER_SET, "UTF-8"); + + QRCodeWriter qrCodeWriter = new QRCodeWriter(); + BitMatrix matrix; + try { + matrix = qrCodeWriter.encode(content, BarcodeFormat.QR_CODE, width, height, hints); + } catch (WriterException e) { + throw new IllegalStateException(e); + } + + ByteArrayOutputStream os = new ByteArrayOutputStream(); + try { + MatrixToImageWriter.writeToStream(matrix, "png", os); + } catch (IOException e) { + throw new IllegalStateException(e); + } + return os.toByteArray(); + } + +} \ No newline at end of file diff --git a/src/main/java/cc/honyee/infrastructure/MatchUtils.java b/src/main/java/cc/honyee/infrastructure/MatchUtils.java new file mode 100644 index 0000000..d2b3704 --- /dev/null +++ b/src/main/java/cc/honyee/infrastructure/MatchUtils.java @@ -0,0 +1,47 @@ +/* + * 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.honyee.infrastructure; + +import org.apache.commons.lang.StringUtils; + +/** + * @author Shengzhao Li + */ +public abstract class MatchUtils { + + /** + * BigDecimal regex. + */ + public static final String BIG_DECIMAL_REGEX = "^(\\d+)||(\\d+\\.\\d+)$"; + + /** + * Positive Number regex. + */ + public static final String POSITIVE_NUMBER_REGEX = "^\\d+$"; + + /** + * Email regex. + */ + public static final String EMAIL_REGEX = ".+@.+\\.[a-z]+"; + + public static boolean isBigDecimal(String text) { + return StringUtils.isNotEmpty(text) && text.matches(BIG_DECIMAL_REGEX); + } + + public static boolean isEmail(String email) { + return StringUtils.isNotEmpty(email) && email.matches(EMAIL_REGEX); + } + + public static boolean isPositiveNumber(String numberText) { + return StringUtils.isNotEmpty(numberText) && numberText.matches(POSITIVE_NUMBER_REGEX); + } +} \ No newline at end of file diff --git a/src/main/java/cc/honyee/infrastructure/PasswordHandler.java b/src/main/java/cc/honyee/infrastructure/PasswordHandler.java new file mode 100644 index 0000000..36ff12a --- /dev/null +++ b/src/main/java/cc/honyee/infrastructure/PasswordHandler.java @@ -0,0 +1,79 @@ +/* + * 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.honyee.infrastructure; + +import cc.honyee.domain.shared.GuidGenerator; +import org.springframework.security.authentication.encoding.Md5PasswordEncoder; +import org.springframework.util.StringUtils; + +/** + * @author Shengzhao Li + */ +public abstract class PasswordHandler { + + + /** + * Encrypt factor, use it for reversible password + */ + private static final int ENCRYPT_FACTOR = 7; + + /** + * Return a random password from {@link java.util.UUID}, + * the length is 8. + * + * @return Random password + */ + public static String randomPassword() { + String uuid = GuidGenerator.generate(); + return uuid.substring(0, 8); + } + + /** + * Encrypt password ,if original password is empty, + * will call {@link #randomPassword()} get a random original password. + * + * @param originalPassword Original password + * @return Encrypted password + */ + public static String encryptPassword(String originalPassword) { + Md5PasswordEncoder md5PasswordEncoder = new Md5PasswordEncoder(); + return md5PasswordEncoder.encodePassword(originalPassword, null); + } + + /** + * Encrypt the reversible password + * + * @param originalPassword originalPassword + * @return encrypted password + */ + public static String encryptReversiblePassword(String originalPassword) { + if (!StringUtils.hasText(originalPassword)) { + return originalPassword; + } + byte[] bytes = originalPassword.getBytes(); + for (int i = 0; i < bytes.length; i++) { + byte b = bytes[i]; + bytes[i] = (byte) (b ^ ENCRYPT_FACTOR); + } + return new String(bytes); + } + + /** + * Decrypt the encrypted password. + * + * @param encryptedPassword encryptedPassword + * @return decrypted password + */ + public static String decryptReversiblePassword(String encryptedPassword) { + return encryptReversiblePassword(encryptedPassword); + } +} \ No newline at end of file diff --git a/src/main/java/cc/honyee/infrastructure/mybatis/OauthRepositoryMyBatis.java b/src/main/java/cc/honyee/infrastructure/mybatis/OauthRepositoryMyBatis.java new file mode 100644 index 0000000..338c811 --- /dev/null +++ b/src/main/java/cc/honyee/infrastructure/mybatis/OauthRepositoryMyBatis.java @@ -0,0 +1,20 @@ +/* + * 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.honyee.infrastructure.mybatis; + +import cc.honyee.domain.oauth.OauthRepository; + +/** + * @author Shengzhao Li + */ +public interface OauthRepositoryMyBatis extends OauthRepository { +} \ No newline at end of file diff --git a/src/main/java/cc/honyee/infrastructure/mybatis/UserRepositoryMyBatis.java b/src/main/java/cc/honyee/infrastructure/mybatis/UserRepositoryMyBatis.java new file mode 100644 index 0000000..07e49cd --- /dev/null +++ b/src/main/java/cc/honyee/infrastructure/mybatis/UserRepositoryMyBatis.java @@ -0,0 +1,20 @@ +/* + * 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.honyee.infrastructure.mybatis; + +import cc.honyee.domain.user.UserRepository; + +/** + * @author Shengzhao Li + */ +public interface UserRepositoryMyBatis extends UserRepository { +} \ No newline at end of file diff --git a/src/main/java/cc/honyee/service/OauthService.java b/src/main/java/cc/honyee/service/OauthService.java new file mode 100644 index 0000000..4dbbe4f --- /dev/null +++ b/src/main/java/cc/honyee/service/OauthService.java @@ -0,0 +1,23 @@ +/* + * 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.honyee.service; + +import cc.honyee.domain.oauth.OauthClientDetails; + +/** + * @author Shengzhao Li + */ + +public interface OauthService { + + OauthClientDetails loadOauthClientDetails(String clientId); +} \ No newline at end of file diff --git a/src/main/java/cc/honyee/service/UserService.java b/src/main/java/cc/honyee/service/UserService.java new file mode 100644 index 0000000..b1f0833 --- /dev/null +++ b/src/main/java/cc/honyee/service/UserService.java @@ -0,0 +1,20 @@ +/* + * 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.honyee.service; + +import org.springframework.security.core.userdetails.UserDetailsService; + +/** + * @author Shengzhao Li + */ +public interface UserService extends UserDetailsService { +} \ No newline at end of file diff --git a/src/main/java/cc/honyee/service/impl/OauthServiceImpl.java b/src/main/java/cc/honyee/service/impl/OauthServiceImpl.java new file mode 100644 index 0000000..c0ad51f --- /dev/null +++ b/src/main/java/cc/honyee/service/impl/OauthServiceImpl.java @@ -0,0 +1,33 @@ +/* + * 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.honyee.service.impl; + +import cc.honyee.domain.oauth.OauthClientDetails; +import cc.honyee.domain.oauth.OauthRepository; +import cc.honyee.service.OauthService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +/** + * @author Shengzhao Li + */ +@Service("oauthService") +public class OauthServiceImpl implements OauthService { + + @Autowired + private OauthRepository oauthRepository; + + @Override + public OauthClientDetails loadOauthClientDetails(String clientId) { + return oauthRepository.findOauthClientDetails(clientId); + } +} \ No newline at end of file diff --git a/src/main/java/cc/honyee/service/impl/UserServiceImpl.java b/src/main/java/cc/honyee/service/impl/UserServiceImpl.java new file mode 100644 index 0000000..cfdc901 --- /dev/null +++ b/src/main/java/cc/honyee/service/impl/UserServiceImpl.java @@ -0,0 +1,43 @@ +/* + * 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.honyee.service.impl; + +import cc.honyee.domain.shared.security.HonyeeUserDetails; +import cc.honyee.domain.user.User; +import cc.honyee.domain.user.UserRepository; +import cc.honyee.service.UserService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.security.core.userdetails.UserDetails; +import org.springframework.security.core.userdetails.UsernameNotFoundException; +import org.springframework.security.oauth2.provider.BaseClientDetails; +import org.springframework.security.oauth2.provider.ClientDetails; +import org.springframework.stereotype.Service; + +/** + * @author Shengzhao Li + */ +@Service("userService") +public class UserServiceImpl implements UserService { + + @Autowired + private UserRepository userRepository; + + @Override + public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException { + User user = userRepository.findByUsername(username); + if (user == null) { + throw new UsernameNotFoundException("Not found any user for username[" + username + "]"); + } + + return new HonyeeUserDetails(user); + } +} \ No newline at end of file diff --git a/src/main/java/cc/honyee/web/context/BeanContextLoaderListener.java b/src/main/java/cc/honyee/web/context/BeanContextLoaderListener.java new file mode 100644 index 0000000..ec60acf --- /dev/null +++ b/src/main/java/cc/honyee/web/context/BeanContextLoaderListener.java @@ -0,0 +1,33 @@ +/* + * 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.honyee.web.context; + +import cc.honyee.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/honyee/web/context/SpringSecurityHolder.java b/src/main/java/cc/honyee/web/context/SpringSecurityHolder.java new file mode 100644 index 0000000..7b8462e --- /dev/null +++ b/src/main/java/cc/honyee/web/context/SpringSecurityHolder.java @@ -0,0 +1,36 @@ +/* + * 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.honyee.web.context; + +import cc.honyee.domain.shared.security.HonyeeUserDetails; +import cc.honyee.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 HonyeeUserDetails userDetails() { + Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); + if (authentication == null) { + return null; + } + Object principal = authentication.getPrincipal(); + if (principal instanceof HonyeeUserDetails) { + return (HonyeeUserDetails) principal; + } + return null; + } +} \ No newline at end of file diff --git a/src/main/java/cc/honyee/web/controller/UserController.java b/src/main/java/cc/honyee/web/controller/UserController.java new file mode 100644 index 0000000..699d014 --- /dev/null +++ b/src/main/java/cc/honyee/web/controller/UserController.java @@ -0,0 +1,41 @@ +/* + * 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.honyee.web.controller; + +import cc.honyee.service.UserService; +import cc.honyee.web.validator.UserFormDtoValidator; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Controller; +import org.springframework.ui.Model; +import org.springframework.web.bind.annotation.RequestMapping; + +/** + * @author Shengzhao Li + */ +@Controller +@RequestMapping("/user/") +public class UserController { + + + @Autowired + private UserService userService; + @Autowired + private UserFormDtoValidator validator; + + @RequestMapping("overview.htm") + public String overview(Model model) { + + return "user_overview"; + } + + +} \ No newline at end of file diff --git a/src/main/java/cc/honyee/web/controller/mobile/MobileController.java b/src/main/java/cc/honyee/web/controller/mobile/MobileController.java new file mode 100644 index 0000000..8ee6bb2 --- /dev/null +++ b/src/main/java/cc/honyee/web/controller/mobile/MobileController.java @@ -0,0 +1,30 @@ +/* + * 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.honyee.web.controller.mobile; + +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.RequestMapping; + +/** + * @author Shengzhao Li + */ +@Controller +@RequestMapping("/m/") +public class MobileController { + + + @RequestMapping("dashboard.htm") + public String dashboard() { + return "mobile/dashboard"; + } + +} \ No newline at end of file diff --git a/src/main/java/cc/honyee/web/controller/unity/UnityController.java b/src/main/java/cc/honyee/web/controller/unity/UnityController.java new file mode 100644 index 0000000..6c82038 --- /dev/null +++ b/src/main/java/cc/honyee/web/controller/unity/UnityController.java @@ -0,0 +1,30 @@ +/* + * 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.honyee.web.controller.unity; + +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.RequestMapping; + +/** + * @author Shengzhao Li + */ +@Controller +@RequestMapping("/unity/") +public class UnityController { + + + @RequestMapping("dashboard.htm") + public String dashboard() { + return "unity/dashboard"; + } + +} \ No newline at end of file diff --git a/src/main/java/cc/honyee/web/oauth/OauthUserApprovalHandler.java b/src/main/java/cc/honyee/web/oauth/OauthUserApprovalHandler.java new file mode 100644 index 0000000..0850d80 --- /dev/null +++ b/src/main/java/cc/honyee/web/oauth/OauthUserApprovalHandler.java @@ -0,0 +1,59 @@ +/* + * Copyright 2002-2011 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package cc.honyee.web.oauth; + +import cc.honyee.domain.oauth.OauthClientDetails; +import cc.honyee.service.OauthService; +import org.springframework.security.core.Authentication; +import org.springframework.security.oauth2.provider.AuthorizationRequest; +import org.springframework.security.oauth2.provider.approval.TokenServicesUserApprovalHandler; + +/** + * @author Shengzhao Li + */ +public class OauthUserApprovalHandler extends TokenServicesUserApprovalHandler { + + private OauthService oauthService; + + public OauthUserApprovalHandler() { + } + + + /** + * Allows automatic approval for a white list of clients in the implicit grant case. + * + * @param authorizationRequest The authorization request. + * @param userAuthentication the current user authentication + * @return Whether the specified request has been approved by the current user. + */ + public boolean isApproved(AuthorizationRequest authorizationRequest, Authentication userAuthentication) { + if (super.isApproved(authorizationRequest, userAuthentication)) { + return true; + } + if (!userAuthentication.isAuthenticated()) { + return false; + } + + OauthClientDetails clientDetails = oauthService.loadOauthClientDetails(authorizationRequest.getClientId()); + return (clientDetails != null && clientDetails.trusted()); + + } + + public void setOauthService(OauthService oauthService) { + this.oauthService = oauthService; + } +} diff --git a/src/main/java/cc/honyee/web/validator/UserFormDtoValidator.java b/src/main/java/cc/honyee/web/validator/UserFormDtoValidator.java new file mode 100644 index 0000000..83d0874 --- /dev/null +++ b/src/main/java/cc/honyee/web/validator/UserFormDtoValidator.java @@ -0,0 +1,80 @@ +/* + * 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.honyee.web.validator; + +import cc.honyee.domain.dto.user.UserFormDto; +import cc.honyee.infrastructure.MatchUtils; +import cc.honyee.service.UserService; +import org.apache.commons.lang.StringUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; +import org.springframework.validation.Errors; +import org.springframework.validation.Validator; + +/** + * @author Shengzhao Li + */ +@Component +public class UserFormDtoValidator implements Validator { + + @Autowired + private UserService userService; + + @Override + public boolean supports(Class aClass) { + return UserFormDto.class.equals(aClass); + } + + @Override + public void validate(Object target, Errors errors) { + UserFormDto userFormDto = (UserFormDto) target; + validateUsername(userFormDto, errors); + validateEmail(userFormDto, errors); + + if (userFormDto.isNewly()) { + validatePassword(userFormDto, errors); + } + } + + private void validatePassword(UserFormDto userFormDto, Errors errors) { + String password = userFormDto.getPassword(); + if (password.length() < 6) { + errors.rejectValue("password", null, "用户密码至少6位"); + return; + } + if (!password.equals(userFormDto.getRePassword())) { + errors.rejectValue("rePassword", null, "两次输入的密码不相同"); + } + + } + + private void validateEmail(UserFormDto userFormDto, Errors errors) { + String email = userFormDto.getEmail(); + if (!MatchUtils.isEmail(email)) { + errors.rejectValue("email", null, "邮件地址格式错误"); + } + } + + private void validateUsername(UserFormDto userFormDto, Errors errors) { + String username = userFormDto.getUsername(); + if (StringUtils.isEmpty(username)) { + errors.rejectValue("username", null, "用户名不能为空"); + return; + } + if (!username.equals(userFormDto.getExistUsername())) { +// boolean exist = userService.loadExistUsername(username); +// if (exist) { +// errors.rejectValue("username", null, "该用户名已经存在"); +// } + } + } +} \ No newline at end of file diff --git a/src/main/resources/cc/honyee/infrastructure/mybatis/OauthMapper.xml b/src/main/resources/cc/honyee/infrastructure/mybatis/OauthMapper.xml new file mode 100644 index 0000000..c9953e4 --- /dev/null +++ b/src/main/resources/cc/honyee/infrastructure/mybatis/OauthMapper.xml @@ -0,0 +1,33 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/main/resources/cc/honyee/infrastructure/mybatis/UserMapper.xml b/src/main/resources/cc/honyee/infrastructure/mybatis/UserMapper.xml new file mode 100644 index 0000000..14d8645 --- /dev/null +++ b/src/main/resources/cc/honyee/infrastructure/mybatis/UserMapper.xml @@ -0,0 +1,57 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + insert into user_(guid,archived,create_time,email,password,username,phone, last_login_time) + values + (#{guid},#{archived},#{createTime},#{email},#{password},#{username}, #{phone}, #{lastLoginTime}) + + + + update user_ set + username = #{username}, + password = #{password}, + phone = #{phone}, + email = #{email} + where guid = #{guid} + + + \ No newline at end of file diff --git a/src/main/resources/database.properties b/src/main/resources/database.properties new file mode 100644 index 0000000..83f3ab0 --- /dev/null +++ b/src/main/resources/database.properties @@ -0,0 +1,8 @@ +#JDBC configuration information +jdbc.driverClassName=com.mysql.jdbc.Driver +############ +# localhost +############ +jdbc.url=jdbc:mysql://localhost:3306/oauth2?autoReconnect=true&autoReconnectForPools=true&useUnicode=true&characterEncoding=utf8 +jdbc.username=honyee +jdbc.password=honyee \ No newline at end of file diff --git a/src/main/resources/displaytag.properties b/src/main/resources/displaytag.properties new file mode 100644 index 0000000..c2c6253 --- /dev/null +++ b/src/main/resources/displaytag.properties @@ -0,0 +1,111 @@ +basic.empty.showtable=true +basic.show.header=true + +# page | list +sort.amount=page + +export.amount=list +export.decorated=true + +paging.banner.group_size=5 +paging.banner.placement=bottom + + +css.tr.even=even +css.tr.odd=odd +css.th.sorted=sorted +css.th.ascending=order1 +css.th.descending=order2 +css.table= +css.th.sortable=sortable + +# factory classes for extensions +factory.requestHelper=org.displaytag.util.DefaultRequestHelperFactory + +# factory class for decorators +factory.decorator=org.displaytag.decorator.DefaultDecoratorFactory + +# locale provider (Jstl provider by default) +locale.provider=org.displaytag.localization.I18nJstlAdapter + +# locale.resolver (nothing by default, simply use locale from request) +#locale.resolver= + +export.types=csv excel xml pdf + +export.csv.class=org.displaytag.export.CsvView +export.excel.class=org.displaytag.export.ExcelView +export.xml.class=org.displaytag.export.XmlView +export.pdf.class=org.displaytag.export.PdfView + +export.csv=true +export.csv.label=CSV +export.csv.include_header=false +export.csv.filename= + +export.excel=true +export.excel.label=Excel +export.excel.include_header=true +export.excel.filename= + +export.xml=true +export.xml.label=XML +export.xml.filename= + +export.pdf=false +export.pdf.label=PDF +export.pdf.include_header=true +export.pdf.filename= + +export.rtf=false +export.rtf.label=RTF +export.rtf.include_header=true +export.rtf.filename= + +# messages + +basic.msg.empty_list= +basic.msg.empty_list_row=  +error.msg.invalid_page=invalid page + +export.banner=

+export.banner.sepchar= | + +paging.banner.item_name=\u6761 +paging.banner.items_name=\u6761 + +paging.banner.no_items_found= +paging.banner.one_item_found= +paging.banner.all_items_found= +paging.banner.some_items_found= + +#paging.banner.full=[\u9996\u9875/\u4e0a\u9875] {0} [\u4e0b\u9875/\u672b\u9875] +#paging.banner.first=[\u9996\u9875/\u4e0a\u9875] {0} [\u4e0b\u9875/\u672b\u9875] +#paging.banner.last=[\u9996\u9875/\u4e0a\u9875] {0} [\u4e0b\u9875/\u672b\u9875] +#paging.banner.onepage={0} +paging.banner.full= +paging.banner.first= +paging.banner.last= +paging.banner.onepage= + + +#paging.banner.page.selected={0} +#paging.banner.page.link={0} +#paging.banner.page.separator=  +paging.banner.page.selected=
  • {0}
  • +paging.banner.page.link=
  • {0}
  • +paging.banner.page.separator= + + +# external sort and pagination +pagination.sort.param=sort +pagination.sortdirection.param=dir +pagination.pagenumber.param=pageNumber +pagination.searchid.param=searchid +pagination.sort.asc.value=asc +pagination.sort.desc.value=desc +pagination.sort.skippagenumber=true + +# unused +save.excel.banner=\u4fdd\u5b58 ({1} \u5b57\u8282) +save.excel.filename=export.xls \ No newline at end of file diff --git a/src/main/resources/logging.properties b/src/main/resources/logging.properties new file mode 100644 index 0000000..1d66b3e --- /dev/null +++ b/src/main/resources/logging.properties @@ -0,0 +1,14 @@ +handlers = org.apache.juli.FileHandler, java.util.logging.ConsoleHandler + +############################################################ +# Handler specific properties. +# Describes specific configuration info for Handlers. +# The configuration for Tomcat server +############################################################ + +org.apache.juli.FileHandler.level = FINE +org.apache.juli.FileHandler.directory = ${catalina.base}/logs +org.apache.juli.FileHandler.prefix = error-debug. + +java.util.logging.ConsoleHandler.level = FINE +java.util.logging.ConsoleHandler.formatter = java.util.logging.SimpleFormatter diff --git a/src/main/resources/mail.properties b/src/main/resources/mail.properties new file mode 100644 index 0000000..7656705 --- /dev/null +++ b/src/main/resources/mail.properties @@ -0,0 +1,22 @@ +#Email configure +#mail host name +host.name=smtp.exmail.qq.com +#mail send port,default 25 +mail.smtp.port=25 +#mail use username +mail.username=no-reply@honyee.cc +#mail use password +mail.password=honyee@2013 +#default mail address +default.mail.address=no-reply@honyee.cc + # auth +mail.smtp.auth=true +# true is use new thread send mail, default false +#If develop in production, change it to true +mail.send.use.thread=false + + +#Develop configuration +#If develop in production, change it to false +mail.develop.environment=true +mail.develop.address=shengzhao@honyee.cc \ No newline at end of file diff --git a/src/main/resources/mybatis.xml b/src/main/resources/mybatis.xml new file mode 100644 index 0000000..b37fd4c --- /dev/null +++ b/src/main/resources/mybatis.xml @@ -0,0 +1,23 @@ + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/main/resources/spring/context.xml b/src/main/resources/spring/context.xml new file mode 100644 index 0000000..c8573c1 --- /dev/null +++ b/src/main/resources/spring/context.xml @@ -0,0 +1,66 @@ + + + + + + + + + + + + + classpath:database.properties + classpath:mail.properties + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/main/resources/spring/infrastructure.xml b/src/main/resources/spring/infrastructure.xml new file mode 100644 index 0000000..7f2abf3 --- /dev/null +++ b/src/main/resources/spring/infrastructure.xml @@ -0,0 +1,22 @@ + + + + + + + + + + + + + + ${mail.smtp.auth} + + + + + \ No newline at end of file diff --git a/src/main/resources/spring/security.xml b/src/main/resources/spring/security.xml new file mode 100644 index 0000000..388f33d --- /dev/null +++ b/src/main/resources/spring/security.xml @@ -0,0 +1,181 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/main/resources/spring/transaction.xml b/src/main/resources/spring/transaction.xml new file mode 100644 index 0000000..5084b2a --- /dev/null +++ b/src/main/resources/spring/transaction.xml @@ -0,0 +1,21 @@ + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/main/resources/template/job_default_content.html b/src/main/resources/template/job_default_content.html new file mode 100644 index 0000000..9cd9e64 --- /dev/null +++ b/src/main/resources/template/job_default_content.html @@ -0,0 +1,21 @@ +

    职位描述:

    + +

     

    + +

     

    + +

    岗位职责:

    + +

     

    + +

     

    + +

     

    + +

    联系方式:

    + +

     

    + +

     

    + +

     

    diff --git a/src/main/webapp/WEB-INF/decorators.xml b/src/main/webapp/WEB-INF/decorators.xml new file mode 100644 index 0000000..27d7f9c --- /dev/null +++ b/src/main/webapp/WEB-INF/decorators.xml @@ -0,0 +1,15 @@ + + + + + + + /* + + + + + + + + \ No newline at end of file diff --git a/src/main/webapp/WEB-INF/hy-servlet.xml b/src/main/webapp/WEB-INF/hy-servlet.xml new file mode 100644 index 0000000..5173212 --- /dev/null +++ b/src/main/webapp/WEB-INF/hy-servlet.xml @@ -0,0 +1,38 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/main/webapp/WEB-INF/jsp/decorators/main.jsp b/src/main/webapp/WEB-INF/jsp/decorators/main.jsp new file mode 100644 index 0000000..ba8a025 --- /dev/null +++ b/src/main/webapp/WEB-INF/jsp/decorators/main.jsp @@ -0,0 +1,41 @@ +<%-- + * 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. +--%> +<%-- + * + * @author Shengzhao Li +--%> + +<%@ page contentType="text/html;charset=UTF-8" language="java" %> +<%@ taglib uri="http://www.opensymphony.com/sitemesh/decorator" prefix="decorator" %> +<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> + + + + + + + + + + + + + <decorator:title default=""/> - Oauth + + + + +
    + +
    + + \ No newline at end of file diff --git a/src/main/webapp/WEB-INF/jsp/mobile/dashboard.jsp b/src/main/webapp/WEB-INF/jsp/mobile/dashboard.jsp new file mode 100644 index 0000000..0031bac --- /dev/null +++ b/src/main/webapp/WEB-INF/jsp/mobile/dashboard.jsp @@ -0,0 +1,26 @@ +<%-- + * 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. +--%> +<%-- + * + * @author Shengzhao Li +--%> + +<%@ page contentType="text/html;charset=UTF-8" language="java" %> + + + + Mobile dashboard + + +

    Hi Mobile.

    + + \ No newline at end of file diff --git a/src/main/webapp/WEB-INF/jsp/oauth_approval.jsp b/src/main/webapp/WEB-INF/jsp/oauth_approval.jsp new file mode 100644 index 0000000..7cda532 --- /dev/null +++ b/src/main/webapp/WEB-INF/jsp/oauth_approval.jsp @@ -0,0 +1,38 @@ +<%-- + * 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. +--%> +<%-- + * + * @author Shengzhao Li +--%> + +<%@ page contentType="text/html;charset=UTF-8" language="java" %> + + + + + Oauth Approval + +

    OAuth Approval

    + +

    Do you authorize '${authorizationRequest.clientId}' to access your protected resources?

    + +
    + + +
    +
    + + +
    + + \ No newline at end of file diff --git a/src/main/webapp/WEB-INF/jsp/oauth_error.jsp b/src/main/webapp/WEB-INF/jsp/oauth_error.jsp new file mode 100644 index 0000000..6a75683 --- /dev/null +++ b/src/main/webapp/WEB-INF/jsp/oauth_error.jsp @@ -0,0 +1,28 @@ +<%-- + * 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. +--%> +<%-- + * + * @author Shengzhao Li +--%> + +<%@ page contentType="text/html;charset=UTF-8" language="java" %> + + + + Oauth Error + + +

    + Illegal action. +

    + + \ No newline at end of file diff --git a/src/main/webapp/WEB-INF/jsp/unity/dashboard.jsp b/src/main/webapp/WEB-INF/jsp/unity/dashboard.jsp new file mode 100644 index 0000000..57493a2 --- /dev/null +++ b/src/main/webapp/WEB-INF/jsp/unity/dashboard.jsp @@ -0,0 +1,26 @@ +<%-- + * 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. +--%> +<%-- + * + * @author Shengzhao Li +--%> + +<%@ page contentType="text/html;charset=UTF-8" language="java" %> + + + + Unity dashboard + + +

    Hi Unity.

    + + \ No newline at end of file diff --git a/src/main/webapp/WEB-INF/jsp/user_overview.jsp b/src/main/webapp/WEB-INF/jsp/user_overview.jsp new file mode 100644 index 0000000..a3a69d5 --- /dev/null +++ b/src/main/webapp/WEB-INF/jsp/user_overview.jsp @@ -0,0 +1,26 @@ +<%-- + * 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. +--%> +<%-- + * + * @author Shengzhao Li +--%> + +<%@ page contentType="text/html;charset=UTF-8" language="java" %> + + + + User Overview + + +

    User Overview

    + + \ No newline at end of file diff --git a/src/main/webapp/WEB-INF/logback.xml b/src/main/webapp/WEB-INF/logback.xml new file mode 100644 index 0000000..a74bca6 --- /dev/null +++ b/src/main/webapp/WEB-INF/logback.xml @@ -0,0 +1,29 @@ + + + + + + + %d{yyyy-MM-dd HH:mm:ss} %level %class:%line - %msg%n + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/main/webapp/WEB-INF/web.xml b/src/main/webapp/WEB-INF/web.xml new file mode 100644 index 0000000..22f6e82 --- /dev/null +++ b/src/main/webapp/WEB-INF/web.xml @@ -0,0 +1,140 @@ + + + + spring-oauth + + + + webAppRootKey + spring-oauth-server + + + + + encodingFilter + org.springframework.web.filter.CharacterEncodingFilter + + encoding + UTF-8 + + + forceEncoding + true + + + + encodingFilter + /* + + + + + gzipFilter + + net.sf.ehcache.constructs.web.filter.GzipFilter + + + + gzipFilter + *.css + + + gzipFilter + *.png + + + gzipFilter + *.gif + + + gzipFilter + *.html + + + gzipFilter + *.htm + + + gzipFilter + *.js + + + gzipFilter + *.json + + + + + springSecurityFilterChain + org.springframework.web.filter.DelegatingFilterProxy + + + + springSecurityFilterChain + /* + + + + + sitemesh + com.opensymphony.sitemesh.webapp.SiteMeshFilter + + + sitemesh + /* + + + + ico + image/vnd.microsoft.icon + + + + + contextConfigLocation + classpath:spring/*.xml + + + logbackConfigLocation + /WEB-INF/logback.xml + + + ch.qos.logback.ext.spring.web.LogbackConfigListener + + + + + cc.honyee.web.context.BeanContextLoaderListener + + + + + hy + org.springframework.web.servlet.DispatcherServlet + 2 + + + hy + / + + + + + + + + + 30 + + + + + index.jsp + + + + \ No newline at end of file diff --git a/src/main/webapp/index.jsp b/src/main/webapp/index.jsp new file mode 100644 index 0000000..d4d7bb8 --- /dev/null +++ b/src/main/webapp/index.jsp @@ -0,0 +1,38 @@ +<%-- + * 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. +--%> +<%-- + * + * @author Shengzhao Li +--%> + +<%@ page contentType="text/html;charset=UTF-8" language="java" %> + + + + Home + + +

    spring-oauth is work!

    +Logout + + + \ No newline at end of file diff --git a/src/main/webapp/login.jsp b/src/main/webapp/login.jsp new file mode 100644 index 0000000..e47f029 --- /dev/null +++ b/src/main/webapp/login.jsp @@ -0,0 +1,38 @@ +<%-- + * 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. +--%> +<%-- + * + * @author Shengzhao Li +--%> + +<%@ page contentType="text/html;charset=UTF-8" language="java" %> + + + + Unity login + + +

    Unity login

    + +
    + + + +
    +
    + + +
    + +
    + + \ No newline at end of file diff --git a/src/test/java/cc/honyee/ContextTest.java b/src/test/java/cc/honyee/ContextTest.java new file mode 100644 index 0000000..f02c248 --- /dev/null +++ b/src/test/java/cc/honyee/ContextTest.java @@ -0,0 +1,39 @@ +/* + * 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.honyee; + +import cc.honyee.domain.shared.BeanProvider; +import cc.honyee.domain.shared.security.HonyeeUserDetails; +import cc.honyee.domain.shared.security.SecurityUtils; +import cc.honyee.web.context.SpringSecurityHolder; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.testng.AbstractTransactionalTestNGSpringContextTests; +import org.springframework.test.context.transaction.BeforeTransaction; + +/** + * @author Shengzhao Li + */ +@ContextConfiguration(locations = {"classpath:testApplicationContext.xml"}) +public abstract class ContextTest extends AbstractTransactionalTestNGSpringContextTests { + + @BeforeTransaction + public void beforeTest() { + BeanProvider.initialize(applicationContext); + SecurityUtils securityUtils = new SecurityUtils(); + securityUtils.setSecurityHolder(new SpringSecurityHolder() { + @Override + public HonyeeUserDetails userDetails() { + return null; + } + }); + } +} \ No newline at end of file diff --git a/src/test/java/cc/honyee/infrastructure/AbstractRepositoryTest.java b/src/test/java/cc/honyee/infrastructure/AbstractRepositoryTest.java new file mode 100644 index 0000000..e9aaf58 --- /dev/null +++ b/src/test/java/cc/honyee/infrastructure/AbstractRepositoryTest.java @@ -0,0 +1,41 @@ +/* + * 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.honyee.infrastructure; + +import cc.honyee.ContextTest; +import org.mybatis.spring.SqlSessionTemplate; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.jdbc.core.JdbcTemplate; + +/** + * @author Shengzhao Li + */ +public abstract class AbstractRepositoryTest extends ContextTest { + + + @Autowired + private JdbcTemplate jdbcTemplate; + + @Autowired + private SqlSessionTemplate sqlSessionTemplate; + + + public SqlSessionTemplate sqlSessionTemplate() { + return sqlSessionTemplate; + } + + public JdbcTemplate jdbcTemplate() { + return jdbcTemplate; + } + + +} \ No newline at end of file diff --git a/src/test/java/cc/honyee/infrastructure/DateUtilsTest.java b/src/test/java/cc/honyee/infrastructure/DateUtilsTest.java new file mode 100644 index 0000000..631f012 --- /dev/null +++ b/src/test/java/cc/honyee/infrastructure/DateUtilsTest.java @@ -0,0 +1,66 @@ +/* + * 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.honyee.infrastructure; + +import org.testng.annotations.Test; + +import java.util.Date; + +import static org.testng.Assert.*; + +/** + * @author Shengzhao Li + */ +public class DateUtilsTest { + + @Test + public void isToday() throws Exception { + boolean today = DateUtils.isToday(DateUtils.now()); + assertTrue(today); + + today = DateUtils.isToday(DateUtils.getDate("2013-03-09")); + assertFalse(today); + } + + @Test + public void isDate() throws Exception { + boolean isDate = DateUtils.isDate(null); + assertFalse(isDate); + + isDate = DateUtils.isDate("2013-09-11"); + assertTrue(isDate); + + isDate = DateUtils.isDate("20130911"); + assertFalse(isDate); + } + + /** + * OOps! what happened, waiting................ + */ + @Test(enabled = false) + public void periodAsDays() { + Date start = DateUtils.now(); + Date end = DateUtils.now(); + + long days = DateUtils.periodAsDays(start, end); + System.out.println("Period: " + days); + assertEquals(days, 0); + + start = DateUtils.getDate("2013-03-01 12:23:23", DateUtils.DEFAULT_DATE_TIME_FORMAT); + end = DateUtils.getDate("2013-03-11 16:00:11", DateUtils.DEFAULT_DATE_TIME_FORMAT); + System.out.println("Start [" + DateUtils.toDateTime(start) + "], End [" + DateUtils.toDateTime(end) + "]"); + + days = DateUtils.periodAsDays(start, end); + System.out.println("Period: " + days); + assertEquals(days, 10); + } +} \ No newline at end of file diff --git a/src/test/java/cc/honyee/infrastructure/DimensionalCodeHelperTest.java b/src/test/java/cc/honyee/infrastructure/DimensionalCodeHelperTest.java new file mode 100644 index 0000000..ccb9024 --- /dev/null +++ b/src/test/java/cc/honyee/infrastructure/DimensionalCodeHelperTest.java @@ -0,0 +1,79 @@ +/* + * 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.honyee.infrastructure; + +import com.google.zxing.*; +import com.google.zxing.client.j2se.BufferedImageLuminanceSource; +import com.google.zxing.client.j2se.MatrixToImageWriter; +import com.google.zxing.common.BitMatrix; +import com.google.zxing.common.HybridBinarizer; +import com.google.zxing.qrcode.QRCodeReader; +import com.google.zxing.qrcode.QRCodeWriter; +import org.springframework.core.io.ClassPathResource; +import org.springframework.core.io.Resource; +import org.testng.annotations.Test; + +import javax.imageio.ImageIO; +import java.io.File; +import java.io.IOException; +import java.net.URISyntaxException; +import java.util.HashMap; +import java.util.Map; + +import static org.testng.Assert.assertNotNull; + +/** + * @author Shengzhao Li + */ +public class DimensionalCodeHelperTest { + + @Test + public void encode() throws Exception { + + File file = file(); + + Map hints = new HashMap<>(); + hints.put(EncodeHintType.CHARACTER_SET, "UTF-8"); + + QRCodeWriter qrCodeWriter = new QRCodeWriter(); + BitMatrix encode = qrCodeWriter.encode("http://honyee.biz 宏义", BarcodeFormat.QR_CODE, 200, 200, hints); + + assertNotNull(encode); + MatrixToImageWriter.writeToFile(encode, "png", file); + + } + + @Test + public void decode() throws Exception { + + File file = file(); + + QRCodeReader qrCodeReader = new QRCodeReader(); + + Map hints = new HashMap<>(); + hints.put(DecodeHintType.CHARACTER_SET, "UTF-8"); + + LuminanceSource source = new BufferedImageLuminanceSource(ImageIO.read(file)); + Binarizer binarizer = new HybridBinarizer(source); + BinaryBitmap image = new BinaryBitmap(binarizer); + + Result result = qrCodeReader.decode(image, hints); + String text = result.getText(); + System.out.println(text); + } + + private File file() throws IOException, URISyntaxException { + Resource resource = new ClassPathResource("dim-code.png"); + return resource.getFile(); + } + +} \ No newline at end of file diff --git a/src/test/java/cc/honyee/infrastructure/GuidTest.java b/src/test/java/cc/honyee/infrastructure/GuidTest.java new file mode 100644 index 0000000..1341045 --- /dev/null +++ b/src/test/java/cc/honyee/infrastructure/GuidTest.java @@ -0,0 +1,31 @@ +/* + * 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.honyee.infrastructure; + +import cc.honyee.domain.shared.GuidGenerator; +import org.testng.annotations.Test; + +/** + * @author Shengzhao Li + */ +public class GuidTest { + + + @Test + public void guid() { + for (int i = 0; i < 5; i++) { + String generate = GuidGenerator.generate(); + System.out.println(generate); + } + } + +} \ No newline at end of file diff --git a/src/test/java/cc/honyee/infrastructure/MD5Test.java b/src/test/java/cc/honyee/infrastructure/MD5Test.java new file mode 100644 index 0000000..61d7f32 --- /dev/null +++ b/src/test/java/cc/honyee/infrastructure/MD5Test.java @@ -0,0 +1,30 @@ +/* + * 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.honyee.infrastructure; + +import org.springframework.security.authentication.encoding.Md5PasswordEncoder; +import org.testng.annotations.Test; + +/** + * @author Shengzhao Li + */ +public class MD5Test { + + + @Test + public void encode() { + Md5PasswordEncoder encoder = new Md5PasswordEncoder(); + String encode = encoder.encodePassword("honyee2013", null); + System.out.println(encode); + } + +} \ No newline at end of file diff --git a/src/test/java/cc/honyee/infrastructure/MatchUtilsTest.java b/src/test/java/cc/honyee/infrastructure/MatchUtilsTest.java new file mode 100644 index 0000000..3bff5ff --- /dev/null +++ b/src/test/java/cc/honyee/infrastructure/MatchUtilsTest.java @@ -0,0 +1,35 @@ +/* + * 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.honyee.infrastructure; + +import org.testng.annotations.Test; + +import static org.testng.Assert.assertFalse; +import static org.testng.Assert.assertTrue; + +/** + * @author Shengzhao Li + */ +public class MatchUtilsTest { + + + @Test + public void isEmail() { + + boolean result = MatchUtils.isEmail("addd"); + assertFalse(result); + + result = MatchUtils.isEmail("addd@honyee.cc"); + assertTrue(result); + } + +} \ No newline at end of file diff --git a/src/test/java/cc/honyee/infrastructure/mybatis/OauthRepositoryMyBatisTest.java b/src/test/java/cc/honyee/infrastructure/mybatis/OauthRepositoryMyBatisTest.java new file mode 100644 index 0000000..e5bebae --- /dev/null +++ b/src/test/java/cc/honyee/infrastructure/mybatis/OauthRepositoryMyBatisTest.java @@ -0,0 +1,39 @@ +/* + * 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.honyee.infrastructure.mybatis; + +import cc.honyee.domain.oauth.OauthClientDetails; +import cc.honyee.domain.oauth.OauthRepository; +import cc.honyee.infrastructure.AbstractRepositoryTest; +import org.springframework.beans.factory.annotation.Autowired; +import org.testng.annotations.Test; + +import static org.testng.Assert.assertNull; + +/** + * @author Shengzhao Li + */ +public class OauthRepositoryMyBatisTest extends AbstractRepositoryTest { + + + @Autowired + private OauthRepository oauthRepositoryMyBatis; + + + @Test + public void findOauthClientDetails() { + OauthClientDetails oauthClientDetails = oauthRepositoryMyBatis.findOauthClientDetails("unity-client"); + assertNull(oauthClientDetails); + + } + +} \ No newline at end of file diff --git a/src/test/java/cc/honyee/infrastructure/mybatis/UserRepositoryMyBatisTest.java b/src/test/java/cc/honyee/infrastructure/mybatis/UserRepositoryMyBatisTest.java new file mode 100644 index 0000000..41c5f9a --- /dev/null +++ b/src/test/java/cc/honyee/infrastructure/mybatis/UserRepositoryMyBatisTest.java @@ -0,0 +1,77 @@ +/* + * 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.honyee.infrastructure.mybatis; + +import cc.honyee.domain.user.User; +import cc.honyee.domain.user.UserRepository; +import cc.honyee.infrastructure.AbstractRepositoryTest; +import org.springframework.beans.factory.annotation.Autowired; +import org.testng.annotations.Test; + +import static org.testng.AssertJUnit.*; + +/** + * @author Shengzhao Li + */ +public class UserRepositoryMyBatisTest extends AbstractRepositoryTest { + + @Autowired + private UserRepository userRepository; + + + @Test + public void findByGuid() { + User user = userRepository.findByGuid("oood"); + assertNull(user); + + user = new User("user", "123", "123", "ewo@honyee.cc"); + userRepository.saveUser(user); + + user = userRepository.findByGuid(user.guid()); + assertNotNull(user); + assertNotNull(user.email()); + + + } + + + @Test + public void updateUser() { + User user = new User("user", "123", "123", "ewo@honyee.cc"); + userRepository.saveUser(user); + + user = userRepository.findByGuid(user.guid()); + assertNotNull(user); + assertNotNull(user.email()); + + String newEmail = "test@honyee.cc"; + user.email(newEmail).phone("12344444"); + userRepository.updateUser(user); + + user = userRepository.findByGuid(user.guid()); + assertNotNull(user); + assertEquals(user.email(), newEmail); + } + + + @Test + public void findByUsername() { + String username = "user"; + User user = new User(username, "123", "123", "ewo@honyee.cc"); + userRepository.saveUser(user); + + User result = userRepository.findByUsername(username); + assertNotNull(result); + } + + +} \ No newline at end of file diff --git a/src/test/resources/database.properties b/src/test/resources/database.properties new file mode 100644 index 0000000..2d50ba3 --- /dev/null +++ b/src/test/resources/database.properties @@ -0,0 +1,8 @@ +#JDBC configuration information +jdbc.driverClassName=com.mysql.jdbc.Driver +############ +# localhost +############ +jdbc.url=jdbc:mysql://localhost:3306/oauth2_test?autoReconnect=true&autoReconnectForPools=true&useUnicode=true&characterEncoding=utf8 +jdbc.username=honyee +jdbc.password=honyee \ No newline at end of file diff --git a/src/test/resources/dim-code.png b/src/test/resources/dim-code.png new file mode 100644 index 0000000..683af6e Binary files /dev/null and b/src/test/resources/dim-code.png differ diff --git a/src/test/resources/testApplicationContext.xml b/src/test/resources/testApplicationContext.xml new file mode 100644 index 0000000..6497252 --- /dev/null +++ b/src/test/resources/testApplicationContext.xml @@ -0,0 +1,64 @@ + + + + + + + + classpath:database.properties + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file