securing with nextcloud oidc
This commit is contained in:
@ -1,7 +1,14 @@
|
||||
package de.jottyfan.bico.modules;
|
||||
|
||||
import java.security.Principal;
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.security.core.context.SecurityContextHolder;
|
||||
import org.springframework.security.oauth2.client.authentication.OAuth2AuthenticationToken;
|
||||
import org.springframework.security.oauth2.core.user.OAuth2User;
|
||||
import org.springframework.web.bind.annotation.ModelAttribute;
|
||||
|
||||
import de.jottyfan.bico.modules.profile.ProfileService;
|
||||
|
||||
@ -15,15 +22,31 @@ public abstract class CommonController {
|
||||
@Autowired
|
||||
private ProfileService profileService;
|
||||
|
||||
@Value("${spring.security.oauth2.client.provider.nextcloud.issuer-uri}")
|
||||
private String nextcloudUrl;
|
||||
|
||||
@ModelAttribute("hasBUrole")
|
||||
public Boolean hasBURole(Principal principal) {
|
||||
OAuth2AuthenticationToken token = (OAuth2AuthenticationToken) principal;
|
||||
OAuth2User user = token.getPrincipal();
|
||||
@SuppressWarnings("unchecked")
|
||||
List<String> roles = (List<String>) user.getAttributes().get("roles");
|
||||
return roles.contains("Bibelunterricht");
|
||||
}
|
||||
|
||||
/**
|
||||
* get the theme for the current session
|
||||
*
|
||||
* @return the theme; light or dark at the moment
|
||||
*/
|
||||
public Model useThemedModel(Model model) {
|
||||
// TODO: add profile's user name
|
||||
String username = "jotty";
|
||||
model.addAttribute("theme", profileService.getTheme(username));
|
||||
return model;
|
||||
@ModelAttribute("theme")
|
||||
public String getTheme() {
|
||||
String username = SecurityContextHolder.getContext().getAuthentication().getName();
|
||||
return profileService.getTheme(username);
|
||||
}
|
||||
|
||||
@ModelAttribute("nextcloudUrl")
|
||||
public String getNextcloudUrl() {
|
||||
return nextcloudUrl;
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,6 @@
|
||||
package de.jottyfan.bico.modules.index;
|
||||
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
|
||||
import de.jottyfan.bico.modules.CommonController;
|
||||
@ -14,8 +13,7 @@ import de.jottyfan.bico.modules.CommonController;
|
||||
@Controller
|
||||
public class IndexController extends CommonController {
|
||||
@GetMapping("/")
|
||||
public String getIndex(Model model) {
|
||||
useThemedModel(model);
|
||||
public String getIndex() {
|
||||
return "redirect:/sheet";
|
||||
}
|
||||
}
|
||||
|
@ -20,7 +20,7 @@ public class SheetController extends CommonController {
|
||||
|
||||
@GetMapping("/sheet")
|
||||
public String getSheet(Model model) {
|
||||
useThemedModel(model).addAttribute("list", service.getList());
|
||||
model.addAttribute("list", service.getList());
|
||||
return "/sheet";
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user