diff --git a/application/src/main/java/org/thingsboard/server/controller/OAuth2Controller.java b/application/src/main/java/org/thingsboard/server/controller/OAuth2Controller.java index ecd74bef39..323eb19bcd 100644 --- a/application/src/main/java/org/thingsboard/server/controller/OAuth2Controller.java +++ b/application/src/main/java/org/thingsboard/server/controller/OAuth2Controller.java @@ -40,7 +40,7 @@ public class OAuth2Controller extends BaseController { @ResponseBody public List getOAuth2Clients(HttpServletRequest request) throws ThingsboardException { try { - return oAuth2Service.getOAuth2Clients(MiscUtils.getScheme(request), MiscUtils.getDomainName(request)); + return oAuth2Service.getOAuth2Clients(MiscUtils.getScheme(request), MiscUtils.getDomainNameAndPort(request)); } catch (Exception e) { throw handleException(e); } diff --git a/application/src/main/java/org/thingsboard/server/utils/MiscUtils.java b/application/src/main/java/org/thingsboard/server/utils/MiscUtils.java index ad242c96e5..e2d9302d79 100644 --- a/application/src/main/java/org/thingsboard/server/utils/MiscUtils.java +++ b/application/src/main/java/org/thingsboard/server/utils/MiscUtils.java @@ -68,6 +68,22 @@ public class MiscUtils { return request.getServerName(); } + public static String getDomainNameAndPort(HttpServletRequest request){ + String domainName = getDomainName(request); + String scheme = getScheme(request); + int port = MiscUtils.getPort(request); + if (needsPort(scheme, port)) { + domainName += ":" + port; + } + return domainName; + } + + private static boolean needsPort(String scheme, int port) { + boolean isHttpDefault = "http".equals(scheme.toLowerCase()) && port == 80; + boolean isHttpsDefault = "https".equals(scheme.toLowerCase()) && port == 443; + return !isHttpDefault && !isHttpsDefault; + } + public static int getPort(HttpServletRequest request){ String forwardedProto = request.getHeader("x-forwarded-proto"); diff --git a/ui-ngx/proxy.conf.js b/ui-ngx/proxy.conf.js index af558a7a7a..5be6bde1d1 100644 --- a/ui-ngx/proxy.conf.js +++ b/ui-ngx/proxy.conf.js @@ -27,6 +27,14 @@ const PROXY_CONFIG = { "target": ruleNodeUiforwardUrl, "secure": false, }, + "/oauth2": { + "target": forwardUrl, + "secure": false, + }, + "/login/oauth2": { + "target": forwardUrl, + "secure": false, + }, "/static": { "target": forwardUrl, "secure": false, diff --git a/ui-ngx/src/app/modules/home/components/profile/device-profile-provision-configuration.component.ts b/ui-ngx/src/app/modules/home/components/profile/device-profile-provision-configuration.component.ts index 9793af2748..e25c07e005 100644 --- a/ui-ngx/src/app/modules/home/components/profile/device-profile-provision-configuration.component.ts +++ b/ui-ngx/src/app/modules/home/components/profile/device-profile-provision-configuration.component.ts @@ -14,7 +14,7 @@ /// limitations under the License. /// -import { Component, forwardRef, Input, OnInit } from "@angular/core"; +import { Component, forwardRef, Input, OnInit } from '@angular/core'; import { ControlValueAccessor, FormBuilder, @@ -25,13 +25,13 @@ import { ValidationErrors, Validator, Validators -} from "@angular/forms"; -import { coerceBooleanProperty } from "@angular/cdk/coercion"; +} from '@angular/forms'; +import { coerceBooleanProperty } from '@angular/cdk/coercion'; import { DeviceProvisionConfiguration, DeviceProvisionType, deviceProvisionTypeTranslationMap -} from "@shared/models/device.models"; +} from '@shared/models/device.models'; import { generateSecret, isDefinedAndNotNull } from '@core/utils'; @Component({ @@ -126,7 +126,11 @@ export class DeviceProfileProvisionConfigurationComponent implements ControlValu if (this.disabled){ this.provisionConfigurationFormGroup.disable(); } else { - this.provisionConfigurationFormGroup.enable({emitEvent: false}); + if (this.provisionConfigurationFormGroup.get('type').value !== DeviceProvisionType.DISABLED) { + this.provisionConfigurationFormGroup.enable({emitEvent: false}); + } else { + this.provisionConfigurationFormGroup.get('type').enable({emitEvent: false}); + } } } diff --git a/ui-ngx/src/app/modules/home/components/profile/device-profile.component.ts b/ui-ngx/src/app/modules/home/components/profile/device-profile.component.ts index 09223491e1..e837caf660 100644 --- a/ui-ngx/src/app/modules/home/components/profile/device-profile.component.ts +++ b/ui-ngx/src/app/modules/home/components/profile/device-profile.component.ts @@ -94,8 +94,6 @@ export class DeviceProfileComponent extends EntityComponent { name: [entity ? entity.name : '', [Validators.required]], type: [entity ? entity.type : null, [Validators.required]], transportType: [entity ? entity.transportType : null, [Validators.required]], - provisionType: [deviceProvisionConfiguration.type, [Validators.required]], - provisionDeviceKey: [deviceProvisionConfiguration.provisionDeviceKey], profileData: this.fb.group({ configuration: [entity && !this.isAdd ? entity.profileData?.configuration : {}, Validators.required], transportConfiguration: [entity && !this.isAdd ? entity.profileData?.transportConfiguration : {}, Validators.required], diff --git a/ui-ngx/src/app/modules/home/pages/admin/oauth2-settings.component.ts b/ui-ngx/src/app/modules/home/pages/admin/oauth2-settings.component.ts index 400b2d3fc2..58cbe536d7 100644 --- a/ui-ngx/src/app/modules/home/pages/admin/oauth2-settings.component.ts +++ b/ui-ngx/src/app/modules/home/pages/admin/oauth2-settings.component.ts @@ -52,6 +52,7 @@ import { OAuth2Service } from '@core/http/oauth2.service'; export class OAuth2SettingsComponent extends PageComponent implements OnInit, HasConfirmForm, OnDestroy { private URL_REGEXP = /^[A-Za-z][A-Za-z\d.+-]*:\/*(?:\w+(?::\w+)?@)?[^\s/]+(?::\d+)?(?:\/[\w#!:.,?+=&%@\-/]*)?$/; + private DOMAIN_AND_PORT_REGEXP = /^(?:\w+(?::\w+)?@)?[^\s/]+(?::\d+)?$/; private subscriptions: Subscription[] = []; private templates = new Map(); private defaultProvider = { @@ -233,7 +234,7 @@ export class OAuth2SettingsComponent extends PageComponent implements OnInit, Ha const domain = this.fb.group({ name: [domainInfo ? domainInfo.name : this.window.location.hostname, [ Validators.required, - Validators.pattern('((?![:/]).)*$')]], + Validators.pattern(this.DOMAIN_AND_PORT_REGEXP)]], scheme: [domainInfo?.scheme ? domainInfo.scheme : DomainSchema.HTTPS, Validators.required] }, {validators: this.uniqueDomainValidator}); return domain;