mirror of
https://github.com/Azure/cosmos-explorer.git
synced 2024-11-25 15:06:55 +00:00
Check for accounts that are restricted from connection string login. (#1673)
* Call Portal Backend to check for accounts that are restricted from connection string login. * Remove debug logging and revert to actual backend endpoint. * Use React hooks for displaying error message. * Move accountrestrictions route under guest. * Check restrictions before resource token check. * Revert test changes.
This commit is contained in:
parent
b949f60c2a
commit
70c031d04b
@ -30,6 +30,18 @@ export const fetchEncryptedToken = async (connectionString: string): Promise<str
|
|||||||
return decodeURIComponent(result.readWrite || result.read);
|
return decodeURIComponent(result.readWrite || result.read);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const isAccountRestrictedForConnectionStringLogin = async (connectionString: string): Promise<boolean> => {
|
||||||
|
const headers = new Headers();
|
||||||
|
headers.append(HttpHeaders.connectionString, connectionString);
|
||||||
|
const url = configContext.BACKEND_ENDPOINT + "/api/guest/accountrestrictions/checkconnectionstringlogin";
|
||||||
|
const response = await fetch(url, { headers, method: "POST" });
|
||||||
|
if (!response.ok) {
|
||||||
|
throw response;
|
||||||
|
}
|
||||||
|
|
||||||
|
return (await response.text()) === "True";
|
||||||
|
};
|
||||||
|
|
||||||
export const ConnectExplorer: React.FunctionComponent<Props> = ({
|
export const ConnectExplorer: React.FunctionComponent<Props> = ({
|
||||||
setEncryptedToken,
|
setEncryptedToken,
|
||||||
login,
|
login,
|
||||||
@ -38,6 +50,7 @@ export const ConnectExplorer: React.FunctionComponent<Props> = ({
|
|||||||
setConnectionString,
|
setConnectionString,
|
||||||
}: Props) => {
|
}: Props) => {
|
||||||
const [isFormVisible, { setTrue: showForm }] = useBoolean(false);
|
const [isFormVisible, { setTrue: showForm }] = useBoolean(false);
|
||||||
|
const [errorMessage, setErrorMessage] = React.useState("");
|
||||||
const enableConnectionStringLogin = !userContext.features.disableConnectionStringLogin;
|
const enableConnectionStringLogin = !userContext.features.disableConnectionStringLogin;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@ -53,6 +66,12 @@ export const ConnectExplorer: React.FunctionComponent<Props> = ({
|
|||||||
id="connectWithConnectionString"
|
id="connectWithConnectionString"
|
||||||
onSubmit={async (event) => {
|
onSubmit={async (event) => {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
|
setErrorMessage("");
|
||||||
|
|
||||||
|
if (await isAccountRestrictedForConnectionStringLogin(connectionString)) {
|
||||||
|
setErrorMessage("This account has been blocked from connection-string login.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (isResourceTokenConnectionString(connectionString)) {
|
if (isResourceTokenConnectionString(connectionString)) {
|
||||||
setAuthType(AuthType.ResourceToken);
|
setAuthType(AuthType.ResourceToken);
|
||||||
@ -76,10 +95,12 @@ export const ConnectExplorer: React.FunctionComponent<Props> = ({
|
|||||||
setConnectionString(event.target.value);
|
setConnectionString(event.target.value);
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
<span className="errorDetailsInfoTooltip" style={{ display: "none" }}>
|
{errorMessage.length > 0 && (
|
||||||
<img className="errorImg" src={ErrorImage} alt="Error notification" />
|
<span className="errorDetailsInfoTooltip">
|
||||||
<span className="errorDetails"></span>
|
<img className="errorImg" src={ErrorImage} alt="Error notification" />
|
||||||
</span>
|
<span className="errorDetails">{errorMessage}</span>
|
||||||
|
</span>
|
||||||
|
)}
|
||||||
</p>
|
</p>
|
||||||
<p className="connectExplorerContent">
|
<p className="connectExplorerContent">
|
||||||
<input className="filterbtnstyle" type="submit" value="Connect" />
|
<input className="filterbtnstyle" type="submit" value="Connect" />
|
||||||
|
Loading…
Reference in New Issue
Block a user