浏览代码

运行在夏博电脑上了

zhuhaiwen 3 年之前
父节点
当前提交
0e33057656

+ 219 - 214
oa-app/src/main/java/com/css/oa/config/CasConfigurationProperties.java

@ -1,233 +1,238 @@
1 1
package com.css.oa.config;
2 2
3
import org.jasig.cas.client.proxy.ProxyGrantingTicketStorage;
3 4
import org.springframework.boot.context.properties.ConfigurationProperties;
5
import org.springframework.context.annotation.Configuration;
6
import org.thymeleaf.standard.expression.Each;
4 7
8
import java.util.Arrays;
9
import java.util.List;
5 10
/**
6 11
 * SingleSignOutFilter 配置如下:
7 12
 * <table>
8
 * <thead>
9
 * <tr>
10
 * <th>Property</th>
11
 * <th>Description</th>
12
 * <th>Required</th>
13
 * </tr>
14
 * </thead>
15
 * <tbody>
16
 * <tr>
17
 * <td><code>artifactParameterName</code></td>
18
 * <td>The ticket artifact parameter name. Defaults to <code>ticket</code></td>
19
 * <td>No</td>
20
 * </tr>
21
 * <tr>
22
 * <td><code>logoutParameterName</code></td>
23
 * <td>Defaults to <code>logoutRequest</code></td>
24
 * <td>No</td>
25
 * </tr>
26
 * <tr>
27
 * <td><code>frontLogoutParameterName</code></td>
28
 * <td>Defaults to <code>SAMLRequest</code></td>
29
 * <td>No</td>
30
 * </tr>
31
 * <tr>
32
 * <td><code>relayStateParameterName</code></td>
33
 * <td>Defaults to <code>RelayState</code></td>
34
 * <td>No</td>
35
 * </tr>
36
 * <tr>
37
 * <td><code>eagerlyCreateSessions</code></td>
38
 * <td>Defaults to <code>true</code></td>
39
 * <td>No</td>
40
 * </tr>
41
 * <tr>
42
 * <td><code>artifactParameterOverPost</code></td>
43
 * <td>Defaults to  <code>false</code></td>
44
 * <td>No</td>
45
 * </tr>
46
 * <tr>
47
 * <td><code>casServerUrlPrefix</code></td>
48
 * <td>URL to root of CAS Web application context.</td>
49
 * <td>Yes</td>
50
 * </tr></tbody></table>
13
 <thead>
14
 <tr>
15
 <th>Property</th>
16
 <th>Description</th>
17
 <th>Required</th>
18
 </tr>
19
 </thead>
20
 <tbody>
21
 <tr>
22
 <td><code>artifactParameterName</code></td>
23
 <td>The ticket artifact parameter name. Defaults to <code>ticket</code></td>
24
 <td>No</td>
25
 </tr>
26
 <tr>
27
 <td><code>logoutParameterName</code></td>
28
 <td>Defaults to <code>logoutRequest</code></td>
29
 <td>No</td>
30
 </tr>
31
 <tr>
32
 <td><code>frontLogoutParameterName</code></td>
33
 <td>Defaults to <code>SAMLRequest</code></td>
34
 <td>No</td>
35
 </tr>
36
 <tr>
37
 <td><code>relayStateParameterName</code></td>
38
 <td>Defaults to <code>RelayState</code></td>
39
 <td>No</td>
40
 </tr>
41
 <tr>
42
 <td><code>eagerlyCreateSessions</code></td>
43
 <td>Defaults to <code>true</code></td>
44
 <td>No</td>
45
 </tr>
46
 <tr>
47
 <td><code>artifactParameterOverPost</code></td>
48
 <td>Defaults to  <code>false</code></td>
49
 <td>No</td>
50
 </tr>
51
 <tr>
52
 <td><code>casServerUrlPrefix</code></td>
53
 <td>URL to root of CAS Web application context.</td>
54
 <td>Yes</td>
55
 </tr></tbody></table>
51 56
 * --------------------------------------------</br>
52 57
 * AuthenticationFilter 配置如下:
53 58
 * <table>
54
 * <thead>
55
 * <tr>
56
 * <th>Property</th>
57
 * <th>Description</th>
58
 * <th>Required</th>
59
 * </tr>
60
 * </thead>
61
 * <tbody>
62
 * <tr>
63
 * <td><code>casServerLoginUrl</code></td>
64
 * <td>Defines the location of the CAS server login URL, i.e. <code>https://localhost:8443/cas/login</code></td>
65
 * <td>Yes</td>
66
 * </tr>
67
 * <tr>
68
 * <td><code>serverName</code></td>
69
 * <td>The name of the server this application is hosted on. Service URL will be dynamically constructed using this, i.e. <a href="https://localhost:8443" rel="nofollow">https://localhost:8443</a> (you must include the protocol, but port is optional if it's a standard port).</td>
70
 * <td>Yes</td>
71
 * </tr>
72
 * <tr>
73
 * <td><code>service</code></td>
74
 * <td>The service URL to send to the CAS server, i.e. <code>https://localhost:8443/yourwebapp/index.html</code></td>
75
 * <td>No</td>
76
 * </tr>
77
 * <tr>
78
 * <td><code>renew</code></td>
79
 * <td>specifies whether <code>renew=true</code> should be sent to the CAS server. Valid values are either <code>true/false</code> (or no value at all). Note that <code>renew</code> cannot be specified as local <code>init-param</code> setting.</td>
80
 * <td>No</td>
81
 * </tr>
82
 * <tr>
83
 * <td><code>gateway</code></td>
84
 * <td>specifies whether <code>gateway=true</code> should be sent to the CAS server. Valid values are either <code>true/false</code> (or no value at all)</td>
85
 * <td>No</td>
86
 * </tr>
87
 * <tr>
88
 * <td><code>artifactParameterName</code></td>
89
 * <td>specifies the name of the request parameter on where to find the artifact (i.e. <code>ticket</code>).</td>
90
 * <td>No</td>
91
 * </tr>
92
 * <tr>
93
 * <td><code>serviceParameterName</code></td>
94
 * <td>specifies the name of the request parameter on where to find the service (i.e. <code>service</code>)</td>
95
 * <td>No</td>
96
 * </tr>
97
 * <tr>
98
 * <td><code>encodeServiceUrl</code></td>
99
 * <td>Whether the client should auto encode the service url. Defaults to <code>true</code></td>
100
 * <td>No</td>
101
 * </tr>
102
 * <tr>
103
 * <td><code>ignorePattern</code></td>
104
 * <td>Defines the url pattern to ignore, when intercepting authentication requests.</td>
105
 * <td>No</td>
106
 * </tr>
107
 * <tr>
108
 * <td><code>ignoreUrlPatternType</code></td>
109
 * <td>Defines the type of the pattern specified. Defaults to <code>REGEX</code>. Other types are <code>CONTAINS</code>, <code>EXACT</code>.</td>
110
 * <td>No</td>
111
 * </tr>
112
 * <tr>
113
 * <td><code>gatewayStorageClass</code></td>
114
 * <td>The storage class used to record gateway requests</td>
115
 * <td>No</td>
116
 * </tr>
117
 * <tr>
118
 * <td><code>authenticationRedirectStrategyClass</code></td>
119
 * <td>The class name of the component to decide how to handle authn redirects to CAS</td>
120
 * <td>No</td>
121
 * </tr></tbody></table>
122
 * <p>
59
 <thead>
60
 <tr>
61
 <th>Property</th>
62
 <th>Description</th>
63
 <th>Required</th>
64
 </tr>
65
 </thead>
66
 <tbody>
67
 <tr>
68
 <td><code>casServerLoginUrl</code></td>
69
 <td>Defines the location of the CAS server login URL, i.e. <code>https://localhost:8443/cas/login</code></td>
70
 <td>Yes</td>
71
 </tr>
72
 <tr>
73
 <td><code>serverName</code></td>
74
 <td>The name of the server this application is hosted on. Service URL will be dynamically constructed using this, i.e. <a href="https://localhost:8443" rel="nofollow">https://localhost:8443</a> (you must include the protocol, but port is optional if it's a standard port).</td>
75
 <td>Yes</td>
76
 </tr>
77
 <tr>
78
 <td><code>service</code></td>
79
 <td>The service URL to send to the CAS server, i.e. <code>https://localhost:8443/yourwebapp/index.html</code></td>
80
 <td>No</td>
81
 </tr>
82
 <tr>
83
 <td><code>renew</code></td>
84
 <td>specifies whether <code>renew=true</code> should be sent to the CAS server. Valid values are either <code>true/false</code> (or no value at all). Note that <code>renew</code> cannot be specified as local <code>init-param</code> setting.</td>
85
 <td>No</td>
86
 </tr>
87
 <tr>
88
 <td><code>gateway</code></td>
89
 <td>specifies whether <code>gateway=true</code> should be sent to the CAS server. Valid values are either <code>true/false</code> (or no value at all)</td>
90
 <td>No</td>
91
 </tr>
92
 <tr>
93
 <td><code>artifactParameterName</code></td>
94
 <td>specifies the name of the request parameter on where to find the artifact (i.e. <code>ticket</code>).</td>
95
 <td>No</td>
96
 </tr>
97
 <tr>
98
 <td><code>serviceParameterName</code></td>
99
 <td>specifies the name of the request parameter on where to find the service (i.e. <code>service</code>)</td>
100
 <td>No</td>
101
 </tr>
102
 <tr>
103
 <td><code>encodeServiceUrl</code></td>
104
 <td>Whether the client should auto encode the service url. Defaults to <code>true</code></td>
105
 <td>No</td>
106
 </tr>
107
 <tr>
108
 <td><code>ignorePattern</code></td>
109
 <td>Defines the url pattern to ignore, when intercepting authentication requests.</td>
110
 <td>No</td>
111
 </tr>
112
 <tr>
113
 <td><code>ignoreUrlPatternType</code></td>
114
 <td>Defines the type of the pattern specified. Defaults to <code>REGEX</code>. Other types are <code>CONTAINS</code>, <code>EXACT</code>.</td>
115
 <td>No</td>
116
 </tr>
117
 <tr>
118
 <td><code>gatewayStorageClass</code></td>
119
 <td>The storage class used to record gateway requests</td>
120
 <td>No</td>
121
 </tr>
122
 <tr>
123
 <td><code>authenticationRedirectStrategyClass</code></td>
124
 <td>The class name of the component to decide how to handle authn redirects to CAS</td>
125
 <td>No</td>
126
 </tr></tbody></table>
127
 *
123 128
 * ---------------------------------------------------<br/>
124 129
 * Cas20ProxyReceivingTicketValidationFilter 配置如下:
125 130
 * <table>
126
 * <thead>
127
 * <tr>
128
 * <th>Property</th>
129
 * <th>Description</th>
130
 * <th>Required</th>
131
 * </tr>
132
 * </thead>
133
 * <tbody>
134
 * <tr>
135
 * <td><code>casServerUrlPrefix</code></td>
136
 * <td>The start of the CAS server URL, i.e. <code>https://localhost:8443/cas</code></td>
137
 * <td>Yes</td>
138
 * </tr>
139
 * <tr>
140
 * <td><code>serverName</code></td>
141
 * <td>The name of the server this application is hosted on. Service URL will be dynamically constructed using this, i.e. <code>https://localhost:8443</code> (you must include the protocol, but port is optional if it's a standard port).</td>
142
 * <td>Yes</td>
143
 * </tr>
144
 * <tr>
145
 * <td><code>renew</code></td>
146
 * <td>Specifies whether <code>renew=true</code> should be sent to the CAS server. Valid values are either <code>true/false</code> (or no value at all). Note that <code>renew</code> cannot be specified as local <code>init-param</code> setting.</td>
147
 * <td>No</td>
148
 * </tr>
149
 * <tr>
150
 * <td><code>redirectAfterValidation</code></td>
151
 * <td>Whether to redirect to the same URL after ticket validation, but without the ticket in the parameter. Defaults to <code>true</code>.</td>
152
 * <td>No</td>
153
 * </tr>
154
 * <tr>
155
 * <td><code>useSession</code></td>
156
 * <td>Whether to store the Assertion in session or not. If sessions are not used, tickets will be required for each request. Defaults to <code>true</code>.</td>
157
 * <td>No</td>
158
 * </tr>
159
 * <tr>
160
 * <td><code>exceptionOnValidationFailure</code></td>
161
 * <td>whether to throw an exception or not on ticket validation failure. Defaults to <code>true</code></td>
162
 * <td>No</td>
163
 * </tr>
164
 * <tr>
165
 * <td><code>proxyReceptorUrl</code></td>
166
 * <td>The URL to watch for <code>PGTIOU/PGT</code> responses from the CAS server. Should be defined from the root of the context. For example, if your application is deployed in <code>/cas-client-app</code> and you want the proxy receptor URL to be <code>/cas-client-app/my/receptor</code> you need to configure proxyReceptorUrl to be <code>/my/receptor</code>.</td>
167
 * <td>No</td>
168
 * </tr>
169
 * <tr>
170
 * <td><code>acceptAnyProxy</code></td>
171
 * <td>Specifies whether any proxy is OK. Defaults to <code>false</code>.</td>
172
 * <td>No</td>
173
 * </tr>
174
 * <tr>
175
 * <td><code>allowedProxyChains</code></td>
176
 * <td>Specifies the proxy chain. Each acceptable proxy chain should include a space-separated list of URLs (for exact match) or regular expressions of URLs (starting by the <code>^</code> character). Each acceptable proxy chain should appear on its own line.</td>
177
 * <td>No</td>
178
 * </tr>
179
 * <tr>
180
 * <td><code>proxyCallbackUrl</code></td>
181
 * <td>The callback URL to provide the CAS server to accept Proxy Granting Tickets.</td>
182
 * <td>No</td>
183
 * </tr>
184
 * <tr>
185
 * <td><code>proxyGrantingTicketStorageClass</code></td>
186
 * <td>Specify an implementation of the ProxyGrantingTicketStorage class that has a no-arg constructor.</td>
187
 * <td>No</td>
188
 * </tr>
189
 * <tr>
190
 * <td><code>sslConfigFile</code></td>
191
 * <td>A reference to a properties file that includes SSL settings for client-side SSL config, used during back-channel calls. The configuration includes keys for <code>protocol</code> which defaults to <code>SSL</code>, <code>keyStoreType</code>, <code>keyStorePath</code>, <code>keyStorePass</code>, <code>keyManagerType</code> which defaults to <code>SunX509</code> and <code>certificatePassword</code>.</td>
192
 * <td>No.</td>
193
 * </tr>
194
 * <tr>
195
 * <td><code>encoding</code></td>
196
 * <td>Specifies the encoding charset the client should use</td>
197
 * <td>No</td>
198
 * </tr>
199
 * <tr>
200
 * <td><code>secretKey</code></td>
201
 * <td>The secret key used by the <code>proxyGrantingTicketStorageClass</code> if it supports encryption.</td>
202
 * <td>No</td>
203
 * </tr>
204
 * <tr>
205
 * <td><code>cipherAlgorithm</code></td>
206
 * <td>The algorithm used by the <code>proxyGrantingTicketStorageClass</code> if it supports encryption. Defaults to <code>DESede</code></td>
207
 * <td>No</td>
208
 * </tr>
209
 * <tr>
210
 * <td><code>millisBetweenCleanUps</code></td>
211
 * <td>Startup delay for the cleanup task to remove expired tickets from the storage. Defaults to <code>60000 msec</code></td>
212
 * <td>No</td>
213
 * </tr>
214
 * <tr>
215
 * <td><code>ticketValidatorClass</code></td>
216
 * <td>Ticket validator class to use/create</td>
217
 * <td>No</td>
218
 * </tr>
219
 * <tr>
220
 * <td><code>hostnameVerifier</code></td>
221
 * <td>Hostname verifier class name, used when making back-channel calls</td>
222
 * <td>No</td>
223
 * </tr></tbody></table>
131
 <thead>
132
 <tr>
133
 <th>Property</th>
134
 <th>Description</th>
135
 <th>Required</th>
136
 </tr>
137
 </thead>
138
 <tbody>
139
 <tr>
140
 <td><code>casServerUrlPrefix</code></td>
141
 <td>The start of the CAS server URL, i.e. <code>https://localhost:8443/cas</code></td>
142
 <td>Yes</td>
143
 </tr>
144
 <tr>
145
 <td><code>serverName</code></td>
146
 <td>The name of the server this application is hosted on. Service URL will be dynamically constructed using this, i.e. <code>https://localhost:8443</code> (you must include the protocol, but port is optional if it's a standard port).</td>
147
 <td>Yes</td>
148
 </tr>
149
 <tr>
150
 <td><code>renew</code></td>
151
 <td>Specifies whether <code>renew=true</code> should be sent to the CAS server. Valid values are either <code>true/false</code> (or no value at all). Note that <code>renew</code> cannot be specified as local <code>init-param</code> setting.</td>
152
 <td>No</td>
153
 </tr>
154
 <tr>
155
 <td><code>redirectAfterValidation</code></td>
156
 <td>Whether to redirect to the same URL after ticket validation, but without the ticket in the parameter. Defaults to <code>true</code>.</td>
157
 <td>No</td>
158
 </tr>
159
 <tr>
160
 <td><code>useSession</code></td>
161
 <td>Whether to store the Assertion in session or not. If sessions are not used, tickets will be required for each request. Defaults to <code>true</code>.</td>
162
 <td>No</td>
163
 </tr>
164
 <tr>
165
 <td><code>exceptionOnValidationFailure</code></td>
166
 <td>whether to throw an exception or not on ticket validation failure. Defaults to <code>true</code></td>
167
 <td>No</td>
168
 </tr>
169
 <tr>
170
 <td><code>proxyReceptorUrl</code></td>
171
 <td>The URL to watch for <code>PGTIOU/PGT</code> responses from the CAS server. Should be defined from the root of the context. For example, if your application is deployed in <code>/cas-client-app</code> and you want the proxy receptor URL to be <code>/cas-client-app/my/receptor</code> you need to configure proxyReceptorUrl to be <code>/my/receptor</code>.</td>
172
 <td>No</td>
173
 </tr>
174
 <tr>
175
 <td><code>acceptAnyProxy</code></td>
176
 <td>Specifies whether any proxy is OK. Defaults to <code>false</code>.</td>
177
 <td>No</td>
178
 </tr>
179
 <tr>
180
 <td><code>allowedProxyChains</code></td>
181
 <td>Specifies the proxy chain. Each acceptable proxy chain should include a space-separated list of URLs (for exact match) or regular expressions of URLs (starting by the <code>^</code> character). Each acceptable proxy chain should appear on its own line.</td>
182
 <td>No</td>
183
 </tr>
184
 <tr>
185
 <td><code>proxyCallbackUrl</code></td>
186
 <td>The callback URL to provide the CAS server to accept Proxy Granting Tickets.</td>
187
 <td>No</td>
188
 </tr>
189
 <tr>
190
 <td><code>proxyGrantingTicketStorageClass</code></td>
191
 <td>Specify an implementation of the ProxyGrantingTicketStorage class that has a no-arg constructor.</td>
192
 <td>No</td>
193
 </tr>
194
 <tr>
195
 <td><code>sslConfigFile</code></td>
196
 <td>A reference to a properties file that includes SSL settings for client-side SSL config, used during back-channel calls. The configuration includes keys for <code>protocol</code> which defaults to <code>SSL</code>, <code>keyStoreType</code>, <code>keyStorePath</code>, <code>keyStorePass</code>, <code>keyManagerType</code> which defaults to <code>SunX509</code> and <code>certificatePassword</code>.</td>
197
 <td>No.</td>
198
 </tr>
199
 <tr>
200
 <td><code>encoding</code></td>
201
 <td>Specifies the encoding charset the client should use</td>
202
 <td>No</td>
203
 </tr>
204
 <tr>
205
 <td><code>secretKey</code></td>
206
 <td>The secret key used by the <code>proxyGrantingTicketStorageClass</code> if it supports encryption.</td>
207
 <td>No</td>
208
 </tr>
209
 <tr>
210
 <td><code>cipherAlgorithm</code></td>
211
 <td>The algorithm used by the <code>proxyGrantingTicketStorageClass</code> if it supports encryption. Defaults to <code>DESede</code></td>
212
 <td>No</td>
213
 </tr>
214
 <tr>
215
 <td><code>millisBetweenCleanUps</code></td>
216
 <td>Startup delay for the cleanup task to remove expired tickets from the storage. Defaults to <code>60000 msec</code></td>
217
 <td>No</td>
218
 </tr>
219
 <tr>
220
 <td><code>ticketValidatorClass</code></td>
221
 <td>Ticket validator class to use/create</td>
222
 <td>No</td>
223
 </tr>
224
 <tr>
225
 <td><code>hostnameVerifier</code></td>
226
 <td>Hostname verifier class name, used when making back-channel calls</td>
227
 <td>No</td>
228
 </tr></tbody></table>
224 229
 */
