mirror of
https://github.com/Frooodle/Stirling-PDF.git
synced 2025-02-12 00:15:51 +01:00
wip - refactoring & cleanup
This commit is contained in:
parent
c439ccd02a
commit
ace34004f9
@ -197,14 +197,14 @@ public class CustomLogoutSuccessHandler extends SimpleUrlLogoutSuccessHandler {
|
|||||||
+ clientId
|
+ clientId
|
||||||
+ "&post_logout_redirect_uri="
|
+ "&post_logout_redirect_uri="
|
||||||
+ response.encodeRedirectURL(redirect_url);
|
+ response.encodeRedirectURL(redirect_url);
|
||||||
log.info("Redirecting to Keycloak logout URL: " + logoutUrl);
|
log.info("Redirecting to Keycloak logout URL: {}", logoutUrl);
|
||||||
response.sendRedirect(logoutUrl);
|
response.sendRedirect(logoutUrl);
|
||||||
}
|
}
|
||||||
case "github" -> {
|
case "github" -> {
|
||||||
// Add GitHub specific logout URL if needed
|
// Add GitHub specific logout URL if needed
|
||||||
// todo: why does the redirect go to github? shouldn't it come to Stirling PDF?
|
// todo: why does the redirect go to github? shouldn't it come to Stirling PDF?
|
||||||
String githubLogoutUrl = "https://github.com/logout";
|
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);
|
response.sendRedirect(redirect_url);
|
||||||
}
|
}
|
||||||
case "google" -> {
|
case "google" -> {
|
||||||
|
@ -64,19 +64,13 @@ public class OAuth2Configuration {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private Optional<ClientRegistration> googleClientRegistration() {
|
private Optional<ClientRegistration> googleClientRegistration() {
|
||||||
OAUTH2 oauth = applicationProperties.getSecurity().getOauth2();
|
if (isOauthOrClientEmpty()) {
|
||||||
|
|
||||||
if (oauth == null || !oauth.getEnabled()) {
|
|
||||||
return Optional.empty();
|
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()
|
return google != null && google.isSettingsValid()
|
||||||
? Optional.of(
|
? Optional.of(
|
||||||
ClientRegistration.withRegistrationId(google.getName())
|
ClientRegistration.withRegistrationId(google.getName())
|
||||||
@ -95,15 +89,13 @@ public class OAuth2Configuration {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private Optional<ClientRegistration> keycloakClientRegistration() {
|
private Optional<ClientRegistration> keycloakClientRegistration() {
|
||||||
OAUTH2 oauth = applicationProperties.getSecurity().getOauth2();
|
if (isOauthOrClientEmpty()) {
|
||||||
if (oauth == null || !oauth.getEnabled()) {
|
|
||||||
return Optional.empty();
|
return Optional.empty();
|
||||||
}
|
}
|
||||||
Client client = oauth.getClient();
|
|
||||||
if (client == null) {
|
KeycloakProvider keycloak =
|
||||||
return Optional.empty();
|
applicationProperties.getSecurity().getOauth2().getClient().getKeycloak();
|
||||||
}
|
|
||||||
KeycloakProvider keycloak = client.getKeycloak();
|
|
||||||
return keycloak != null && keycloak.isSettingsValid()
|
return keycloak != null && keycloak.isSettingsValid()
|
||||||
? Optional.of(
|
? Optional.of(
|
||||||
ClientRegistrations.fromIssuerLocation(keycloak.getIssuer())
|
ClientRegistrations.fromIssuerLocation(keycloak.getIssuer())
|
||||||
@ -181,7 +173,7 @@ public class OAuth2Configuration {
|
|||||||
|
|
||||||
Client client = oauth.getClient();
|
Client client = oauth.getClient();
|
||||||
|
|
||||||
return client != null;
|
return client == null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -5,7 +5,6 @@ import java.util.Collection;
|
|||||||
|
|
||||||
import lombok.NoArgsConstructor;
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
// @Setter
|
|
||||||
@NoArgsConstructor
|
@NoArgsConstructor
|
||||||
public class GithubProvider extends Provider {
|
public class GithubProvider extends Provider {
|
||||||
|
|
||||||
@ -22,7 +21,7 @@ public class GithubProvider extends Provider {
|
|||||||
|
|
||||||
public GithubProvider(
|
public GithubProvider(
|
||||||
String clientId, String clientSecret, Collection<String> scopes, String useAsUsername) {
|
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.clientId = clientId;
|
||||||
this.clientSecret = clientSecret;
|
this.clientSecret = clientSecret;
|
||||||
this.scopes = scopes;
|
this.scopes = scopes;
|
||||||
|
@ -5,7 +5,6 @@ import java.util.Collection;
|
|||||||
|
|
||||||
import lombok.NoArgsConstructor;
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
// @Setter
|
|
||||||
@NoArgsConstructor
|
@NoArgsConstructor
|
||||||
public class GoogleProvider extends Provider {
|
public class GoogleProvider extends Provider {
|
||||||
|
|
||||||
|
@ -5,7 +5,6 @@ import java.util.Collection;
|
|||||||
|
|
||||||
import lombok.NoArgsConstructor;
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
// @Setter
|
|
||||||
@NoArgsConstructor
|
@NoArgsConstructor
|
||||||
public class KeycloakProvider extends Provider {
|
public class KeycloakProvider extends Provider {
|
||||||
|
|
||||||
|
@ -4,10 +4,10 @@ import java.util.Arrays;
|
|||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import lombok.Getter;
|
import lombok.Data;
|
||||||
import lombok.NoArgsConstructor;
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
@Getter
|
@Data
|
||||||
@NoArgsConstructor
|
@NoArgsConstructor
|
||||||
public abstract class Provider {
|
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: why are we passing name here if it's not used?
|
||||||
|
// todo: use util class/method
|
||||||
public boolean isSettingsValid() {
|
public boolean isSettingsValid() {
|
||||||
return isValid(this.getIssuer(), "issuer")
|
return isValid(this.getIssuer(), "issuer")
|
||||||
&& isValid(this.getClientId(), "clientId")
|
&& isValid(this.getClientId(), "clientId")
|
||||||
@ -53,32 +54,8 @@ public abstract class Provider {
|
|||||||
return value != null && !value.isEmpty();
|
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) {
|
public void setScopes(String scopes) {
|
||||||
this.scopes =
|
this.scopes =
|
||||||
Arrays.stream(scopes.split(",")).map(String::trim).collect(Collectors.toList());
|
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