Skip to content

Commit

Permalink
KEYCLOAK-14540 Determine project/product name
Browse files Browse the repository at this point in the history
  • Loading branch information
mabartos authored and pdrozd committed Jun 7, 2021
1 parent 6b365d7 commit 4b009eb
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 13 deletions.
28 changes: 21 additions & 7 deletions common/src/main/java/org/keycloak/common/Profile.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@

package org.keycloak.common;

import static org.keycloak.common.Profile.Type.DEPRECATED;

import org.jboss.logging.Logger;

import java.io.File;
Expand All @@ -28,6 +26,8 @@
import java.util.Properties;
import java.util.Set;

import static org.keycloak.common.Profile.Type.DEPRECATED;

/**
* @author <a href="mailto:[email protected]">Bill Burke</a>
* @version $Revision: 1 $
Expand All @@ -36,13 +36,17 @@ public class Profile {

private static final Logger logger = Logger.getLogger(Profile.class);

public static final String PRODUCT_NAME = ProductValue.RHSSO.getName();
public static final String PROJECT_NAME = ProductValue.KEYCLOAK.getName();

public enum Type {
DEFAULT,
DISABLED_BY_DEFAULT,
PREVIEW,
EXPERIMENTAL,
DEPRECATED;
}

public enum Feature {
AUTHORIZATION(Type.DEFAULT),
ACCOUNT2(Type.DEFAULT),
Expand All @@ -59,8 +63,8 @@ public enum Feature {
CIBA(Type.PREVIEW),
MAP_STORAGE(Type.EXPERIMENTAL);

private Type typeProject;
private Type typeProduct;
private final Type typeProject;
private final Type typeProduct;

Feature(Type type) {
this(type, type);
Expand All @@ -85,8 +89,18 @@ public boolean hasDifferentProductType() {
}

private enum ProductValue {
KEYCLOAK,
RHSSO
KEYCLOAK("Keycloak"),
RHSSO("RH-SSO");

private final String name;

ProductValue(String name) {
this.name = name;
}

public String getName() {
return name;
}
}

private enum ProfileValue {
Expand All @@ -112,7 +126,7 @@ public Profile(PropertyResolver resolver) {
this.propertyResolver = resolver;
Config config = new Config();

product = "rh-sso".equals(Version.NAME) ? ProductValue.RHSSO : ProductValue.KEYCLOAK;
product = PRODUCT_NAME.toLowerCase().equals(Version.NAME) ? ProductValue.RHSSO : ProductValue.KEYCLOAK;
profile = ProfileValue.valueOf(config.getProfile().toUpperCase());

for (Feature f : Feature.values()) {
Expand Down
2 changes: 1 addition & 1 deletion common/src/test/java/org/keycloak/common/ProfileTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public void checkDefaultsKeycloak() {
public void checkDefaultsRH_SSO() {
System.setProperty("keycloak.profile", "product");
String backUpName = Version.NAME;
Version.NAME = "rh-sso";
Version.NAME = Profile.PRODUCT_NAME.toLowerCase();
Profile.init();

Assert.assertEquals("product", Profile.getName());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -688,4 +688,14 @@ protected static InputStream httpsAwareConfigurationStream(InputStream input) th
}
return in;
}

/**
* Get product/project name
*
* @return f.e. 'RH-SSO' or 'Keycloak'
*/
protected String getProjectName() {
final boolean isProduct = adminClient.serverInfo().getInfo().getProfileInfo().getName().equals("product");
return isProduct ? Profile.PRODUCT_NAME : Profile.PROJECT_NAME;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -330,12 +330,10 @@ protected void assertLoggedInAccountManagement(String username, String email) {
}

protected void waitForAccountManagementTitle() {
boolean isProduct = adminClient.serverInfo().getInfo().getProfileInfo().getName().equals("product");
String title = isProduct ? "rh-sso account management" : "keycloak account management";
final String title = getProjectName().toLowerCase() + " account management";
waitForPage(driver, title, true);
}


protected void assertErrorPage(String expectedError) {
errorPage.assertCurrent();
Assert.assertEquals(expectedError, errorPage.getError());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1117,19 +1117,20 @@ public void resetPasswordLinkNewTabAndProperRedirectAccount() throws IOException
final String REQUIRED_URI = OAuthClient.AUTH_SERVER_ROOT + "/realms/test/account/applications";
final String REDIRECT_URI = getAccountRedirectUrl() + "?path=applications";
final String CLIENT_ID = "account";
final String ACCOUNT_MANAGEMENT_TITLE = getProjectName() + " Account Management";

try (BrowserTabUtil tabUtil = BrowserTabUtil.getInstanceAndSetEnv(driver)) {
assertThat(tabUtil.getCountOfTabs(), Matchers.is(1));

driver.navigate().to(REQUIRED_URI);
resetPasswordTwiceInNewTab(defaultUser, CLIENT_ID, false, REDIRECT_URI, REQUIRED_URI);
assertThat(driver.getTitle(), Matchers.equalTo("Keycloak Account Management"));
assertThat(driver.getTitle(), Matchers.equalTo(ACCOUNT_MANAGEMENT_TITLE));

oauth.openLogout();

driver.navigate().to(REQUIRED_URI);
resetPasswordTwiceInNewTab(defaultUser, CLIENT_ID, true, REDIRECT_URI, REQUIRED_URI);
assertThat(driver.getTitle(), Matchers.equalTo("Keycloak Account Management"));
assertThat(driver.getTitle(), Matchers.equalTo(ACCOUNT_MANAGEMENT_TITLE));
}
}

Expand Down

0 comments on commit 4b009eb

Please sign in to comment.