Browse Source

客户端

root 5 years ago
parent
commit
8df64930ef

+ 97 - 0
src/main/java/com/kingkong/bljs/dao/ClientMapper.java

@@ -0,0 +1,97 @@
1
+package com.kingkong.bljs.dao;
2
+
3
+import com.kingkong.bljs.entity.Client;
4
+import org.apache.ibatis.annotations.Delete;
5
+import org.apache.ibatis.annotations.Insert;
6
+import org.apache.ibatis.annotations.ResultMap;
7
+import org.apache.ibatis.annotations.Select;
8
+import org.apache.ibatis.annotations.Update;
9
+
10
+public interface ClientMapper {
11
+    /**
12
+     * This method was generated by MyBatis Generator.
13
+     * This method corresponds to the database table K_USER.K_CLIENT
14
+     *
15
+     * @mbg.generated Mon May 27 16:39:18 CST 2019
16
+     */
17
+    @Delete({
18
+        "delete from K_USER.K_CLIENT",
19
+        "where CLIENT_ID = #{clientId,jdbcType=VARCHAR}"
20
+    })
21
+    int deleteByPrimaryKey(String clientId);
22
+
23
+    /**
24
+     * This method was generated by MyBatis Generator.
25
+     * This method corresponds to the database table K_USER.K_CLIENT
26
+     *
27
+     * @mbg.generated Mon May 27 16:39:18 CST 2019
28
+     */
29
+    @Insert({
30
+        "insert into K_USER.K_CLIENT (CLIENT_ID, ID, ",
31
+        "NAME, CLIENT_SECRET, ",
32
+        "REDIRECT_URI, CREATED_AT, ",
33
+        "UPDATED_AT, DELETED_AT, ",
34
+        "APP_ID)",
35
+        "values (#{clientId,jdbcType=VARCHAR}, #{id,jdbcType=DECIMAL}, ",
36
+        "#{name,jdbcType=VARCHAR}, #{clientSecret,jdbcType=VARCHAR}, ",
37
+        "#{redirectUri,jdbcType=VARCHAR}, #{createdAt,jdbcType=DATE}, ",
38
+        "#{updatedAt,jdbcType=DATE}, #{deletedAt,jdbcType=DATE}, ",
39
+        "#{appId,jdbcType=DECIMAL})"
40
+    })
41
+    int insert(Client record);
42
+
43
+    /**
44
+     * This method was generated by MyBatis Generator.
45
+     * This method corresponds to the database table K_USER.K_CLIENT
46
+     *
47
+     * @mbg.generated Mon May 27 16:39:18 CST 2019
48
+     */
49
+    int insertSelective(Client record);
50
+
51
+    /**
52
+     * This method was generated by MyBatis Generator.
53
+     * This method corresponds to the database table K_USER.K_CLIENT
54
+     *
55
+     * @mbg.generated Mon May 27 16:39:18 CST 2019
56
+     */
57
+    @Select({
58
+        "select",
59
+        "CLIENT_ID, ID, NAME, CLIENT_SECRET, REDIRECT_URI, CREATED_AT, UPDATED_AT, DELETED_AT, ",
60
+        "APP_ID",
61
+        "from K_USER.K_CLIENT",
62
+        "where CLIENT_ID = #{clientId,jdbcType=VARCHAR}"
63
+    })
64
+    @ResultMap("com.kingkong.bljs.dao.ClientMapper.BaseResultMap")
65
+    Client selectByPrimaryKey(String clientId);
66
+
67
+    /**
68
+     * This method was generated by MyBatis Generator.
69
+     * This method corresponds to the database table K_USER.K_CLIENT
70
+     *
71
+     * @mbg.generated Mon May 27 16:39:18 CST 2019
72
+     */
73
+    int updateByPrimaryKeySelective(Client record);
74
+
75
+    /**
76
+     * This method was generated by MyBatis Generator.
77
+     * This method corresponds to the database table K_USER.K_CLIENT
78
+     *
79
+     * @mbg.generated Mon May 27 16:39:18 CST 2019
80
+     */
81
+    @Update({
82
+        "update K_USER.K_CLIENT",
83
+        "set ID = #{id,jdbcType=DECIMAL},",
84
+          "NAME = #{name,jdbcType=VARCHAR},",
85
+          "CLIENT_SECRET = #{clientSecret,jdbcType=VARCHAR},",
86
+          "REDIRECT_URI = #{redirectUri,jdbcType=VARCHAR},",
87
+          "CREATED_AT = #{createdAt,jdbcType=DATE},",
88
+          "UPDATED_AT = #{updatedAt,jdbcType=DATE},",
89
+          "DELETED_AT = #{deletedAt,jdbcType=DATE},",
90
+          "APP_ID = #{appId,jdbcType=DECIMAL}",
91
+        "where CLIENT_ID = #{clientId,jdbcType=VARCHAR}"
92
+    })
93
+    int updateByPrimaryKey(Client record);
94
+
95
+    @Select({"select * from k_client where client_id=#{clientId}"})
96
+    Client selectByClientId(String clientId);
97
+}

