wip - refactoring

This commit is contained in:
Dario Ghunney Ware 2025-02-02 02:36:53 +00:00
parent f067e5df8c
commit 67ee304f82
3 changed files with 13 additions and 20 deletions

View File

@ -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);

View File

@ -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> user = userRepository.findByUsernameIgnoreCaseWithSettings(username);
if (!user.isPresent()) {
if (user.isEmpty()) {
return "redirect:/error";
}
// Convert settings map to JSON string

View File

@ -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));
}
}