Skip to content

Commit

Permalink
without tests
Browse files Browse the repository at this point in the history
  • Loading branch information
cgeorgilakis-grnet committed Oct 8, 2024
1 parent 00077e6 commit c597716
Show file tree
Hide file tree
Showing 24 changed files with 407 additions and 144 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1043,7 +1043,7 @@ importKeys=Import keys
useMetadataDescriptorUrl=Use metadata descriptor URL
useMetadataDescriptorUrlHelp=If the switch is on, the certificates to validate signatures will be downloaded and cached from the given "Metadata descriptor URL". The "Reload keys" action can be used to refresh the certificates in the cache. If the switch is off, certificates from "Validating X509 certificates" option are used, they need to be manually updated when changed in the IDP.
metadataDescriptorUrl=Metadata descriptor URL
metadataDescriptorUrlHelp=External URL where Identity Provider publishes the metadata information needed by the client (certificates, keys, other URLs,...).
metadataDescriptorUrlHelp=External URL where Identity Provider publishes the metadata information needed by the client (certificates, keys, other URLs,...). This url is used for auto-updated IdPs and when use metadata descriptor URL is true.
reloadKeysSuccess=Keys successfully reloaded
reloadKeysError=Error reloading keys. {{error}}
reloadKeysSuccessButFalse=The reload was not executed, maybe the time between request was too short.
Expand Down Expand Up @@ -3254,4 +3254,5 @@ eventTypes.REMOVE_CREDENTIAL_ERROR.description=Remove credential error
autoUpdatedIdPsInterval= Autoupdated Identity Providers execution interval
autoUpdatedIdPsIntervalHelp= Every how much time autoupdated Identity Providers will be updated based on metadata url
autoUpdatedIdPsLastRefreshTime= Last execution time of autoupdated Identity Providers task
autoUpdate= Auto Update",
autoUpdate= Auto Update
autoUpdateHelp= When auto update is true, IdP metadata will be updated based on metadata descriptor URL
37 changes: 24 additions & 13 deletions js/apps/admin-ui/src/identity-providers/add/DescriptorSettings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ const Fields = ({ readOnly }: DescriptorSettingsProps) => {
name: "config.validateSignature",
});

const autoUpdated = useWatch({
control,
name: "config.autoUpdate",
});

