Enhance Azure AD

https://github.com/rancher/rancher/issues/15175
This commit is contained in:
loganhz 2018-08-23 16:41:01 +08:00
parent 4688f13e49
commit 376c858ab5
6 changed files with 150 additions and 28 deletions

View File

@ -0,0 +1,67 @@
import Component from '@ember/component';
import layout from './template';
import { get, set, observer, setProperties } from '@ember/object';
import C from 'ui/utils/constants';
export default Component.extend({
layout,
authConfig: null,
isEnabled: null,
region: null,
init() {
this._super(...arguments);
if ( get(this, 'isEnabled') ) {
const endpoint = get(this, 'authConfig.endpoint');
if ( C.AZURE_AD.STANDARD.ENDPOINT.startsWith(endpoint) ) {
set(this, 'region', C.AZURE_AD.STANDARD.KEY);
} else if ( C.AZURE_AD.CHINA.ENDPOINT.startsWith(endpoint) ) {
set(this, 'region', C.AZURE_AD.CHINA.KEY);
} else {
set(this, 'region', C.AZURE_AD.CUSTOM.KEY);
}
} else {
set(this, 'region', C.AZURE_AD.STANDARD.KEY);
this.regionDidChange();
}
},
regionDidChange: observer('region', 'authConfig.tenantId', function() {
const config = get(this, 'authConfig');
const tenantId = get(this, 'authConfig.tenantId') || '';
const region = get(this, 'region');
switch (region) {
case C.AZURE_AD.STANDARD.KEY:
setProperties(config, {
endpoint: C.AZURE_AD.STANDARD.ENDPOINT,
graphEndpoint: C.AZURE_AD.STANDARD.GRAPH_ENDPOINT,
tokenEndpoint: `${ C.AZURE_AD.STANDARD.ENDPOINT }${ tenantId }/oauth2/token`,
authEndpoint: `${ C.AZURE_AD.STANDARD.ENDPOINT }${ tenantId }/oauth2/authorize`,
});
break;
case C.AZURE_AD.CHINA.KEY:
setProperties(config, {
endpoint: C.AZURE_AD.CHINA.ENDPOINT,
graphEndpoint: C.AZURE_AD.CHINA.GRAPH_ENDPOINT,
tokenEndpoint: `${ C.AZURE_AD.CHINA.ENDPOINT }${ tenantId }/oauth2/token`,
authEndpoint: `${ C.AZURE_AD.CHINA.ENDPOINT }${ tenantId }/oauth2/authorize`,
});
break;
case C.AZURE_AD.CUSTOM.KEY:
setProperties(config, {
endpoint: C.AZURE_AD.STANDARD.ENDPOINT,
graphEndpoint: '',
tokenEndpoint: '',
authEndpoint: '',
});
break;
}
}),
});

View File

