Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
deaac63
feat: SSO rework — add Test Login, emailClaim, discoveryUri, and prot…
aji-aju Apr 14, 2026
4a8079c
fix: exclude test-login/initiate from JwtFilter and hide authorizer f…
aji-aju Apr 14, 2026
defa649
fix: hide emailClaim, discoveryUri, adminPrincipals fields and add pr…
aji-aju Apr 14, 2026
d31e3ba
fix: rewrite Test Login endpoints to return Response instead of void
aji-aju Apr 14, 2026
08a1bd2
fix: hide OIDC prompt field in all provider UI schemas
aji-aju Apr 14, 2026
c03452b
fix: move Test Login endpoints from SystemResource to ConfigResource
aji-aju Apr 14, 2026
89dce53
fix: make TestLoginHandler self-contained — build OIDC client from fo…
aji-aju Apr 14, 2026
a0403de
fix: use OIDCProviderMetadata.parse() instead of resolve() for discov…
aji-aju Apr 14, 2026
9f5df34
fix: use registered callback URL for Test Login to avoid redirect_uri…
aji-aju Apr 14, 2026
482eb07
fix: stale formData on first Test Login click + disable Save until em…
aji-aju Apr 14, 2026
a23611f
feat: add OIDC provider dropdown (Google, Azure, Okta, Auth0, Cognito…
aji-aju Apr 14, 2026
30834fe
fix: validate Discovery URI placeholders and auto-sync before validation
aji-aju Apr 14, 2026
3a7df3e
feat: prompt in advanced, discovery URI defaults, validation before T…
aji-aju Apr 14, 2026
bf19099
fix: pass skipTestLoginFields to validateAuthorizerConfiguration
aji-aju Apr 14, 2026
2c04fbc
feat: add offline_access to default scope, hide scope/prompt/okta aut…
aji-aju Apr 14, 2026
45dc809
fix: remove @Valid from validate endpoint to prevent LDAP/SAML field …
aji-aju Apr 14, 2026
bcf8222
fix: update all hardcoded scope defaults to include offline_access
aji-aju Apr 14, 2026
c4e7f3b
fix: use localStorage for popup communication, restore scope/prompt/a…
aji-aju Apr 14, 2026
74b9247
fix: show top-level discoveryUri, hide nested oidcConfiguration.disco…
aji-aju Apr 14, 2026
e327e3d
fix: write discoveryUri to top-level field, prioritize top-level in T…
aji-aju Apr 14, 2026
0530555
feat: pass all OIDC params through Test Login + revert offline_access…
aji-aju Apr 14, 2026
deb49ff
feat: SSO confidential — Validate → Test Login → Save gate + backend …
aji-aju Apr 15, 2026
46044b9
fix: match admin principals by email in addition to username
aji-aju Apr 15, 2026
31874fb
feat: SAML Test Login + OIDC validator refinement
aji-aju Apr 15, 2026
bd308eb
fix: audit fixes — PKCE, nonce, SAML session, normalize hardening
aji-aju Apr 16, 2026
11f157c
fix: OIDC Test Login — POST form body + 302 redirect
aji-aju Apr 16, 2026
99e1f98
feat: LDAP Test Login + unit test coverage for all three protocols
aji-aju Apr 21, 2026
6a9b047
Merge remote-tracking branch 'origin/main' into feat/sso-rework-test-…
aji-aju Apr 24, 2026
c5279a8
chore: apply mvn spotless:apply to unblock Java checkstyle
aji-aju Apr 24, 2026
b4357ff
Merge branch 'main' into feat/sso-rework-test-login
siddhant1 May 11, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,17 @@
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.ws.rs.Consumes;
import jakarta.ws.rs.FormParam;
import jakarta.ws.rs.GET;
import jakarta.ws.rs.POST;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.Produces;
import jakarta.ws.rs.core.Context;
import jakarta.ws.rs.core.MediaType;
import jakarta.ws.rs.core.Response;
import java.util.HashMap;
import java.util.Map;
import org.openmetadata.api.configuration.UiThemePreference;
Expand All @@ -38,6 +45,9 @@
import org.openmetadata.service.resources.Collection;
import org.openmetadata.service.resources.settings.SettingsCache;
import org.openmetadata.service.security.auth.SecurityConfigurationManager;
import org.openmetadata.service.security.auth.TestLdapHandler;
import org.openmetadata.service.security.auth.TestLoginHandler;
import org.openmetadata.service.security.auth.TestSamlHandler;
import org.openmetadata.service.security.jwt.JWKSResponse;
import org.openmetadata.service.security.jwt.JWTTokenGenerator;

Expand Down Expand Up @@ -219,4 +229,144 @@ public PipelineServiceAPIClientConfig getPipelineServiceConfig() {
public JWKSResponse getJWKSResponse() {
return jwtTokenGenerator.getJWKSResponse();
}

@POST
@Path("/auth/test-login/initiate")
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
@Operation(
operationId = "testLoginInitiate",
summary = "Initiate OIDC Test Login",
description =
"Initiates an OIDC Test Login flow by redirecting to the IdP. "
+ "Accepts form-encoded body so secrets stay out of the URL. "
+ "Opens in a popup window via hidden form POST with target=_blank.")
public Response testLoginInitiate(
@Context HttpServletRequest request,
@FormParam("discoveryUri") String discoveryUri,
@FormParam("clientId") String clientId,
@FormParam("clientSecret") String clientSecret,
@FormParam("scope") String scope,
@FormParam("callbackUrl") String callbackUrl,
@FormParam("prompt") String prompt,
@FormParam("maxAge") String maxAge,
@FormParam("clientAuthenticationMethod") String clientAuthMethod,
@FormParam("disablePkce") String disablePkce,
@FormParam("useNonce") String useNonce,
@FormParam("customParams") String customParams) {
return TestLoginHandler.handleInitiate(
request,
discoveryUri,
clientId,
clientSecret,
scope,
callbackUrl,
prompt,
maxAge,
clientAuthMethod,
disablePkce,
useNonce,
customParams);
}

@POST
@Path("/auth/test-login/saml-initiate")
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
@Operation(
operationId = "samlTestLoginInitiate",
summary = "Initiate SAML Test Login",
description =
"Initiates a SAML Test Login flow by redirecting the browser to the IdP SSO URL "
+ "with a SAML AuthnRequest. Expects form-encoded body with idpEntityId, "
+ "idpSsoLoginUrl, idpX509Certificate, spEntityId, spAcsUrl, nameIdFormat. "
+ "Browser is typically navigated to this endpoint via a hidden form POST "
+ "with target=_blank so the response 302 loads inside the popup.")
public Response samlTestLoginInitiate(
@Context HttpServletRequest request,
@Context HttpServletResponse response,
@FormParam("idpEntityId") String idpEntityId,
@FormParam("idpSsoLoginUrl") String idpSsoLoginUrl,
@FormParam("idpX509Certificate") String idpX509Certificate,
@FormParam("spEntityId") String spEntityId,
@FormParam("spAcsUrl") String spAcsUrl,
@FormParam("nameIdFormat") String nameIdFormat) {
return TestSamlHandler.handleInitiate(
request,
response,
idpEntityId,
idpSsoLoginUrl,
idpX509Certificate,
spEntityId,
spAcsUrl,
nameIdFormat);
}

@POST
@Path("/auth/test-login")
@Operation(
operationId = "testLoginLdap",
summary = "Test Login (LDAP) — saved config",
description =
"Tests LDAP authentication using the SAVED LDAP configuration. "
+ "For pre-save LDAP Test Login, use /auth/test-login/ldap-initiate instead.")
public Response testLoginLdap(Map<String, String> credentials) {
String email = credentials.get("email");
String password = credentials.get("password");
Map<String, Object> result = TestLoginHandler.handleLdapTestLogin(email, password);

return Response.ok(result).build();
}

@POST
@Path("/auth/test-login/ldap-initiate")
@Consumes(MediaType.APPLICATION_JSON)
@Operation(
operationId = "ldapTestLoginInitiate",
summary = "Initiate LDAP Test Login (pre-save)",
description =
"Tests LDAP authentication using form-provided configuration — does not rely on "
+ "saved state. Accepts { ldapConfiguration, email, password } as JSON body. "
+ "Binds as admin, searches for the user by mailAttributeName, binds as the user "
+ "to verify password, and returns the derived email + domain + admin principal.")
public Response ldapTestLoginInitiate(LdapTestLoginRequest body) {
if (body == null || body.getLdapConfiguration() == null) {
return Response.status(Response.Status.BAD_REQUEST)
.entity(Map.of("success", false, "error", "ldapConfiguration is required"))
.build();
}
Map<String, Object> result =
TestLdapHandler.handleLdapTestLogin(
body.getLdapConfiguration(), body.getEmail(), body.getPassword());
return Response.ok(result).build();
}

public static class LdapTestLoginRequest {
private org.openmetadata.schema.auth.LdapConfiguration ldapConfiguration;
private String email;
private String password;

public org.openmetadata.schema.auth.LdapConfiguration getLdapConfiguration() {
return ldapConfiguration;
}

public void setLdapConfiguration(
org.openmetadata.schema.auth.LdapConfiguration ldapConfiguration) {
this.ldapConfiguration = ldapConfiguration;
}

public String getEmail() {
return email;
}

public void setEmail(String email) {
this.email = email;
}

public String getPassword() {
return password;
}

public void setPassword(String password) {
this.password = password;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -644,6 +644,9 @@ public SecurityConfiguration getSecurityConfig(@Context SecurityContext security
String configJson = JsonUtils.pojoToJson(originalConfig);
SecurityConfiguration config = JsonUtils.readValue(configJson, SecurityConfiguration.class);

// Hydrate canonical fields from legacy locations so UI sees a consistent shape
systemRepository.hydrateForResponse(config.getAuthenticationConfiguration());

// Apply password masking if needed - only to the copy
if (authorizer.shouldMaskPasswords(securityContext)) {
// Mask OIDC configuration if present
Expand Down Expand Up @@ -685,14 +688,15 @@ public SecurityConfiguration getSecurityConfig(@Context SecurityContext security
public Response updateSecurityConfig(
@Context UriInfo uriInfo,
@Context SecurityContext securityContext,
@Valid SecurityConfiguration securityConfig) {
SecurityConfiguration securityConfig) {
authorizer.authorizeAdmin(securityContext);

try {
AuthenticationConfiguration authConfig = securityConfig.getAuthenticationConfiguration();

// Auto-populate publicKeyUrls for OIDC confidential clients before saving
systemRepository.autoPopulatePublicKeyUrlsIfNeeded(authConfig);
// Normalize authentication configuration for persistence: mirror canonical and legacy
// field locations, derive authority/publicKeyUrls from discoveryUri, default callbackUrl.
systemRepository.normalizeForPersistence(authConfig);

// Update both configurations in a transaction
Settings authSettings =
Expand Down Expand Up @@ -761,6 +765,12 @@ public Response patchSecurityConfig(
SecurityConfiguration updatedConfig =
JsonUtils.readValue(jsonString, SecurityConfiguration.class);

// Normalize after patch so derived fields (authority, publicKeyUrls, etc.)
// stay in sync with patched canonical fields like discoveryUri or oidcConfig.id.
if (updatedConfig.getAuthenticationConfiguration() != null) {
systemRepository.normalizeForPersistence(updatedConfig.getAuthenticationConfiguration());
}

String currentUsername = SecurityUtil.getUserName(securityContext);
SecurityValidationResponse validationResponse =
systemRepository.validateSecurityConfiguration(
Expand Down Expand Up @@ -826,11 +836,23 @@ public Response patchSecurityConfig(
schema = @Schema(implementation = SecurityValidationResponse.class)))
})
public SecurityValidationResponse validateSecurityConfig(
@Context SecurityContext securityContext, @Valid SecurityConfiguration securityConfig) {
@Context SecurityContext securityContext,
@QueryParam("context") String context,
SecurityConfiguration securityConfig) {
authorizer.authorizeAdmin(securityContext);

// Normalize configuration before validation so authority, publicKeyUrls,
// and mirrored fields are populated from discoveryUri.
AuthenticationConfiguration authConfig = securityConfig.getAuthenticationConfiguration();
if (authConfig != null) {
systemRepository.normalizeForPersistence(authConfig);
}

String currentUsername = SecurityUtil.getUserName(securityContext);
boolean isTestLoginContext = "testLogin".equals(context);

return systemRepository.validateSecurityConfiguration(
securityConfig, applicationConfig, currentUsername);
securityConfig, applicationConfig, currentUsername, isTestLoginContext);
}

@GET
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,31 @@
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.ws.rs.core.Response;
import lombok.extern.slf4j.Slf4j;
import org.openmetadata.service.security.auth.TestLoginHandler;
import org.openmetadata.service.security.auth.TestSamlHandler;

@WebServlet("/callback")
@Slf4j
public class AuthCallbackServlet extends HttpServlet {

private static final String OIDC_TEST_LOGIN_PREFIX = "test-login:";

@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) {
// Check if this is an MCP OAuth callback (pac4j state matches a pending MCP auth request).
// MCP uses /mcp/callback with DB-backed state restoration, but SSO providers redirect to
// /callback (the registered redirect URI). Forward to /mcp/callback so McpCallbackServlet
// can handle it with proper state restoration from DB.
String state = req.getParameter("state");

// Check if this is an OIDC Test Login callback (state prefixed with "test-login:")
if (state != null && state.startsWith(OIDC_TEST_LOGIN_PREFIX)) {
handleOidcTestLogin(req, resp);
return;
}

if (AuthenticationCodeFlowHandler.isMcpState(state)) {
try {
LOG.debug("Forwarding MCP OAuth callback to /mcp/callback");
Expand All @@ -40,8 +52,49 @@ protected void doGet(HttpServletRequest req, HttpServletResponse resp) {

@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) {
// SAML uses POST for callback with SAMLResponse
// SAML uses POST for callback with SAMLResponse. Test Login SAML prefixes
// RelayState with "saml-test-login:" so we can route to the test handler.
String relayState = req.getParameter("RelayState");
if (relayState != null && relayState.startsWith(TestSamlHandler.RELAY_STATE_PREFIX)) {
handleSamlTestLogin(req, resp);
return;
}
AuthServeletHandler handler = AuthServeletHandlerRegistry.getHandler();
handler.handleCallback(req, resp);
}

private void handleOidcTestLogin(HttpServletRequest req, HttpServletResponse resp) {
try {
LOG.debug("Handling OIDC Test Login callback");
writeResponse(resp, TestLoginHandler.handleCallback(req));
} catch (Exception e) {
LOG.error("Failed to handle OIDC Test Login callback", e);
sendInternalError(resp, "Failed to process Test Login");
}
}

private void handleSamlTestLogin(HttpServletRequest req, HttpServletResponse resp) {
try {
LOG.debug("Handling SAML Test Login callback");
writeResponse(resp, TestSamlHandler.handleCallback(req));
} catch (Exception e) {
LOG.error("Failed to handle SAML Test Login callback", e);
sendInternalError(resp, "Failed to process SAML Test Login");
}
}

private void writeResponse(HttpServletResponse resp, Response response) throws Exception {
resp.setContentType(
response.getMediaType() != null ? response.getMediaType().toString() : "text/html");
resp.setStatus(response.getStatus());
resp.getWriter().write(response.getEntity().toString());
}

private void sendInternalError(HttpServletResponse resp, String message) {
try {
resp.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, message);
} catch (Exception writeEx) {
LOG.error("Failed to write error response", writeEx);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -892,7 +892,7 @@ private User getOrCreateOidcUser(String userName, String email, Map<String, Obje
User user =
Entity.getEntityByName(Entity.USER, userName, "id,roles,teams", Include.NON_DELETED);

boolean shouldBeAdmin = getAdminPrincipals().contains(userName);
boolean shouldBeAdmin = SecurityUtil.isAdminPrincipal(getAdminPrincipals(), userName, email);
boolean needsUpdate = false;

LOG.debug(
Expand Down Expand Up @@ -922,7 +922,7 @@ private User getOrCreateOidcUser(String userName, String email, Map<String, Obje
}

if (authenticationConfiguration.getEnableSelfSignup()) {
boolean isAdmin = getAdminPrincipals().contains(userName);
boolean isAdmin = SecurityUtil.isAdminPrincipal(getAdminPrincipals(), userName, email);
LOG.debug("Creating new OIDC user - Username: {}, isAdmin: {}", userName, isAdmin);

String domain = email.split("@")[1];
Expand Down Expand Up @@ -1122,7 +1122,7 @@ public static void validatePrincipalClaimsMapping(Map<String, String> mapping) {
// If emtpy, jwtPrincipalClaims will be used so no need to validate
}

private HTTPResponse executeTokenHttpRequest(TokenRequest request) throws IOException {
public HTTPResponse executeTokenHttpRequest(TokenRequest request) throws IOException {
HTTPRequest tokenHttpRequest = request.toHTTPRequest();
client.getConfiguration().configureHttpRequest(tokenHttpRequest);

Expand All @@ -1135,7 +1135,7 @@ private HTTPResponse executeTokenHttpRequest(TokenRequest request) throws IOExce
return httpResponse;
}

private TokenRequest createTokenRequest(final AuthorizationGrant grant) {
public TokenRequest createTokenRequest(final AuthorizationGrant grant) {
if (clientAuthentication != null) {
return new TokenRequest(
client.getConfiguration().findProviderMetadata().getTokenEndpointURI(),
Expand Down
Loading
Loading