Java Code Examples for org.keycloak.representations.idm.RealmRepresentation#setSupportedLocales()

The following examples show how to use org.keycloak.representations.idm.RealmRepresentation#setSupportedLocales() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: UncaughtErrorPageTest.java    From keycloak with Apache License 2.0 6 votes vote down vote up
@Test
public void internationalisationEnabled() throws MalformedURLException {
    RealmResource testRealm = realmsResouce().realm("master");
    RealmRepresentation rep = testRealm.toRepresentation();
    rep.setInternationalizationEnabled(true);
    rep.setDefaultLocale("en");
    rep.setSupportedLocales(Collections.singleton("en"));
    testRealm.update(rep);

    try {
        checkPageNotFound("/auth/realms/master/nosuch");
        checkPageNotFound("/auth/nosuch");
    } finally {
        rep.setInternationalizationEnabled(false);
        testRealm.update(rep);
    }
}
 
Example 2
Source File: AbstractUiTest.java    From keycloak with Apache License 2.0 6 votes vote down vote up
protected void configureInternationalizationForRealm(RealmRepresentation realm) {
    final String localizedTheme = isAccountPreviewTheme() ? LOCALIZED_THEME_PREVIEW : LOCALIZED_THEME;

    // fetch the supported locales for the special test theme that includes some fake test locales
    Set<String> supportedLocales = adminClient.serverInfo().getInfo().getThemes().get("login").stream()
            .filter(x -> x.getName().equals(LOCALIZED_THEME))
            .flatMap(x -> Arrays.stream(x.getLocales()))
            .collect(Collectors.toSet());

    realm.setInternationalizationEnabled(true);
    realm.setSupportedLocales(supportedLocales);
    realm.setLoginTheme(LOCALIZED_THEME);
    realm.setAdminTheme(LOCALIZED_THEME);
    realm.setAccountTheme(localizedTheme);
    realm.setEmailTheme(LOCALIZED_THEME);
}
 
Example 3
Source File: DemoServletsAdapterTest.java    From keycloak with Apache License 2.0 4 votes vote down vote up
@Test
public void testOIDCUiLocalesParamForwarding() {
    ProfileAssume.assumeCommunity();

    RealmRepresentation demoRealmRep = testRealmResource().toRepresentation();
    boolean enabled = demoRealmRep.isInternationalizationEnabled();
    String defaultLocale = demoRealmRep.getDefaultLocale();
    Set<String> locales = demoRealmRep.getSupportedLocales();
    demoRealmRep.setInternationalizationEnabled(true);
    demoRealmRep.setDefaultLocale("en");
    demoRealmRep.setSupportedLocales(Stream.of("en", "de").collect(Collectors.toSet()));
    testRealmResource().update(demoRealmRep);

    try {
        // test login with ui_locales to de+en
        String portalUri = securePortal.getUriBuilder().build().toString();
        UriBuilder uriBuilder = securePortal.getUriBuilder();
        String appUri = uriBuilder.clone().queryParam(OAuth2Constants.UI_LOCALES_PARAM, "de en").build().toString();
        URLUtils.navigateToUri(appUri);
        assertCurrentUrlStartsWithLoginUrlOf(testRealmPage);
        // check the ui_locales param is there
        Map<String, String> parameters = getQueryFromUrl(driver.getCurrentUrl());
        assertThat(parameters.get(OAuth2Constants.UI_LOCALES_PARAM), allOf(containsString("de"), containsString("en")));

        String appUriDe = uriBuilder.clone().queryParam(OAuth2Constants.UI_LOCALES_PARAM, "de").build().toString();
        URLUtils.navigateToUri(appUriDe);
        assertCurrentUrlStartsWithLoginUrlOf(testRealmPage);

        // check that the page is in german
        assertPageContains("Passwort");
        testRealmLoginPage.form().login("[email protected]", "password");
        // check no ui_locales in the final url adapter url
        assertCurrentUrlEquals(portalUri);
        assertLogged();
        // logout
        String logoutUri = OIDCLoginProtocolService.logoutUrl(authServerPage.createUriBuilder())
                .queryParam(OAuth2Constants.REDIRECT_URI, securePortal.toString()).build("demo").toString();
        driver.navigate().to(logoutUri);
        assertCurrentUrlStartsWithLoginUrlOf(testRealmPage);
        securePortal.navigateTo();
        assertCurrentUrlStartsWithLoginUrlOf(testRealmPage);
    } finally {
        demoRealmRep.setInternationalizationEnabled(enabled);
        demoRealmRep.setDefaultLocale(defaultLocale);
        demoRealmRep.setSupportedLocales(locales);
        testRealmResource().update(demoRealmRep);
    }
}