@ -0,0 +1,59 @@
<label class="acc-label mt-5">{{t 'authPage.azuread.configure.endpoints.label'}}{{field-required}}</label>
<div class="row">
<div class="col span-6">
<div class="radio">
<label>
{{radio-button selection=region value='standard'}} {{t 'authPage.azuread.configure.regions.standard'}}
</label>
</div>
</div>
</div>
<div class="row">
<div class="col span-6">
<div class="radio">
<label>
{{radio-button selection=region value='china'}} {{t 'authPage.azuread.configure.regions.china'}}
</label>
</div>
</div>
</div>
<div class="row">
<div class="col span-6">
<div class="radio">
<label>
{{radio-button selection=region value='custom'}} {{t 'authPage.azuread.configure.regions.custom'}}
</label>
</div>
</div>
</div>
{{!-- {{#if (eq region 'custom')}} --}}
<div class="row">
<div class="col span-6">
<div class="inline-form">
<label class="acc-label pb-5" for="endpoint">{{t 'authPage.azuread.configure.azureADEndpoint.label'}}{{field-required}}</label>
{{input id="endpoint" type="url" value=authConfig.endpoint classNames="form-control"}}
</div>
</div>
<div class="col span-6">
<div class="inline-form">
<label class="acc-label pb-5" for="graph-endpoint">{{t 'authPage.azuread.configure.azureADGraphEndpoint.label'}}{{field-required}}</label>
{{input id="graph-endpoint" type="url" value=authConfig.graphEndpoint classNames="form-control"}}
</div>
</div>
</div>
<div class="row">
<div class="col span-6">
<div class="inline-form">
<label class="acc-label pb-5" for="token-endpoint" >{{t 'authPage.azuread.configure.azureADTokenEndpoint.label'}}{{field-required}}</label>
{{input id="token-endpoint" type="url" value=authConfig.tokenEndpoint classNames="form-control"}}
</div>
</div>
<div class="col span-6">
<div class="inline-form">
<label class="acc-label pb-5" for="auth-endpoint">{{t 'authPage.azuread.configure.azureADAuthEndpoint.label'}}{{field-required}}</label>
{{input id="auth-endpoint" type="url" value=authConfig.authEndpoint classNames="form-control"}}
</div>
</div>
</div>
{{!-- {{/if}} --}}

View File

@ -17,6 +17,7 @@ export default Controller.extend(AuthMixin, {
editing: false,
errors: null,
error: null,
region: null,
_boundSucceed: null,
authConfig: alias('model.azureADConfig'),

View File

@ -106,34 +106,9 @@
</div>
</div>
</div>
<div class="row">
<div class="col span-6">
<div class="inline-form">
<label class="acc-label pb-5" for="endpoint">{{t 'authPage.azuread.configure.azureADEndpoint.label'}}{{field-required}}</label>
{{input id="endpoint" type="url" value=authConfig.endpoint classNames="form-control"}}
</div>
</div>
<div class="col span-6">
<div class="inline-form">
<label class="acc-label pb-5" for="graph-endpoint">{{t 'authPage.azuread.configure.azureADGraphEndpoint.label'}}{{field-required}}</label>
{{input id="graph-endpoint" type="url" value=authConfig.graphEndpoint classNames="form-control"}}
</div>
</div>
</div>
<div class="row">
<div class="col span-6">
<div class="inline-form">
<label class="acc-label pb-5" for="token-endpoint" >{{t 'authPage.azuread.configure.azureADTokenEndpoint.label'}}{{field-required}}</label>
{{input id="token-endpoint" type="url" value=authConfig.tokenEndpoint classNames="form-control"}}
</div>
</div>
<div class="col span-6">
<div class="inline-form">
<label class="acc-label pb-5" for="auth-endpoint">{{t 'authPage.azuread.configure.azureADAuthEndpoint.label'}}{{field-required}}</label>
{{input id="auth-endpoint" type="url" value=authConfig.authEndpoint classNames="form-control"}}
</div>
</div>
</div>
{{#if authConfig}}
{{azuread-endpoints isEnabled=isEnabled authConfig=authConfig}}
{{/if}}
<div class="row mt-10">
<div class="inline-form">
<button class="btn bg-primary" style="display: block;margin: 0 auto;" {{action "test"}}>

View File

@ -604,6 +604,20 @@ C.SUPPORTED_SCHEMA_INPUTS = [
'base64',
];
C.AZURE_AD = {
STANDARD: {
KEY: 'standard',
ENDPOINT: 'https://login.microsoftonline.com/',
GRAPH_ENDPOINT: 'https://graph.windows.net/'
},
CHINA: {
KEY: 'china',
ENDPOINT: 'https://login.chinacloudapi.cn/',
GRAPH_ENDPOINT: 'https://graph.chinacloudapi.cn/'
},
CUSTOM: { KEY: 'custom' }
};
C.AZURE_DEFAULTS = [
'aadClientCertPassword',
'aadClientCertPath',

View File

@ -511,6 +511,12 @@ authPage:
label: Token Endpoint
azureADAuthEndpoint:
label: Auth Endpoint
endpoints:
label: Endpoints
regions:
standard: Standard
china: China
custom: Custom
tenantId:
label: Tenant ID
placeholder: A long UUID string