Skip to content

Commit

Permalink
CB-5734 return template configuration for auth provider (#3162)
Browse files Browse the repository at this point in the history
* CB-5734 return template configuration for auth provider

* CB-5734 feat: fetch templateConfiguration

---------

Co-authored-by: Sychev Andrey <44414066+SychevAndrey@users.noreply.github.com>
Co-authored-by: Andrey Sychev <nukemoore@gmail.com>
Co-authored-by: Evgenia <139753579+EvgeniaBzzz@users.noreply.github.com>
  • Loading branch information
4 people authored Dec 27, 2024
1 parent 92ee21d commit ca83a1f
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
public interface SMAuthProviderFederated extends SMSignOutLinkProvider {

@NotNull
String getSignInLink(String id, @NotNull Map<String, Object> providerConfig) throws DBException;
String getSignInLink(String id) throws DBException;

@Override
default String getUserSignOutLink(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ public Map<String, Object> getParameters() {
@Property
public String getSignInLink() throws DBException {
SMAuthProvider<?> instance = providerDescriptor.getInstance();
return instance instanceof SMAuthProviderFederated ?
buildRedirectUrl(((SMAuthProviderFederated) instance).getSignInLink(getId(), config.getParameters()))
return instance instanceof SMAuthProviderFederated smAuthProviderFederated ?
buildRedirectUrl(smAuthProviderFederated.getSignInLink(getId()))
: null;
}

Expand All @@ -86,34 +86,40 @@ private String buildRedirectUrl(String baseUrl) {
@Property
public String getSignOutLink() throws DBException {
SMAuthProvider<?> instance = providerDescriptor.getInstance();
return instance instanceof SMSignOutLinkProvider
? ((SMSignOutLinkProvider) instance).getCommonSignOutLink(getId(), config.getParameters())
return instance instanceof SMSignOutLinkProvider smSignOutLinkProvider
? smSignOutLinkProvider.getCommonSignOutLink(getId(), config.getParameters())
: null;
}

@Property
public String getRedirectLink() throws DBException {
SMAuthProvider<?> instance = providerDescriptor.getInstance();
return instance instanceof SMAuthProviderFederated ? ((SMAuthProviderFederated) instance).getRedirectLink(getId(), config.getParameters()) : null;
return instance instanceof SMAuthProviderFederated smAuthProviderFederated
? smAuthProviderFederated.getRedirectLink(getId(), config.getParameters())
: null;
}

@Property
public String getMetadataLink() throws DBException {
SMAuthProvider<?> instance = providerDescriptor.getInstance();
return instance instanceof SMAuthProviderFederated ? ((SMAuthProviderFederated) instance).getMetadataLink(getId(), config.getParameters()) : null;
return instance instanceof SMAuthProviderFederated smAuthProviderFederated
? smAuthProviderFederated.getMetadataLink(getId(), config.getParameters())
: null;
}

@Property
public String getAcsLink() throws DBException {
SMAuthProvider<?> instance = providerDescriptor.getInstance();
return instance instanceof SMAuthProviderFederated ? ((SMAuthProviderFederated) instance).getAcsLink(getId(), config.getParameters()) : null;
return instance instanceof SMAuthProviderFederated smAuthProviderFederated
? smAuthProviderFederated.getAcsLink(getId(), config.getParameters())
: null;
}

@Property
public String getEntityIdLink() throws DBException {
SMAuthProvider<?> instance = providerDescriptor.getInstance();
return instance instanceof SMAuthProviderFederated
? ((SMAuthProviderFederated) instance).getEntityIdLink(getId(), config.getParameters())
return instance instanceof SMAuthProviderFederated smAuthProviderFederated
? smAuthProviderFederated.getEntityIdLink(getId(), config.getParameters())
: null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ type AuthProviderInfo {
# Provider configurations (applicable only if configurable=true)
configurations: [AuthProviderConfiguration!]

templateConfiguration: AuthProviderConfiguration! @since(version: "24.1.2")

credentialProfiles: [AuthProviderCredentialsProfile!]!

requiredFeatures: [String!]!
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@
import io.cloudbeaver.auth.SMAuthProviderFederated;
import io.cloudbeaver.auth.provisioning.SMProvisioner;
import io.cloudbeaver.model.app.ServletAuthConfiguration;
import io.cloudbeaver.model.session.WebSession;
import io.cloudbeaver.registry.WebAuthProviderConfiguration;
import io.cloudbeaver.registry.WebAuthProviderDescriptor;
import io.cloudbeaver.server.CBApplication;
import io.cloudbeaver.server.WebAppUtils;
import org.jkiss.code.NotNull;
import org.jkiss.dbeaver.Log;
import org.jkiss.dbeaver.model.security.SMAuthCredentialsProfile;
import org.jkiss.dbeaver.model.security.SMAuthProviderCustomConfiguration;
Expand All @@ -38,17 +38,15 @@
public class WebAuthProviderInfo {

private static final Log log = Log.getLog(WebAuthProviderInfo.class);
private static final SMAuthProviderCustomConfiguration TEMPLATE_CONFIG = new SMAuthProviderCustomConfiguration("{configuration_id}");

@NotNull
private final WebAuthProviderDescriptor descriptor;

public WebAuthProviderInfo(WebAuthProviderDescriptor descriptor) {
public WebAuthProviderInfo(@NotNull WebAuthProviderDescriptor descriptor) {
this.descriptor = descriptor;
}

WebAuthProviderDescriptor getDescriptor() {
return descriptor;
}

public String getId() {
return descriptor.getId();
}
Expand Down Expand Up @@ -126,6 +124,10 @@ public String[] getRequiredFeatures() {
return rf == null ? new String[0] : rf;
}

public WebAuthProviderConfiguration getTemplateConfiguration() {
return new WebAuthProviderConfiguration(descriptor, TEMPLATE_CONFIG);
}

@Override
public String toString() {
return getLabel();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1607,7 +1607,7 @@ public SMAuthInfo authenticate(
if (SMAuthProviderFederated.class.isAssignableFrom(authProviderInstance.getClass())) {
//async auth
var authProviderFederated = (SMAuthProviderFederated) authProviderInstance;
String signInLink = buildRedirectLink(authProviderFederated.getSignInLink(authProviderConfigurationId, Map.of()),
String signInLink = buildRedirectLink(authProviderFederated.getSignInLink(authProviderConfigurationId),
authAttemptId);
String signOutLink = authProviderFederated.getCommonSignOutLink(authProviderConfigurationId,
providerConfig.getParameters());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,14 @@ fragment AuthProviderInfo on AuthProviderInfo {
supportProvisioning
required
authHidden
templateConfiguration {
id
signInLink
signOutLink
metadataLink
acsLink
entityIdLink
}

#configurationParameters {
# id
Expand Down

0 comments on commit ca83a1f

Please sign in to comment.