Test Failed
Push — master ( d00f41...91a4bb )
by Misagh
32:47 queued 09:02
created

getLocation()   A

Complexity

Conditions 1

Size

Total Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
dl 0
loc 2
rs 10
c 0
b 0
f 0
1
package org.apereo.cas.configuration.model.core;
2
3
import org.apereo.cas.CasProtocolConstants;
4
import org.apereo.cas.configuration.support.Beans;
5
import org.apereo.cas.configuration.support.RequiresModule;
6
import org.apereo.cas.configuration.support.RequiredProperty;
7
import org.springframework.core.io.ClassPathResource;
8
import org.springframework.core.io.Resource;
9
10
import java.io.Serializable;
11
import java.util.LinkedHashMap;
12
import java.util.Map;
13
14
/**
15
 * This is {@link CasServerProperties}.
16
 *
17
 * @author Misagh Moayyed
18
 * @since 5.0.0
19
 */
20
@RequiresModule(name = "cas-server-core", automated = true)
21
public class CasServerProperties implements Serializable {
22
23
    private static final long serialVersionUID = 7876382696803430817L;
24
25
    /**
26
     * Full name of the CAS server. This is public-facing address
27
     * of the CAS deployment and not the individual node address,
28
     * in the event that CAS is clustered.
29
     */
30
    @RequiredProperty
31
    private String name = "https://cas.example.org:8443";
32
33
    /**
34
     * A concatenation of the server name plus the CAS context path.
35
     * Deployments at root likely need to blank out this value.
36
     */
37
    @RequiredProperty
38
    private String prefix = name.concat("/cas");
39
    /**
40
     * Embedded container AJP settings.
41
     */
42
    private Ajp ajp = new Ajp();
43
    /**
44
     * Embedded container HTTP port settings as an additional option.
45
     */
46
    private Http http = new Http();
47
    /**
48
     * Http proxy configuration properties.
49
     * In the event that you decide to run CAS without any SSL configuration in the embedded Tomcat container and on a non-secure
50
     * port yet wish to customize the connector configuration that is linked to the running port (i.e. 8080), this setting may apply.
51
     */
52
    private HttpProxy httpProxy = new HttpProxy();
53
    /**
54
     * Embedded container's SSL valve setting.
55
     */
56
    private SslValve sslValve = new SslValve();
57
    /**
58
     * Embedded container's rewrite valve setting.
59
     */
60
    private RewriteValve rewriteValve = new RewriteValve();
61
    /**
62
     * Configuration properties for access logging beyond defaults.
63
     */
64
    private ExtendedAccessLog extAccessLog = new ExtendedAccessLog();
65
66
    public HttpProxy getHttpProxy() {
67
        return httpProxy;
68
    }
69
70
    public void setHttpProxy(final HttpProxy httpProxy) {
71
        this.httpProxy = httpProxy;
72
    }
73
74
    public ExtendedAccessLog getExtAccessLog() {
75
        return extAccessLog;
76
    }
77
78
    public void setExtAccessLog(final ExtendedAccessLog extAccessLog) {
79
        this.extAccessLog = extAccessLog;
80
    }
81
82
    public Http getHttp() {
83
        return http;
84
    }
85
86
    public void setHttp(final Http http) {
87
        this.http = http;
88
    }
89
90
    public Ajp getAjp() {
91
        return ajp;
92
    }
93
94
    public void setAjp(final Ajp ajp) {
95
        this.ajp = ajp;
96
    }
97
98
    public SslValve getSslValve() {
99
        return sslValve;
100
    }
101
102
    public void setSslValve(final SslValve sslValve) {
103
        this.sslValve = sslValve;
104
    }
105
106
    public String getName() {
107
        return name;
108
    }
109
110
    public void setName(final String name) {
111
        this.name = name;
112
    }
113
114
    public String getPrefix() {
115
        return prefix;
116
    }
117
118
    public void setPrefix(final String prefix) {
119
        this.prefix = prefix;
120
    }
121
122
    public String getLoginUrl() {
123
        return getPrefix().concat(CasProtocolConstants.ENDPOINT_LOGIN);
124
    }
125
126
    public String getLogoutUrl() {
127
        return getPrefix().concat(CasProtocolConstants.ENDPOINT_LOGOUT);
128
    }
129
130
    public RewriteValve getRewriteValve() {
131
        return rewriteValve;
132
    }
133
134
    public void setRewriteValve(final RewriteValve rewriteValve) {
135
        this.rewriteValve = rewriteValve;
136
    }
137
138
    public static class Ajp implements Serializable {
139
140
        private static final long serialVersionUID = -32143821503580896L;
141
        /**
142
         * Sets the protocol to handle incoming traffic.
143
         */
144
        private String protocol = "AJP/1.3";
145
146
        /**
147
         * The TCP port number on which this Connector will create a server socket and await incoming connections.
148
         * Your operating system will allow only one server application to listen to a
149
         * particular port number on a particular IP address. If the special value of 0 (zero) is used,
150
         * then Tomcat will select a free port at random to use for this connector.
151
         * This is typically only useful in embedded and testing applications.
152
         */
153
        private int port = 8009;
154
155
        /**
156
         * Set this attribute to true if you wish to have calls to request.isSecure() to return true for requests received
157
         * by this Connector (you would want this on an SSL Connector). The default value is false.
158
         */
159
        private boolean secure;
160
161
        /**
162
         * A boolean value which can be used to enable or disable
163
         * the TRACE HTTP method. If not specified, this attribute is set to false.
164
         */
165
        private boolean allowTrace;
166
167
        /**
168
         * Set this attribute to the name of the protocol you wish to have returned by calls to request.getScheme(). For example,
169
         * you would set this attribute to "https" for an SSL Connector.
170
         */
171
        private String scheme = "http";
172
173
        /**
174
         * Enable AJP support in CAS for the embedded Apache Tomcat container.
175
         */
176
        private boolean enabled;
177
        /**
178
         * The default timeout for asynchronous requests in milliseconds. If not specified, this attribute is set to 10000 (10 seconds).
179
         */
180
        private String asyncTimeout = "PT5S";
181
        /**
182
         * Set to true if you want calls to request.getRemoteHost() to perform DNS lookups in order to return the actual host name of the remote client.
183
         * Set to false to skip the DNS lookup and return the IP address in String form instead (thereby improving performance).
184
         * By default, DNS lookups are disabled.
185
         */
186
        private boolean enableLookups;
187
        /**
188
         * The maximum size in bytes of the POST which will be handled by the container
189
         * FORM URL parameter parsing. The feature can be disabled by setting this attribute to a value
190
         * less than or equal to 0. If not specified, this attribute is set to 2097152 (2 megabytes).
191
         */
192
        private int maxPostSize = 20971520;
193
        /**
194
         * If this Connector is being used in a proxy configuration, configure this attribute
195
         * to specify the server port to be returned for calls to request.getServerPort().
196
         */
197
        private int proxyPort = -1;
198
        /**
199
         * If this Connector is supporting non-SSL requests, and a request is received
200
         * for which a matching <security-constraint> requires SSL transport,
201
         * Catalina will automatically redirect the request to the port number specified here.
202
         */
203
        private int redirectPort = -1;
204
        /**
205
         * Additional attributes to be set on the AJP connector in form of key-value pairs.
206
         * Examples include:
207
         * <ul>
208
         * <li>{@code tomcatAuthentication}: If set to true, the authentication will be done in Tomcat.
209
         * Otherwise, the authenticated principal will be propagated from the native webserver
210
         * and used for authorization in Tomcat.
211
         * Note that this principal will have no roles associated with it. The default value is true.</li>
212
         * <li>{@code maxThreads}: The maximum number of request processing threads to be created
213
         * by this Connector, which therefore determines the maximum number of simultaneous
214
         * requests that can be handled. If not specified, this attribute is set to 200.
215
         * If an executor is associated with this connector, this attribute is
216
         * ignored as the connector will execute tasks using the executor rather than an internal thread pool.</li>
217
         * <li>{@code keepAliveTimeout}: The number of milliseconds this Connector
218
         * will wait for another AJP request before closing the connection.
219
         * The default value is to use the value that has been set for the connectionTimeout attribute.</li>
220
         * <li>{@code maxCookieCount}: The maximum number of cookies that are permitted for a request.
221
         * A value of less than zero means no limit. If not specified, a default value of 200 will be used.</li>
222
         * <li>{@code bufferSize}: The size of the output buffer to use. If less than or equal to zero,
223
         * then output buffering is disabled. The default value is -1 (i.e. buffering disabled)</li>
224
         * <li>{@code clientCertProvider}: When client certificate information is presented in a
225
         * form other than instances of java.security.cert.X509Certificate it needs to be converted
226
         * before it can be used and this property controls which JSSE provider is used to perform
227
         * the conversion. For example it is used with the AJP connectors,
228
         * the HTTP APR connector and with the org.apache.catalina.valves.SSLValve.If not specified,
229
         * the default provider will be used.</li>
230
         * <li>{@code connectionTimeout}: The number of milliseconds this Connector
231
         * will wait, after accepting a connection,
232
         * for the request URI line to be presented. The default value is infinite (i.e. no timeout).</li>
233
         * <li>{@code address}: For servers with more than one IP address,
234
         * this attribute specifies which address will be used for listening on
235
         * the specified port. By default, this port will be used on all IP addresses associated with the server.
236
         * A value of 127.0.0.1 indicates that the Connector will only listen on the loopback interface.</li>
237
         * </ul>
238
         * <p>
239
         * See the Apache Tomcat documentation for a full list.
240
         */
241
        private Map<String, Object> attributes = new LinkedHashMap<>();
242
243
        public Map<String, Object> getAttributes() {
244
            return attributes;
245
        }
246
247
        public void setAttributes(final Map<String, Object> attributes) {
248
            this.attributes = attributes;
249
        }
250
251
        public String getProtocol() {
252
            return protocol;
253
        }
254
255
        public void setProtocol(final String protocol) {
256
            this.protocol = protocol;
257
        }
258
259
        public int getPort() {
260
            return port;
261
        }
262
263
        public void setPort(final int port) {
264
            this.port = port;
265
        }
266
267
        public boolean isSecure() {
268
            return secure;
269
        }
270
271
        public void setSecure(final boolean secure) {
272
            this.secure = secure;
273
        }
274
275
        public boolean isAllowTrace() {
276
            return allowTrace;
277
        }
278
279
        public void setAllowTrace(final boolean allowTrace) {
280
            this.allowTrace = allowTrace;
281
        }
282
283
        public String getScheme() {
284
            return scheme;
285
        }
286
287
        public void setScheme(final String scheme) {
288
            this.scheme = scheme;
289
        }
290
291
        public boolean isEnabled() {
292
            return enabled;
293
        }
294
295
        public void setEnabled(final boolean enabled) {
296
            this.enabled = enabled;
297
        }
298
299
        public long getAsyncTimeout() {
300
            return Beans.newDuration(asyncTimeout).toMillis();
301
        }
302
303
        public void setAsyncTimeout(final String asyncTimeout) {
304
            this.asyncTimeout = asyncTimeout;
305
        }
306
307
        public boolean isEnableLookups() {
308
309
            return enableLookups;
310
        }
311
312
        public void setEnableLookups(final boolean enableLookups) {
313
            this.enableLookups = enableLookups;
314
        }
315
316
        public int getMaxPostSize() {
317
            return maxPostSize;
318
        }
319
320
        public void setMaxPostSize(final int maxPostSize) {
321
            this.maxPostSize = maxPostSize;
322
        }
323
324
        public int getProxyPort() {
325
            return proxyPort;
326
        }
327
328
        public void setProxyPort(final int proxyPort) {
329
            this.proxyPort = proxyPort;
330
        }
331
332
        public int getRedirectPort() {
333
            return redirectPort;
334
        }
335
336
        public void setRedirectPort(final int redirectPort) {
337
            this.redirectPort = redirectPort;
338
        }
339
    }
340
341
    public static class ExtendedAccessLog implements Serializable {
342
343
        private static final long serialVersionUID = 6738161402499196038L;
344
        /**
345
         * Flag to indicate whether extended log facility is enabled.
346
         */
347
        private boolean enabled;
348
349
        /**
350
         * String representing extended log pattern.
351
         */
352
        private String pattern = "c-ip s-ip cs-uri sc-status time X-threadname x-H(secure) x-H(remoteUser)";
353
354
        /**
355
         * File name suffix for extended log.
356
         */
357
        private String suffix = ".log";
358
359
        /**
360
         * File name prefix for extended log.
361
         */
362
        private String prefix = "localhost_access_extended";
363
364
        /**
365
         * Directory name for extended log.
366
         */
367
        private String directory;
368
369
        public String getDirectory() {
370
            return directory;
371
        }
372
373
        public void setDirectory(final String directory) {
374
            this.directory = directory;
375
        }
376
377
        public boolean isEnabled() {
378
            return enabled;
379
        }
380
381
        public void setEnabled(final boolean enabled) {
382
            this.enabled = enabled;
383
        }
384
385
        public String getPattern() {
386
            return pattern;
387
        }
388
389
        public void setPattern(final String pattern) {
390
            this.pattern = pattern;
391
        }
392
393
        public String getSuffix() {
394
            return suffix;
395
        }
396
397
        public void setSuffix(final String suffix) {
398
            this.suffix = suffix;
399
        }
400
401
        public String getPrefix() {
402
            return prefix;
403
        }
404
405
        public void setPrefix(final String prefix) {
406
            this.prefix = prefix;
407
        }
408
    }
409
410
    public static class HttpProxy implements Serializable {
411
        private static final long serialVersionUID = 9129851352067677264L;
412
        /**
413
         * Enable the container running in proxy mode.
414
         */
415
        private boolean enabled;
416
        /**
417
         * Scheme used for the proxy.
418
         */
419
        private String scheme = "https";
420
        /**
421
         * Whether proxy should run in secure mode.
422
         */
423
        private boolean secure = true;
424
        /**
425
         * Redirect port for the proxy.
426
         */
427
        private int redirectPort;
428
        /**
429
         * Proxy port for the proxy.
430
         */
431
        private int proxyPort;
432
        /**
433
         * Proxy protocol to use.
434
         */
435
        private String protocol = "AJP/1.3";
436
        /**
437
         * Custom attributes to set on the proxy connector.
438
         */
439
        private Map<String, Object> attributes = new LinkedHashMap<>();
440
441
        public Map<String, Object> getAttributes() {
442
            return attributes;
443
        }
444
445
        public void setAttributes(final Map<String, Object> attributes) {
446
            this.attributes = attributes;
447
        }
448
449
        public String getProtocol() {
450
            return protocol;
451
        }
452
453
        public void setProtocol(final String protocol) {
454
            this.protocol = protocol;
455
        }
456
457
        public int getRedirectPort() {
458
            return redirectPort;
459
        }
460
461
        public void setRedirectPort(final int redirectPort) {
462
            this.redirectPort = redirectPort;
463
        }
464
465
        public int getProxyPort() {
466
            return proxyPort;
467
        }
468
469
        public void setProxyPort(final int proxyPort) {
470
            this.proxyPort = proxyPort;
471
        }
472
473
        public boolean isEnabled() {
474
            return enabled;
475
        }
476
477
        public void setEnabled(final boolean enabled) {
478
            this.enabled = enabled;
479
        }
480
481
        public String getScheme() {
482
            return scheme;
483
        }
484
485
        public void setScheme(final String scheme) {
486
            this.scheme = scheme;
487
        }
488
489
        public boolean isSecure() {
490
            return secure;
491
        }
492
493
        public void setSecure(final boolean secure) {
494
            this.secure = secure;
495
        }
496
    }
497
498
    public static class Http implements Serializable {
499
500
        private static final long serialVersionUID = -8809922027350085888L;
501
        /**
502
         * Enable a separate port for the embedded container for HTTP access.
503
         */
504
        private boolean enabled;
505
506
        /**
507
         * The HTTP port to use.
508
         */
509
        private int port = 8080;
510
511
        /**
512
         * HTTP protocol to use.
513
         */
514
        private String protocol = "org.apache.coyote.http11.Http11NioProtocol";
515
516
        /**
517
         * Additional attributes to be set on the connector.
518
         */
519
        private Map<String, Object> attributes = new LinkedHashMap<>();
520
521
        public Map<String, Object> getAttributes() {
522
            return attributes;
523
        }
524
525
        public void setAttributes(final Map<String, Object> attributes) {
526
            this.attributes = attributes;
527
        }
528
529
        public String getProtocol() {
530
            return protocol;
531
        }
532
533
        public void setProtocol(final String protocol) {
534
            this.protocol = protocol;
535
        }
536
537
        public boolean isEnabled() {
538
            return enabled;
539
        }
540
541
        public void setEnabled(final boolean enabled) {
542
            this.enabled = enabled;
543
        }
544
545
        public int getPort() {
546
            return port;
547
        }
548
549
        public void setPort(final int port) {
550
            this.port = port;
551
        }
552
    }
553
554
    public static class RewriteValve implements Serializable {
555
        private static final long serialVersionUID = 9030094143985594411L;
556
        /**
557
         * Location of a rewrite valve specifically by Apache Tomcat
558
         * to activate URL rewriting.
559
         */
560
        private Resource location = new ClassPathResource("container/tomcat/rewrite.config");
561
562
        public Resource getLocation() {
563
            return location;
564
        }
565
566
        public void setLocation(final Resource location) {
567
            this.location = location;
568
        }
569
    }
570
571
    public static class SslValve implements Serializable {
572
        private static final long serialVersionUID = 3164446071136700242L;
573
        /**
574
         * Enable the SSL valve for apache tomcat.
575
         */
576
        private boolean enabled;
577
578
        /**
579
         * Allows setting a custom name for the ssl_client_cert header.
580
         * If not specified, the default of ssl_client_cert is used.
581
         */
582
        private String sslClientCertHeader = "ssl_client_cert";
583
        /**
584
         * Allows setting a custom name for the ssl_cipher header.
585
         * If not specified, the default of ssl_cipher is used.
586
         */
587
        private String sslCipherHeader = "ssl_cipher";
588
        /**
589
         * Allows setting a custom name for the ssl_session_id header.
590
         * If not specified, the default of ssl_session_id is used.
591
         */
592
        private String sslSessionIdHeader = "ssl_session_id";
593
        /**
594
         * Allows setting a custom name for the ssl_cipher_usekeysize header.
595
         * If not specified, the default of ssl_cipher_usekeysize is used.
596
         */
597
        private String sslCipherUserKeySizeHeader = "ssl_cipher_usekeysize";
598
599
        public boolean isEnabled() {
600
            return enabled;
601
        }
602
603
        public void setEnabled(final boolean enabled) {
604
            this.enabled = enabled;
605
        }
606
607
        public String getSslClientCertHeader() {
608
            return sslClientCertHeader;
609
        }
610
611
        public void setSslClientCertHeader(final String sslClientCertHeader) {
612
            this.sslClientCertHeader = sslClientCertHeader;
613
        }
614
615
        public String getSslCipherHeader() {
616
            return sslCipherHeader;
617
        }
618
619
        public void setSslCipherHeader(final String sslCipherHeader) {
620
            this.sslCipherHeader = sslCipherHeader;
621
        }
622
623
        public String getSslSessionIdHeader() {
624
            return sslSessionIdHeader;
625
        }
626
627
        public void setSslSessionIdHeader(final String sslSessionIdHeader) {
628
            this.sslSessionIdHeader = sslSessionIdHeader;
629
        }
630
631
        public String getSslCipherUserKeySizeHeader() {
632
            return sslCipherUserKeySizeHeader;
633
        }
634
635
        public void setSslCipherUserKeySizeHeader(final String sslCipherUserKeySizeHeader) {
636
            this.sslCipherUserKeySizeHeader = sslCipherUserKeySizeHeader;
637
        }
638
    }
639
}
640