You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicecomb.apache.org by li...@apache.org on 2019/05/10 02:15:39 UTC
[servicecomb-samples] 01/04: authentication: initial project commit
This is an automated email from the ASF dual-hosted git repository.
liubao pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/servicecomb-samples.git
commit 0991cc9ae8cc873ee939140f0809dc07d6340210
Author: liubao <ba...@huawei.com>
AuthorDate: Wed May 8 14:25:29 2019 +0800
authentication: initial project commit
---
authentication/AuthenticationServer/pom.xml | 155 ++++++++++++++++
.../authentication/AuthenticationServer.java | 30 +++
.../service/AuthenticationServiceImpl.java | 60 ++++++
.../main/resources/META-INF/spring/user.bean.xml | 56 ++++++
.../src/main/resources/config/SessionMapper.xml | 57 ++++++
.../src/main/resources/config/UserMapper.xml | 46 +++++
.../src/main/resources/config/create_db_user.sql | 46 +++++
.../src/main/resources/config/mybatis-config.xml | 27 +++
.../src/main/resources/log4j2.xml | 43 +++++
.../src/main/resources/microservice.yaml | 35 ++++
authentication/Client/pom.xml | 128 +++++++++++++
.../apache/servicecomb/authentication/Client.java | 30 +++
.../main/resources/META-INF/spring/user.bean.xml | 56 ++++++
.../src/main/resources/config/SessionMapper.xml | 57 ++++++
.../src/main/resources/config/UserMapper.xml | 46 +++++
.../src/main/resources/config/create_db_user.sql | 46 +++++
.../src/main/resources/config/mybatis-config.xml | 27 +++
.../Client/src/main/resources/log4j2.xml | 43 +++++
.../Client/src/main/resources/microservice.yaml | 35 ++++
authentication/Gateway/pom.xml | 88 +++++++++
.../samples/porter/gateway/ApiDispatcher.java | 68 +++++++
.../samples/porter/gateway/AuthHandler.java | 31 ++++
.../porter/gateway/CustomVertxRestDispatcher.java | 196 ++++++++++++++++++++
.../samples/porter/gateway/EdgeSSLCustom.java | 38 ++++
.../samples/porter/gateway/GatewayMain.java | 26 +++
.../porter/gateway/InternalAccessHandler.java | 37 ++++
.../porter/gateway/StaticWebpageDispatcher.java | 52 ++++++
...cecomb.transport.rest.vertx.VertxHttpDispatcher | 20 ++
.../main/resources/META-INF/spring/cse.bean.xml | 27 +++
.../src/main/resources/config/cse.handler.xml | 23 +++
.../Gateway/src/main/resources/log4j2.xml | 43 +++++
.../Gateway/src/main/resources/microservice.yaml | 67 +++++++
.../Gateway/src/main/resources/ui/css/style.css | 49 +++++
.../src/main/resources/ui/js/jquery-1.11.1.min.js | 4 +
.../Gateway/src/main/resources/ui/js/login.js | 52 ++++++
.../Gateway/src/main/resources/ui/js/upload.js | 63 +++++++
.../Gateway/src/main/resources/ui/login.html | 45 +++++
.../Gateway/src/main/resources/ui/upload.html | 61 ++++++
authentication/README.md | 26 +++
authentication/ResourceServer/pom.xml | 128 +++++++++++++
.../servicecomb/authentication/ResourceServer.java | 30 +++
.../authentication/resource/FileEndpoint.java | 45 +++++
.../authentication/resource/FileStoreService.java | 31 ++++
.../resource/LocalFileStoreService.java | 64 +++++++
.../main/resources/META-INF/spring/user.bean.xml | 56 ++++++
.../src/main/resources/config/SessionMapper.xml | 57 ++++++
.../src/main/resources/config/UserMapper.xml | 46 +++++
.../src/main/resources/config/create_db_user.sql | 46 +++++
.../src/main/resources/config/mybatis-config.xml | 27 +++
.../ResourceServer/src/main/resources/log4j2.xml | 43 +++++
.../src/main/resources/microservice.yaml | 35 ++++
.../api/AuthenticationServer/endpoint/pom.xml | 38 ++++
.../authentication/api/AuthenticationEndpoint.java | 39 ++++
authentication/api/AuthenticationServer/pom.xml | 36 ++++
.../api/AuthenticationServer/service/pom.xml | 31 ++++
.../authentication/api/AuthenticationService.java | 35 ++++
.../servicecomb/authentication/api/Token.java | 40 ++++
.../servicecomb/authentication/api/Tokens.java | 48 +++++
authentication/api/common/endpoint/pom.xml | 38 ++++
.../samples/porter/file/api/InspectorEndpoint.java | 206 +++++++++++++++++++++
.../samples/porter/file/api/LogEndpoint.java | 72 +++++++
authentication/api/common/pom.xml | 36 ++++
authentication/api/common/service/pom.xml | 31 ++++
.../samples/porter/common/api/LogService.java | 26 +++
authentication/api/pom.xml | 90 +++++++++
65 files changed, 3413 insertions(+)
diff --git a/authentication/AuthenticationServer/pom.xml b/authentication/AuthenticationServer/pom.xml
new file mode 100644
index 0000000..0c7a295
--- /dev/null
+++ b/authentication/AuthenticationServer/pom.xml
@@ -0,0 +1,155 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- ~ Licensed to the Apache Software Foundation (ASF) under one or more
+ ~ contributor license agreements. See the NOTICE file distributed with ~
+ this work for additional information regarding copyright ownership. ~ The
+ ASF licenses this file to You 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. -->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <groupId>org.apache.servicecomb.authentication</groupId>
+ <artifactId>authentication-server</artifactId>
+ <version>0.0.1-SNAPSHOT</version>
+ <packaging>jar</packaging>
+
+ <properties>
+ <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+ </properties>
+
+ <dependencyManagement>
+ <dependencies>
+ <dependency>
+ <groupId>org.mybatis</groupId>
+ <artifactId>mybatis</artifactId>
+ <version>3.4.5</version>
+ </dependency>
+ <dependency>
+ <groupId>org.mybatis</groupId>
+ <artifactId>mybatis-spring</artifactId>
+ <version>1.3.0</version>
+ </dependency>
+ <dependency>
+ <groupId>mysql</groupId>
+ <artifactId>mysql-connector-java</artifactId>
+ <version>5.1.46</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.servicecomb.authentication</groupId>
+ <artifactId>authentication-server-api-endpoint</artifactId>
+ <version>0.0.1-SNAPSHOT</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.servicecomb</groupId>
+ <artifactId>java-chassis-dependencies</artifactId>
+ <version>1.2.0</version>
+ <type>pom</type>
+ <scope>import</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework.security.oauth</groupId>
+ <artifactId>spring-security-oauth2</artifactId>
+ <version>2.3.2.RELEASE</version>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework.security</groupId>
+ <artifactId>spring-security-jwt</artifactId>
+ <version>1.0.7.RELEASE</version>
+ </dependency>
+ </dependencies>
+ </dependencyManagement>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.springframework.security.oauth</groupId>
+ <artifactId>spring-security-oauth2</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework.security</groupId>
+ <artifactId>spring-security-jwt</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.servicecomb.authentication</groupId>
+ <artifactId>authentication-server-api-endpoint</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.servicecomb</groupId>
+ <artifactId>solution-basic</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.servicecomb</groupId>
+ <artifactId>inspector</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.mybatis</groupId>
+ <artifactId>mybatis</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>mysql</groupId>
+ <artifactId>mysql-connector-java</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.commons</groupId>
+ <artifactId>commons-dbcp2</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.mybatis</groupId>
+ <artifactId>mybatis-spring</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-jdbc</artifactId>
+ <scope>compile</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-aop</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-context-support</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-tx</artifactId>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <pluginManagement>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <version>3.1</version>
+ <configuration>
+ <source>1.8</source>
+ <target>1.8</target>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.springframework.boot</groupId>
+ <artifactId>spring-boot-maven-plugin</artifactId>
+ <version>2.1.2.RELEASE</version>
+ <executions>
+ <execution>
+ <goals>
+ <goal>repackage</goal>
+ </goals>
+ <configuration>
+ <mainClass>${main.class}</mainClass>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </pluginManagement>
+ </build>
+</project>
\ No newline at end of file
diff --git a/authentication/AuthenticationServer/src/main/java/org/apache/servicecomb/authentication/AuthenticationServer.java b/authentication/AuthenticationServer/src/main/java/org/apache/servicecomb/authentication/AuthenticationServer.java
new file mode 100644
index 0000000..f38125a
--- /dev/null
+++ b/authentication/AuthenticationServer/src/main/java/org/apache/servicecomb/authentication/AuthenticationServer.java
@@ -0,0 +1,30 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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 org.apache.servicecomb.authentication;
+
+import org.apache.servicecomb.foundation.common.utils.BeanUtils;
+
+public class AuthenticationServer {
+ public static void main(String[] args) {
+ try {
+ BeanUtils.init();
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+}
diff --git a/authentication/AuthenticationServer/src/main/java/org/apache/servicecomb/authentication/service/AuthenticationServiceImpl.java b/authentication/AuthenticationServer/src/main/java/org/apache/servicecomb/authentication/service/AuthenticationServiceImpl.java
new file mode 100644
index 0000000..be46f5c
--- /dev/null
+++ b/authentication/AuthenticationServer/src/main/java/org/apache/servicecomb/authentication/service/AuthenticationServiceImpl.java
@@ -0,0 +1,60 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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 org.apache.servicecomb.authentication.service;
+
+import org.apache.servicecomb.authentication.api.AuthenticationService;
+import org.apache.servicecomb.authentication.api.Token;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Qualifier;
+import org.springframework.security.core.userdetails.UserDetails;
+import org.springframework.security.core.userdetails.UserDetailsService;
+import org.springframework.security.core.userdetails.UsernameNotFoundException;
+import org.springframework.security.crypto.password.PasswordEncoder;
+import org.springframework.stereotype.Service;
+
+@Service
+public class AuthenticationServiceImpl implements AuthenticationService {
+ @Autowired
+ @Qualifier("userDetailsService")
+ private UserDetailsService userDetailsService;
+
+ @Autowired
+ @Qualifier("passwordEncoder")
+ private PasswordEncoder passwordEncoder;
+
+ @Override
+ public Token login(String userName, String password) {
+ UserDetails userDetails;
+ try {
+ userDetails = userDetailsService.loadUserByUsername(userName);
+ } catch (UsernameNotFoundException e) {
+ return null;
+ }
+ if(passwordEncoder.matches(password, userDetails.getPassword())) {
+ return null;
+ } else {
+ return null;
+ }
+ }
+
+ @Override
+ public Token refresh(String refreshToken) {
+ return null;
+ }
+
+}
diff --git a/authentication/AuthenticationServer/src/main/resources/META-INF/spring/user.bean.xml b/authentication/AuthenticationServer/src/main/resources/META-INF/spring/user.bean.xml
new file mode 100644
index 0000000..661608f
--- /dev/null
+++ b/authentication/AuthenticationServer/src/main/resources/META-INF/spring/user.bean.xml
@@ -0,0 +1,56 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ~ Licensed to the Apache Software Foundation (ASF) under one or more
+ ~ contributor license agreements. See the NOTICE file distributed with
+ ~ this work for additional information regarding copyright ownership.
+ ~ The ASF licenses this file to You 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.
+ -->
+
+<beans xmlns="http://www.springframework.org/schema/beans"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
+ xmlns:util="http://www.springframework.org/schema/util"
+ xmlns:context="http://www.springframework.org/schema/context"
+ xmlns:tx="http://www.springframework.org/schema/tx"
+ xsi:schemaLocation="
+ http://www.springframework.org/schema/beans classpath:org/springframework/beans/factory/xml/spring-beans-3.0.xsd
+ http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.1.xsd http://www.springframework.org/schema/data/jpa http://www.springframework.org/schema/data/jpa/spring-jpa.xsd
+ http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd">
+ <bean id="servicecomb.samples.executor.groupThreadPool" class="org.apache.servicecomb.core.executor.GroupExecutor"
+ init-method="init"/>
+
+ <bean id="dataSource"
+ class="org.apache.commons.dbcp2.BasicDataSource"
+ destroy-method="close">
+ <property name="driverClassName" value="${db.driverClassName:com.mysql.jdbc.Driver}" />
+ <property name="url"
+ value="${db.url:jdbc:mysql://localhost/porter_user_db}" />
+ <property name="username" value="${db.username:root}" />
+ <property name="password" value="${db.password:}" />
+ </bean>
+
+ <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
+ <property name="dataSource" ref="dataSource" />
+ <property name="configLocation" value="classpath:/config/mybatis-config.xml"></property>
+ </bean>
+
+ <bean id="userMapper" class="org.mybatis.spring.mapper.MapperFactoryBean">
+ <property name="mapperInterface"
+ value="org.apache.servicecomb.samples.porter.user.dao.UserMapper" />
+ <property name="sqlSessionFactory" ref="sqlSessionFactory" />
+ </bean>
+ <bean id="sessionMapper" class="org.mybatis.spring.mapper.MapperFactoryBean">
+ <property name="mapperInterface"
+ value="org.apache.servicecomb.samples.porter.user.dao.SessionMapper" />
+ <property name="sqlSessionFactory" ref="sqlSessionFactory" />
+ </bean>
+</beans>
\ No newline at end of file
diff --git a/authentication/AuthenticationServer/src/main/resources/config/SessionMapper.xml b/authentication/AuthenticationServer/src/main/resources/config/SessionMapper.xml
new file mode 100644
index 0000000..989e786
--- /dev/null
+++ b/authentication/AuthenticationServer/src/main/resources/config/SessionMapper.xml
@@ -0,0 +1,57 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ~ Licensed to the Apache Software Foundation (ASF) under one or more
+ ~ contributor license agreements. See the NOTICE file distributed with
+ ~ this work for additional information regarding copyright ownership.
+ ~ The ASF licenses this file to You 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.
+ -->
+
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="org.apache.servicecomb.samples.porter.user.dao.SessionMapper">
+ <resultMap id="sessionInfo" type="org.apache.servicecomb.samples.porter.user.dao.SessionInfoModel">
+ <result column="ID" jdbcType="INTEGER" property="id" />
+ <result column="SESSION_ID" jdbcType="VARCHAR" property="sessiondId" />
+ <result column="USER_NAME" jdbcType="VARCHAR" property="userName" />
+ <result column="ROLE_NAME" jdbcType="VARCHAR" property="roleName" />
+ <result column="CREATION_TIME" jdbcType="TIMESTAMP" property="creationTime" />
+ <result column="ACTIVE_TIME" jdbcType="TIMESTAMP" property="activeTime" />
+ </resultMap>
+
+ <sql id="all_column">
+ ID, SESSION_ID, USER_NAME, ROLE_NAME, CREATION_TIME, ACTIVE_TIME
+ </sql>
+
+ <sql id="all_column_auto">
+ SESSION_ID, USER_NAME, ROLE_NAME
+ </sql>
+
+ <insert id="createSession" parameterType="org.apache.servicecomb.samples.porter.user.dao.SessionInfoModel">
+ insert into T_SESSION (
+ <include refid="all_column_auto" />
+ )
+ values (#{sessiondId,jdbcType=VARCHAR}, #{userName,jdbcType=VARCHAR},
+ #{roleName,jdbcType=VARCHAR})
+ </insert>
+
+ <select id="getSessioinInfo" parameterType="java.lang.String"
+ resultMap="sessionInfo">
+ select
+ <include refid="all_column" />
+ from T_SESSION where SESSION_ID = #{0,jdbcType=VARCHAR}
+ </select>
+
+ <update id="updateSessionInfo" parameterType="java.lang.String">
+ update T_SESSION
+ set CREATION_TIME = CREATION_TIME where SESSION_ID = #{0,jdbcType=VARCHAR};
+ </update>
+</mapper>
\ No newline at end of file
diff --git a/authentication/AuthenticationServer/src/main/resources/config/UserMapper.xml b/authentication/AuthenticationServer/src/main/resources/config/UserMapper.xml
new file mode 100644
index 0000000..c02e60d
--- /dev/null
+++ b/authentication/AuthenticationServer/src/main/resources/config/UserMapper.xml
@@ -0,0 +1,46 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ~ Licensed to the Apache Software Foundation (ASF) under one or more
+ ~ contributor license agreements. See the NOTICE file distributed with
+ ~ this work for additional information regarding copyright ownership.
+ ~ The ASF licenses this file to You 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.
+ -->
+
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="org.apache.servicecomb.samples.porter.user.dao.UserMapper">
+ <resultMap id="userInfo" type="org.apache.servicecomb.samples.porter.user.dao.UserInfo">
+ <result column="ID" jdbcType="INTEGER" property="id" />
+ <result column="USER_NAME" jdbcType="VARCHAR" property="userName" />
+ <result column="PASSWORD" jdbcType="VARCHAR" property="password" />
+ <result column="ROLE_NAME" jdbcType="VARCHAR" property="roleName" />
+ </resultMap>
+
+ <sql id="all_column">
+ ID, USER_NAME, PASSWORD, ROLE_NAME
+ </sql>
+
+ <insert id="createUser" parameterType="org.apache.servicecomb.samples.porter.user.dao.UserInfo">
+ insert into T_USER (
+ <include refid="all_column" />
+ )
+ values (#{id,jdbcType=INTEGER}, #{userName,jdbcType=VARCHAR},
+ #{password,jdbcType=VARCHAR},#{roleName,jdbcType=VARCHAR})
+ </insert>
+
+ <select id="getUserInfo" parameterType="java.lang.String"
+ resultMap="userInfo">
+ select
+ <include refid="all_column" />
+ from T_USER where USER_NAME = #{0,jdbcType=VARCHAR}
+ </select>
+</mapper>
\ No newline at end of file
diff --git a/authentication/AuthenticationServer/src/main/resources/config/create_db_user.sql b/authentication/AuthenticationServer/src/main/resources/config/create_db_user.sql
new file mode 100644
index 0000000..a07c5d9
--- /dev/null
+++ b/authentication/AuthenticationServer/src/main/resources/config/create_db_user.sql
@@ -0,0 +1,46 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.
+ */
+
+CREATE DATABASE IF NOT EXISTS porter_user_db;
+
+USE porter_user_db;
+
+DROP TABLE IF EXISTS T_USER;
+
+CREATE TABLE `T_USER` (
+ `ID` INTEGER(8) NOT NULL AUTO_INCREMENT COMMENT 'user id',
+ `USER_NAME` VARCHAR(64) NOT NULL COMMENT 'user name',
+ `PASSWORD` VARCHAR(64) NOT NULL COMMENT 'user password',
+ `ROLE_NAME` VARCHAR(64) NOT NULL COMMENT 'user role',
+ PRIMARY KEY (`ID`)
+);
+
+#### password is encrypted for test
+insert into T_USER(USER_NAME, PASSWORD, ROLE_NAME) values("admin", "n4bQgYhMfWWaL+qgxVrQFaO/TxsrC4Is0V1sFbDwCgg=", "admin");
+insert into T_USER(USER_NAME, PASSWORD, ROLE_NAME) values("guest", "n4bQgYhMfWWaL+qgxVrQFaO/TxsrC4Is0V1sFbDwCgg=", "guest");
+
+DROP TABLE IF EXISTS T_SESSION;
+
+CREATE TABLE `T_SESSION` (
+ `ID` INTEGER(8) NOT NULL AUTO_INCREMENT COMMENT 'id',
+ `SESSION_ID` VARCHAR(64) NOT NULL COMMENT 'session id',
+ `USER_NAME` VARCHAR(64) NOT NULL COMMENT 'user name',
+ `ROLE_NAME` VARCHAR(64) NOT NULL COMMENT 'user role',
+ `CREATION_TIME` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT 'creation time',
+ `ACTIVE_TIME` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT 'last active time',
+ PRIMARY KEY (`ID`)
+);
diff --git a/authentication/AuthenticationServer/src/main/resources/config/mybatis-config.xml b/authentication/AuthenticationServer/src/main/resources/config/mybatis-config.xml
new file mode 100644
index 0000000..894caac
--- /dev/null
+++ b/authentication/AuthenticationServer/src/main/resources/config/mybatis-config.xml
@@ -0,0 +1,27 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<!--
+ ~ Licensed to the Apache Software Foundation (ASF) under one or more
+ ~ contributor license agreements. See the NOTICE file distributed with
+ ~ this work for additional information regarding copyright ownership.
+ ~ The ASF licenses this file to You 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.
+ -->
+
+<!DOCTYPE configuration
+ PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
+ "http://mybatis.org/dtd/mybatis-3-config.dtd">
+<configuration>
+ <mappers>
+ <mapper resource="config/UserMapper.xml"/>
+ <mapper resource="config/SessionMapper.xml"/>
+ </mappers>
+</configuration>
\ No newline at end of file
diff --git a/authentication/AuthenticationServer/src/main/resources/log4j2.xml b/authentication/AuthenticationServer/src/main/resources/log4j2.xml
new file mode 100644
index 0000000..3c70391
--- /dev/null
+++ b/authentication/AuthenticationServer/src/main/resources/log4j2.xml
@@ -0,0 +1,43 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ~ Licensed to the Apache Software Foundation (ASF) under one or more
+ ~ contributor license agreements. See the NOTICE file distributed with
+ ~ this work for additional information regarding copyright ownership.
+ ~ The ASF licenses this file to You 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.
+ -->
+
+<!--this is sample configuration, please modify as your wish-->
+
+<configuration>
+ <Properties>
+ <Property name="log_path">./user/log/</Property>
+ </Properties>
+
+ <Appenders>
+ <Console name="Console" target="SYSTEM_OUT">
+ <PatternLayout pattern="[%d][%t][%p][%c:%L] %m%n"/>
+ </Console>
+ <RollingFile name="DailyRollingFile" fileName="${log_path}/output.log"
+ filePattern="${log_path}/zcrTest%d{yyyy-MM-dd}.log">
+ <PatternLayout pattern="[%d][%t][%p][%c:%L] %m%n"/>
+ <TimeBasedTriggeringPolicy interval="1"/>
+ <SizeBasedTriggeringPolicy size="10 MB"/>
+ </RollingFile>
+ </Appenders>
+ <Loggers>
+ <Root level="info">
+ <AppenderRef ref="Console"/>
+ <AppenderRef ref="DailyRollingFile"/>
+ </Root>
+ </Loggers>
+</configuration>
\ No newline at end of file
diff --git a/authentication/AuthenticationServer/src/main/resources/microservice.yaml b/authentication/AuthenticationServer/src/main/resources/microservice.yaml
new file mode 100644
index 0000000..1e6b0af
--- /dev/null
+++ b/authentication/AuthenticationServer/src/main/resources/microservice.yaml
@@ -0,0 +1,35 @@
+#
+## ---------------------------------------------------------------------------
+## Licensed to the Apache Software Foundation (ASF) under one or more
+## contributor license agreements. See the NOTICE file distributed with
+## this work for additional information regarding copyright ownership.
+## The ASF licenses this file to You 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.
+## ---------------------------------------------------------------------------
+
+# override common configurations in common module
+servicecomb-config-order: 100
+
+APPLICATION_ID: authentication-application
+service_description:
+ version: 0.0.1
+ name: authentication-server
+
+servicecomb:
+ service:
+ registry:
+ address: http://localhost:30100
+ instance:
+ watch: false
+
+ rest:
+ address: 0.0.0.0:9091
diff --git a/authentication/Client/pom.xml b/authentication/Client/pom.xml
new file mode 100644
index 0000000..60978df
--- /dev/null
+++ b/authentication/Client/pom.xml
@@ -0,0 +1,128 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- ~ Licensed to the Apache Software Foundation (ASF) under one or more
+ ~ contributor license agreements. See the NOTICE file distributed with ~
+ this work for additional information regarding copyright ownership. ~ The
+ ASF licenses this file to You 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. -->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <groupId>org.apache.servicecomb.authentication</groupId>
+ <artifactId>client</artifactId>
+ <version>0.0.1-SNAPSHOT</version>
+ <packaging>jar</packaging>
+
+ <properties>
+ <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+ </properties>
+
+ <dependencyManagement>
+ <dependencies>
+ <dependency>
+ <groupId>org.mybatis</groupId>
+ <artifactId>mybatis</artifactId>
+ <version>3.4.5</version>
+ </dependency>
+ <dependency>
+ <groupId>org.mybatis</groupId>
+ <artifactId>mybatis-spring</artifactId>
+ <version>1.3.0</version>
+ </dependency>
+ <dependency>
+ <groupId>mysql</groupId>
+ <artifactId>mysql-connector-java</artifactId>
+ <version>5.1.46</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.servicecomb</groupId>
+ <artifactId>java-chassis-dependencies</artifactId>
+ <version>1.2.0</version>
+ <type>pom</type>
+ <scope>import</scope>
+ </dependency>
+ </dependencies>
+ </dependencyManagement>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.servicecomb</groupId>
+ <artifactId>solution-basic</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.servicecomb</groupId>
+ <artifactId>inspector</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.mybatis</groupId>
+ <artifactId>mybatis</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>mysql</groupId>
+ <artifactId>mysql-connector-java</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.commons</groupId>
+ <artifactId>commons-dbcp2</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.mybatis</groupId>
+ <artifactId>mybatis-spring</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-jdbc</artifactId>
+ <scope>compile</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-aop</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-context-support</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-tx</artifactId>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <pluginManagement>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <version>3.1</version>
+ <configuration>
+ <source>1.8</source>
+ <target>1.8</target>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.springframework.boot</groupId>
+ <artifactId>spring-boot-maven-plugin</artifactId>
+ <version>2.1.2.RELEASE</version>
+ <executions>
+ <execution>
+ <goals>
+ <goal>repackage</goal>
+ </goals>
+ <configuration>
+ <mainClass>${main.class}</mainClass>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </pluginManagement>
+ </build>
+</project>
\ No newline at end of file
diff --git a/authentication/Client/src/main/java/org/apache/servicecomb/authentication/Client.java b/authentication/Client/src/main/java/org/apache/servicecomb/authentication/Client.java
new file mode 100644
index 0000000..4ba1070
--- /dev/null
+++ b/authentication/Client/src/main/java/org/apache/servicecomb/authentication/Client.java
@@ -0,0 +1,30 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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 org.apache.servicecomb.authentication;
+
+import org.apache.servicecomb.foundation.common.utils.BeanUtils;
+
+public class Client {
+ public static void main(String[] args) {
+ try {
+ BeanUtils.init();
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+}
diff --git a/authentication/Client/src/main/resources/META-INF/spring/user.bean.xml b/authentication/Client/src/main/resources/META-INF/spring/user.bean.xml
new file mode 100644
index 0000000..661608f
--- /dev/null
+++ b/authentication/Client/src/main/resources/META-INF/spring/user.bean.xml
@@ -0,0 +1,56 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ~ Licensed to the Apache Software Foundation (ASF) under one or more
+ ~ contributor license agreements. See the NOTICE file distributed with
+ ~ this work for additional information regarding copyright ownership.
+ ~ The ASF licenses this file to You 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.
+ -->
+
+<beans xmlns="http://www.springframework.org/schema/beans"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
+ xmlns:util="http://www.springframework.org/schema/util"
+ xmlns:context="http://www.springframework.org/schema/context"
+ xmlns:tx="http://www.springframework.org/schema/tx"
+ xsi:schemaLocation="
+ http://www.springframework.org/schema/beans classpath:org/springframework/beans/factory/xml/spring-beans-3.0.xsd
+ http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.1.xsd http://www.springframework.org/schema/data/jpa http://www.springframework.org/schema/data/jpa/spring-jpa.xsd
+ http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd">
+ <bean id="servicecomb.samples.executor.groupThreadPool" class="org.apache.servicecomb.core.executor.GroupExecutor"
+ init-method="init"/>
+
+ <bean id="dataSource"
+ class="org.apache.commons.dbcp2.BasicDataSource"
+ destroy-method="close">
+ <property name="driverClassName" value="${db.driverClassName:com.mysql.jdbc.Driver}" />
+ <property name="url"
+ value="${db.url:jdbc:mysql://localhost/porter_user_db}" />
+ <property name="username" value="${db.username:root}" />
+ <property name="password" value="${db.password:}" />
+ </bean>
+
+ <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
+ <property name="dataSource" ref="dataSource" />
+ <property name="configLocation" value="classpath:/config/mybatis-config.xml"></property>
+ </bean>
+
+ <bean id="userMapper" class="org.mybatis.spring.mapper.MapperFactoryBean">
+ <property name="mapperInterface"
+ value="org.apache.servicecomb.samples.porter.user.dao.UserMapper" />
+ <property name="sqlSessionFactory" ref="sqlSessionFactory" />
+ </bean>
+ <bean id="sessionMapper" class="org.mybatis.spring.mapper.MapperFactoryBean">
+ <property name="mapperInterface"
+ value="org.apache.servicecomb.samples.porter.user.dao.SessionMapper" />
+ <property name="sqlSessionFactory" ref="sqlSessionFactory" />
+ </bean>
+</beans>
\ No newline at end of file
diff --git a/authentication/Client/src/main/resources/config/SessionMapper.xml b/authentication/Client/src/main/resources/config/SessionMapper.xml
new file mode 100644
index 0000000..989e786
--- /dev/null
+++ b/authentication/Client/src/main/resources/config/SessionMapper.xml
@@ -0,0 +1,57 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ~ Licensed to the Apache Software Foundation (ASF) under one or more
+ ~ contributor license agreements. See the NOTICE file distributed with
+ ~ this work for additional information regarding copyright ownership.
+ ~ The ASF licenses this file to You 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.
+ -->
+
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="org.apache.servicecomb.samples.porter.user.dao.SessionMapper">
+ <resultMap id="sessionInfo" type="org.apache.servicecomb.samples.porter.user.dao.SessionInfoModel">
+ <result column="ID" jdbcType="INTEGER" property="id" />
+ <result column="SESSION_ID" jdbcType="VARCHAR" property="sessiondId" />
+ <result column="USER_NAME" jdbcType="VARCHAR" property="userName" />
+ <result column="ROLE_NAME" jdbcType="VARCHAR" property="roleName" />
+ <result column="CREATION_TIME" jdbcType="TIMESTAMP" property="creationTime" />
+ <result column="ACTIVE_TIME" jdbcType="TIMESTAMP" property="activeTime" />
+ </resultMap>
+
+ <sql id="all_column">
+ ID, SESSION_ID, USER_NAME, ROLE_NAME, CREATION_TIME, ACTIVE_TIME
+ </sql>
+
+ <sql id="all_column_auto">
+ SESSION_ID, USER_NAME, ROLE_NAME
+ </sql>
+
+ <insert id="createSession" parameterType="org.apache.servicecomb.samples.porter.user.dao.SessionInfoModel">
+ insert into T_SESSION (
+ <include refid="all_column_auto" />
+ )
+ values (#{sessiondId,jdbcType=VARCHAR}, #{userName,jdbcType=VARCHAR},
+ #{roleName,jdbcType=VARCHAR})
+ </insert>
+
+ <select id="getSessioinInfo" parameterType="java.lang.String"
+ resultMap="sessionInfo">
+ select
+ <include refid="all_column" />
+ from T_SESSION where SESSION_ID = #{0,jdbcType=VARCHAR}
+ </select>
+
+ <update id="updateSessionInfo" parameterType="java.lang.String">
+ update T_SESSION
+ set CREATION_TIME = CREATION_TIME where SESSION_ID = #{0,jdbcType=VARCHAR};
+ </update>
+</mapper>
\ No newline at end of file
diff --git a/authentication/Client/src/main/resources/config/UserMapper.xml b/authentication/Client/src/main/resources/config/UserMapper.xml
new file mode 100644
index 0000000..c02e60d
--- /dev/null
+++ b/authentication/Client/src/main/resources/config/UserMapper.xml
@@ -0,0 +1,46 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ~ Licensed to the Apache Software Foundation (ASF) under one or more
+ ~ contributor license agreements. See the NOTICE file distributed with
+ ~ this work for additional information regarding copyright ownership.
+ ~ The ASF licenses this file to You 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.
+ -->
+
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="org.apache.servicecomb.samples.porter.user.dao.UserMapper">
+ <resultMap id="userInfo" type="org.apache.servicecomb.samples.porter.user.dao.UserInfo">
+ <result column="ID" jdbcType="INTEGER" property="id" />
+ <result column="USER_NAME" jdbcType="VARCHAR" property="userName" />
+ <result column="PASSWORD" jdbcType="VARCHAR" property="password" />
+ <result column="ROLE_NAME" jdbcType="VARCHAR" property="roleName" />
+ </resultMap>
+
+ <sql id="all_column">
+ ID, USER_NAME, PASSWORD, ROLE_NAME
+ </sql>
+
+ <insert id="createUser" parameterType="org.apache.servicecomb.samples.porter.user.dao.UserInfo">
+ insert into T_USER (
+ <include refid="all_column" />
+ )
+ values (#{id,jdbcType=INTEGER}, #{userName,jdbcType=VARCHAR},
+ #{password,jdbcType=VARCHAR},#{roleName,jdbcType=VARCHAR})
+ </insert>
+
+ <select id="getUserInfo" parameterType="java.lang.String"
+ resultMap="userInfo">
+ select
+ <include refid="all_column" />
+ from T_USER where USER_NAME = #{0,jdbcType=VARCHAR}
+ </select>
+</mapper>
\ No newline at end of file
diff --git a/authentication/Client/src/main/resources/config/create_db_user.sql b/authentication/Client/src/main/resources/config/create_db_user.sql
new file mode 100644
index 0000000..a07c5d9
--- /dev/null
+++ b/authentication/Client/src/main/resources/config/create_db_user.sql
@@ -0,0 +1,46 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.
+ */
+
+CREATE DATABASE IF NOT EXISTS porter_user_db;
+
+USE porter_user_db;
+
+DROP TABLE IF EXISTS T_USER;
+
+CREATE TABLE `T_USER` (
+ `ID` INTEGER(8) NOT NULL AUTO_INCREMENT COMMENT 'user id',
+ `USER_NAME` VARCHAR(64) NOT NULL COMMENT 'user name',
+ `PASSWORD` VARCHAR(64) NOT NULL COMMENT 'user password',
+ `ROLE_NAME` VARCHAR(64) NOT NULL COMMENT 'user role',
+ PRIMARY KEY (`ID`)
+);
+
+#### password is encrypted for test
+insert into T_USER(USER_NAME, PASSWORD, ROLE_NAME) values("admin", "n4bQgYhMfWWaL+qgxVrQFaO/TxsrC4Is0V1sFbDwCgg=", "admin");
+insert into T_USER(USER_NAME, PASSWORD, ROLE_NAME) values("guest", "n4bQgYhMfWWaL+qgxVrQFaO/TxsrC4Is0V1sFbDwCgg=", "guest");
+
+DROP TABLE IF EXISTS T_SESSION;
+
+CREATE TABLE `T_SESSION` (
+ `ID` INTEGER(8) NOT NULL AUTO_INCREMENT COMMENT 'id',
+ `SESSION_ID` VARCHAR(64) NOT NULL COMMENT 'session id',
+ `USER_NAME` VARCHAR(64) NOT NULL COMMENT 'user name',
+ `ROLE_NAME` VARCHAR(64) NOT NULL COMMENT 'user role',
+ `CREATION_TIME` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT 'creation time',
+ `ACTIVE_TIME` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT 'last active time',
+ PRIMARY KEY (`ID`)
+);
diff --git a/authentication/Client/src/main/resources/config/mybatis-config.xml b/authentication/Client/src/main/resources/config/mybatis-config.xml
new file mode 100644
index 0000000..894caac
--- /dev/null
+++ b/authentication/Client/src/main/resources/config/mybatis-config.xml
@@ -0,0 +1,27 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<!--
+ ~ Licensed to the Apache Software Foundation (ASF) under one or more
+ ~ contributor license agreements. See the NOTICE file distributed with
+ ~ this work for additional information regarding copyright ownership.
+ ~ The ASF licenses this file to You 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.
+ -->
+
+<!DOCTYPE configuration
+ PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
+ "http://mybatis.org/dtd/mybatis-3-config.dtd">
+<configuration>
+ <mappers>
+ <mapper resource="config/UserMapper.xml"/>
+ <mapper resource="config/SessionMapper.xml"/>
+ </mappers>
+</configuration>
\ No newline at end of file
diff --git a/authentication/Client/src/main/resources/log4j2.xml b/authentication/Client/src/main/resources/log4j2.xml
new file mode 100644
index 0000000..3c70391
--- /dev/null
+++ b/authentication/Client/src/main/resources/log4j2.xml
@@ -0,0 +1,43 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ~ Licensed to the Apache Software Foundation (ASF) under one or more
+ ~ contributor license agreements. See the NOTICE file distributed with
+ ~ this work for additional information regarding copyright ownership.
+ ~ The ASF licenses this file to You 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.
+ -->
+
+<!--this is sample configuration, please modify as your wish-->
+
+<configuration>
+ <Properties>
+ <Property name="log_path">./user/log/</Property>
+ </Properties>
+
+ <Appenders>
+ <Console name="Console" target="SYSTEM_OUT">
+ <PatternLayout pattern="[%d][%t][%p][%c:%L] %m%n"/>
+ </Console>
+ <RollingFile name="DailyRollingFile" fileName="${log_path}/output.log"
+ filePattern="${log_path}/zcrTest%d{yyyy-MM-dd}.log">
+ <PatternLayout pattern="[%d][%t][%p][%c:%L] %m%n"/>
+ <TimeBasedTriggeringPolicy interval="1"/>
+ <SizeBasedTriggeringPolicy size="10 MB"/>
+ </RollingFile>
+ </Appenders>
+ <Loggers>
+ <Root level="info">
+ <AppenderRef ref="Console"/>
+ <AppenderRef ref="DailyRollingFile"/>
+ </Root>
+ </Loggers>
+</configuration>
\ No newline at end of file
diff --git a/authentication/Client/src/main/resources/microservice.yaml b/authentication/Client/src/main/resources/microservice.yaml
new file mode 100644
index 0000000..411b4c6
--- /dev/null
+++ b/authentication/Client/src/main/resources/microservice.yaml
@@ -0,0 +1,35 @@
+#
+## ---------------------------------------------------------------------------
+## Licensed to the Apache Software Foundation (ASF) under one or more
+## contributor license agreements. See the NOTICE file distributed with
+## this work for additional information regarding copyright ownership.
+## The ASF licenses this file to You 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.
+## ---------------------------------------------------------------------------
+
+# override common configurations in common module
+servicecomb-config-order: 100
+
+APPLICATION_ID: authentication-application
+service_description:
+ version: 0.0.1
+ name: authentication-server
+
+servicecomb:
+ service:
+ registry:
+ address: http://localhost:30100
+ instance:
+ watch: false
+
+ rest:
+ address: 0.0.0.0:9092
diff --git a/authentication/Gateway/pom.xml b/authentication/Gateway/pom.xml
new file mode 100644
index 0000000..9223b6b
--- /dev/null
+++ b/authentication/Gateway/pom.xml
@@ -0,0 +1,88 @@
+<!--
+ ~ Licensed to the Apache Software Foundation (ASF) under one or more
+ ~ contributor license agreements. See the NOTICE file distributed with
+ ~ this work for additional information regarding copyright ownership.
+ ~ The ASF licenses this file to You 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.
+ -->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <groupId>org.apache.servicecomb.authentication</groupId>
+ <artifactId>gateway</artifactId>
+ <version>0.0.1-SNAPSHOT</version>
+ <packaging>jar</packaging>
+
+ <properties>
+ <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+ </properties>
+
+ <dependencyManagement>
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.servicecomb</groupId>
+ <artifactId>java-chassis-dependencies</artifactId>
+ <version>1.2.0</version>
+ <type>pom</type>
+ <scope>import</scope>
+ </dependency>
+ </dependencies>
+ </dependencyManagement>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.servicecomb</groupId>
+ <artifactId>solution-basic</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.servicecomb</groupId>
+ <artifactId>inspector</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.servicecomb</groupId>
+ <artifactId>edge-core</artifactId>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <pluginManagement>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <version>3.1</version>
+ <configuration>
+ <source>1.8</source>
+ <target>1.8</target>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.springframework.boot</groupId>
+ <artifactId>spring-boot-maven-plugin</artifactId>
+ <version>2.1.2.RELEASE</version>
+ <executions>
+ <execution>
+ <goals>
+ <goal>repackage</goal>
+ </goals>
+ <configuration>
+ <mainClass>${main.class}</mainClass>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </pluginManagement>
+ </build>
+</project>
\ No newline at end of file
diff --git a/authentication/Gateway/src/main/java/org/apache/servicecomb/samples/porter/gateway/ApiDispatcher.java b/authentication/Gateway/src/main/java/org/apache/servicecomb/samples/porter/gateway/ApiDispatcher.java
new file mode 100644
index 0000000..e801ebd
--- /dev/null
+++ b/authentication/Gateway/src/main/java/org/apache/servicecomb/samples/porter/gateway/ApiDispatcher.java
@@ -0,0 +1,68 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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 org.apache.servicecomb.samples.porter.gateway;
+
+import java.util.Map;
+
+import org.apache.servicecomb.edge.core.AbstractEdgeDispatcher;
+import org.apache.servicecomb.edge.core.EdgeInvocation;
+
+import io.vertx.ext.web.Cookie;
+import io.vertx.ext.web.Router;
+import io.vertx.ext.web.RoutingContext;
+import io.vertx.ext.web.handler.CookieHandler;
+
+public class ApiDispatcher extends AbstractEdgeDispatcher {
+ @Override
+ public int getOrder() {
+ return 10002;
+ }
+
+ @Override
+ public void init(Router router) {
+ String regex = "/api/([^\\/]+)/(.*)";
+ router.routeWithRegex(regex).handler(CookieHandler.create());
+ router.routeWithRegex(regex).handler(createBodyHandler());
+ router.routeWithRegex(regex).failureHandler(this::onFailure).handler(this::onRequest);
+ }
+
+ protected void onRequest(RoutingContext context) {
+ Map<String, String> pathParams = context.pathParams();
+ String microserviceName = pathParams.get("param0");
+ String path = "/" + pathParams.get("param1");
+
+ EdgeInvocation invoker = new EdgeInvocation() {
+ // Authentication. Notice: adding context must after setContext or will override by network
+ protected void setContext() throws Exception {
+ super.setContext();
+ // get session id from header and cookie for debug reasons
+ String sessionId = context.request().getHeader("session-id");
+ if (sessionId != null) {
+ this.invocation.addContext("session-id", sessionId);
+ } else {
+ Cookie sessionCookie = context.getCookie("session-id");
+ if (sessionCookie != null) {
+ this.invocation.addContext("session-id", sessionCookie.getValue());
+ }
+ }
+ }
+ };
+ invoker.init(microserviceName, context, path, httpServerFilters);
+ invoker.edgeInvoke();
+ }
+}
diff --git a/authentication/Gateway/src/main/java/org/apache/servicecomb/samples/porter/gateway/AuthHandler.java b/authentication/Gateway/src/main/java/org/apache/servicecomb/samples/porter/gateway/AuthHandler.java
new file mode 100644
index 0000000..7119753
--- /dev/null
+++ b/authentication/Gateway/src/main/java/org/apache/servicecomb/samples/porter/gateway/AuthHandler.java
@@ -0,0 +1,31 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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 org.apache.servicecomb.samples.porter.gateway;
+
+import org.apache.servicecomb.core.Handler;
+import org.apache.servicecomb.core.Invocation;
+import org.apache.servicecomb.swagger.invocation.AsyncResponse;
+
+
+public class AuthHandler implements Handler {
+ @Override
+ public void handle(Invocation invocation, AsyncResponse asyncResponse) throws Exception {
+ // TODO check session
+ invocation.next(asyncResponse);
+ }
+}
diff --git a/authentication/Gateway/src/main/java/org/apache/servicecomb/samples/porter/gateway/CustomVertxRestDispatcher.java b/authentication/Gateway/src/main/java/org/apache/servicecomb/samples/porter/gateway/CustomVertxRestDispatcher.java
new file mode 100644
index 0000000..a2941be
--- /dev/null
+++ b/authentication/Gateway/src/main/java/org/apache/servicecomb/samples/porter/gateway/CustomVertxRestDispatcher.java
@@ -0,0 +1,196 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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 org.apache.servicecomb.samples.porter.gateway;
+
+import javax.ws.rs.core.HttpHeaders;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response.Status;
+import javax.ws.rs.core.Response.Status.Family;
+
+import org.apache.servicecomb.common.rest.AbstractRestInvocation;
+import org.apache.servicecomb.common.rest.RestConst;
+import org.apache.servicecomb.common.rest.VertxRestInvocation;
+import org.apache.servicecomb.core.Const;
+import org.apache.servicecomb.core.CseContext;
+import org.apache.servicecomb.core.Transport;
+import org.apache.servicecomb.foundation.vertx.http.HttpServletRequestEx;
+import org.apache.servicecomb.foundation.vertx.http.HttpServletResponseEx;
+import org.apache.servicecomb.foundation.vertx.http.VertxServerRequestToHttpServletRequest;
+import org.apache.servicecomb.foundation.vertx.http.VertxServerResponseToHttpServletResponse;
+import org.apache.servicecomb.swagger.invocation.exception.InvocationException;
+import org.apache.servicecomb.transport.rest.vertx.AbstractVertxHttpDispatcher;
+import org.apache.servicecomb.transport.rest.vertx.VertxRestDispatcher;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import io.netty.handler.codec.http.multipart.HttpPostRequestDecoder.ErrorDataDecoderException;
+import io.vertx.core.json.JsonObject;
+import io.vertx.ext.web.Router;
+import io.vertx.ext.web.RoutingContext;
+import io.vertx.ext.web.handler.CookieHandler;
+
+// copied from org.apache.servicecomb.transport.rest.vertx.VertxRestDispatcher
+public class CustomVertxRestDispatcher extends AbstractVertxHttpDispatcher {
+ private static final Logger LOGGER = LoggerFactory.getLogger(VertxRestDispatcher.class);
+
+ private Transport transport;
+
+ @Override
+ public int getOrder() {
+ return 10001;
+ }
+
+ @Override
+ public boolean enabled() {
+ return true;
+ }
+
+ @Override
+ public void init(Router router) {
+ String regex = "[/v1/log/|/inspector|/v1/auth](.*)";
+ router.routeWithRegex(regex).handler(CookieHandler.create());
+ router.routeWithRegex(regex).handler(createBodyHandler());
+ router.routeWithRegex(regex).failureHandler(this::failureHandler).handler(this::onRequest);
+ }
+
+ private void failureHandler(RoutingContext context) {
+ LOGGER.error("http server failed.", context.failure());
+
+ AbstractRestInvocation restProducerInvocation = context.get(RestConst.REST_PRODUCER_INVOCATION);
+ Throwable e = context.failure();
+ if (ErrorDataDecoderException.class.isInstance(e)) {
+ Throwable cause = e.getCause();
+ if (InvocationException.class.isInstance(cause)) {
+ e = cause;
+ }
+ }
+
+ // only when unexpected exception happens, it will run into here.
+ // the connection should be closed.
+ handleFailureAndClose(context, restProducerInvocation, e);
+ }
+
+ /**
+ * Try to find out the failure information and send it in response.
+ */
+ private void handleFailureAndClose(RoutingContext context, AbstractRestInvocation restProducerInvocation,
+ Throwable e) {
+ if (null != restProducerInvocation) {
+ // if there is restProducerInvocation, let it send exception in response. The exception is allowed to be null.
+ sendFailResponseByInvocation(context, restProducerInvocation, e);
+ return;
+ }
+
+ if (null != e) {
+ // if there exists exception, try to send this exception by RoutingContext
+ sendExceptionByRoutingContext(context, e);
+ return;
+ }
+
+ // if there is no exception, the response is determined by status code.
+ sendFailureRespDeterminedByStatus(context);
+ }
+
+ /**
+ * Try to determine response by status code, and send response.
+ */
+ private void sendFailureRespDeterminedByStatus(RoutingContext context) {
+ Family statusFamily = Family.familyOf(context.statusCode());
+ if (Family.CLIENT_ERROR.equals(statusFamily) || Family.SERVER_ERROR.equals(statusFamily) || Family.OTHER
+ .equals(statusFamily)) {
+ context.response().putHeader(HttpHeaders.CONTENT_TYPE, MediaType.WILDCARD)
+ .setStatusCode(context.statusCode()).end();
+ } else {
+ // it seems the status code is not set properly
+ context.response().putHeader(HttpHeaders.CONTENT_TYPE, MediaType.WILDCARD)
+ .setStatusCode(Status.INTERNAL_SERVER_ERROR.getStatusCode())
+ .setStatusMessage(Status.INTERNAL_SERVER_ERROR.getReasonPhrase())
+ .end(wrapResponseBody(Status.INTERNAL_SERVER_ERROR.getReasonPhrase()));
+ }
+ context.response().close();
+ }
+
+ /**
+ * Use routingContext to send failure information in throwable.
+ */
+ private void sendExceptionByRoutingContext(RoutingContext context, Throwable e) {
+ if (InvocationException.class.isInstance(e)) {
+ InvocationException invocationException = (InvocationException) e;
+ context.response().putHeader(HttpHeaders.CONTENT_TYPE, MediaType.WILDCARD)
+ .setStatusCode(invocationException.getStatusCode()).setStatusMessage(invocationException.getReasonPhrase())
+ .end(wrapResponseBody(invocationException.getReasonPhrase()));
+ } else {
+ context.response().putHeader(HttpHeaders.CONTENT_TYPE, MediaType.WILDCARD)
+ .setStatusCode(Status.INTERNAL_SERVER_ERROR.getStatusCode()).end(wrapResponseBody(e.getMessage()));
+ }
+ context.response().close();
+ }
+
+ /**
+ * Consumer will treat the response body as json by default, so it's necessary to wrap response body as Json string
+ * to avoid deserialization error.
+ *
+ * @param message response body
+ * @return response body wrapped as Json string
+ */
+ String wrapResponseBody(String message) {
+ if (isValidJson(message)) {
+ return message;
+ }
+
+ JsonObject jsonObject = new JsonObject();
+ jsonObject.put("message", message);
+
+ return jsonObject.toString();
+ }
+
+ /**
+ * Check if the message is a valid Json string.
+ * @param message the message to be checked.
+ * @return true if message is a valid Json string, otherwise false.
+ */
+ private boolean isValidJson(String message) {
+ try {
+ new JsonObject(message);
+ } catch (Exception ignored) {
+ return false;
+ }
+ return true;
+ }
+
+ /**
+ * Use restProducerInvocation to send failure message. The throwable is allowed to be null.
+ */
+ private void sendFailResponseByInvocation(RoutingContext context, AbstractRestInvocation restProducerInvocation,
+ Throwable e) {
+ restProducerInvocation.sendFailResponse(e);
+ context.response().close();
+ }
+
+ private void onRequest(RoutingContext context) {
+ if (transport == null) {
+ transport = CseContext.getInstance().getTransportManager().findTransport(Const.RESTFUL);
+ }
+ HttpServletRequestEx requestEx = new VertxServerRequestToHttpServletRequest(context);
+ HttpServletResponseEx responseEx = new VertxServerResponseToHttpServletResponse(context.response());
+
+ VertxRestInvocation vertxRestInvocation = new VertxRestInvocation();
+ context.put(RestConst.REST_PRODUCER_INVOCATION, vertxRestInvocation);
+ vertxRestInvocation.invoke(transport, requestEx, responseEx, httpServerFilters);
+ }
+}
diff --git a/authentication/Gateway/src/main/java/org/apache/servicecomb/samples/porter/gateway/EdgeSSLCustom.java b/authentication/Gateway/src/main/java/org/apache/servicecomb/samples/porter/gateway/EdgeSSLCustom.java
new file mode 100644
index 0000000..159c10d
--- /dev/null
+++ b/authentication/Gateway/src/main/java/org/apache/servicecomb/samples/porter/gateway/EdgeSSLCustom.java
@@ -0,0 +1,38 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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 org.apache.servicecomb.samples.porter.gateway;
+
+import java.io.File;
+
+import org.apache.servicecomb.foundation.ssl.SSLCustom;
+
+public class EdgeSSLCustom extends SSLCustom {
+
+ @Override
+ public char[] decode(char[] plain) {
+ return plain;
+ }
+
+ @Override
+ public String getFullPath(String name) {
+ String fullName = System.getProperty("user.dir") + File.separator + name;
+ System.out.println(fullName);
+ return (new File(fullName)).getAbsolutePath();
+ }
+
+}
diff --git a/authentication/Gateway/src/main/java/org/apache/servicecomb/samples/porter/gateway/GatewayMain.java b/authentication/Gateway/src/main/java/org/apache/servicecomb/samples/porter/gateway/GatewayMain.java
new file mode 100644
index 0000000..a219d2d
--- /dev/null
+++ b/authentication/Gateway/src/main/java/org/apache/servicecomb/samples/porter/gateway/GatewayMain.java
@@ -0,0 +1,26 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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 org.apache.servicecomb.samples.porter.gateway;
+
+import org.apache.servicecomb.foundation.common.utils.BeanUtils;
+
+public class GatewayMain {
+ public static void main(String[] args) throws Exception {
+ BeanUtils.init();
+ }
+}
diff --git a/authentication/Gateway/src/main/java/org/apache/servicecomb/samples/porter/gateway/InternalAccessHandler.java b/authentication/Gateway/src/main/java/org/apache/servicecomb/samples/porter/gateway/InternalAccessHandler.java
new file mode 100644
index 0000000..0b181d8
--- /dev/null
+++ b/authentication/Gateway/src/main/java/org/apache/servicecomb/samples/porter/gateway/InternalAccessHandler.java
@@ -0,0 +1,37 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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 org.apache.servicecomb.samples.porter.gateway;
+
+import org.apache.servicecomb.core.Handler;
+import org.apache.servicecomb.core.Invocation;
+import org.apache.servicecomb.swagger.invocation.AsyncResponse;
+import org.apache.servicecomb.swagger.invocation.exception.InvocationException;
+
+public class InternalAccessHandler implements Handler {
+
+ @Override
+ public void handle(Invocation invocation, AsyncResponse asyncReponse) throws Exception {
+ if (invocation.getOperationMeta().getSwaggerOperation().getTags() != null
+ && invocation.getOperationMeta().getSwaggerOperation().getTags().contains("INTERNAL")) {
+ asyncReponse.consumerFail(new InvocationException(403, "", "not allowed"));
+ return;
+ }
+ invocation.next(asyncReponse);
+ }
+
+}
diff --git a/authentication/Gateway/src/main/java/org/apache/servicecomb/samples/porter/gateway/StaticWebpageDispatcher.java b/authentication/Gateway/src/main/java/org/apache/servicecomb/samples/porter/gateway/StaticWebpageDispatcher.java
new file mode 100644
index 0000000..791c512
--- /dev/null
+++ b/authentication/Gateway/src/main/java/org/apache/servicecomb/samples/porter/gateway/StaticWebpageDispatcher.java
@@ -0,0 +1,52 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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 org.apache.servicecomb.samples.porter.gateway;
+
+import org.apache.servicecomb.transport.rest.vertx.VertxHttpDispatcher;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.netflix.config.DynamicPropertyFactory;
+
+import io.vertx.ext.web.Router;
+import io.vertx.ext.web.handler.StaticHandler;
+
+public class StaticWebpageDispatcher implements VertxHttpDispatcher {
+ private static final Logger LOGGER = LoggerFactory.getLogger(StaticWebpageDispatcher.class);
+
+ private static final String WEB_ROOT = DynamicPropertyFactory.getInstance()
+ .getStringProperty("gateway.webroot", "/var/static")
+ .get();
+
+ @Override
+ public int getOrder() {
+ return Integer.MAX_VALUE;
+ }
+
+ @Override
+ public void init(Router router) {
+ String regex = "/ui/(.*)";
+ StaticHandler webpageHandler = StaticHandler.create();
+ webpageHandler.setWebRoot(WEB_ROOT);
+ LOGGER.info("server static web page for WEB_ROOT={}", WEB_ROOT);
+ router.routeWithRegex(regex).failureHandler((context) -> {
+ LOGGER.error("", context.failure());
+ }).handler(webpageHandler);
+ }
+
+}
diff --git a/authentication/Gateway/src/main/resources/META-INF/services/org.apache.servicecomb.transport.rest.vertx.VertxHttpDispatcher b/authentication/Gateway/src/main/resources/META-INF/services/org.apache.servicecomb.transport.rest.vertx.VertxHttpDispatcher
new file mode 100644
index 0000000..bada1de
--- /dev/null
+++ b/authentication/Gateway/src/main/resources/META-INF/services/org.apache.servicecomb.transport.rest.vertx.VertxHttpDispatcher
@@ -0,0 +1,20 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You 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.
+#
+
+org.apache.servicecomb.samples.porter.gateway.ApiDispatcher
+org.apache.servicecomb.samples.porter.gateway.StaticWebpageDispatcher
+org.apache.servicecomb.samples.porter.gateway.CustomVertxRestDispatcher
\ No newline at end of file
diff --git a/authentication/Gateway/src/main/resources/META-INF/spring/cse.bean.xml b/authentication/Gateway/src/main/resources/META-INF/spring/cse.bean.xml
new file mode 100644
index 0000000..b5816c3
--- /dev/null
+++ b/authentication/Gateway/src/main/resources/META-INF/spring/cse.bean.xml
@@ -0,0 +1,27 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ~ Licensed to the Apache Software Foundation (ASF) under one or more
+ ~ contributor license agreements. See the NOTICE file distributed with
+ ~ this work for additional information regarding copyright ownership.
+ ~ The ASF licenses this file to You 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.
+ -->
+
+<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xmlns:context="http://www.springframework.org/schema/context"
+ xsi:schemaLocation="
+ http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
+ http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
+
+ <bean id="servicecomb.samples.executor.groupThreadPool" class="org.apache.servicecomb.core.executor.GroupExecutor"
+ init-method="init"/>
+</beans>
diff --git a/authentication/Gateway/src/main/resources/config/cse.handler.xml b/authentication/Gateway/src/main/resources/config/cse.handler.xml
new file mode 100644
index 0000000..e9dd306
--- /dev/null
+++ b/authentication/Gateway/src/main/resources/config/cse.handler.xml
@@ -0,0 +1,23 @@
+<!--
+ ~ Licensed to the Apache Software Foundation (ASF) under one or more
+ ~ contributor license agreements. See the NOTICE file distributed with
+ ~ this work for additional information regarding copyright ownership.
+ ~ The ASF licenses this file to You 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.
+ -->
+
+<config>
+ <handler id="auth"
+ class="org.apache.servicecomb.samples.porter.gateway.AuthHandler" />
+ <handler id="internalAccess"
+ class="org.apache.servicecomb.samples.porter.gateway.InternalAccessHandler" />
+</config>
diff --git a/authentication/Gateway/src/main/resources/log4j2.xml b/authentication/Gateway/src/main/resources/log4j2.xml
new file mode 100644
index 0000000..b51f28e
--- /dev/null
+++ b/authentication/Gateway/src/main/resources/log4j2.xml
@@ -0,0 +1,43 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ~ Licensed to the Apache Software Foundation (ASF) under one or more
+ ~ contributor license agreements. See the NOTICE file distributed with
+ ~ this work for additional information regarding copyright ownership.
+ ~ The ASF licenses this file to You 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.
+ -->
+
+<!--this is sample configuration, please modify as your wish-->
+
+<configuration>
+ <Properties>
+ <Property name="log_path">./gateway/log/</Property>
+ </Properties>
+
+ <Appenders>
+ <Console name="Console" target="SYSTEM_OUT">
+ <PatternLayout pattern="[%d][%t][%p][%c:%L] %m%n"/>
+ </Console>
+ <RollingFile name="DailyRollingFile" fileName="${log_path}/output.log"
+ filePattern="${log_path}/zcrTest%d{yyyy-MM-dd}.log">
+ <PatternLayout pattern="[%d][%t][%p][%c:%L] %m%n"/>
+ <TimeBasedTriggeringPolicy interval="1"/>
+ <SizeBasedTriggeringPolicy size="10 MB"/>
+ </RollingFile>
+ </Appenders>
+ <Loggers>
+ <Root level="info">
+ <AppenderRef ref="Console"/>
+ <AppenderRef ref="DailyRollingFile"/>
+ </Root>
+ </Loggers>
+</configuration>
\ No newline at end of file
diff --git a/authentication/Gateway/src/main/resources/microservice.yaml b/authentication/Gateway/src/main/resources/microservice.yaml
new file mode 100644
index 0000000..5b1cd91
--- /dev/null
+++ b/authentication/Gateway/src/main/resources/microservice.yaml
@@ -0,0 +1,67 @@
+#
+## ---------------------------------------------------------------------------
+## Licensed to the Apache Software Foundation (ASF) under one or more
+## contributor license agreements. See the NOTICE file distributed with
+## this work for additional information regarding copyright ownership.
+## The ASF licenses this file to You 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.
+## ---------------------------------------------------------------------------
+
+# override common configurations in common module
+servicecomb-config-order: 100
+
+APPLICATION_ID: authentication-application
+service_description:
+ version: 0.0.1
+ name: gateway
+
+servicecomb:
+ service:
+ registry:
+ address: http://localhost:30100
+ instance:
+ watch: false
+
+ rest:
+ address: 0.0.0.0:9090
+
+ handler:
+ chain:
+ Consumer:
+ default: internalAccess,auth,qps-flowcontrol-consumer,loadbalance
+
+ uploads:
+ directory: tmp_for_upload_gateway
+
+ samples:
+ logdir: D:\code\servicecomb-samples\porter_lightweight\gateway-service
+
+ inspector:
+ enabled: false
+
+ executors:
+ Provider:
+ log: servicecomb.samples.executor.groupThreadPool
+ inspector: servicecomb.samples.executor.groupThreadPool
+
+# disable all servicecomb difault dispatchers, all of them are overriden
+ http:
+ dispatcher:
+ edge:
+ default:
+ enabled: false # overriden by ApiDispatcher
+ rest:
+ eanbled: false # overriden by CustomVertxRestDispatcher
+
+# StaticWebpageDispatcher checking file exists is async, and will mark request status to ended, and VertxRestDispatcher read
+# body will print exception.
+#gateway.webroot: /code/servicecomb-samples/porter_lightweight/gateway-service/src/main/resources
diff --git a/authentication/Gateway/src/main/resources/ui/css/style.css b/authentication/Gateway/src/main/resources/ui/css/style.css
new file mode 100644
index 0000000..5731863
--- /dev/null
+++ b/authentication/Gateway/src/main/resources/ui/css/style.css
@@ -0,0 +1,49 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.
+ */
+
+.error {
+ font-family:verdana;
+ color:red;
+}
+
+.header {
+ background-color:black;
+ color:white;
+ text-align:center;
+ padding:5px;
+}
+
+.nav {
+ line-height:30px;
+ background-color:#eeeeee;
+ height:300px;
+ width:100px;
+ float:left;
+ padding:5px;
+}
+
+.section {
+ text-align:center;
+ padding:5px;
+}
+
+.footer {
+ color:red;
+ clear:both;
+ text-align:center;
+ padding:25px;
+}
\ No newline at end of file
diff --git a/authentication/Gateway/src/main/resources/ui/js/jquery-1.11.1.min.js b/authentication/Gateway/src/main/resources/ui/js/jquery-1.11.1.min.js
new file mode 100644
index 0000000..ab28a24
--- /dev/null
+++ b/authentication/Gateway/src/main/resources/ui/js/jquery-1.11.1.min.js
@@ -0,0 +1,4 @@
+/*! jQuery v1.11.1 | (c) 2005, 2014 jQuery Foundation, Inc. | jquery.org/license */
+!function(a,b){"object"==typeof module&&"object"==typeof module.exports?module.exports=a.document?b(a,!0):function(a){if(!a.document)throw new Error("jQuery requires a window with a document");return b(a)}:b(a)}("undefined"!=typeof window?window:this,function(a,b){var c=[],d=c.slice,e=c.concat,f=c.push,g=c.indexOf,h={},i=h.toString,j=h.hasOwnProperty,k={},l="1.11.1",m=function(a,b){return new m.fn.init(a,b)},n=/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g,o=/^-ms-/,p=/-([\da-z])/gi,q=function(a,b [...]
+if(k&&j[k]&&(e||j[k].data)||void 0!==d||"string"!=typeof b)return k||(k=i?a[h]=c.pop()||m.guid++:h),j[k]||(j[k]=i?{}:{toJSON:m.noop}),("object"==typeof b||"function"==typeof b)&&(e?j[k]=m.extend(j[k],b):j[k].data=m.extend(j[k].data,b)),g=j[k],e||(g.data||(g.data={}),g=g.data),void 0!==d&&(g[m.camelCase(b)]=d),"string"==typeof b?(f=g[b],null==f&&(f=g[m.camelCase(b)])):f=g,f}}function R(a,b,c){if(m.acceptData(a)){var d,e,f=a.nodeType,g=f?m.cache:a,h=f?a[m.expando]:m.expando;if(g[h]){if(b&& [...]
+},cur:function(){var a=Zb.propHooks[this.prop];return a&&a.get?a.get(this):Zb.propHooks._default.get(this)},run:function(a){var b,c=Zb.propHooks[this.prop];return this.pos=b=this.options.duration?m.easing[this.easing](a,this.options.duration*a,0,1,this.options.duration):a,this.now=(this.end-this.start)*b+this.start,this.options.step&&this.options.step.call(this.elem,this.now,this),c&&c.set?c.set(this):Zb.propHooks._default.set(this),this}},Zb.prototype.init.prototype=Zb.prototype,Zb.prop [...]
diff --git a/authentication/Gateway/src/main/resources/ui/js/login.js b/authentication/Gateway/src/main/resources/ui/js/login.js
new file mode 100644
index 0000000..c7e7c8e
--- /dev/null
+++ b/authentication/Gateway/src/main/resources/ui/js/login.js
@@ -0,0 +1,52 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.
+ */
+
+function loginAction() {
+ var username = document.getElementById("username").value;
+ var password = document.getElementById("paasword").value;
+ var formData = {};
+ formData.userName = username;
+ formData.password = password;
+
+ $.ajax({
+ type: 'POST',
+ url: "/api/user-service/v1/user/login",
+ data: formData,
+ success: function (data) {
+ console.log(data);
+ setCookie("session-id", data.sessiondId, 1);
+ window.location = "/ui/upload.html";
+ },
+ error: function(data) {
+ console.log(data);
+ var error = document.getElementById("error");
+ error.textContent="Login failed";
+ error.hidden=false;
+ },
+ async: true
+ });
+}
+
+function setCookie(name,value,days) {
+ var expires = "";
+ if (days) {
+ var date = new Date();
+ date.setTime(date.getTime() + (days*24*60*60*1000));
+ expires = "; expires=" + date.toUTCString();
+ }
+ document.cookie = name + "=" + (value || "") + expires + "; path=/";
+}
\ No newline at end of file
diff --git a/authentication/Gateway/src/main/resources/ui/js/upload.js b/authentication/Gateway/src/main/resources/ui/js/upload.js
new file mode 100644
index 0000000..7d66555
--- /dev/null
+++ b/authentication/Gateway/src/main/resources/ui/js/upload.js
@@ -0,0 +1,63 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.
+ */
+
+function uploadAction() {
+ var formData = new FormData(document.getElementById("upload_form"));
+
+ $.ajax({
+ type: 'POST',
+ url: "/api/file-service/upload",
+ data: formData,
+ processData:false,
+ contentType:false,
+ success: function (data) {
+ console.log(data);
+ var error = document.getElementById("error");
+ error.textContent="Upload Successfully";
+ error.hidden=false;
+ },
+ error: function(data) {
+ console.log(data);
+ var error = document.getElementById("error");
+ error.textContent="Upload failed";
+ error.hidden=false;
+ },
+ async: true
+ });
+}
+
+function deleteAction() {
+ var fileID = document.getElementById("fileID").value;
+ $.ajax({
+ type: 'DELETE',
+ url: "/api/file-service/delete?" + $.param({ id: fileID }),
+ data: {},
+ success: function (data) {
+ console.log(data);
+ var error = document.getElementById("error");
+ error.textContent="Delete successfully";
+ error.hidden=false;
+ },
+ error: function(data) {
+ console.log(data);
+ var error = document.getElementById("error");
+ error.textContent="Delete failed";
+ error.hidden=false;
+ },
+ async: true
+ });
+}
\ No newline at end of file
diff --git a/authentication/Gateway/src/main/resources/ui/login.html b/authentication/Gateway/src/main/resources/ui/login.html
new file mode 100644
index 0000000..c8b45fb
--- /dev/null
+++ b/authentication/Gateway/src/main/resources/ui/login.html
@@ -0,0 +1,45 @@
+<!DOCTYPE html>
+
+<!--
+ ~ Licensed to the Apache Software Foundation (ASF) under one or more
+ ~ contributor license agreements. See the NOTICE file distributed with
+ ~ this work for additional information regarding copyright ownership.
+ ~ The ASF licenses this file to You 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.
+ -->
+
+<html>
+
+ <head>
+ <title>PORTER</title>
+ <link href="css/style.css" rel="stylesheet" type="text/css" media="all" />
+ <script type="text/javascript" src="js/jquery-1.11.1.min.js"></script>
+ <script type="text/javascript" src="js/login.js"></script>
+ </head>
+
+ <body>
+ <div class="header">
+ <h2>Login</h2>
+ </div>
+ <div class="section">
+ <form method="POST" enctype="multipart/form-data">
+ <input id="username" type="text" placeholder="Username" required="true"/>
+ <input id="paasword" type="password" placeholder="Password" required="true"/>
+ <input type="button" value="Login" onclick="loginAction()">
+ </form>
+ </div>
+ <div class="footer">
+ <p id="error" hidden="true" class="error"/>
+ </div>
+ </body>
+
+</html>
\ No newline at end of file
diff --git a/authentication/Gateway/src/main/resources/ui/upload.html b/authentication/Gateway/src/main/resources/ui/upload.html
new file mode 100644
index 0000000..bd5eeff
--- /dev/null
+++ b/authentication/Gateway/src/main/resources/ui/upload.html
@@ -0,0 +1,61 @@
+<!DOCTYPE html>
+<!--
+ ~ Licensed to the Apache Software Foundation (ASF) under one or more
+ ~ contributor license agreements. See the NOTICE file distributed with
+ ~ this work for additional information regarding copyright ownership.
+ ~ The ASF licenses this file to You 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.
+ -->
+
+<html>
+
+ <head>
+ <title>PORTER</title>
+ <link href="css/style.css" rel="stylesheet" type="text/css" media="all" />
+ <script type="text/javascript" src="js/jquery-1.11.1.min.js"></script>
+ <script type="text/javascript" src="js/upload.js"></script>
+ </head>
+
+ <body>
+ <div class="header">
+ <h2>Upload</h2>
+ </div>
+ <div class="section">
+ <form id="upload_form" method="POST">
+ <p>
+ File Name: <input type="file" name="fileName"/>
+ </p>
+ <p>
+ <input type="button" value="Upload" onclick="uploadAction()">
+ </p>
+ </form>
+ </div>
+
+ <div class="header">
+ <h2>Delete file</h2>
+ </div>
+ <div class="section">
+ <form id="delete_form" method="DELETE">
+ <p>
+ File ID: <input id="fileID" type="text"/>
+ </p>
+ <p>
+ <input type="button" value="Delete" onclick="deleteAction()">
+ </p>
+ </form>
+ </div>
+ <div class="footer">
+ <p id="error" hidden="true" class="error"/>
+ </div>
+ </body>
+
+</html>
\ No newline at end of file
diff --git a/authentication/README.md b/authentication/README.md
new file mode 100644
index 0000000..48798cd
--- /dev/null
+++ b/authentication/README.md
@@ -0,0 +1,26 @@
+本项目提供认证鉴权服务的实现,主要提供了基于角色的权限管理,和基于JWT的微服务授权模式。微服务的命名参考了OAuth2协议里面的命名方式。可以参考[OAuth2.0原理和验证流程分析](https://www.jianshu.com/p/d74ce6ca0c33)对于OAuth2认证过程的介绍,本项目的认证过程非常类似OAuth2的密码模式。
+
+项目的目标是提供一个商业可用的鉴权实现,对于项目代码实现的问题可以提交issue,本项目也接纳PR,共同完善。
+
+* AuthenticationServer
+
+认证鉴权服务。提供用户管理、角色管理。并提供登录认证、权限查询等接口。鉴权服务及相关API是核心交付件,也是能够被重用的部分。开发者可以基于这个项目开发认证鉴权服务。
+
+* Gateway
+提供请求拦截,校验用户是否已经经过认证。一方面演示网关如何和配套鉴权服务完成开发,本项目也是自动化测试的组成部分。
+
+* Client
+Client模拟的是使用使用者。一方面演示客户端如何获取Token,本项目也是自动化测试的组成部分。
+
+* ResourceServer
+ResourceServer模拟的是业务服务。一方面演示业务服务如何进行权限配置,本项目也是自动化测试的组成部分。
+
+
+## 实现说明
+
+* 用户管理
+用户管理采用了org.springframework.security.core.userdetails的模型,包括:
+ 1. UserDetailsService:加载用户信息。
+ 2. UserDetails:用户信息。
+ 3. GrantedAuthority:角色信息。
+ 4. PasswordEncoder:用户密码加密和匹配。
\ No newline at end of file
diff --git a/authentication/ResourceServer/pom.xml b/authentication/ResourceServer/pom.xml
new file mode 100644
index 0000000..52aea79
--- /dev/null
+++ b/authentication/ResourceServer/pom.xml
@@ -0,0 +1,128 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- ~ Licensed to the Apache Software Foundation (ASF) under one or more
+ ~ contributor license agreements. See the NOTICE file distributed with ~
+ this work for additional information regarding copyright ownership. ~ The
+ ASF licenses this file to You 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. -->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <groupId>org.apache.servicecomb.authentication</groupId>
+ <artifactId>resource-server</artifactId>
+ <version>0.0.1-SNAPSHOT</version>
+ <packaging>jar</packaging>
+
+ <properties>
+ <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+ </properties>
+
+ <dependencyManagement>
+ <dependencies>
+ <dependency>
+ <groupId>org.mybatis</groupId>
+ <artifactId>mybatis</artifactId>
+ <version>3.4.5</version>
+ </dependency>
+ <dependency>
+ <groupId>org.mybatis</groupId>
+ <artifactId>mybatis-spring</artifactId>
+ <version>1.3.0</version>
+ </dependency>
+ <dependency>
+ <groupId>mysql</groupId>
+ <artifactId>mysql-connector-java</artifactId>
+ <version>5.1.46</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.servicecomb</groupId>
+ <artifactId>java-chassis-dependencies</artifactId>
+ <version>1.2.0</version>
+ <type>pom</type>
+ <scope>import</scope>
+ </dependency>
+ </dependencies>
+ </dependencyManagement>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.servicecomb</groupId>
+ <artifactId>solution-basic</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.servicecomb</groupId>
+ <artifactId>inspector</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.mybatis</groupId>
+ <artifactId>mybatis</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>mysql</groupId>
+ <artifactId>mysql-connector-java</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.commons</groupId>
+ <artifactId>commons-dbcp2</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.mybatis</groupId>
+ <artifactId>mybatis-spring</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-jdbc</artifactId>
+ <scope>compile</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-aop</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-context-support</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-tx</artifactId>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <pluginManagement>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <version>3.1</version>
+ <configuration>
+ <source>1.8</source>
+ <target>1.8</target>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.springframework.boot</groupId>
+ <artifactId>spring-boot-maven-plugin</artifactId>
+ <version>2.1.2.RELEASE</version>
+ <executions>
+ <execution>
+ <goals>
+ <goal>repackage</goal>
+ </goals>
+ <configuration>
+ <mainClass>${main.class}</mainClass>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </pluginManagement>
+ </build>
+</project>
\ No newline at end of file
diff --git a/authentication/ResourceServer/src/main/java/org/apache/servicecomb/authentication/ResourceServer.java b/authentication/ResourceServer/src/main/java/org/apache/servicecomb/authentication/ResourceServer.java
new file mode 100644
index 0000000..f2653ab
--- /dev/null
+++ b/authentication/ResourceServer/src/main/java/org/apache/servicecomb/authentication/ResourceServer.java
@@ -0,0 +1,30 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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 org.apache.servicecomb.authentication;
+
+import org.apache.servicecomb.foundation.common.utils.BeanUtils;
+
+public class ResourceServer {
+ public static void main(String[] args) {
+ try {
+ BeanUtils.init();
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+}
diff --git a/authentication/ResourceServer/src/main/java/org/apache/servicecomb/authentication/resource/FileEndpoint.java b/authentication/ResourceServer/src/main/java/org/apache/servicecomb/authentication/resource/FileEndpoint.java
new file mode 100644
index 0000000..4b6a5b6
--- /dev/null
+++ b/authentication/ResourceServer/src/main/java/org/apache/servicecomb/authentication/resource/FileEndpoint.java
@@ -0,0 +1,45 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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 org.apache.servicecomb.authentication.resource;
+
+import org.apache.servicecomb.provider.rest.common.RestSchema;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.http.MediaType;
+import org.springframework.web.bind.annotation.DeleteMapping;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestParam;
+import org.springframework.web.bind.annotation.RequestPart;
+import org.springframework.web.multipart.MultipartFile;
+
+@RestSchema(schemaId = "FileEndpoint")
+@RequestMapping(path = "/v1/file")
+public class FileEndpoint {
+ @Autowired
+ private FileStoreService fileService;
+
+ @PostMapping(path = "/upload", produces = MediaType.TEXT_PLAIN_VALUE)
+ public String uploadFile(@RequestPart(name = "fileName") MultipartFile file) {
+ return fileService.uploadFile(file);
+ }
+
+ @DeleteMapping(path = "/delete", produces = MediaType.APPLICATION_JSON_VALUE)
+ public boolean deleteFile(@RequestParam(name = "id") String id) {
+ return fileService.deleteFile(id);
+ }
+}
diff --git a/authentication/ResourceServer/src/main/java/org/apache/servicecomb/authentication/resource/FileStoreService.java b/authentication/ResourceServer/src/main/java/org/apache/servicecomb/authentication/resource/FileStoreService.java
new file mode 100644
index 0000000..ed03665
--- /dev/null
+++ b/authentication/ResourceServer/src/main/java/org/apache/servicecomb/authentication/resource/FileStoreService.java
@@ -0,0 +1,31 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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 org.apache.servicecomb.authentication.resource;
+
+import org.springframework.web.multipart.MultipartFile;
+
+/**
+ * file storage service, can implement using file system, OBS, etc.
+ */
+public interface FileStoreService {
+
+ public String uploadFile(MultipartFile file);
+
+ public boolean deleteFile(String id);
+
+}
diff --git a/authentication/ResourceServer/src/main/java/org/apache/servicecomb/authentication/resource/LocalFileStoreService.java b/authentication/ResourceServer/src/main/java/org/apache/servicecomb/authentication/resource/LocalFileStoreService.java
new file mode 100644
index 0000000..d487144
--- /dev/null
+++ b/authentication/ResourceServer/src/main/java/org/apache/servicecomb/authentication/resource/LocalFileStoreService.java
@@ -0,0 +1,64 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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 org.apache.servicecomb.authentication.resource;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.util.UUID;
+
+import org.springframework.stereotype.Component;
+import org.springframework.web.multipart.MultipartFile;
+
+/**
+ * Simple file storage implementation.
+ * Caution: file check and other security constraints not implemented.
+ */
+@Component
+public class LocalFileStoreService implements FileStoreService {
+ // maxmum BUFFER_SIZE * BUFFER_NUM
+ private static final int BUFFER_SIZE = 10240;
+
+ private static final File BASE_FILE = new File(".");
+
+ @Override
+ public String uploadFile(MultipartFile file) {
+ byte[] buffer = new byte[BUFFER_SIZE];
+ String fileId = UUID.randomUUID().toString();
+
+ File outFile = new File(BASE_FILE, fileId);
+ int len;
+ try (InputStream is = file.getInputStream(); OutputStream os = new FileOutputStream(outFile)) {
+ while ((len = is.read(buffer)) != -1) {
+ os.write(buffer, 0, len);
+ }
+ } catch (IOException e) {
+ return null;
+ }
+ return fileId;
+ }
+
+ @Override
+ public boolean deleteFile(String id) {
+ File outFile = new File(BASE_FILE, id);
+ return outFile.delete();
+ }
+
+}
diff --git a/authentication/ResourceServer/src/main/resources/META-INF/spring/user.bean.xml b/authentication/ResourceServer/src/main/resources/META-INF/spring/user.bean.xml
new file mode 100644
index 0000000..661608f
--- /dev/null
+++ b/authentication/ResourceServer/src/main/resources/META-INF/spring/user.bean.xml
@@ -0,0 +1,56 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ~ Licensed to the Apache Software Foundation (ASF) under one or more
+ ~ contributor license agreements. See the NOTICE file distributed with
+ ~ this work for additional information regarding copyright ownership.
+ ~ The ASF licenses this file to You 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.
+ -->
+
+<beans xmlns="http://www.springframework.org/schema/beans"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
+ xmlns:util="http://www.springframework.org/schema/util"
+ xmlns:context="http://www.springframework.org/schema/context"
+ xmlns:tx="http://www.springframework.org/schema/tx"
+ xsi:schemaLocation="
+ http://www.springframework.org/schema/beans classpath:org/springframework/beans/factory/xml/spring-beans-3.0.xsd
+ http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.1.xsd http://www.springframework.org/schema/data/jpa http://www.springframework.org/schema/data/jpa/spring-jpa.xsd
+ http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd">
+ <bean id="servicecomb.samples.executor.groupThreadPool" class="org.apache.servicecomb.core.executor.GroupExecutor"
+ init-method="init"/>
+
+ <bean id="dataSource"
+ class="org.apache.commons.dbcp2.BasicDataSource"
+ destroy-method="close">
+ <property name="driverClassName" value="${db.driverClassName:com.mysql.jdbc.Driver}" />
+ <property name="url"
+ value="${db.url:jdbc:mysql://localhost/porter_user_db}" />
+ <property name="username" value="${db.username:root}" />
+ <property name="password" value="${db.password:}" />
+ </bean>
+
+ <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
+ <property name="dataSource" ref="dataSource" />
+ <property name="configLocation" value="classpath:/config/mybatis-config.xml"></property>
+ </bean>
+
+ <bean id="userMapper" class="org.mybatis.spring.mapper.MapperFactoryBean">
+ <property name="mapperInterface"
+ value="org.apache.servicecomb.samples.porter.user.dao.UserMapper" />
+ <property name="sqlSessionFactory" ref="sqlSessionFactory" />
+ </bean>
+ <bean id="sessionMapper" class="org.mybatis.spring.mapper.MapperFactoryBean">
+ <property name="mapperInterface"
+ value="org.apache.servicecomb.samples.porter.user.dao.SessionMapper" />
+ <property name="sqlSessionFactory" ref="sqlSessionFactory" />
+ </bean>
+</beans>
\ No newline at end of file
diff --git a/authentication/ResourceServer/src/main/resources/config/SessionMapper.xml b/authentication/ResourceServer/src/main/resources/config/SessionMapper.xml
new file mode 100644
index 0000000..989e786
--- /dev/null
+++ b/authentication/ResourceServer/src/main/resources/config/SessionMapper.xml
@@ -0,0 +1,57 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ~ Licensed to the Apache Software Foundation (ASF) under one or more
+ ~ contributor license agreements. See the NOTICE file distributed with
+ ~ this work for additional information regarding copyright ownership.
+ ~ The ASF licenses this file to You 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.
+ -->
+
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="org.apache.servicecomb.samples.porter.user.dao.SessionMapper">
+ <resultMap id="sessionInfo" type="org.apache.servicecomb.samples.porter.user.dao.SessionInfoModel">
+ <result column="ID" jdbcType="INTEGER" property="id" />
+ <result column="SESSION_ID" jdbcType="VARCHAR" property="sessiondId" />
+ <result column="USER_NAME" jdbcType="VARCHAR" property="userName" />
+ <result column="ROLE_NAME" jdbcType="VARCHAR" property="roleName" />
+ <result column="CREATION_TIME" jdbcType="TIMESTAMP" property="creationTime" />
+ <result column="ACTIVE_TIME" jdbcType="TIMESTAMP" property="activeTime" />
+ </resultMap>
+
+ <sql id="all_column">
+ ID, SESSION_ID, USER_NAME, ROLE_NAME, CREATION_TIME, ACTIVE_TIME
+ </sql>
+
+ <sql id="all_column_auto">
+ SESSION_ID, USER_NAME, ROLE_NAME
+ </sql>
+
+ <insert id="createSession" parameterType="org.apache.servicecomb.samples.porter.user.dao.SessionInfoModel">
+ insert into T_SESSION (
+ <include refid="all_column_auto" />
+ )
+ values (#{sessiondId,jdbcType=VARCHAR}, #{userName,jdbcType=VARCHAR},
+ #{roleName,jdbcType=VARCHAR})
+ </insert>
+
+ <select id="getSessioinInfo" parameterType="java.lang.String"
+ resultMap="sessionInfo">
+ select
+ <include refid="all_column" />
+ from T_SESSION where SESSION_ID = #{0,jdbcType=VARCHAR}
+ </select>
+
+ <update id="updateSessionInfo" parameterType="java.lang.String">
+ update T_SESSION
+ set CREATION_TIME = CREATION_TIME where SESSION_ID = #{0,jdbcType=VARCHAR};
+ </update>
+</mapper>
\ No newline at end of file
diff --git a/authentication/ResourceServer/src/main/resources/config/UserMapper.xml b/authentication/ResourceServer/src/main/resources/config/UserMapper.xml
new file mode 100644
index 0000000..c02e60d
--- /dev/null
+++ b/authentication/ResourceServer/src/main/resources/config/UserMapper.xml
@@ -0,0 +1,46 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ~ Licensed to the Apache Software Foundation (ASF) under one or more
+ ~ contributor license agreements. See the NOTICE file distributed with
+ ~ this work for additional information regarding copyright ownership.
+ ~ The ASF licenses this file to You 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.
+ -->
+
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="org.apache.servicecomb.samples.porter.user.dao.UserMapper">
+ <resultMap id="userInfo" type="org.apache.servicecomb.samples.porter.user.dao.UserInfo">
+ <result column="ID" jdbcType="INTEGER" property="id" />
+ <result column="USER_NAME" jdbcType="VARCHAR" property="userName" />
+ <result column="PASSWORD" jdbcType="VARCHAR" property="password" />
+ <result column="ROLE_NAME" jdbcType="VARCHAR" property="roleName" />
+ </resultMap>
+
+ <sql id="all_column">
+ ID, USER_NAME, PASSWORD, ROLE_NAME
+ </sql>
+
+ <insert id="createUser" parameterType="org.apache.servicecomb.samples.porter.user.dao.UserInfo">
+ insert into T_USER (
+ <include refid="all_column" />
+ )
+ values (#{id,jdbcType=INTEGER}, #{userName,jdbcType=VARCHAR},
+ #{password,jdbcType=VARCHAR},#{roleName,jdbcType=VARCHAR})
+ </insert>
+
+ <select id="getUserInfo" parameterType="java.lang.String"
+ resultMap="userInfo">
+ select
+ <include refid="all_column" />
+ from T_USER where USER_NAME = #{0,jdbcType=VARCHAR}
+ </select>
+</mapper>
\ No newline at end of file
diff --git a/authentication/ResourceServer/src/main/resources/config/create_db_user.sql b/authentication/ResourceServer/src/main/resources/config/create_db_user.sql
new file mode 100644
index 0000000..a07c5d9
--- /dev/null
+++ b/authentication/ResourceServer/src/main/resources/config/create_db_user.sql
@@ -0,0 +1,46 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.
+ */
+
+CREATE DATABASE IF NOT EXISTS porter_user_db;
+
+USE porter_user_db;
+
+DROP TABLE IF EXISTS T_USER;
+
+CREATE TABLE `T_USER` (
+ `ID` INTEGER(8) NOT NULL AUTO_INCREMENT COMMENT 'user id',
+ `USER_NAME` VARCHAR(64) NOT NULL COMMENT 'user name',
+ `PASSWORD` VARCHAR(64) NOT NULL COMMENT 'user password',
+ `ROLE_NAME` VARCHAR(64) NOT NULL COMMENT 'user role',
+ PRIMARY KEY (`ID`)
+);
+
+#### password is encrypted for test
+insert into T_USER(USER_NAME, PASSWORD, ROLE_NAME) values("admin", "n4bQgYhMfWWaL+qgxVrQFaO/TxsrC4Is0V1sFbDwCgg=", "admin");
+insert into T_USER(USER_NAME, PASSWORD, ROLE_NAME) values("guest", "n4bQgYhMfWWaL+qgxVrQFaO/TxsrC4Is0V1sFbDwCgg=", "guest");
+
+DROP TABLE IF EXISTS T_SESSION;
+
+CREATE TABLE `T_SESSION` (
+ `ID` INTEGER(8) NOT NULL AUTO_INCREMENT COMMENT 'id',
+ `SESSION_ID` VARCHAR(64) NOT NULL COMMENT 'session id',
+ `USER_NAME` VARCHAR(64) NOT NULL COMMENT 'user name',
+ `ROLE_NAME` VARCHAR(64) NOT NULL COMMENT 'user role',
+ `CREATION_TIME` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT 'creation time',
+ `ACTIVE_TIME` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT 'last active time',
+ PRIMARY KEY (`ID`)
+);
diff --git a/authentication/ResourceServer/src/main/resources/config/mybatis-config.xml b/authentication/ResourceServer/src/main/resources/config/mybatis-config.xml
new file mode 100644
index 0000000..894caac
--- /dev/null
+++ b/authentication/ResourceServer/src/main/resources/config/mybatis-config.xml
@@ -0,0 +1,27 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<!--
+ ~ Licensed to the Apache Software Foundation (ASF) under one or more
+ ~ contributor license agreements. See the NOTICE file distributed with
+ ~ this work for additional information regarding copyright ownership.
+ ~ The ASF licenses this file to You 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.
+ -->
+
+<!DOCTYPE configuration
+ PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
+ "http://mybatis.org/dtd/mybatis-3-config.dtd">
+<configuration>
+ <mappers>
+ <mapper resource="config/UserMapper.xml"/>
+ <mapper resource="config/SessionMapper.xml"/>
+ </mappers>
+</configuration>
\ No newline at end of file
diff --git a/authentication/ResourceServer/src/main/resources/log4j2.xml b/authentication/ResourceServer/src/main/resources/log4j2.xml
new file mode 100644
index 0000000..3c70391
--- /dev/null
+++ b/authentication/ResourceServer/src/main/resources/log4j2.xml
@@ -0,0 +1,43 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ~ Licensed to the Apache Software Foundation (ASF) under one or more
+ ~ contributor license agreements. See the NOTICE file distributed with
+ ~ this work for additional information regarding copyright ownership.
+ ~ The ASF licenses this file to You 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.
+ -->
+
+<!--this is sample configuration, please modify as your wish-->
+
+<configuration>
+ <Properties>
+ <Property name="log_path">./user/log/</Property>
+ </Properties>
+
+ <Appenders>
+ <Console name="Console" target="SYSTEM_OUT">
+ <PatternLayout pattern="[%d][%t][%p][%c:%L] %m%n"/>
+ </Console>
+ <RollingFile name="DailyRollingFile" fileName="${log_path}/output.log"
+ filePattern="${log_path}/zcrTest%d{yyyy-MM-dd}.log">
+ <PatternLayout pattern="[%d][%t][%p][%c:%L] %m%n"/>
+ <TimeBasedTriggeringPolicy interval="1"/>
+ <SizeBasedTriggeringPolicy size="10 MB"/>
+ </RollingFile>
+ </Appenders>
+ <Loggers>
+ <Root level="info">
+ <AppenderRef ref="Console"/>
+ <AppenderRef ref="DailyRollingFile"/>
+ </Root>
+ </Loggers>
+</configuration>
\ No newline at end of file
diff --git a/authentication/ResourceServer/src/main/resources/microservice.yaml b/authentication/ResourceServer/src/main/resources/microservice.yaml
new file mode 100644
index 0000000..47b05c1
--- /dev/null
+++ b/authentication/ResourceServer/src/main/resources/microservice.yaml
@@ -0,0 +1,35 @@
+#
+## ---------------------------------------------------------------------------
+## Licensed to the Apache Software Foundation (ASF) under one or more
+## contributor license agreements. See the NOTICE file distributed with
+## this work for additional information regarding copyright ownership.
+## The ASF licenses this file to You 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.
+## ---------------------------------------------------------------------------
+
+# override common configurations in common module
+servicecomb-config-order: 100
+
+APPLICATION_ID: authentication-application
+service_description:
+ version: 0.0.1
+ name: resource-server
+
+servicecomb:
+ service:
+ registry:
+ address: http://localhost:30100
+ instance:
+ watch: false
+
+ rest:
+ address: 0.0.0.0:9092
diff --git a/authentication/api/AuthenticationServer/endpoint/pom.xml b/authentication/api/AuthenticationServer/endpoint/pom.xml
new file mode 100644
index 0000000..5eebece
--- /dev/null
+++ b/authentication/api/AuthenticationServer/endpoint/pom.xml
@@ -0,0 +1,38 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ~ Licensed to the Apache Software Foundation (ASF) under one or more
+ ~ contributor license agreements. See the NOTICE file distributed with
+ ~ this work for additional information regarding copyright ownership.
+ ~ The ASF licenses this file to You 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.
+ -->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.apache.servicecomb.authentication</groupId>
+ <artifactId>authentication-server-api</artifactId>
+ <version>0.0.1-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>authentication-server-api-endpoint</artifactId>
+ <packaging>jar</packaging>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.servicecomb.authentication</groupId>
+ <artifactId>authentication-server-api-service</artifactId>
+ <version>${project.parent.version}</version>
+ </dependency>
+ </dependencies>
+</project>
diff --git a/authentication/api/AuthenticationServer/endpoint/src/main/java/org/apache/servicecomb/authentication/api/AuthenticationEndpoint.java b/authentication/api/AuthenticationServer/endpoint/src/main/java/org/apache/servicecomb/authentication/api/AuthenticationEndpoint.java
new file mode 100644
index 0000000..dfc9c51
--- /dev/null
+++ b/authentication/api/AuthenticationServer/endpoint/src/main/java/org/apache/servicecomb/authentication/api/AuthenticationEndpoint.java
@@ -0,0 +1,39 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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 org.apache.servicecomb.authentication.api;
+
+import org.apache.servicecomb.provider.rest.common.RestSchema;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestParam;
+
+@RestSchema(schemaId = "AuthenticationEndpoint")
+@RequestMapping(path = "/v1/auth/login")
+public class AuthenticationEndpoint {
+ @Autowired
+ private AuthenticationService authenticationService;
+
+ public Token login(@RequestParam(name = "userName") String userName,
+ @RequestParam(name = "password") String password) {
+ return authenticationService.login(userName, password);
+ }
+
+ public Token refresh(@RequestParam(name = "refreshToken") String refreshToken) {
+ return authenticationService.refresh(refreshToken);
+ }
+}
diff --git a/authentication/api/AuthenticationServer/pom.xml b/authentication/api/AuthenticationServer/pom.xml
new file mode 100644
index 0000000..946a2fb
--- /dev/null
+++ b/authentication/api/AuthenticationServer/pom.xml
@@ -0,0 +1,36 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ~ Licensed to the Apache Software Foundation (ASF) under one or more
+ ~ contributor license agreements. See the NOTICE file distributed with
+ ~ this work for additional information regarding copyright ownership.
+ ~ The ASF licenses this file to You 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.
+ -->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.apache.servicecomb.authentication</groupId>
+ <artifactId>authentication-api</artifactId>
+ <version>0.0.1-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>authentication-server-api</artifactId>
+ <packaging>pom</packaging>
+
+ <modules>
+ <module>service</module>
+ <module>endpoint</module>
+ </modules>
+</project>
\ No newline at end of file
diff --git a/authentication/api/AuthenticationServer/service/pom.xml b/authentication/api/AuthenticationServer/service/pom.xml
new file mode 100644
index 0000000..4433ff6
--- /dev/null
+++ b/authentication/api/AuthenticationServer/service/pom.xml
@@ -0,0 +1,31 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ~ Licensed to the Apache Software Foundation (ASF) under one or more
+ ~ contributor license agreements. See the NOTICE file distributed with
+ ~ this work for additional information regarding copyright ownership.
+ ~ The ASF licenses this file to You 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.
+ -->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.apache.servicecomb.authentication</groupId>
+ <artifactId>authentication-server-api</artifactId>
+ <version>0.0.1-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>authentication-server-api-service</artifactId>
+ <packaging>jar</packaging>
+
+</project>
diff --git a/authentication/api/AuthenticationServer/service/src/main/java/org/apache/servicecomb/authentication/api/AuthenticationService.java b/authentication/api/AuthenticationServer/service/src/main/java/org/apache/servicecomb/authentication/api/AuthenticationService.java
new file mode 100644
index 0000000..77635ad
--- /dev/null
+++ b/authentication/api/AuthenticationServer/service/src/main/java/org/apache/servicecomb/authentication/api/AuthenticationService.java
@@ -0,0 +1,35 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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 org.apache.servicecomb.authentication.api;
+
+public interface AuthenticationService {
+ /**
+ * login using user name and password.
+ * @param userName user name
+ * @param password password
+ * @return After successfully login, token is created. Or null is returned.
+ */
+ Token login(String userName, String password);
+
+ /**
+ * acquired new token using refresh token.
+ * @param refreshToken refresh token
+ * @return After successfully authenticated, token is created. Or null is returned.
+ */
+ Token refresh(String refreshToken);
+}
diff --git a/authentication/api/AuthenticationServer/service/src/main/java/org/apache/servicecomb/authentication/api/Token.java b/authentication/api/AuthenticationServer/service/src/main/java/org/apache/servicecomb/authentication/api/Token.java
new file mode 100644
index 0000000..732fe22
--- /dev/null
+++ b/authentication/api/AuthenticationServer/service/src/main/java/org/apache/servicecomb/authentication/api/Token.java
@@ -0,0 +1,40 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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 org.apache.servicecomb.authentication.api;
+
+public class Token {
+ private String accessToken;
+
+ private String refreshToken;
+
+ public String getAccessToken() {
+ return accessToken;
+ }
+
+ public void setAccessToken(String accessToken) {
+ this.accessToken = accessToken;
+ }
+
+ public String getRefreshToken() {
+ return refreshToken;
+ }
+
+ public void setRefreshToken(String refreshToken) {
+ this.refreshToken = refreshToken;
+ }
+}
diff --git a/authentication/api/AuthenticationServer/service/src/main/java/org/apache/servicecomb/authentication/api/Tokens.java b/authentication/api/AuthenticationServer/service/src/main/java/org/apache/servicecomb/authentication/api/Tokens.java
new file mode 100644
index 0000000..54c2175
--- /dev/null
+++ b/authentication/api/AuthenticationServer/service/src/main/java/org/apache/servicecomb/authentication/api/Tokens.java
@@ -0,0 +1,48 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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 org.apache.servicecomb.authentication.api;
+
+/**
+ *
+ * After successfully login, tokens are created. </br>
+ * <B>Access Token:</B> used to access resources.</br>
+ * <B>Refresh Token:</B> used to acquire new tokens.</br>
+ *
+ */
+public class Tokens {
+ private String accessToken;
+
+ private String refreshToken;
+
+ public String getAccessToken() {
+ return accessToken;
+ }
+
+ public void setAccessToken(String accessToken) {
+ this.accessToken = accessToken;
+ }
+
+ public String getRefreshToken() {
+ return refreshToken;
+ }
+
+ public void setRefreshToken(String refreshToken) {
+ this.refreshToken = refreshToken;
+ }
+
+}
diff --git a/authentication/api/common/endpoint/pom.xml b/authentication/api/common/endpoint/pom.xml
new file mode 100644
index 0000000..de2736a
--- /dev/null
+++ b/authentication/api/common/endpoint/pom.xml
@@ -0,0 +1,38 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ~ Licensed to the Apache Software Foundation (ASF) under one or more
+ ~ contributor license agreements. See the NOTICE file distributed with
+ ~ this work for additional information regarding copyright ownership.
+ ~ The ASF licenses this file to You 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.
+ -->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.apache.servicecomb.authentication</groupId>
+ <artifactId>authentication-common-api</artifactId>
+ <version>0.0.1-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>authentication-common-api-endpoint</artifactId>
+ <packaging>jar</packaging>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.servicecomb.authentication</groupId>
+ <artifactId>authentication-common-api-service</artifactId>
+ <version>${project.parent.version}</version>
+ </dependency>
+ </dependencies>
+</project>
diff --git a/authentication/api/common/endpoint/src/main/java/org/apache/servicecomb/samples/porter/file/api/InspectorEndpoint.java b/authentication/api/common/endpoint/src/main/java/org/apache/servicecomb/samples/porter/file/api/InspectorEndpoint.java
new file mode 100644
index 0000000..731f6ac
--- /dev/null
+++ b/authentication/api/common/endpoint/src/main/java/org/apache/servicecomb/samples/porter/file/api/InspectorEndpoint.java
@@ -0,0 +1,206 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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 org.apache.servicecomb.samples.porter.file.api;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.File;
+import java.nio.charset.StandardCharsets;
+import java.util.Collection;
+import java.util.Map.Entry;
+import java.util.zip.ZipEntry;
+import java.util.zip.ZipOutputStream;
+
+import javax.servlet.http.Part;
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.QueryParam;
+import javax.ws.rs.core.HttpHeaders;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response.Status;
+
+import org.apache.servicecomb.common.rest.resource.ClassPathStaticResourceHandler;
+import org.apache.servicecomb.common.rest.resource.StaticResourceHandler;
+import org.apache.servicecomb.config.inject.ConfigObjectFactory;
+import org.apache.servicecomb.foundation.common.part.InputStreamPart;
+import org.apache.servicecomb.inspector.internal.InspectorConfig;
+import org.apache.servicecomb.inspector.internal.swagger.AppendStyleProcessor;
+import org.apache.servicecomb.inspector.internal.swagger.SchemaFormat;
+import org.apache.servicecomb.provider.rest.common.RestSchema;
+import org.apache.servicecomb.serviceregistry.RegistryUtils;
+import org.apache.servicecomb.swagger.SwaggerUtils;
+import org.apache.servicecomb.swagger.invocation.Response;
+import org.apache.servicecomb.swagger.invocation.exception.InvocationException;
+import org.asciidoctor.Asciidoctor;
+import org.asciidoctor.Asciidoctor.Factory;
+import org.asciidoctor.Attributes;
+import org.asciidoctor.AttributesBuilder;
+import org.asciidoctor.OptionsBuilder;
+import org.asciidoctor.SafeMode;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.common.collect.Ordering;
+
+import io.github.swagger2markup.Swagger2MarkupConfig;
+import io.github.swagger2markup.Swagger2MarkupConverter;
+import io.github.swagger2markup.Swagger2MarkupConverter.Builder;
+import io.github.swagger2markup.builder.Swagger2MarkupConfigBuilder;
+import io.swagger.annotations.ApiResponse;
+import io.swagger.models.parameters.Parameter;
+
+// copied from org.apache.servicecomb.inspector.internal.InspectorImpl;
+@RestSchema(schemaId = "inspector")
+@Path("/inspector")
+public class InspectorEndpoint {
+ private static final Logger LOGGER = LoggerFactory.getLogger(InspectorEndpoint.class);
+
+ private InspectorConfig inspectorConfig;
+
+ private volatile Asciidoctor asciidoctor;
+
+ private StaticResourceHandler resourceHandler = new ClassPathStaticResourceHandler();
+
+ public InspectorEndpoint() {
+ this.inspectorConfig = new ConfigObjectFactory().create(InspectorConfig.class);
+ }
+
+ @Path("/schemas")
+ @GET
+ public Collection<String> getSchemaIds() {
+ return RegistryUtils.getServiceRegistry().getMicroservice().getSchemaMap().keySet();
+ }
+
+ @Path("/download/schemas")
+ @GET
+ @ApiResponse(code = 200, message = "", response = File.class)
+ public Response downloadSchemas(@QueryParam("format") SchemaFormat format) {
+ if (format == null) {
+ format = SchemaFormat.SWAGGER;
+ }
+
+ // normally, schema will not be too big, just save them in memory temporarily
+ ByteArrayOutputStream os = new ByteArrayOutputStream();
+ try (ZipOutputStream zos = new ZipOutputStream(os)) {
+ for (Entry<String, String> entry : RegistryUtils.getServiceRegistry().getMicroservice().getSchemaMap().entrySet()) {
+ // begin writing a new ZIP entry, positions the stream to the start of the entry data
+ zos.putNextEntry(new ZipEntry(entry.getKey() + format.getSuffix()));
+
+ String content = entry.getValue();
+ if (SchemaFormat.HTML.equals(format)) {
+ content = swaggerToHtml(content);
+ }
+ zos.write(content.getBytes(StandardCharsets.UTF_8));
+ zos.closeEntry();
+ }
+ } catch (Throwable e) {
+ String msg = "failed to create schemas zip file, format=" + format + ".";
+ LOGGER.error(msg, e);
+ return Response.failResp(new InvocationException(Status.INTERNAL_SERVER_ERROR, msg));
+ }
+
+ Part part = new InputStreamPart(null, new ByteArrayInputStream(os.toByteArray()))
+ .setSubmittedFileName(RegistryUtils.getMicroservice().getServiceName() + format.getSuffix() + ".zip");
+ return Response.ok(part);
+ }
+
+ @Path("/schemas/{schemaId}")
+ @GET
+ @ApiResponse(code = 200, message = "", response = File.class)
+ public Response getSchemaContentById(@PathParam("schemaId") String schemaId,
+ @QueryParam("format") SchemaFormat format, @QueryParam("download") boolean download) {
+ String swaggerContent = RegistryUtils.getServiceRegistry().getMicroservice().getSchemaMap().get(schemaId);
+ if (swaggerContent == null) {
+ return Response.failResp(new InvocationException(Status.NOT_FOUND, Status.NOT_FOUND.getReasonPhrase()));
+ }
+
+ if (format == null) {
+ format = SchemaFormat.SWAGGER;
+ }
+
+ byte[] bytes;
+ if (SchemaFormat.HTML.equals(format)) {
+ String html = swaggerToHtml(swaggerContent);
+ bytes = html.getBytes(StandardCharsets.UTF_8);
+ } else {
+ bytes = swaggerContent.getBytes(StandardCharsets.UTF_8);
+ }
+
+ Part part = new InputStreamPart(null, new ByteArrayInputStream(bytes))
+ .setSubmittedFileName(schemaId + format.getSuffix());
+
+ Response response = Response.ok(part);
+ if (!download) {
+ response.getHeaders().addHeader(HttpHeaders.CONTENT_DISPOSITION, "inline");
+ }
+ response.getHeaders().addHeader(HttpHeaders.CONTENT_TYPE, MediaType.TEXT_HTML);
+ return response;
+ }
+
+ // swagger not support cookie parameter
+ // so if swaggerContent contains cookie parameter, will cause problem.
+ private String swaggerToHtml(String swaggerContent) {
+ if (asciidoctor == null) {
+ synchronized (this) {
+ if (asciidoctor == null) {
+ // very slow, need a few seconds
+ LOGGER.info("create AsciiDoctor start.");
+ asciidoctor = Factory.create();
+ asciidoctor.javaExtensionRegistry().docinfoProcessor(AppendStyleProcessor.class);
+ LOGGER.info("create AsciiDoctor end.");
+ }
+ }
+ }
+
+ // swagger to markup
+ Builder markupBuilder = Swagger2MarkupConverter.from(SwaggerUtils.parseSwagger(swaggerContent));
+ // default not support cookie parameter
+ // so must customize config
+ Swagger2MarkupConfig markupConfig = new Swagger2MarkupConfigBuilder()
+ .withParameterOrdering(Ordering
+ .explicit("path", "query", "header", "cookie", "formData", "body")
+ .onResultOf(Parameter::getIn))
+ .build();
+ String markup = markupBuilder.withConfig(markupConfig).build().toString();
+
+ // markup to html
+ OptionsBuilder builder = OptionsBuilder.options();
+ builder.docType("book")
+ .backend("html5")
+ .headerFooter(true)
+ .safe(SafeMode.UNSAFE)
+ .attributes(AttributesBuilder.attributes()
+ .attribute("toclevels", 3)
+ .attribute(Attributes.TOC_2, true)
+ .attribute(Attributes.TOC_POSITION, "left")
+ .attribute(Attributes.LINK_CSS, true)
+ .attribute(Attributes.STYLESHEET_NAME, inspectorConfig.getAsciidoctorCss())
+ .attribute(Attributes.SECTION_NUMBERS, true)
+ .attribute(Attributes.SECT_NUM_LEVELS, 4));
+ return asciidoctor.convert(markup, builder.asMap());
+ }
+
+ @Path("/{path : .+}")
+ @GET
+ @ApiResponse(code = 200, message = "", response = File.class)
+ public Response getStaticResource(@PathParam("path") String path) {
+ return resourceHandler.handle(path);
+ }
+}
+
diff --git a/authentication/api/common/endpoint/src/main/java/org/apache/servicecomb/samples/porter/file/api/LogEndpoint.java b/authentication/api/common/endpoint/src/main/java/org/apache/servicecomb/samples/porter/file/api/LogEndpoint.java
new file mode 100644
index 0000000..8e49a6e
--- /dev/null
+++ b/authentication/api/common/endpoint/src/main/java/org/apache/servicecomb/samples/porter/file/api/LogEndpoint.java
@@ -0,0 +1,72 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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 org.apache.servicecomb.samples.porter.file.api;
+
+import java.io.File;
+import java.io.FileFilter;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.servicecomb.provider.rest.common.RestSchema;
+import org.apache.servicecomb.samples.porter.common.api.LogService;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestParam;
+
+import com.netflix.config.DynamicPropertyFactory;
+
+@RestSchema(schemaId = "log")
+@RequestMapping(path = "/v1/log")
+public class LogEndpoint implements LogService {
+ // protect your file in real applications
+ private static final File LOG_DIR =
+ new File(DynamicPropertyFactory.getInstance().getStringProperty("servicecomb.samples.logdir", ".").get());
+
+ private static final String FILE_POST_FIX = ".log";
+
+ @Override
+ @GetMapping(path = "/getLogFileList")
+ public List<String> getLogFileList() {
+ File[] files = LOG_DIR.listFiles(new FileFilter() {
+ @Override
+ public boolean accept(File file) {
+ return isLogFile(file);
+ }
+ });
+
+ List<String> result = new ArrayList<>(files.length);
+ for (int i = 0; i < files.length; i++) {
+ result.add(files[i].getName());
+ }
+ return result;
+ }
+
+ @Override
+ @GetMapping(path = "/getLogFileContent")
+ public File getLogFileContent(@RequestParam(name = "fileName") String fileName) {
+ File file = new File(LOG_DIR, fileName);
+ if (isLogFile(file)) {
+ return file;
+ }
+ return null;
+ }
+
+ private boolean isLogFile(File file) {
+ return file.isFile() && file.canRead() && file.getName().endsWith(FILE_POST_FIX);
+ }
+}
diff --git a/authentication/api/common/pom.xml b/authentication/api/common/pom.xml
new file mode 100644
index 0000000..b4a9fbc
--- /dev/null
+++ b/authentication/api/common/pom.xml
@@ -0,0 +1,36 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ~ Licensed to the Apache Software Foundation (ASF) under one or more
+ ~ contributor license agreements. See the NOTICE file distributed with
+ ~ this work for additional information regarding copyright ownership.
+ ~ The ASF licenses this file to You 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.
+ -->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.apache.servicecomb.authentication</groupId>
+ <artifactId>authentication-api</artifactId>
+ <version>0.0.1-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>authentication-common-api</artifactId>
+ <packaging>pom</packaging>
+
+ <modules>
+ <module>service</module>
+ <module>endpoint</module>
+ </modules>
+</project>
\ No newline at end of file
diff --git a/authentication/api/common/service/pom.xml b/authentication/api/common/service/pom.xml
new file mode 100644
index 0000000..538be70
--- /dev/null
+++ b/authentication/api/common/service/pom.xml
@@ -0,0 +1,31 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ~ Licensed to the Apache Software Foundation (ASF) under one or more
+ ~ contributor license agreements. See the NOTICE file distributed with
+ ~ this work for additional information regarding copyright ownership.
+ ~ The ASF licenses this file to You 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.
+ -->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.apache.servicecomb.authentication</groupId>
+ <artifactId>authentication-common-api</artifactId>
+ <version>0.0.1-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>authentication-common-api-service</artifactId>
+ <packaging>jar</packaging>
+
+</project>
diff --git a/authentication/api/common/service/src/main/java/org/apache/servicecomb/samples/porter/common/api/LogService.java b/authentication/api/common/service/src/main/java/org/apache/servicecomb/samples/porter/common/api/LogService.java
new file mode 100644
index 0000000..9991543
--- /dev/null
+++ b/authentication/api/common/service/src/main/java/org/apache/servicecomb/samples/porter/common/api/LogService.java
@@ -0,0 +1,26 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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 org.apache.servicecomb.samples.porter.common.api;
+
+import java.io.File;
+import java.util.List;
+
+public interface LogService {
+ List<String> getLogFileList();
+ File getLogFileContent(String fileName);
+}
diff --git a/authentication/api/pom.xml b/authentication/api/pom.xml
new file mode 100644
index 0000000..cdc3926
--- /dev/null
+++ b/authentication/api/pom.xml
@@ -0,0 +1,90 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ~ Licensed to the Apache Software Foundation (ASF) under one or more
+ ~ contributor license agreements. See the NOTICE file distributed with
+ ~ this work for additional information regarding copyright ownership.
+ ~ The ASF licenses this file to You 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.
+ -->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <groupId>org.apache.servicecomb.authentication</groupId>
+ <artifactId>authentication-api</artifactId>
+ <version>0.0.1-SNAPSHOT</version>
+ <packaging>pom</packaging>
+
+ <properties>
+ <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+ </properties>
+
+ <modules>
+ <module>common</module>
+ <module>AuthenticationServer</module>
+ </modules>
+
+ <dependencyManagement>
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.servicecomb</groupId>
+ <artifactId>java-chassis-dependencies</artifactId>
+ <version>1.2.0</version>
+ <type>pom</type>
+ <scope>import</scope>
+ </dependency>
+ </dependencies>
+ </dependencyManagement>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.servicecomb</groupId>
+ <artifactId>solution-basic</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.servicecomb</groupId>
+ <artifactId>inspector</artifactId>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <pluginManagement>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <version>3.1</version>
+ <configuration>
+ <source>1.8</source>
+ <target>1.8</target>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.springframework.boot</groupId>
+ <artifactId>spring-boot-maven-plugin</artifactId>
+ <version>2.1.2.RELEASE</version>
+ <executions>
+ <execution>
+ <goals>
+ <goal>repackage</goal>
+ </goals>
+ <configuration>
+ <mainClass>${main.class}</mainClass>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </pluginManagement>
+ </build>
+</project>
\ No newline at end of file