Search in sources :

Example 1 with OpenIdAlfioAuthentication

use of alfio.config.authentication.support.OpenIdAlfioAuthentication in project alf.io by alfio-event.

the class IndexController method adminHome.

// 
// admin index
@GetMapping("/admin")
public void adminHome(Model model, @Value("${alfio.version}") String version, HttpServletRequest request, HttpServletResponse response, Principal principal) throws IOException {
    model.addAttribute("alfioVersion", version);
    model.addAttribute("username", principal.getName());
    model.addAttribute("basicConfigurationNeeded", configurationManager.isBasicConfigurationNeeded());
    boolean isDBAuthentication = !(principal instanceof OpenIdAlfioAuthentication);
    model.addAttribute("isDBAuthentication", isDBAuthentication);
    if (!isDBAuthentication) {
        String idpLogoutRedirectionUrl = ((OpenIdAlfioAuthentication) SecurityContextHolder.getContext().getAuthentication()).getIdpLogoutRedirectionUrl();
        model.addAttribute("idpLogoutRedirectionUrl", idpLogoutRedirectionUrl);
    } else {
        model.addAttribute("idpLogoutRedirectionUrl", null);
    }
    Collection<String> authorities = SecurityContextHolder.getContext().getAuthentication().getAuthorities().stream().map(GrantedAuthority::getAuthority).collect(Collectors.toList());
    boolean isAdmin = authorities.contains(Role.ADMIN.getRoleName());
    model.addAttribute("isOwner", isAdmin || authorities.contains(Role.OWNER.getRoleName()));
    model.addAttribute("isAdmin", isAdmin);
    // 
    addCommonModelAttributes(model, request, version);
    model.addAttribute("displayProjectBanner", isAdmin && configurationManager.getForSystem(SHOW_PROJECT_BANNER).getValueAsBooleanOrDefault());
    try (var os = response.getOutputStream()) {
        response.setContentType(TEXT_HTML_CHARSET_UTF_8);
        response.setCharacterEncoding(UTF_8);
        var nonce = addCspHeader(response, false);
        model.addAttribute("nonce", nonce);
        templateManager.renderHtml(new ClassPathResource("alfio/web-templates/admin-index.ms"), model.asMap(), os);
    }
}
Also used : OpenIdAlfioAuthentication(alfio.config.authentication.support.OpenIdAlfioAuthentication) ClassPathResource(org.springframework.core.io.ClassPathResource)

Aggregations

OpenIdAlfioAuthentication (alfio.config.authentication.support.OpenIdAlfioAuthentication)1 ClassPathResource (org.springframework.core.io.ClassPathResource)1