Skip to content

Commit

Permalink
[squash] added changed needed for community stability deployment support
Browse files Browse the repository at this point in the history
  • Loading branch information
Prarthona Paul committed Mar 15, 2024
1 parent b281759 commit 91442a1
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -233,5 +233,8 @@ interface ElytronMessages extends BasicLogger {
@Message(id = 23056, value = "No message entity")
IOException noMessageEntity();

@Message(id = 23057, value = "Attribute '%s' is not supported")
IOException unsupportedAttribute(String error);

}

Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ public class Oidc {
public static final String DISCOVERY_PATH = ".well-known/openid-configuration";
public static final String KEYCLOAK_REALMS_PATH = "realms/";
public static final String JSON_CONFIG_CONTEXT_PARAM = "org.wildfly.security.http.oidc.json.config";
public static final String JSON_CONFIG_UNSUPPORTED_ATTRIBUTE_PARAM = "unsupported-attribute";
static final String ACCOUNT_PATH = "account";
public static final String CLIENTS_MANAGEMENT_REGISTER_NODE_PATH = "clients-managements/register-node";
public static final String CLIENTS_MANAGEMENT_UNREGISTER_NODE_PATH = "clients-managements/unregister-node";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@
package org.wildfly.security.http.oidc;

import static org.wildfly.security.http.oidc.ElytronMessages.log;
import static org.wildfly.security.http.oidc.Oidc.SSLRequired;
import static org.wildfly.security.http.oidc.Oidc.TokenStore;
import static org.wildfly.security.http.oidc.Oidc.*;

import java.io.IOException;
import java.io.InputStream;
Expand Down Expand Up @@ -176,6 +175,16 @@ public HttpClient call() {
};
}

public static OidcClientConfiguration buildWithoutUnsupportedAttributes(String unsupportedAttributesParam, InputStream is) {
OidcJsonConfiguration oidcJsonConfiguration = loadOidcJsonConfiguration(is);
try {
failIfUnsupportedAttribute(unsupportedAttributesParam, oidcJsonConfiguration);
return new OidcClientConfigurationBuilder().internalBuild(oidcJsonConfiguration);
} catch (IOException e) {
throw new RuntimeException(e);
}
}

public static OidcClientConfiguration build(InputStream is) {
OidcJsonConfiguration oidcJsonConfiguration = loadOidcJsonConfiguration(is);
return new OidcClientConfigurationBuilder().internalBuild(oidcJsonConfiguration);
Expand All @@ -197,4 +206,20 @@ public static OidcJsonConfiguration loadOidcJsonConfiguration(InputStream is) {
public static OidcClientConfiguration build(OidcJsonConfiguration oidcJsonConfiguration) {
return new OidcClientConfigurationBuilder().internalBuild(oidcJsonConfiguration);
}

private static void failIfUnsupportedAttribute(String unsupportedAttributesParameter, OidcJsonConfiguration config) throws IOException {
if (unsupportedAttributesParameter == null) {
return;
}
String[] unsupportedAttributes = unsupportedAttributesParameter.split(" ");
for (String attributeName : unsupportedAttributes) {
switch(attributeName) {
case SCOPE:
if (config.getScope()!= null) {
throw log.unsupportedAttribute(attributeName);
}
break;
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,7 @@
package org.wildfly.security.http.oidc;

import static org.wildfly.security.http.oidc.ElytronMessages.log;
import static org.wildfly.security.http.oidc.Oidc.JSON_CONFIG_CONTEXT_PARAM;
import static org.wildfly.security.http.oidc.Oidc.OIDC_CLIENT_CONFIG_RESOLVER;
import static org.wildfly.security.http.oidc.Oidc.OIDC_CLIENT_CONTEXT_KEY;
import static org.wildfly.security.http.oidc.Oidc.OIDC_CONFIG_FILE_LOCATION;
import static org.wildfly.security.http.oidc.Oidc.OIDC_JSON_FILE;
import static org.wildfly.security.http.oidc.Oidc.*;

import jakarta.servlet.ServletContext;
import jakarta.servlet.ServletContextEvent;
Expand Down Expand Up @@ -66,7 +62,7 @@ public void contextInitialized(ServletContextEvent sce) {
if (is == null) {
oidcClientConfiguration = new OidcClientConfiguration();
} else {
oidcClientConfiguration = OidcClientConfigurationBuilder.build(is);
oidcClientConfiguration = OidcClientConfigurationBuilder.buildWithoutUnsupportedAttributes(servletContext.getInitParameter(JSON_CONFIG_UNSUPPORTED_ATTRIBUTE_PARAM), is);
}
clientContext = new OidcClientContext(oidcClientConfiguration);
}
Expand Down

0 comments on commit 91442a1

Please sign in to comment.