225 230
@ConfigurationProperties(prefix = "spring.cas")
226 231
public class CasConfigurationProperties {
227
    private String casServerUrlPrefix = "http://10.1.193.115:8100/cas";
228
    private String casServerLoginUrl = casServerUrlPrefix + "/login";
229
    private String casServerLogoutUrl = casServerUrlPrefix + "/logout";
230
    private String serverName = "http://10.1.176.129:8081/zhbg";
232
    private String casServerUrlPrefix;
233
    private String casServerLoginUrl;
234
    private String casServerLogoutUrl;
235
    private String serverName;
231 236
    private boolean useSession = true;
232 237
    private boolean redirectAfterValidation = true;
233 238
    private String ignorePattern = "\\.(js|img|css)(\\?.*)?$";

+ 0 - 88
oa-app/src/main/java/com/css/oa/config/WebSecurityConfig.java

@ -1,88 +0,0 @@
1
package com.css.oa.config;
2
3
import org.jasig.cas.client.session.SingleSignOutHttpSessionListener;
4
import org.jasig.cas.client.util.AbstractCasFilter;
5
import org.jasig.cas.client.validation.AssertionImpl;
6
import org.springframework.beans.factory.annotation.Autowired;
7
import org.springframework.boot.autoconfigure.security.SecurityProperties;
8
import org.springframework.boot.web.servlet.ServletListenerRegistrationBean;
9
import org.springframework.context.annotation.Bean;
10
import org.springframework.context.annotation.Configuration;
11
import org.springframework.core.annotation.Order;
12
import org.springframework.security.authentication.AnonymousAuthenticationToken;
13
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
14
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
15
import org.springframework.security.config.annotation.web.builders.WebSecurity;
16
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
17
import org.springframework.security.core.Authentication;
18
import org.springframework.security.core.context.SecurityContextHolder;
19
import org.springframework.security.core.userdetails.User;
20
import org.springframework.security.provisioning.UserDetailsManager;
21
import org.springframework.security.web.authentication.SavedRequestAwareAuthenticationSuccessHandler;
22
import org.springframework.web.cors.CorsUtils;
23
24
import javax.servlet.ServletException;
25
import javax.servlet.http.HttpServletRequest;
26
import javax.servlet.http.HttpServletResponse;
27
import java.io.IOException;
28
29
@Configuration
30
//@Order(SecurityProperties.ACCESS_OVERRIDE_ORDER)
31
@Order(SecurityProperties.BASIC_AUTH_ORDER)
32
public class WebSecurityConfig extends WebSecurityConfigurerAdapter{
33
    @Autowired
34
    private CasConfigurationProperties autoconfig;
35
36
    @Bean
37
    public UserDetailsManager userDetailsService(AuthenticationManagerBuilder auth) throws Exception {
38
        auth.inMemoryAuthentication().withUser("demo").password("demo").roles("USER");
39
        return (UserDetailsManager) auth.getDefaultUserDetailsService();
40
    }
41
42
    @Override
43
    public void configure(WebSecurity web) throws Exception {
44
        web.ignoring().antMatchers("/css/**", "/js/**");
45
    }
46
47
    @Override
48
    protected void configure(HttpSecurity http) throws Exception {
49
        http.headers().frameOptions().disable();
50
        http.csrf().disable();
51
        http.httpBasic().disable();
52
        http.formLogin()
53
            .loginPage("/casLogin")
54
            .loginProcessingUrl("/login")
55
            .defaultSuccessUrl("/index")
56
            .successHandler(new SavedRequestAwareAuthenticationSuccessHandler(){
57
                @Override
58
                public void onAuthenticationSuccess(HttpServletRequest request,
59
                                                    HttpServletResponse response, Authentication authentication)
60
                    throws ServletException, IOException {
61
                    super.onAuthenticationSuccess(request, response, authentication);
62
                    Authentication auth = SecurityContextHolder.getContext().getAuthentication();
63
                    if (!(auth instanceof AnonymousAuthenticationToken)) {
64
                        User user = (User) auth.getPrincipal();
65
                        request.getSession().setAttribute(AbstractCasFilter.CONST_CAS_ASSERTION, new AssertionImpl(user.getUsername()));
66
                    }
67
                }
68
            })
69
            .permitAll();
70
        http.authorizeRequests()
71
            .requestMatchers(CorsUtils::isPreFlightRequest).permitAll()
72
            .antMatchers("/register", "/casLogin").permitAll()
73
            .anyRequest().authenticated();
74
        http.logout()
75
            .logoutUrl("/logout")
76
            .logoutSuccessUrl(autoconfig.getCasServerLogoutUrl() + "?service=" + autoconfig.getServerName() + "/index")
77
            .permitAll();
78
        http.antMatcher("/**");
79
    }
80
81
    @Bean
82
    public ServletListenerRegistrationBean<SingleSignOutHttpSessionListener> singleSignOutHttpSessionListener(){
83
        ServletListenerRegistrationBean<SingleSignOutHttpSessionListener> servletListenerRegistrationBean =
84
            new ServletListenerRegistrationBean<>();
85
        servletListenerRegistrationBean.setListener(new SingleSignOutHttpSessionListener());
86
        return servletListenerRegistrationBean;
87
    }
88
}

+ 64 - 64
oa-app/src/main/java/com/css/oa/exam/admin/controller/AdminController.java

@ -3,16 +3,16 @@ package com.css.oa.exam.admin.controller;
3 3
import com.css.oa.exam.admin.bean.LoginUser;
4 4
import com.css.oa.exam.base.BaseController;
5 5
import io.swagger.annotations.Api;
6
import org.springframework.beans.factory.annotation.Autowired;
7
import org.springframework.security.authentication.AnonymousAuthenticationToken;
8
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
9
import org.springframework.security.core.Authentication;
10
import org.springframework.security.core.authority.AuthorityUtils;
11
import org.springframework.security.core.context.SecurityContextHolder;
12
import org.springframework.security.core.userdetails.User;
13
import org.springframework.security.core.userdetails.UserDetailsService;
14
import org.springframework.security.provisioning.UserDetailsManager;
15
import org.springframework.ui.Model;
6
//import org.springframework.beans.factory.annotation.Autowired;
7
//import org.springframework.security.authentication.AnonymousAuthenticationToken;
8
//import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
9
//import org.springframework.security.core.Authentication;
10
//import org.springframework.security.core.authority.AuthorityUtils;
11
//import org.springframework.security.core.context.SecurityContextHolder;
12
//import org.springframework.security.core.userdetails.User;
13
//import org.springframework.security.core.userdetails.UserDetailsService;
14
//import org.springframework.security.provisioning.UserDetailsManager;
15
//import org.springframework.ui.Model;
16 16
import org.springframework.web.bind.annotation.*;
17 17
18 18
import javax.servlet.http.HttpServletRequest;
@ -21,59 +21,59 @@ import javax.servlet.http.HttpServletRequest;
21 21
@RestController
22 22
@RequestMapping("/admin")
23 23
public class AdminController extends BaseController {
24
25
    @Autowired
26
    private UserDetailsService userDetailsService;
27
28
    @GetMapping("*")
29
    public String welcome() {
30
        return "redirect:casLogin";
31
    }
32
33
    @GetMapping("index")
34
    public String index() {
35
        return "welcome";
36
    }
37
38
    @GetMapping("login")
39
    public String loginPage(Model model) {
40
        Authentication auth = SecurityContextHolder.getContext().getAuthentication();
41
        if (!(auth instanceof AnonymousAuthenticationToken)) {
42
            return "redirect:index";
43
        }
44
        LoginUser user = new LoginUser();
45
        model.addAttribute("user",user);
46
        return "login";
47
    }
48
49
    @GetMapping("casLogin")
50
    public String casLogin(HttpServletRequest request) {
51
        if (request.getRemoteUser() != null) {
52
            Authentication auth = new UsernamePasswordAuthenticationToken(request.getRemoteUser(), request.getRemoteUser(),
53
                    AuthorityUtils.createAuthorityList("USER"));
54
            SecurityContextHolder.getContext().setAuthentication(auth);
55
            return "redirect:index";
56
        }
57
        return "redirect:login";
58
    }
59
60
    @GetMapping("register")
61
    public String registerPage(Model model) {
62
        LoginUser user = new LoginUser();
63
        model.addAttribute("user",user);
64
        return "register";
65
    }
66
67
    @PostMapping("register")
68
    public String register(LoginUser user) {
69
        UserDetailsManager userDetailsManager = (UserDetailsManager) userDetailsService;
70
        boolean exists = userDetailsManager.userExists(user.getUsername());
71
        if (!exists) {
72
            userDetailsManager.createUser(new User(user.getUsername(), user.getPassword(), AuthorityUtils.createAuthorityList("USER")));
73
            return "redirect:register?success";
74
        } else {
75
            return "redirect:register?error";
76
        }
77
    }
24
//
25
//    @Autowired
26
//    private UserDetailsService userDetailsService;
27
//
28
//    @GetMapping("*")
29
//    public String welcome() {
30
//        return "redirect:casLogin";
31
//    }
32
//
33
//    @GetMapping("index")
34
//    public String index() {
35
//        return "welcome";
36
//    }
37
//
38
//    @GetMapping("login")
39
//    public String loginPage(Model model) {
40
//        Authentication auth = SecurityContextHolder.getContext().getAuthentication();
41
//        if (!(auth instanceof AnonymousAuthenticationToken)) {
42
//            return "redirect:index";
43
//        }
44
//        LoginUser user = new LoginUser();
45
//        model.addAttribute("user",user);
46
//        return "login";
47
//    }
48
//
49
//    @GetMapping("casLogin")
50
//    public String casLogin(HttpServletRequest request) {
51
//        if (request.getRemoteUser() != null) {
52
//            Authentication auth = new UsernamePasswordAuthenticationToken(request.getRemoteUser(), request.getRemoteUser(),
53
//                    AuthorityUtils.createAuthorityList("USER"));
54
//            SecurityContextHolder.getContext().setAuthentication(auth);
55
//            return "redirect:index";
56
//        }
57
//        return "redirect:login";
58
//    }
59
//
60
//    @GetMapping("register")
61
//    public String registerPage(Model model) {
62
//        LoginUser user = new LoginUser();
63
//        model.addAttribute("user",user);
64
//        return "register";
65
//    }
66
//
67
//    @PostMapping("register")
68
//    public String register(LoginUser user) {
69
//        UserDetailsManager userDetailsManager = (UserDetailsManager) userDetailsService;
70
//        boolean exists = userDetailsManager.userExists(user.getUsername());
71
//        if (!exists) {
72
//            userDetailsManager.createUser(new User(user.getUsername(), user.getPassword(), AuthorityUtils.createAuthorityList("USER")));
73
//            return "redirect:register?success";
74
//        } else {
75
//            return "redirect:register?error";
76
//        }
77
//    }
78 78
79 79
}

+ 78 - 0
oa-app/src/main/java/com/css/oa/exam/admin/controller/CasLoginController.java

@ -0,0 +1,78 @@
1
package com.css.oa.exam.admin.controller;
2
3
import cn.com.dhcc.uums.entity.SSOUser;
4
import cn.com.dhcc.uums.util.SSOTools;
5
import com.css.bpm.platform.org.dept.repository.entity.DeptEntity;
6
import com.css.oa.utils.*;
7
import com.fasterxml.jackson.databind.ObjectMapper;
8
import io.swagger.annotations.Api;
9
import io.swagger.annotations.ApiOperation;
10
import org.apache.commons.lang3.StringUtils;
11
import org.slf4j.Logger;
12
import org.slf4j.LoggerFactory;
13
import org.springframework.beans.BeanUtils;
14
import org.springframework.beans.factory.annotation.Autowired;
15
import org.springframework.data.domain.Page;
16
import org.springframework.web.bind.annotation.GetMapping;
17
import org.springframework.web.bind.annotation.RequestMapping;
18
import org.springframework.web.bind.annotation.RequestParam;
19
import org.springframework.web.bind.annotation.RestController;
20
21
import javax.servlet.http.HttpServletRequest;
22
import javax.servlet.http.HttpServletResponse;
23
import javax.servlet.http.HttpSession;
24
import java.io.IOException;
25
import java.util.ArrayList;
26
import java.util.Date;
27
import java.util.List;
28
29
@Api(tags = {"职称申报和评审-单点登录"})
30
@RestController
31
@RequestMapping("/casLogin")
32
public class CasLoginController {
33
//
34
//    @Autowired
35
//    DepartmentService departmentService;
36
//    @Autowired
37
//    CoreUserService coreUserService;
38
    @Autowired
39
    DeptAPIService deptAPIService;
40
41
    Logger log = LoggerFactory.getLogger(CasLoginController.class);
42
43
44
    @ApiOperation(value = "登录")
45
    @RequestMapping("/login")
46
    public void login(HttpSession session, HttpServletResponse response, HttpServletRequest request) {
47
        try {
48
49
            SSOUser ssoUser = SSOTools.getSSOUser(request);
50
            session.setAttribute("UUID", ssoUser.getId());
51
            session.setAttribute("USER_NAME", ssoUser.getUserName());
52
            session.setAttribute("ORG_NAME", ssoUser.getOrgName());
53
            session.setAttribute("DEP_NAME", ssoUser.getDepName());
54
            session.setAttribute("ROLE_INFO", ssoUser.getRoleInfoList().get(0));
55
            String contextPath = request.getContextPath();
56
            response.sendRedirect("http://localhost:8081/#/title_declaration/announcement_management");
57
        } catch (Exception e){
58
            log.error("登录失败!", e);
59
        };
60
    }
61
62
    @ApiOperation(value = "登出")
63
    @RequestMapping("/logout")
64
    public void logout(HttpSession session, HttpServletResponse response, HttpServletRequest request){
65
//        HttpSession session = request.getSession();
66
        try {
67
            session.invalidate();
68
            // http://10.1.193.115:8100/cas/logout?service=http://10.1.176.129:8081/zhbg
69
            response.sendRedirect("http://10.1.193.115:8100/cas/logout?service=http://10.1.176.129:8081/zhbg");
70
        } catch (Exception e){
71
            log.error("登出失败!", e);
72
        };
73
74
    }
75
76
77
78
}

+ 8 - 0
oa-app/src/main/resources/application.yml

@ -3,6 +3,14 @@ server:
3 3
  servlet:
4 4
    context-path: /zhbg
5 5
spring:
6
  cas:
7
    #夏博电脑的IP地址
8
    server-name: http://10.1.176.129:8081/zhbg
9
    #支撑平台服务地址
10
    cas-server-url-prefix: http://10.1.193.115:8100/cas
11
    cas-server-login-url: ${spring.cas.cas-server-url-prefix}/login
12
    cas-server-logout-url: ${spring.cas.cas-server-url-prefix}/logout
13
    ignore-pattern: (register|\.js|\.img|\.css)(\?.*)?$
6 14
  datasource:
7 15
    type: com.alibaba.druid.pool.DruidDataSource
8 16
    url: jdbc:kingbase://192.168.65.232:54321/LOCALHOST

+ 15 - 15
pom.xml

@ -55,21 +55,21 @@
55 55
            <artifactId>cas-client-core</artifactId>
56 56
            <version>3.5.1</version>
57 57
        </dependency>
58
        <dependency>
59
            <groupId>org.springframework.security</groupId>
60
            <artifactId>spring-security-config</artifactId>
61
            <version>4.1.0.RELEASE</version>
62
        </dependency>
63
        <dependency>
64
            <groupId>org.springframework.security</groupId>
65
            <artifactId>spring-security-core</artifactId>
66
            <version>4.1.0.RELEASE</version>
67
        </dependency>
68
        <dependency>
69
            <groupId>org.springframework.security</groupId>
70
            <artifactId>spring-security-web</artifactId>
71
            <version>4.1.0.RELEASE</version>
72
        </dependency>
58
<!--        <dependency>-->
59
<!--            <groupId>org.springframework.security</groupId>-->
60
<!--            <artifactId>spring-security-core</artifactId>-->
61
<!--            <version>4.1.0.RELEASE</version>-->
62
<!--        </dependency>-->
63
<!--        <dependency>-->
64
<!--            <groupId>org.springframework.security</groupId>-->
65
<!--            <artifactId>spring-security-config</artifactId>-->
66
<!--            <version>4.1.0.RELEASE</version>-->
67
<!--        </dependency>-->
68
<!--        <dependency>-->
69
<!--            <groupId>org.springframework.security</groupId>-->
70
<!--            <artifactId>spring-security-web</artifactId>-->
71
<!--            <version>4.1.0.RELEASE</version>-->
72
<!--        </dependency>-->
73 73
        <!--        llg加的测试依赖-->
74 74
        <dependency>
75 75
            <groupId>junit</groupId>