Browse Source

结合zlhis,三方登录

root 5 years ago
parent
commit
d7ce3ab04c

+ 1 - 1
src/main/java/com/kingkong/bljs/api/BaseController.java

@@ -8,7 +8,7 @@ import org.springframework.web.bind.annotation.ResponseStatus;
8
 import java.util.HashMap;
8
 import java.util.HashMap;
9
 import java.util.Map;
9
 import java.util.Map;
10
 
10
 
11
-@ControllerAdvice
11
+//@ControllerAdvice
12
 public class BaseController {
12
 public class BaseController {
13
 
13
 
14
     @ResponseBody
14
     @ResponseBody

+ 1 - 0
src/main/java/com/kingkong/bljs/config/AuthorizationServerConfiguration.java

@@ -19,6 +19,7 @@ import org.springframework.security.oauth2.provider.token.store.redis.RedisToken
19
 
19
 
20
 import java.util.concurrent.TimeUnit;
20
 import java.util.concurrent.TimeUnit;
21
 
21
 
22
+//@Order(2)
22
 @Configuration
23
 @Configuration
23
 @EnableAuthorizationServer
24
 @EnableAuthorizationServer
24
 public class AuthorizationServerConfiguration extends AuthorizationServerConfigurerAdapter {
25
 public class AuthorizationServerConfiguration extends AuthorizationServerConfigurerAdapter {

+ 14 - 4
src/main/java/com/kingkong/bljs/config/ResourceServerConfig.java

@@ -1,11 +1,13 @@
1
 package com.kingkong.bljs.config;
1
 package com.kingkong.bljs.config;
2
 
2
 
3
 import org.springframework.context.annotation.Configuration;
3
 import org.springframework.context.annotation.Configuration;
4
+import org.springframework.core.annotation.Order;
4
 import org.springframework.security.config.annotation.web.builders.HttpSecurity;
5
 import org.springframework.security.config.annotation.web.builders.HttpSecurity;
5
 import org.springframework.security.config.http.SessionCreationPolicy;
6
 import org.springframework.security.config.http.SessionCreationPolicy;
6
 import org.springframework.security.oauth2.config.annotation.web.configuration.EnableResourceServer;
7
 import org.springframework.security.oauth2.config.annotation.web.configuration.EnableResourceServer;
7
 import org.springframework.security.oauth2.config.annotation.web.configuration.ResourceServerConfigurerAdapter;
8
 import org.springframework.security.oauth2.config.annotation.web.configuration.ResourceServerConfigurerAdapter;
8
 
9
 
10
+//@Order(7)
9
 @Configuration
11
 @Configuration
10
 @EnableResourceServer
12
 @EnableResourceServer
11
 public class ResourceServerConfig extends ResourceServerConfigurerAdapter {
13
 public class ResourceServerConfig extends ResourceServerConfigurerAdapter {
@@ -14,10 +16,18 @@ public class ResourceServerConfig extends ResourceServerConfigurerAdapter {
14
     public void configure(HttpSecurity http) throws Exception{
16
     public void configure(HttpSecurity http) throws Exception{
15
 
17
 
16
         http.sessionManagement().sessionCreationPolicy(SessionCreationPolicy.IF_REQUIRED);
18
         http.sessionManagement().sessionCreationPolicy(SessionCreationPolicy.IF_REQUIRED);
17
-        http.authorizeRequests()
18
-                .antMatchers("/oauth/token","/api/app","/api/lang","/test","/api/report").permitAll()
19
-                .antMatchers("/api/**").authenticated()
20
-                .and().cors().and().csrf().disable();
19
+//        http.authorizeRequests()
20
+//                .antMatchers("/oauth/token","/api/app","/api/lang","/test","/api/report").permitAll()
21
+//                .antMatchers("/api/**").authenticated()
22
+//                .and().cors().and().csrf().disable();
23
+        http
24
+                .authorizeRequests()
25
+                .antMatchers("/oauth/*","/api/app","/api/i18n","/test","/api/report").permitAll()
26
+                .antMatchers("/**").authenticated()
27
+                .and().formLogin()
28
+                //.authenticationDetailsSource(authenticationDetailsSource)
29
+                .and().logout().permitAll().and().cors().and().csrf().disable();
30
+
21
 
31
 
22
     }
32
     }
23
 }
33
 }

+ 9 - 7
src/main/java/com/kingkong/bljs/config/WebSecurityConfig.java

@@ -5,6 +5,7 @@ import com.kingkong.bljs.security.CustomtAuthenticationProvider;
5
 import org.springframework.beans.factory.annotation.Autowired;
5
 import org.springframework.beans.factory.annotation.Autowired;
6
 import org.springframework.context.annotation.Bean;
6
 import org.springframework.context.annotation.Bean;
7
 import org.springframework.context.annotation.Configuration;
7
 import org.springframework.context.annotation.Configuration;
8
+import org.springframework.core.annotation.Order;
8
 import org.springframework.security.authentication.AuthenticationDetailsSource;
9
 import org.springframework.security.authentication.AuthenticationDetailsSource;
9
 import org.springframework.security.authentication.AuthenticationManager;
10
 import org.springframework.security.authentication.AuthenticationManager;
10
 import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
11
 import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
@@ -21,6 +22,7 @@ import org.springframework.security.web.authentication.WebAuthenticationDetails;
21
 import javax.servlet.http.HttpServletRequest;
22
 import javax.servlet.http.HttpServletRequest;
22
 import java.util.Arrays;
23
 import java.util.Arrays;
23
 
24
 
25
+//@Order(4)
24
 @Configuration
26
 @Configuration
25
 @EnableWebSecurity
27
 @EnableWebSecurity
26
 @EnableGlobalMethodSecurity(prePostEnabled = true)
28
 @EnableGlobalMethodSecurity(prePostEnabled = true)
@@ -41,13 +43,13 @@ public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
41
     @Override
43
     @Override
42
     protected void configure(HttpSecurity http) throws Exception {
44
     protected void configure(HttpSecurity http) throws Exception {
43
         //设置规则
45
         //设置规则
44
-        http
45
-                .authorizeRequests()
46
-                .antMatchers("/oauth/*","/api/app","/api/i18n","/test","/api/report").permitAll()
47
-                .antMatchers("/**").authenticated()
48
-                .and().formLogin()
49
-                //.authenticationDetailsSource(authenticationDetailsSource)
50
-                .and().logout().permitAll().and().cors().and().csrf().disable();
46
+//        http
47
+//                .authorizeRequests()
48
+//                .antMatchers("/oauth/*","/api/app","/api/i18n","/test","/api/report").permitAll()
49
+//                .antMatchers("/**").authenticated()
50
+//                .and().formLogin()
51
+//                //.authenticationDetailsSource(authenticationDetailsSource)
52
+//                .and().logout().permitAll().and().cors().and().csrf().disable();
51
 
53
 
52
     }
54
     }
53
 
55
 

+ 11 - 0
src/main/java/com/kingkong/bljs/dao/AuthClientMapper.java

@@ -0,0 +1,11 @@
1
+package com.kingkong.bljs.dao;
2
+
3
+import com.kingkong.bljs.entity.AuthClient;
4
+import org.apache.ibatis.annotations.Param;
5
+import org.apache.ibatis.annotations.Select;
6
+
7
+public interface AuthClientMapper {
8
+
9
+    @Select("select * from k_client where client_id=#{code}")
10
+    AuthClient get(String code);
11
+}

+ 38 - 0
src/main/java/com/kingkong/bljs/entity/AuthClient.java

@@ -0,0 +1,38 @@
1
+package com.kingkong.bljs.entity;
2
+
3
+public class AuthClient {
4
+
5
+    private String clientId;
6
+    private String clientSecret;
7
+    private String redirectUri;
8
+
9
+    public String getClientId() {
10
+        return clientId;
11
+    }
12
+
13
+    public String getClientSecret() {
14
+        return clientSecret;
15
+    }
16
+
17
+    public String getRedirectUri() {
18
+        return redirectUri;
19
+    }
20
+
21
+    public AuthClient(String clientId, String clientSecret, String redirectUri) {
22
+        this.clientId = clientId;
23
+        this.clientSecret = clientSecret;
24
+        this.redirectUri = redirectUri;
25
+    }
26
+
27
+    public void setClientId(String clientId) {
28
+        this.clientId = clientId;
29
+    }
30
+
31
+    public void setClientSecret(String clientSecret) {
32
+        this.clientSecret = clientSecret;
33
+    }
34
+
35
+    public void setRedirectUri(String redirectUri) {
36
+        this.redirectUri = redirectUri;
37
+    }
38
+}

+ 15 - 2
src/main/java/com/kingkong/bljs/security/CustomClientDetailService.java

@@ -1,5 +1,8 @@
1
 package com.kingkong.bljs.security;
1
 package com.kingkong.bljs.security;
2
 
2
 
3
+import com.kingkong.bljs.dao.AuthClientMapper;
4
+import com.kingkong.bljs.entity.AuthClient;
5
+import org.springframework.beans.factory.annotation.Autowired;
3
 import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
6
 import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
4
 import org.springframework.security.oauth2.provider.ClientDetails;
7
 import org.springframework.security.oauth2.provider.ClientDetails;
5
 import org.springframework.security.oauth2.provider.ClientDetailsService;
8
 import org.springframework.security.oauth2.provider.ClientDetailsService;
@@ -11,15 +14,25 @@ import java.util.HashSet;
11
 import java.util.Set;
14
 import java.util.Set;
12
 
15
 
13
 public class CustomClientDetailService implements ClientDetailsService {
16
 public class CustomClientDetailService implements ClientDetailsService {
17
+
18
+    @Autowired
19
+    private AuthClientMapper authClientMapper;
20
+
14
     @Override
21
     @Override
15
     public ClientDetails loadClientByClientId(String s) throws ClientRegistrationException {
22
     public ClientDetails loadClientByClientId(String s) throws ClientRegistrationException {
23
+
24
+        AuthClient authClient = authClientMapper.get(s);
25
+
26
+        if(null == authClient)
27
+            throw new ClientRegistrationException("incorrect client id");
28
+
16
         BaseClientDetails clientDetails = new BaseClientDetails();
29
         BaseClientDetails clientDetails = new BaseClientDetails();
17
         clientDetails.setClientId(s);
30
         clientDetails.setClientId(s);
18
-        clientDetails.setClientSecret("{noop}123");
31
+        clientDetails.setClientSecret("{noop}" + authClient.getClientSecret());
19
         clientDetails.setAuthorizedGrantTypes(Arrays.asList("authorization_code","client_credentials", "refresh_token", "password", "implicit"));
32
         clientDetails.setAuthorizedGrantTypes(Arrays.asList("authorization_code","client_credentials", "refresh_token", "password", "implicit"));
20
         clientDetails.setScope(Arrays.asList("*","all"));
33
         clientDetails.setScope(Arrays.asList("*","all"));
21
         Set<String> uris = new HashSet<>();
34
         Set<String> uris = new HashSet<>();
22
-        uris.add("http://localhost:8080/login");
35
+        uris.add(authClient.getRedirectUri());
23
         clientDetails.setRegisteredRedirectUri(uris);
36
         clientDetails.setRegisteredRedirectUri(uris);
24
         clientDetails.setAccessTokenValiditySeconds(3600*24);
37
         clientDetails.setAccessTokenValiditySeconds(3600*24);
25
         return clientDetails;
38
         return clientDetails;

+ 5 - 0
src/main/java/com/kingkong/bljs/security/CustomUserDetailsService.java

@@ -36,6 +36,9 @@ public class CustomUserDetailsService implements UserDetailsService {
36
     @Value("${app.table.app_user}")
36
     @Value("${app.table.app_user}")
37
     private String k_app_user;
37
     private String k_app_user;
38
 
38
 
39
+    @Value("${app.default.app_id}")
40
+    private String default_app_id;
41
+
39
 
42
 
40
 
43
 
41
     @Override
44
     @Override
@@ -47,6 +50,8 @@ public class CustomUserDetailsService implements UserDetailsService {
47
             throw new UsernameNotFoundException("用户不存在!");
50
             throw new UsernameNotFoundException("用户不存在!");
48
 
51
 
49
         String appid = this.request.getParameter("app_id");
52
         String appid = this.request.getParameter("app_id");
53
+        if(null == appid)
54
+            appid = default_app_id;
50
         Map condition = new HashMap();
55
         Map condition = new HashMap();
51
         condition.put("u_id",user.get("id").toString());
56
         condition.put("u_id",user.get("id").toString());
52
         condition.put("app_id",appid);
57
         condition.put("app_id",appid);

+ 54 - 0
src/main/resources/application-his.properties

@@ -0,0 +1,54 @@
1
+spring.datasource.url=jdbc:oracle:thin:@192.168.1.150:1521:orcl
2
+spring.datasource.username=k_user
3
+spring.datasource.password=123
4
+spring.datasource.driver-class-name=oracle.jdbc.driver.OracleDriver
5
+spring.datasource.max-idle=10
6
+spring.datasource.max-wait=10000
7
+spring.datasource.min-idle=5
8
+spring.datasource.initial-size=5
9
+spring.datasource.type=com.alibaba.druid.pool.DruidDataSource
10
+server.port=8092
11
+spring.cache.redis.time-to-live=150000
12
+spring.cache.type=redis
13
+
14
+app.name=ZLSOFT
15
+app.desc=中联软件
16
+app.origin.url=http://localhost:4200
17
+
18
+#应用类型1, 结合中联oracle
19
+app.type=1
20
+#登录程序位置
21
+app.loginpath=D:/work/zllogin.exe
22
+#登录服务名
23
+app.server=orcl3
24
+
25
+#报表pdf存放目录
26
+app.pdfpath=D:\\report-test\\pdf\\
27
+#报表打印程序位置
28
+app.printerpath=D:/report-test/ZLReportPrint.exe
29
+app.table.user=k_user2
30
+app.table.app_user=k_app_user2
31
+app.default.app_id=100
32
+
33
+spring.jackson.default-property-inclusion=always
34
+
35
+mybatis.mapper-locations=classpath:mapper/*.xml
36
+mybatis.type-aliases-package=com.kingkong.bljs.dao
37
+mybatis.configuration.call-setters-on-nulls=true
38
+
39
+spring.redis.database=0
40
+spring.redis.host=127.0.0.1
41
+spring.redis.port=6379
42
+spring.session.store-type=redis
43
+
44
+spring.thymeleaf.cache=false
45
+spring.thymeleaf.prefix=classpath:/templates/
46
+spring.thymeleaf.check-template-location=true
47
+spring.thymeleaf.suffix=.html
48
+spring.thymeleaf.encoding=UTF-8
49
+
50
+
51
+#websocket配置
52
+netty-websocket.host=127.0.0.1
53
+netty-websocket.path=/
54
+netty-websocket.port=9021

+ 1 - 1
src/main/resources/application.properties

@@ -1 +1 @@
1
-spring.profiles.active=c
1
+spring.profiles.active=his