Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable Basic Auth for testing purposes #4632

Merged
merged 21 commits into from
May 16, 2024
Merged
Prev Previous commit
Next Next commit
wip UI integration of basic auth
andreaTP committed May 8, 2024
commit 9fbb57cd0aff62499a78e3a758b66e4036748183
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -32,4 +32,4 @@ python-sdk/apicurioregistrysdk/client
python-sdk/openapi.json
__pycache__


.env
2 changes: 1 addition & 1 deletion ui/ui-app/src/app/components/auth/IfAuth.tsx
Original file line number Diff line number Diff line change
@@ -33,7 +33,7 @@ export const IfAuth: FunctionComponent<IfAuthProps> = (props: IfAuthProps) => {
const accept = () => {
let rval: boolean = true;
if (props.enabled !== undefined) {
rval = rval && (auth.isAuthEnabled() === props.enabled);
rval = rval && (auth.isOidcAuthEnabled() === props.enabled || auth.isBasicAuthEnabled() === props.enabled);
}
if (props.isAuthenticated !== undefined) {
rval = rval && (isAuthenticated === props.isAuthenticated);
65 changes: 27 additions & 38 deletions ui/ui-app/src/services/useAdminService.ts
Original file line number Diff line number Diff line change
@@ -7,9 +7,9 @@ import { DownloadRef } from "@models/downloadRef.model.ts";
import { ConfigurationProperty } from "@models/configurationProperty.model.ts";
import { UpdateConfigurationProperty } from "@models/updateConfigurationProperty.model.ts";
import {
createAuthOptions,
createEndpoint,
createHeaders,
createOptions, httpDelete,
httpDelete,
httpGet, httpPost,
httpPostWithReturn, httpPut,
httpPutWithReturn
@@ -21,17 +21,15 @@ import { RoleMappingSearchResults } from "@models/roleMappingSearchResults.model
const getArtifactTypes = async (config: ConfigService, auth: AuthService): Promise<ArtifactTypeInfo[]> => {
console.info("[AdminService] Getting the global list of artifactTypes.");
const baseHref: string = config.artifactsUrl();
const token: string | undefined = await auth.getToken();
const options = createOptions(createHeaders(token));
const options = await createAuthOptions(auth);
const endpoint: string = createEndpoint(baseHref, "/admin/config/artifactTypes");
return httpGet<ArtifactTypeInfo[]>(endpoint, options);
};

const getRules = async (config: ConfigService, auth: AuthService): Promise<Rule[]> => {
console.info("[AdminService] Getting the global list of rules.");
const baseHref: string = config.artifactsUrl();
const token: string | undefined = await auth.getToken();
const options = createOptions(createHeaders(token));
const options = await createAuthOptions(auth);
const endpoint: string = createEndpoint(baseHref, "/admin/rules");
return httpGet<string[]>(endpoint, options).then( ruleTypes => {
return Promise.all(ruleTypes.map(rt => getRule(config, auth, rt)));
@@ -40,8 +38,7 @@ const getRules = async (config: ConfigService, auth: AuthService): Promise<Rule[

const getRule = async (config: ConfigService, auth: AuthService, type: string): Promise<Rule> => {
const baseHref: string = config.artifactsUrl();
const token: string | undefined = await auth.getToken();
const options = createOptions(createHeaders(token));
const options = await createAuthOptions(auth);
const endpoint: string = createEndpoint(baseHref, "/admin/rules/:rule", {
rule: type
});
@@ -52,8 +49,7 @@ const createRule = async (config: ConfigService, auth: AuthService, type: string
console.info("[AdminService] Creating global rule:", type);

const baseHref: string = config.artifactsUrl();
const token: string | undefined = await auth.getToken();
const options = createOptions(createHeaders(token));
const options = await createAuthOptions(auth);
const endpoint: string = createEndpoint(baseHref, "/admin/rules");
const body: Rule = {
config: configValue,
@@ -66,8 +62,7 @@ const updateRule = async (config: ConfigService, auth: AuthService, type: string
console.info("[AdminService] Updating global rule:", type);

const baseHref: string = config.artifactsUrl();
const token: string | undefined = await auth.getToken();
const options = createOptions(createHeaders(token));
const options = await createAuthOptions(auth);
const endpoint: string = createEndpoint(baseHref, "/admin/rules/:rule", {
"rule": type
});
@@ -79,8 +74,7 @@ const deleteRule = async (config: ConfigService, auth: AuthService, type: string
console.info("[AdminService] Deleting global rule:", type);

const baseHref: string = config.artifactsUrl();
const token: string | undefined = await auth.getToken();
const options = createOptions(createHeaders(token));
const options = await createAuthOptions(auth);
const endpoint: string = createEndpoint(baseHref, "/admin/rules/:rule", {
"rule": type
});
@@ -97,16 +91,14 @@ const getRoleMappings = async (config: ConfigService, auth: AuthService, paging:
};

const baseHref: string = config.artifactsUrl();
const token: string | undefined = await auth.getToken();
const options = createOptions(createHeaders(token));
const options = await createAuthOptions(auth);
const endpoint: string = createEndpoint(baseHref, "/admin/roleMappings", {}, queryParams);
return httpGet<RoleMappingSearchResults>(endpoint, options);
};

const getRoleMapping = async (config: ConfigService, auth: AuthService, principalId: string): Promise<RoleMapping> => {
const baseHref: string = config.artifactsUrl();
const token: string | undefined = await auth.getToken();
const options = createOptions(createHeaders(token));
const options = await createAuthOptions(auth);
const endpoint: string = createEndpoint(baseHref, "/admin/roleMappings/:principalId", {
principalId
});
@@ -117,8 +109,7 @@ const createRoleMapping = async (config: ConfigService, auth: AuthService, princ
console.info("[AdminService] Creating a role mapping:", principalId, role, principalName);

const baseHref: string = config.artifactsUrl();
const token: string | undefined = await auth.getToken();
const options = createOptions(createHeaders(token));
const options = await createAuthOptions(auth);
const endpoint: string = createEndpoint(baseHref, "/admin/roleMappings");
const body: RoleMapping = { principalId, role, principalName };
return httpPost(endpoint, body, options).then(() => {
@@ -130,8 +121,7 @@ const updateRoleMapping = async (config: ConfigService, auth: AuthService, princ
console.info("[AdminService] Updating role mapping:", principalId, role);

const baseHref: string = config.artifactsUrl();
const token: string | undefined = await auth.getToken();
const options = createOptions(createHeaders(token));
const options = await createAuthOptions(auth);
const endpoint: string = createEndpoint(baseHref, "/admin/roleMappings/:principalId", {
principalId
});
@@ -145,8 +135,7 @@ const deleteRoleMapping = async (config: ConfigService, auth: AuthService, princ
console.info("[AdminService] Deleting role mapping for:", principalId);

const baseHref: string = config.artifactsUrl();
const token: string | undefined = await auth.getToken();
const options = createOptions(createHeaders(token));
const options = await createAuthOptions(auth);
const endpoint: string = createEndpoint(baseHref, "/admin/roleMappings/:principalId", {
principalId
});
@@ -155,10 +144,12 @@ const deleteRoleMapping = async (config: ConfigService, auth: AuthService, princ

const exportAs = async (config: ConfigService, auth: AuthService, filename: string): Promise<DownloadRef> => {
const baseHref: string = config.artifactsUrl();
const token: string | undefined = await auth.getToken();
const headers: any = createHeaders(token);
headers["Accept"] = "application/zip";
const options = createOptions(createHeaders(token));
const options = await createAuthOptions(auth);
options.headers = {
...options.headers,
"Accept": "application/zip"
}

const endpoint: string = createEndpoint(baseHref, "/admin/export", {}, {
forBrowser: true
});
@@ -177,28 +168,27 @@ const exportAs = async (config: ConfigService, auth: AuthService, filename: stri

const importFrom = async (config: ConfigService, auth: AuthService, file: string | File, progressFunction: (progressEvent: any) => void): Promise<void> => {
const baseHref: string = config.artifactsUrl();
const token: string | undefined = await auth.getToken();
const headers: any = createHeaders(token);
headers["Content-Type"] = "application/zip";
const options = createOptions(headers);
const options = await createAuthOptions(auth);
options.headers = {
...options.headers,
"Accept": "application/zip"
}
const endpoint: string = createEndpoint(baseHref, "/admin/import");
return httpPost(endpoint, file, options,undefined, progressFunction);
};

const listConfigurationProperties = async (config: ConfigService, auth: AuthService): Promise<ConfigurationProperty[]> => {
console.info("[AdminService] Getting the dynamic config properties.");
const baseHref: string = config.artifactsUrl();
const token: string | undefined = await auth.getToken();
const options = createOptions(createHeaders(token));
const options = await createAuthOptions(auth);
const endpoint: string = createEndpoint(baseHref, "/admin/config/properties");
return httpGet<ConfigurationProperty[]>(endpoint, options);
};

const setConfigurationProperty = async (config: ConfigService, auth: AuthService, propertyName: string, newValue: string): Promise<void> => {
console.info("[AdminService] Setting a config property: ", propertyName);
const baseHref: string = config.artifactsUrl();
const token: string | undefined = await auth.getToken();
const options = createOptions(createHeaders(token));
const options = await createAuthOptions(auth);
const endpoint: string = createEndpoint(baseHref, "/admin/config/properties/:propertyName", {
propertyName
});
@@ -211,8 +201,7 @@ const setConfigurationProperty = async (config: ConfigService, auth: AuthService
const resetConfigurationProperty = async (config: ConfigService, auth: AuthService, propertyName: string): Promise<void> => {
console.info("[AdminService] Resetting a config property: ", propertyName);
const baseHref: string = config.artifactsUrl();
const token: string | undefined = await auth.getToken();
const options = createOptions(createHeaders(token));
const options = await createAuthOptions(auth);
const endpoint: string = createEndpoint(baseHref, "/admin/config/properties/:propertyName", {
propertyName
});
76 changes: 46 additions & 30 deletions ui/ui-app/src/services/useGroupsService.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { ConfigService, useConfigService } from "@services/useConfigService.ts";
import {
createAuthOptions,
createEndpoint,
createHeaders,
createOptions,
@@ -72,41 +73,62 @@ const createArtifact = async (config: ConfigService, auth: AuthService, data: Cr
const baseHref: string = config.artifactsUrl();
const token: string | undefined = await auth.getToken();
const endpoint: string = createEndpoint(baseHref, "/groups/:groupId/artifacts", { groupId: data.groupId });
const options = await createAuthOptions(auth);

const headers: any = createHeaders(token);
if (data.id) {
headers["X-Registry-ArtifactId"] = data.id;
options.headers = {
...options.headers,
"X-Registry-ArtifactId": data.id
}
}
if (data.type) {
headers["X-Registry-ArtifactType"] = data.type;
options.headers = {
...options.headers,
"X-Registry-ArtifactType": data.type
}
}
if (data.sha) {
headers["X-Registry-Hash-Algorithm"] = "SHA256";
headers["X-Registry-Content-Hash"] = data.sha;
options.headers = {
...options.headers,
"X-Registry-Hash-Algorithm": "SHA256",
"X-Registry-Content-Hash": data.sha
}
}

if (data.fromURL) {
headers["Content-Type"] = "application/create.extended+json";
options.headers = {
...options.headers,
"Content-Type": "application/create.extended+json"
}
data.content = `{ "content": "${data.fromURL}" }`;
} else {
headers["Content-Type"] = contentType(data.type, data.content ? data.content : "");
options.headers = {
...options.headers,
"Content-Type": contentType(data.type, data.content ? data.content : "")
}
}

return httpPostWithReturn<any, ArtifactMetaData>(endpoint, data.content, createOptions(headers));
return httpPostWithReturn<any, ArtifactMetaData>(endpoint, data.content, options);
};

const createArtifactVersion = async (config: ConfigService, auth: AuthService, groupId: string|null, artifactId: string, data: CreateVersionData): Promise<VersionMetaData> => {
groupId = normalizeGroupId(groupId);

const baseHref: string = config.artifactsUrl();
const token: string | undefined = await auth.getToken();
const options = await createAuthOptions(auth);
const endpoint: string = createEndpoint(baseHref, "/groups/:groupId/artifacts/:artifactId/versions", { groupId, artifactId });
const headers: any = createHeaders(token);
if (data.type) {
headers["X-Registry-ArtifactType"] = data.type;
options.headers = {
...options.headers,
"X-Registry-ArtifactType": data.type
}
}
options.headers = {
...options.headers,
"Content-Type": contentType(data.type, data.content)
}
headers["Content-Type"] = contentType(data.type, data.content);
return httpPostWithReturn<any, VersionMetaData>(endpoint, data.content, createOptions(headers));
return httpPostWithReturn<any, VersionMetaData>(endpoint, data.content, options);
};

const getArtifacts = async (config: ConfigService, auth: AuthService, criteria: GetArtifactsCriteria, paging: Paging): Promise<ArtifactsSearchResults> => {
@@ -129,9 +151,8 @@ const getArtifacts = async (config: ConfigService, auth: AuthService, criteria:
}
}
const baseHref: string = config.artifactsUrl();
const token: string | undefined = await auth.getToken();
const endpoint: string = createEndpoint(baseHref, "/search/artifacts", {}, queryParams);
const options = createOptions(createHeaders(token));
const options = await createAuthOptions(auth);
return httpGet<ArtifactsSearchResults>(endpoint, options, (data) => {
const results: ArtifactsSearchResults = {
artifacts: data.artifacts,
@@ -147,21 +168,19 @@ const getArtifactMetaData = async (config: ConfigService, auth: AuthService, gro
groupId = normalizeGroupId(groupId);

const baseHref: string = config.artifactsUrl();
const token: string | undefined = await auth.getToken();
const endpoint: string = createEndpoint(baseHref, "/groups/:groupId/artifacts/:artifactId", { groupId, artifactId });
const options = createOptions(createHeaders(token));
const options = await createAuthOptions(auth);
return httpGet<ArtifactMetaData>(endpoint, options);
};

const getArtifactVersionMetaData = async (config: ConfigService, auth: AuthService, groupId: string|null, artifactId: string, version: string): Promise<VersionMetaData> => {
groupId = normalizeGroupId(groupId);

const baseHref: string = config.artifactsUrl();
const token: string | undefined = await auth.getToken();
const versionExpression: string = (version == "latest") ? "branch=latest" : version;
const endpoint: string = createEndpoint(baseHref, "/groups/:groupId/artifacts/:artifactId/versions/:versionExpression",
{ groupId, artifactId, versionExpression });
const options = createOptions(createHeaders(token));
const options = await createAuthOptions(auth);
return httpGet<VersionMetaData>(endpoint, options);
};

@@ -170,9 +189,8 @@ const getArtifactReferences = async (config: ConfigService, auth: AuthService, g
refType: refType || "OUTBOUND"
};
const baseHref: string = config.artifactsUrl();
const token: string | undefined = await auth.getToken();
const endpoint: string = createEndpoint(baseHref, "/ids/globalIds/:globalId/references", { globalId }, queryParams);
const options = createOptions(createHeaders(token));
const options = await createAuthOptions(auth);
return httpGet<ArtifactReference[]>(endpoint, options);
};

@@ -184,21 +202,19 @@ const updateArtifactMetaData = async (config: ConfigService, auth: AuthService,
groupId = normalizeGroupId(groupId);

const baseHref: string = config.artifactsUrl();
const token: string | undefined = await auth.getToken();
const endpoint: string = createEndpoint(baseHref, "/groups/:groupId/artifacts/:artifactId", { groupId, artifactId });
const options = createOptions(createHeaders(token));
const options = await createAuthOptions(auth);
return httpPut<EditableMetaData>(endpoint, metaData, options);
};

const updateArtifactVersionMetaData = async (config: ConfigService, auth: AuthService, groupId: string|null, artifactId: string, version: string, metaData: EditableMetaData): Promise<void> => {
groupId = normalizeGroupId(groupId);

const baseHref: string = config.artifactsUrl();
const token: string | undefined = await auth.getToken();
const versionExpression: string = (version == "latest") ? "branch=latest" : version;
const endpoint: string = createEndpoint(baseHref, "/groups/:groupId/artifacts/:artifactId/versions/:versionExpression",
{ groupId, artifactId, versionExpression });
const options = createOptions(createHeaders(token));
const options = await createAuthOptions(auth);
return httpPut<EditableMetaData>(endpoint, metaData, options);
};

@@ -212,14 +228,15 @@ const getArtifactVersionContent = async (config: ConfigService, auth: AuthServic
groupId = normalizeGroupId(groupId);

const baseHref: string = config.artifactsUrl();
const token: string | undefined = await auth.getToken();
const versionExpression: string = (version == "latest") ? "branch=latest" : version;
const endpoint: string = createEndpoint(baseHref, "/groups/:groupId/artifacts/:artifactId/versions/:versionExpression/content",
{ groupId, artifactId, versionExpression });

const headers: any = createHeaders(token);
headers["Accept"] = "*";
const options = createOptions(headers);
const options = await createAuthOptions(auth);
options.headers = {
...options.headers,
"Accept": "*"
}
options.maxContentLength = 5242880; // TODO 5MB hard-coded, make this configurable?
options.responseType = "text";
options.transformResponse = (data: any) => data;
@@ -231,12 +248,11 @@ const getArtifactVersions = async (config: ConfigService, auth: AuthService, gro

console.info("[GroupsService] Getting the list of versions for artifact: ", groupId, artifactId);
const baseHref: string = config.artifactsUrl();
const token: string | undefined = await auth.getToken();
const endpoint: string = createEndpoint(baseHref, "/groups/:groupId/artifacts/:artifactId/versions", { groupId, artifactId }, {
limit: 500,
offset: 0
});
const options = createOptions(createHeaders(token));
const options = await createAuthOptions(auth);
return httpGet<SearchedVersion[]>(endpoint, options, (data) => {
return data.versions;
});
Loading