+ 212 - 0
src/main/java/com/kingkong/bljs/entity/Client.java

@@ -0,0 +1,212 @@
1
+package com.kingkong.bljs.entity;
2
+
3
+import java.util.Date;
4
+
5
+public class Client {
6
+    /**
7
+     *
8
+     * This field was generated by MyBatis Generator.
9
+     * This field corresponds to the database column K_USER.K_CLIENT.CLIENT_ID
10
+     *
11
+     * @mbg.generated Mon May 27 16:39:18 CST 2019
12
+     */
13
+    private String clientId;
14
+
15
+    /**
16
+     *
17
+     * This field was generated by MyBatis Generator.
18
+     * This field corresponds to the database column K_USER.K_CLIENT.ID
19
+     *
20
+     * @mbg.generated Mon May 27 16:39:18 CST 2019
21
+     */
22
+    private Integer id;
23
+
24
+    /**
25
+     *
26
+     * This field was generated by MyBatis Generator.
27
+     * This field corresponds to the database column K_USER.K_CLIENT.NAME
28
+     *
29
+     * @mbg.generated Mon May 27 16:39:18 CST 2019
30
+     */
31
+    private String name;
32
+
33
+    /**
34
+     *
35
+     * This field was generated by MyBatis Generator.
36
+     * This field corresponds to the database column K_USER.K_CLIENT.CLIENT_SECRET
37
+     *
38
+     * @mbg.generated Mon May 27 16:39:18 CST 2019
39
+     */
40
+    private String clientSecret;
41
+
42
+    /**
43
+     *
44
+     * This field was generated by MyBatis Generator.
45
+     * This field corresponds to the database column K_USER.K_CLIENT.REDIRECT_URI
46
+     *
47
+     * @mbg.generated Mon May 27 16:39:18 CST 2019
48
+     */
49
+    private String redirectUri;
50
+
51
+    /**
52
+     *
53
+     * This field was generated by MyBatis Generator.
54
+     * This field corresponds to the database column K_USER.K_CLIENT.CREATED_AT
55
+     *
56
+     * @mbg.generated Mon May 27 16:39:18 CST 2019
57
+     */
58
+    private Date createdAt;
59
+
60
+    /**
61
+     *
62
+     * This field was generated by MyBatis Generator.
63
+     * This field corresponds to the database column K_USER.K_CLIENT.UPDATED_AT
64
+     *
65
+     * @mbg.generated Mon May 27 16:39:18 CST 2019
66
+     */
67
+    private Date updatedAt;
68
+
69
+    /**
70
+     *
71
+     * This field was generated by MyBatis Generator.
72
+     * This field corresponds to the database column K_USER.K_CLIENT.DELETED_AT
73
+     *
74
+     * @mbg.generated Mon May 27 16:39:18 CST 2019
75
+     */
76
+    private Date deletedAt;
77
+
78
+    /**
79
+     *
80
+     * This field was generated by MyBatis Generator.
81
+     * This field corresponds to the database column K_USER.K_CLIENT.APP_ID
82
+     *
83
+     * @mbg.generated Mon May 27 16:39:18 CST 2019
84
+     */
85
+    private Integer appId;
86
+
87
+    /**
88
+     * This method was generated by MyBatis Generator.
89
+     * This method corresponds to the database table K_USER.K_CLIENT
90
+     *
91
+     * @mbg.generated Mon May 27 16:39:18 CST 2019
92
+     */
93
+    public Client(String clientId, Integer id, String name, String clientSecret, String redirectUri, Date createdAt, Date updatedAt, Date deletedAt, Integer appId) {
94
+        this.clientId = clientId;
95
+        this.id = id;
96
+        this.name = name;
97
+        this.clientSecret = clientSecret;
98
+        this.redirectUri = redirectUri;
99
+        this.createdAt = createdAt;
100
+        this.updatedAt = updatedAt;
101
+        this.deletedAt = deletedAt;
102
+        this.appId = appId;
103
+    }
104
+
105
+    /**
106
+     * This method was generated by MyBatis Generator.
107
+     * This method returns the value of the database column K_USER.K_CLIENT.CLIENT_ID
108
+     *
109
+     * @return the value of K_USER.K_CLIENT.CLIENT_ID
110
+     *
111
+     * @mbg.generated Mon May 27 16:39:18 CST 2019
112
+     */
113
+    public String getClientId() {
114
+        return clientId;
115
+    }
116
+
117
+    /**
118
+     * This method was generated by MyBatis Generator.
119
+     * This method returns the value of the database column K_USER.K_CLIENT.ID
120
+     *
121
+     * @return the value of K_USER.K_CLIENT.ID
122
+     *
123
+     * @mbg.generated Mon May 27 16:39:18 CST 2019
124
+     */
125
+    public Integer getId() {
126
+        return id;
127
+    }
128
+
129
+    /**
130
+     * This method was generated by MyBatis Generator.
131
+     * This method returns the value of the database column K_USER.K_CLIENT.NAME
132
+     *
133
+     * @return the value of K_USER.K_CLIENT.NAME
134
+     *
135
+     * @mbg.generated Mon May 27 16:39:18 CST 2019
136
+     */
137
+    public String getName() {
138
+        return name;
139
+    }
140
+
141
+    /**
142
+     * This method was generated by MyBatis Generator.
143
+     * This method returns the value of the database column K_USER.K_CLIENT.CLIENT_SECRET
144
+     *
145
+     * @return the value of K_USER.K_CLIENT.CLIENT_SECRET
146
+     *
147
+     * @mbg.generated Mon May 27 16:39:18 CST 2019
148
+     */
149
+    public String getClientSecret() {
150
+        return clientSecret;
151
+    }
152
+
153
+    /**
154
+     * This method was generated by MyBatis Generator.
155
+     * This method returns the value of the database column K_USER.K_CLIENT.REDIRECT_URI
156
+     *
157
+     * @return the value of K_USER.K_CLIENT.REDIRECT_URI
158
+     *
159
+     * @mbg.generated Mon May 27 16:39:18 CST 2019
160
+     */
161
+    public String getRedirectUri() {
162
+        return redirectUri;
163
+    }
164
+
165
+    /**
166
+     * This method was generated by MyBatis Generator.
167
+     * This method returns the value of the database column K_USER.K_CLIENT.CREATED_AT
168
+     *
169
+     * @return the value of K_USER.K_CLIENT.CREATED_AT
170
+     *
171
+     * @mbg.generated Mon May 27 16:39:18 CST 2019
172
+     */
173
+    public Date getCreatedAt() {
174
+        return createdAt;
175
+    }
176
+
177
+    /**
178
+     * This method was generated by MyBatis Generator.
179
+     * This method returns the value of the database column K_USER.K_CLIENT.UPDATED_AT
180
+     *
181
+     * @return the value of K_USER.K_CLIENT.UPDATED_AT
182
+     *
183
+     * @mbg.generated Mon May 27 16:39:18 CST 2019
184
+     */
185
+    public Date getUpdatedAt() {
186
+        return updatedAt;
187
+    }
188
+
189
+    /**
190
+     * This method was generated by MyBatis Generator.
191
+     * This method returns the value of the database column K_USER.K_CLIENT.DELETED_AT
192
+     *
193
+     * @return the value of K_USER.K_CLIENT.DELETED_AT
194
+     *
195
+     * @mbg.generated Mon May 27 16:39:18 CST 2019
196
+     */
197
+    public Date getDeletedAt() {
198
+        return deletedAt;
199
+    }
200
+
201
+    /**
202
+     * This method was generated by MyBatis Generator.
203
+     * This method returns the value of the database column K_USER.K_CLIENT.APP_ID
204
+     *
205
+     * @return the value of K_USER.K_CLIENT.APP_ID
206
+     *
207
+     * @mbg.generated Mon May 27 16:39:18 CST 2019
208
+     */
209
+    public Integer getAppId() {
210
+        return appId;
211
+    }
212
+}

