diff --git a/src/main/java/stirling/software/SPDF/config/security/oauth2/OAuth2Configuration.java b/src/main/java/stirling/software/SPDF/config/security/oauth2/OAuth2Configuration.java index 04cc192a8..8fbee5b19 100644 --- a/src/main/java/stirling/software/SPDF/config/security/oauth2/OAuth2Configuration.java +++ b/src/main/java/stirling/software/SPDF/config/security/oauth2/OAuth2Configuration.java @@ -184,7 +184,7 @@ public class OAuth2Configuration { oauth.getClientId(), oauth.getClientSecret(), oauth.getScopes(), - UsernameAttribute.valueOf(oauth.getUseAsUsername().toUpperCase()), + UsernameAttribute.valueOf(oauth.getUseAsUsername()), null, null, null); diff --git a/src/main/java/stirling/software/SPDF/controller/web/AccountWebController.java b/src/main/java/stirling/software/SPDF/controller/web/AccountWebController.java index 4dfcf0ca6..faa2597fb 100644 --- a/src/main/java/stirling/software/SPDF/controller/web/AccountWebController.java +++ b/src/main/java/stirling/software/SPDF/controller/web/AccountWebController.java @@ -114,7 +114,8 @@ public class AccountWebController { providerList .entrySet() .removeIf(entry -> entry.getKey() == null || entry.getValue() == null); - model.addAttribute("providerList", providerList); + model.addAttribute( + "providerList", providerList); // todo: might need to change back to 'providerlist' model.addAttribute("loginMethod", securityProps.getLoginMethod()); boolean altLogin = !providerList.isEmpty() ? securityProps.isAltLogin() : false; @@ -132,7 +133,9 @@ public class AccountWebController { model.addAttribute("error", error); } + String errorOAuth = request.getParameter("errorOAuth"); + if (errorOAuth != null) { switch (errorOAuth) { case "oAuth2AutoCreateDisabled" -> errorOAuth = "login.oAuth2AutoCreateDisabled"; @@ -345,7 +348,7 @@ public class AccountWebController { // Fetch user details from the database, assuming findByUsername method exists Optional user = userRepository.findByUsernameIgnoreCaseWithSettings(username); - if (!user.isPresent()) { + if (user.isEmpty()) { return "redirect:/error"; } // Convert settings map to JSON string diff --git a/src/main/java/stirling/software/SPDF/model/provider/Provider.java b/src/main/java/stirling/software/SPDF/model/provider/Provider.java index 5ba1ba2c4..d8a7de1ff 100644 --- a/src/main/java/stirling/software/SPDF/model/provider/Provider.java +++ b/src/main/java/stirling/software/SPDF/model/provider/Provider.java @@ -16,6 +16,8 @@ import stirling.software.SPDF.model.exception.UnsupportedUsernameAttribute; @NoArgsConstructor public class Provider { + public static final String EXCEPTION_MESSAGE = "The attribute %s is not supported for %s."; + private String issuer; private String name; private String clientName; @@ -83,41 +85,29 @@ public class Provider { } default -> throw new UnsupportedUsernameAttribute( - "The attribute " - + usernameAttribute - + "is not supported for " - + clientName - + "."); + String.format(EXCEPTION_MESSAGE, usernameAttribute, clientName)); } } private UsernameAttribute validateGoogleUsernameAttribute(UsernameAttribute usernameAttribute) { switch (usernameAttribute) { - case EMAIL, NAME, GIVEN_NAME, PREFERRED_NAME -> { + case EMAIL, NAME, GIVEN_NAME, FAMILY_NAME -> { return usernameAttribute; } default -> throw new UnsupportedUsernameAttribute( - "The attribute " - + usernameAttribute - + "is not supported for " - + clientName - + "."); + String.format(EXCEPTION_MESSAGE, usernameAttribute, clientName)); } } private UsernameAttribute validateGitHubUsernameAttribute(UsernameAttribute usernameAttribute) { switch (usernameAttribute) { - case EMAIL, NAME, LOGIN -> { + case LOGIN, EMAIL, NAME -> { return usernameAttribute; } default -> throw new UnsupportedUsernameAttribute( - "The attribute " - + usernameAttribute - + "is not supported for " - + clientName - + "."); + String.format(EXCEPTION_MESSAGE, usernameAttribute, clientName)); } }