camp admin added

This commit is contained in:
Jottyfan
2025-01-30 22:37:22 +01:00
parent bdc0d84e69
commit 30fb52a606
9 changed files with 245 additions and 8 deletions

View File

@ -3,8 +3,6 @@ package de.jottyfan.bico.modules;
import java.security.Principal;
import java.util.List;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.security.core.context.SecurityContextHolder;
@ -12,6 +10,7 @@ import org.springframework.security.oauth2.client.authentication.OAuth2Authentic
import org.springframework.security.oauth2.core.user.OAuth2User;
import org.springframework.web.bind.annotation.ModelAttribute;
import de.jottyfan.bico.Main;
import de.jottyfan.bico.modules.profile.ProfileService;
/**
@ -20,8 +19,7 @@ import de.jottyfan.bico.modules.profile.ProfileService;
*
*/
public abstract class CommonController {
private static final Logger LOGGER = LogManager.getLogger(CommonController.class);
private static final List<String> admins = List.of("andre.sieber", "tobias.kuehne", "jotty");
@Autowired
private ProfileService profileService;
@ -29,6 +27,11 @@ public abstract class CommonController {
@Value("${spring.security.oauth2.client.provider.nextcloud.issuer-uri}")
private String nextcloudUrl;
@ModelAttribute("isCampAdmin")
public Boolean isCampAdmin(Principal principal) {
return admins.contains(principal.getName());
}
@ModelAttribute("hasBUrole")
public Boolean hasBURole(Principal principal) {
OAuth2AuthenticationToken token = (OAuth2AuthenticationToken) principal;
@ -38,7 +41,7 @@ public abstract class CommonController {
List<String> roles = (List<String>) user.getAttributes().get("roles");
return roles.contains("Bibelunterricht");
} else {
LOGGER.warn("token is null, no roles can be detected");
Main.LOGGER.warn("token is null, no roles can be detected");
return false;
}
}
@ -52,7 +55,7 @@ public abstract class CommonController {
List<String> roles = (List<String>) user.getAttributes().get("roles");
return roles.contains("Kinderstunde klein");
} else {
LOGGER.warn("token is null, no roles can be detected");
Main.LOGGER.warn("token is null, no roles can be detected");
return false;
}
}
@ -66,7 +69,7 @@ public abstract class CommonController {
List<String> roles = (List<String>) user.getAttributes().get("roles");
return roles.size() > 0;
} else {
LOGGER.warn("token is null, no roles can be detected");
Main.LOGGER.warn("token is null, no roles can be detected");
return false;
}
}