+ 7 - 5
src/main/java/com/kingkong/bljs/security/CustomClientDetailService.java

@@ -1,7 +1,9 @@
1 1
 package com.kingkong.bljs.security;
2 2
 
3 3
 import com.kingkong.bljs.dao.AppMapper;
4
+import com.kingkong.bljs.dao.ClientMapper;
4 5
 import com.kingkong.bljs.entity.App;
6
+import com.kingkong.bljs.entity.Client;
5 7
 import org.springframework.beans.factory.annotation.Autowired;
6 8
 import org.springframework.security.oauth2.provider.ClientDetails;
7 9
 import org.springframework.security.oauth2.provider.ClientDetailsService;
@@ -15,23 +17,23 @@ import java.util.Set;
15 17
 public class CustomClientDetailService implements ClientDetailsService {
16 18
 
17 19
     @Autowired
18
-    private AppMapper appMapper;
20
+    private ClientMapper clientMapper;
19 21
 
20 22
     @Override
21 23
     public ClientDetails loadClientByClientId(String s) throws ClientRegistrationException {
22 24
 
23
-        App app = appMapper.selectByClientId(s);
25
+        Client client = clientMapper.selectByClientId(s);
24 26
 
25
-        if(null == app)
27
+        if(null == client)
26 28
             throw new ClientRegistrationException("incorrect client id");
27 29
 
28 30
         BaseClientDetails clientDetails = new BaseClientDetails();
29 31
         clientDetails.setClientId(s);
30
-        clientDetails.setClientSecret("{noop}" + app.getClientSecret());
32
+        clientDetails.setClientSecret("{noop}" + client.getClientId());
31 33
         clientDetails.setAuthorizedGrantTypes(Arrays.asList("authorization_code","client_credentials", "refresh_token", "password", "implicit"));
32 34
         clientDetails.setScope(Arrays.asList("*","all"));
33 35
         Set<String> uris = new HashSet<>();
34
-        uris.add(app.getRedirectUri());
36
+        uris.add(client.getRedirectUri());
35 37
         clientDetails.setRegisteredRedirectUri(uris);
36 38
         clientDetails.setAccessTokenValiditySeconds(3600*24);
37 39
         return clientDetails;

+ 1 - 1
src/main/resources/generatorConfig.xml

@@ -87,7 +87,7 @@
87 87
 
88 88
 
89 89
 
90
-        <table tableName="k_three_login" schema="k_user" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false"
90
+        <table tableName="k_client" schema="k_user" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false"
91 91
                enableSelectByExample="false" selectByExampleQueryId="false">
92 92
 
93 93
             <!-- optional   , only for mybatis3 runtime

+ 132 - 0
src/main/resources/mapper/ClientMapper.xml

@@ -0,0 +1,132 @@
1
+<?xml version="1.0" encoding="UTF-8"?>
2
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
3
+<mapper namespace="com.kingkong.bljs.dao.ClientMapper">
4
+  <resultMap id="BaseResultMap" type="com.kingkong.bljs.entity.Client">
5
+    <!--
6
+      WARNING - @mbg.generated
7
+      This element is automatically generated by MyBatis Generator, do not modify.
8
+      This element was generated on Mon May 27 16:39:18 CST 2019.
9
+    -->
10
+    <constructor>
11
+      <idArg column="CLIENT_ID" javaType="java.lang.String" jdbcType="VARCHAR" />
12
+      <arg column="ID" javaType="java.lang.Integer" jdbcType="DECIMAL" />
13
+      <arg column="NAME" javaType="java.lang.String" jdbcType="VARCHAR" />
14
+      <arg column="CLIENT_SECRET" javaType="java.lang.String" jdbcType="VARCHAR" />
15
+      <arg column="REDIRECT_URI" javaType="java.lang.String" jdbcType="VARCHAR" />
16
+      <arg column="CREATED_AT" javaType="java.util.Date" jdbcType="DATE" />
17
+      <arg column="UPDATED_AT" javaType="java.util.Date" jdbcType="DATE" />
18
+      <arg column="DELETED_AT" javaType="java.util.Date" jdbcType="DATE" />
19
+      <arg column="APP_ID" javaType="java.lang.Integer" jdbcType="DECIMAL" />
20
+    </constructor>
21
+  </resultMap>
22
+  <sql id="Base_Column_List">
23
+    <!--
24
+      WARNING - @mbg.generated
25
+      This element is automatically generated by MyBatis Generator, do not modify.
26
+      This element was generated on Mon May 27 16:39:18 CST 2019.
27
+    -->
28
+    CLIENT_ID, ID, NAME, CLIENT_SECRET, REDIRECT_URI, CREATED_AT, UPDATED_AT, DELETED_AT, 
29
+    APP_ID
30
+  </sql>
31
+  <insert id="insertSelective" parameterType="com.kingkong.bljs.entity.Client">
32
+    <!--
33
+      WARNING - @mbg.generated
34
+      This element is automatically generated by MyBatis Generator, do not modify.
35
+      This element was generated on Mon May 27 16:39:18 CST 2019.
36
+    -->
37
+    insert into K_USER.K_CLIENT
38
+    <trim prefix="(" suffix=")" suffixOverrides=",">
39
+      <if test="clientId != null">
40
+        CLIENT_ID,
41
+      </if>
42
+      <if test="id != null">
43
+        ID,
44
+      </if>
45
+      <if test="name != null">
46
+        NAME,
47
+      </if>
48
+      <if test="clientSecret != null">
49
+        CLIENT_SECRET,
50
+      </if>
51
+      <if test="redirectUri != null">
52
+        REDIRECT_URI,
53
+      </if>
54
+      <if test="createdAt != null">
55
+        CREATED_AT,
56
+      </if>
57
+      <if test="updatedAt != null">
58
+        UPDATED_AT,
59
+      </if>
60
+      <if test="deletedAt != null">
61
+        DELETED_AT,
62
+      </if>
63
+      <if test="appId != null">
64
+        APP_ID,
65
+      </if>
66
+    </trim>
67
+    <trim prefix="values (" suffix=")" suffixOverrides=",">
68
+      <if test="clientId != null">
69
+        #{clientId,jdbcType=VARCHAR},
70
+      </if>
71
+      <if test="id != null">
72
+        #{id,jdbcType=DECIMAL},
73
+      </if>
74
+      <if test="name != null">
75
+        #{name,jdbcType=VARCHAR},
76
+      </if>
77
+      <if test="clientSecret != null">
78
+        #{clientSecret,jdbcType=VARCHAR},
79
+      </if>
80
+      <if test="redirectUri != null">
81
+        #{redirectUri,jdbcType=VARCHAR},
82
+      </if>
83
+      <if test="createdAt != null">
84
+        #{createdAt,jdbcType=DATE},
85
+      </if>
86
+      <if test="updatedAt != null">
87
+        #{updatedAt,jdbcType=DATE},
88
+      </if>
89
+      <if test="deletedAt != null">
90
+        #{deletedAt,jdbcType=DATE},
91
+      </if>
92
+      <if test="appId != null">
93
+        #{appId,jdbcType=DECIMAL},
94
+      </if>
95
+    </trim>
96
+  </insert>
97
+  <update id="updateByPrimaryKeySelective" parameterType="com.kingkong.bljs.entity.Client">
98
+    <!--
99
+      WARNING - @mbg.generated
100
+      This element is automatically generated by MyBatis Generator, do not modify.
101
+      This element was generated on Mon May 27 16:39:18 CST 2019.
102
+    -->
103
+    update K_USER.K_CLIENT
104
+    <set>
105
+      <if test="id != null">
106
+        ID = #{id,jdbcType=DECIMAL},
107
+      </if>
108
+      <if test="name != null">
109
+        NAME = #{name,jdbcType=VARCHAR},
110
+      </if>
111
+      <if test="clientSecret != null">
112
+        CLIENT_SECRET = #{clientSecret,jdbcType=VARCHAR},
113
+      </if>
114
+      <if test="redirectUri != null">
115
+        REDIRECT_URI = #{redirectUri,jdbcType=VARCHAR},
116
+      </if>
117
+      <if test="createdAt != null">
118
+        CREATED_AT = #{createdAt,jdbcType=DATE},
119
+      </if>
120
+      <if test="updatedAt != null">
121
+        UPDATED_AT = #{updatedAt,jdbcType=DATE},
122
+      </if>
123
+      <if test="deletedAt != null">
124
+        DELETED_AT = #{deletedAt,jdbcType=DATE},
125
+      </if>
126
+      <if test="appId != null">
127
+        APP_ID = #{appId,jdbcType=DECIMAL},
128
+      </if>
129
+    </set>
130
+    where CLIENT_ID = #{clientId,jdbcType=VARCHAR}
131
+  </update>
132
+</mapper>