mirror of
https://github.com/Frooodle/Stirling-PDF.git
synced 2025-02-07 00:17:07 +01:00
wip - refactoring & cleanup
This commit is contained in:
parent
c439ccd02a
commit
ace34004f9
@ -197,14 +197,14 @@ public class CustomLogoutSuccessHandler extends SimpleUrlLogoutSuccessHandler {
|
||||
+ clientId
|
||||
+ "&post_logout_redirect_uri="
|
||||
+ response.encodeRedirectURL(redirect_url);
|
||||
log.info("Redirecting to Keycloak logout URL: " + logoutUrl);
|
||||
log.info("Redirecting to Keycloak logout URL: {}", logoutUrl);
|
||||
response.sendRedirect(logoutUrl);
|
||||
}
|
||||
case "github" -> {
|
||||
// Add GitHub specific logout URL if needed
|
||||
// todo: why does the redirect go to github? shouldn't it come to Stirling PDF?
|
||||
String githubLogoutUrl = "https://github.com/logout";
|
||||
log.info("Redirecting to GitHub logout URL: " + redirect_url);
|
||||
log.info("Redirecting to GitHub logout URL: {}", redirect_url);
|
||||
response.sendRedirect(redirect_url);
|
||||
}
|
||||
case "google" -> {
|
||||
|
@ -64,19 +64,13 @@ public class OAuth2Configuration {
|
||||
}
|
||||
|
||||
private Optional<ClientRegistration> googleClientRegistration() {
|
||||
OAUTH2 oauth = applicationProperties.getSecurity().getOauth2();
|
||||
|
||||
if (oauth == null || !oauth.getEnabled()) {
|
||||
if (isOauthOrClientEmpty()) {
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
Client client = oauth.getClient();
|
||||
GoogleProvider google =
|
||||
applicationProperties.getSecurity().getOauth2().getClient().getGoogle();
|
||||
|
||||
if (client == null) {
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
GoogleProvider google = client.getGoogle();
|
||||
return google != null && google.isSettingsValid()
|
||||
? Optional.of(
|
||||
ClientRegistration.withRegistrationId(google.getName())
|
||||
@ -95,15 +89,13 @@ public class OAuth2Configuration {
|
||||
}
|
||||
|
||||
private Optional<ClientRegistration> keycloakClientRegistration() {
|
||||
OAUTH2 oauth = applicationProperties.getSecurity().getOauth2();
|
||||
if (oauth == null || !oauth.getEnabled()) {
|
||||
if (isOauthOrClientEmpty()) {
|
||||
return Optional.empty();
|
||||
}
|
||||
Client client = oauth.getClient();
|
||||
if (client == null) {
|
||||
return Optional.empty();
|
||||
}
|
||||
KeycloakProvider keycloak = client.getKeycloak();
|
||||
|
||||
KeycloakProvider keycloak =
|
||||
applicationProperties.getSecurity().getOauth2().getClient().getKeycloak();
|
||||
|
||||
return keycloak != null && keycloak.isSettingsValid()
|
||||
? Optional.of(
|
||||
ClientRegistrations.fromIssuerLocation(keycloak.getIssuer())
|
||||
@ -181,7 +173,7 @@ public class OAuth2Configuration {
|
||||
|
||||
Client client = oauth.getClient();
|
||||
|
||||
return client != null;
|
||||
return client == null;
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -5,7 +5,6 @@ import java.util.Collection;
|
||||
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
// @Setter
|
||||
@NoArgsConstructor
|
||||
public class GithubProvider extends Provider {
|
||||
|
||||
@ -22,7 +21,7 @@ public class GithubProvider extends Provider {
|
||||
|
||||
public GithubProvider(
|
||||
String clientId, String clientSecret, Collection<String> scopes, String useAsUsername) {
|
||||
super(null, NAME, CLIENT_NAME, clientId, clientSecret, scopes, useAsUsername);
|
||||
super(null, NAME, CLIENT_NAME, clientId, clientSecret, scopes, useAsUsername);
|
||||
this.clientId = clientId;
|
||||
this.clientSecret = clientSecret;
|
||||
this.scopes = scopes;
|
||||
|
@ -5,7 +5,6 @@ import java.util.Collection;
|
||||
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
// @Setter
|
||||
@NoArgsConstructor
|
||||
public class GoogleProvider extends Provider {
|
||||
|
||||
|
@ -5,7 +5,6 @@ import java.util.Collection;
|
||||
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
// @Setter
|
||||
@NoArgsConstructor
|
||||
public class KeycloakProvider extends Provider {
|
||||
|
||||
|
@ -4,10 +4,10 @@ import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
@Getter
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
public abstract class Provider {
|
||||
|
||||
@ -37,6 +37,7 @@ public abstract class Provider {
|
||||
}
|
||||
|
||||
// todo: why are we passing name here if it's not used?
|
||||
// todo: use util class/method
|
||||
public boolean isSettingsValid() {
|
||||
return isValid(this.getIssuer(), "issuer")
|
||||
&& isValid(this.getClientId(), "clientId")
|
||||
@ -53,32 +54,8 @@ public abstract class Provider {
|
||||
return value != null && !value.isEmpty();
|
||||
}
|
||||
|
||||
public void setIssuer(String issuer) {
|
||||
this.issuer = issuer;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public void setClientName(String clientName) {
|
||||
this.clientName = clientName;
|
||||
}
|
||||
|
||||
public void setClientId(String clientId) {
|
||||
this.clientId = clientId;
|
||||
}
|
||||
|
||||
public void setClientSecret(String clientSecret) {
|
||||
this.clientSecret = clientSecret;
|
||||
}
|
||||
|
||||
public void setScopes(String scopes) {
|
||||
this.scopes =
|
||||
Arrays.stream(scopes.split(",")).map(String::trim).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
public void setUseAsUsername(String useAsUsername) {
|
||||
this.useAsUsername = useAsUsername;
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,11 @@
|
||||
package stirling.software.SPDF.utils.validation;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
public class CollectionValidator implements Validator<Collection<String>> {
|
||||
|
||||
@Override
|
||||
public boolean validate(Collection<String> input, String path) {
|
||||
return input != null && !input.isEmpty();
|
||||
}
|
||||
}
|
@ -0,0 +1,9 @@
|
||||
package stirling.software.SPDF.utils.validation;
|
||||
|
||||
public class StringValidator implements Validator<String> {
|
||||
|
||||
@Override
|
||||
public boolean validate(String input, String path) {
|
||||
return input != null && !input.isBlank();
|
||||
}
|
||||
}
|
@ -0,0 +1,6 @@
|
||||
package stirling.software.SPDF.utils.validation;
|
||||
|
||||
public interface Validator<T> {
|
||||
|
||||
boolean validate(T input, String path);
|
||||
}
|
Loading…
Reference in New Issue
Block a user