const useMetadataDescriptorUrl = useWatch({
control,
name: "config.useMetadataDescriptorUrl",
Expand All @@ -51,6 +56,25 @@ const Fields = ({ readOnly }: DescriptorSettingsProps) => {
return (
<div className="pf-v5-c-form pf-m-horizontal">
<FormProvider {...form}>
<DefaultSwitchControl
name="config.autoUpdate"
label={t("autoUpdate")}
isDisabled={readOnly}
stringify
/>
<TextControl
name="config.metadataDescriptorUrl"
label={t("metadataDescriptorUrl")}
labelIcon={t("metadataDescriptorUrlHelp")}
type="url"
readOnly={readOnly}
rules={{
required: {
value: useMetadataDescriptorUrl === "true" || autoUpdated === "true",

Check failure on line 73 in js/apps/admin-ui/src/identity-providers/add/DescriptorSettings.tsx

View workflow job for this annotation

GitHub Actions / Admin UI

Insert `⏎···············`
message: t("required"),
}

Check failure on line 75 in js/apps/admin-ui/src/identity-providers/add/DescriptorSettings.tsx

View workflow job for this annotation

GitHub Actions / Admin UI

Insert `,`
}}
/>
<TextControl
name="config.entityId"
label={t("serviceProviderEntityId")}
Expand Down Expand Up @@ -279,19 +303,6 @@ const Fields = ({ readOnly }: DescriptorSettingsProps) => {
/>
{validateSignature === "true" && (
<>
<TextControl
name="config.metadataDescriptorUrl"
label={t("metadataDescriptorUrl")}
labelIcon={t("metadataDescriptorUrlHelp")}
type="url"
readOnly={readOnly}
rules={{
required: {
value: useMetadataDescriptorUrl === "true",
message: t("required"),
},
}}
/>
<DefaultSwitchControl
name="config.useMetadataDescriptorUrl"
label={t("useMetadataDescriptorUrl")}
Expand Down
23 changes: 23 additions & 0 deletions js/apps/admin-ui/src/identity-providers/add/DiscoverySettings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,32 @@ const Fields = ({ readOnly }: DiscoverySettingsProps) => {
control,
name: "config.pkceEnabled",
});
const autoUpdated = useWatch({
control,
name: "config.autoUpdate",
});

return (
<div className="pf-v5-c-form pf-m-horizontal">
<DefaultSwitchControl

Check failure on line 44 in js/apps/admin-ui/src/identity-providers/add/DiscoverySettings.tsx

View workflow job for this annotation

GitHub Actions / Admin UI

Insert `·`
name="config.autoUpdate"

Check failure on line 45 in js/apps/admin-ui/src/identity-providers/add/DiscoverySettings.tsx

View workflow job for this annotation

GitHub Actions / Admin UI

Insert `·`
label={t("autoUpdate")}

Check failure on line 46 in js/apps/admin-ui/src/identity-providers/add/DiscoverySettings.tsx

View workflow job for this annotation

GitHub Actions / Admin UI

Insert `·`
isDisabled={readOnly}

Check failure on line 47 in js/apps/admin-ui/src/identity-providers/add/DiscoverySettings.tsx

View workflow job for this annotation

GitHub Actions / Admin UI

Insert `·`
stringify

Check failure on line 48 in js/apps/admin-ui/src/identity-providers/add/DiscoverySettings.tsx

View workflow job for this annotation

GitHub Actions / Admin UI

Insert `·`
/>

Check failure on line 49 in js/apps/admin-ui/src/identity-providers/add/DiscoverySettings.tsx

View workflow job for this annotation

GitHub Actions / Admin UI

Insert `·`
<TextControl

Check failure on line 50 in js/apps/admin-ui/src/identity-providers/add/DiscoverySettings.tsx

View workflow job for this annotation

GitHub Actions / Admin UI

Insert `·`
name="config.metadataDescriptorUrl"

Check failure on line 51 in js/apps/admin-ui/src/identity-providers/add/DiscoverySettings.tsx

View workflow job for this annotation

GitHub Actions / Admin UI

Insert `·`
label={t("metadataOfDiscoveryEndpoint")}
labelIcon={t("discoveryEndpointHelp")}
type="url"
readOnly={readOnly}
rules={{
required: {
value: autoUpdated === "true",
message: t("required"),
}
}}
/>
<TextControl
name="config.authorizationUrl"
label={t("authorizationUrl")}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import { FormGroup, Spinner, Switch } from "@patternfly/react-core";
import debouncePromise from "p-debounce";
import { ReactNode, useMemo, useState } from "react";
import { useFormContext } from "react-hook-form";
import { useFormContext, useWatch} from "react-hook-form";
import { useTranslation } from "react-i18next";
import { HelpItem, TextControl } from "@keycloak/keycloak-ui-shared";
import { useAdminClient } from "../../admin-client";
import { DefaultSwitchControl } from "../../components/SwitchControl";
import IdentityProviderRepresentation from "@keycloak/keycloak-admin-client/lib/defs/identityProviderRepresentation";

type DiscoveryEndpointFieldProps = {
id: string;
Expand Down Expand Up @@ -34,7 +36,14 @@ export const DiscoveryEndpointField = ({
Object.keys(result).map((k) => setValue(`config.${k}`, result[k]));
};

const discover = async (fromUrl: string) => {
const { control } = useFormContext<IdentityProviderRepresentation>();

const autoUpdated = useWatch({
control,
name: "config.autoUpdate",
});

const discover = async (fromUrl: string) => {
setDiscovering(true);
try {
const result = await adminClient.identityProviders.importFromUrl({
Expand All @@ -43,13 +52,21 @@ export const DiscoveryEndpointField = ({
});
setupForm(result);
setDiscoveryResult(result);
setValue("config.metadataUrl", fromUrl);
} catch (error) {
return (error as Error).message;
} finally {
setDiscovering(false);
}
};

// useEffect(() => {
// if (id === "saml" || id === "oidc") {
// setValue("config.metadataUrl", fromUrl);
// }
// }, [fromUrl]);


const discoverDebounced = useMemo(() => debouncePromise(discover, 1000), []);

return (
Expand Down Expand Up @@ -116,6 +133,11 @@ export const DiscoveryEndpointField = ({
/>
)}
{!discovery && fileUpload}
<DefaultSwitchControl
name="config.autoUpdate"
label={t("autoUpdate")}
stringify
/>
{discovery && !errors.discoveryError && children(true)}
{!discovery && children(false)}
</>
Expand Down
23 changes: 9 additions & 14 deletions js/apps/admin-ui/src/realm-settings/GeneralTab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import {
StackItem,
} from "@patternfly/react-core";
import { useEffect, useState } from "react";
import { Controller, FormProvider, useForm } from "react-hook-form";
import { Controller, FormProvider, useForm, useFormContext } from "react-hook-form";
import { useTranslation } from "react-i18next";
import { useAdminClient } from "../admin-client";
import { DefaultSwitchControl } from "../components/SwitchControl";
Expand All @@ -36,6 +36,7 @@ import {
} from "../util";
import useIsFeatureEnabled, { Feature } from "../utils/useIsFeatureEnabled";
import { UIRealmRepresentation } from "./RealmSettingsTabs";
import { TimeSelector } from "../components/time-selector/TimeSelector";

type RealmSettingsGeneralTabProps = {
realm: UIRealmRepresentation;
Expand All @@ -52,14 +53,6 @@ export const RealmSettingsGeneralTab = ({
const [userProfileConfig, setUserProfileConfig] =
useState<UserProfileConfig>();

const autoUpdatedIdPsInterval = useWatch({
control,
name: "autoUpdatedIdPsInterval",
defaultValue: realm.autoUpdatedIdPsInterval,
});

const autoUpdatedIdPsLastRefreshTime = watch("autoUpdatedIdPsLastRefreshTime") as unknown as string;

useFetch(
() => adminClient.users.getProfile({ realm: realmName }),
(config) => setUserProfileConfig(config),
Expand Down Expand Up @@ -116,9 +109,14 @@ function RealmSettingsGeneralTabForm({
setValue,
formState: { errors },
} = form;
const { watch } = useFormContext();
const isFeatureEnabled = useIsFeatureEnabled();
const isOrganizationsEnabled = isFeatureEnabled(Feature.Organizations);

const autoUpdatedIdPsInterval = watch("autoUpdatedIdPsInterval") as unknown as string;

const autoUpdatedIdPsLastRefreshTime = watch("autoUpdatedIdPsLastRefreshTime") as unknown as string;

const setupForm = () => {
convertToFormValues(realm, setValue);
setValue(
Expand Down Expand Up @@ -258,13 +256,10 @@ function RealmSettingsGeneralTabForm({
>
<Controller
name="autoUpdatedIdPsInterval"
control={form.control}
control={control}
render={({ field }) => (
<TimeSelector
id="autoUpdatedIdPsInterval"
className="auto-updated-idps-interval"
data-testid="auto-updated-idps-interval"
aria-label="auto-updated-idps-interval"
units={["minute", "hour", "day"]}
value={field.value}
onChange={field.onChange}
/>
Expand Down
4 changes: 2 additions & 2 deletions js/libs/keycloak-admin-client/src/defs/realmRepresentation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ export default interface RealmRepresentation {
adminEventsEnabled?: boolean;
adminTheme?: string;
attributes?: Record<string, any>;
autoUpdatedIdPsInterval?: number;
autoUpdatedIdPsLastRefreshTime?: number;
// AuthenticationFlowRepresentation
authenticationFlows?: any[];
// AuthenticatorConfigRepresentation
Expand Down Expand Up @@ -82,8 +84,6 @@ export default interface RealmRepresentation {
offlineSessionMaxLifespan?: number;
offlineSessionMaxLifespanEnabled?: boolean;
organizationsEnabled?: boolean;
autoUpdatedIdPsInterval?: number;
autoUpdatedIdPsLastRefreshTime?: number;
otpPolicyAlgorithm?: string;
otpPolicyDigits?: number;
otpPolicyInitialCounter?: number;
Expand Down
Loading

0 comments on commit c597716

Please sign in to comment.