Commit 8c29339f1364a066553db06444933cd4c0975f51
1 parent
ff4ca5a7
Add support for port in oauth2 domain name. Update proxy.conf to support oauth2 urls
Showing
4 changed files
with
27 additions
and
2 deletions
@@ -40,7 +40,7 @@ public class OAuth2Controller extends BaseController { | @@ -40,7 +40,7 @@ public class OAuth2Controller extends BaseController { | ||
40 | @ResponseBody | 40 | @ResponseBody |
41 | public List<OAuth2ClientInfo> getOAuth2Clients(HttpServletRequest request) throws ThingsboardException { | 41 | public List<OAuth2ClientInfo> getOAuth2Clients(HttpServletRequest request) throws ThingsboardException { |
42 | try { | 42 | try { |
43 | - return oAuth2Service.getOAuth2Clients(MiscUtils.getScheme(request), MiscUtils.getDomainName(request)); | 43 | + return oAuth2Service.getOAuth2Clients(MiscUtils.getScheme(request), MiscUtils.getDomainNameAndPort(request)); |
44 | } catch (Exception e) { | 44 | } catch (Exception e) { |
45 | throw handleException(e); | 45 | throw handleException(e); |
46 | } | 46 | } |
@@ -68,6 +68,22 @@ public class MiscUtils { | @@ -68,6 +68,22 @@ public class MiscUtils { | ||
68 | return request.getServerName(); | 68 | return request.getServerName(); |
69 | } | 69 | } |
70 | 70 | ||
71 | + public static String getDomainNameAndPort(HttpServletRequest request){ | ||
72 | + String domainName = getDomainName(request); | ||
73 | + String scheme = getScheme(request); | ||
74 | + int port = MiscUtils.getPort(request); | ||
75 | + if (needsPort(scheme, port)) { | ||
76 | + domainName += ":" + port; | ||
77 | + } | ||
78 | + return domainName; | ||
79 | + } | ||
80 | + | ||
81 | + private static boolean needsPort(String scheme, int port) { | ||
82 | + boolean isHttpDefault = "http".equals(scheme.toLowerCase()) && port == 80; | ||
83 | + boolean isHttpsDefault = "https".equals(scheme.toLowerCase()) && port == 443; | ||
84 | + return !isHttpDefault && !isHttpsDefault; | ||
85 | + } | ||
86 | + | ||
71 | public static int getPort(HttpServletRequest request){ | 87 | public static int getPort(HttpServletRequest request){ |
72 | String forwardedProto = request.getHeader("x-forwarded-proto"); | 88 | String forwardedProto = request.getHeader("x-forwarded-proto"); |
73 | 89 |
@@ -27,6 +27,14 @@ const PROXY_CONFIG = { | @@ -27,6 +27,14 @@ const PROXY_CONFIG = { | ||
27 | "target": ruleNodeUiforwardUrl, | 27 | "target": ruleNodeUiforwardUrl, |
28 | "secure": false, | 28 | "secure": false, |
29 | }, | 29 | }, |
30 | + "/oauth2": { | ||
31 | + "target": forwardUrl, | ||
32 | + "secure": false, | ||
33 | + }, | ||
34 | + "/login/oauth2": { | ||
35 | + "target": forwardUrl, | ||
36 | + "secure": false, | ||
37 | + }, | ||
30 | "/static": { | 38 | "/static": { |
31 | "target": forwardUrl, | 39 | "target": forwardUrl, |
32 | "secure": false, | 40 | "secure": false, |
@@ -52,6 +52,7 @@ import { OAuth2Service } from '@core/http/oauth2.service'; | @@ -52,6 +52,7 @@ import { OAuth2Service } from '@core/http/oauth2.service'; | ||
52 | export class OAuth2SettingsComponent extends PageComponent implements OnInit, HasConfirmForm, OnDestroy { | 52 | export class OAuth2SettingsComponent extends PageComponent implements OnInit, HasConfirmForm, OnDestroy { |
53 | 53 | ||
54 | private URL_REGEXP = /^[A-Za-z][A-Za-z\d.+-]*:\/*(?:\w+(?::\w+)?@)?[^\s/]+(?::\d+)?(?:\/[\w#!:.,?+=&%@\-/]*)?$/; | 54 | private URL_REGEXP = /^[A-Za-z][A-Za-z\d.+-]*:\/*(?:\w+(?::\w+)?@)?[^\s/]+(?::\d+)?(?:\/[\w#!:.,?+=&%@\-/]*)?$/; |
55 | + private DOMAIN_AND_PORT_REGEXP = /^(?:\w+(?::\w+)?@)?[^\s/]+(?::\d+)?$/; | ||
55 | private subscriptions: Subscription[] = []; | 56 | private subscriptions: Subscription[] = []; |
56 | private templates = new Map<string, OAuth2ClientRegistrationTemplate>(); | 57 | private templates = new Map<string, OAuth2ClientRegistrationTemplate>(); |
57 | private defaultProvider = { | 58 | private defaultProvider = { |
@@ -233,7 +234,7 @@ export class OAuth2SettingsComponent extends PageComponent implements OnInit, Ha | @@ -233,7 +234,7 @@ export class OAuth2SettingsComponent extends PageComponent implements OnInit, Ha | ||
233 | const domain = this.fb.group({ | 234 | const domain = this.fb.group({ |
234 | name: [domainInfo ? domainInfo.name : this.window.location.hostname, [ | 235 | name: [domainInfo ? domainInfo.name : this.window.location.hostname, [ |
235 | Validators.required, | 236 | Validators.required, |
236 | - Validators.pattern('((?![:/]).)*$')]], | 237 | + Validators.pattern(this.DOMAIN_AND_PORT_REGEXP)]], |
237 | scheme: [domainInfo?.scheme ? domainInfo.scheme : DomainSchema.HTTPS, Validators.required] | 238 | scheme: [domainInfo?.scheme ? domainInfo.scheme : DomainSchema.HTTPS, Validators.required] |
238 | }, {validators: this.uniqueDomainValidator}); | 239 | }, {validators: this.uniqueDomainValidator}); |
239 | return domain; | 240 | return domain; |