Search in sources :

Example 1 with Secured

use of com.jeanchampemont.wtfdyum.security.Secured in project WTFDYUM by jchampemont.

the class AdminController method index.

@RequestMapping(method = RequestMethod.GET)
@Secured
public ModelAndView index() {
    if (!authenticationService.isAdmin()) {
        return new ModelAndView("redirect:/");
    }
    ModelAndView result = new ModelAndView("admin/index");
    final Long userId = authenticationService.getCurrentUserId();
    try {
        result.getModel().put("user", twitterService.getUser(SessionManager.getPrincipal(), userId));
    } catch (final WTFDYUMException e) {
        authenticationService.logOut();
        return new ModelAndView("redirect:/");
    }
    result.getModel().put("membersCount", principalService.countMembers());
    Map<String, Integer> featureEnabledCount = adminService.countEnabledFeature(principalService.getMembers()).entrySet().stream().collect(toMap(e -> e.getKey().name(), Map.Entry::getValue));
    result.getModel().put("availableFeatures", Feature.values());
    result.getModel().put("featureEnabledCount", featureEnabledCount);
    return result;
}
Also used : PrincipalService(com.jeanchampemont.wtfdyum.service.PrincipalService) WTFDYUMException(com.jeanchampemont.wtfdyum.utils.WTFDYUMException) Secured(com.jeanchampemont.wtfdyum.security.Secured) AdminService(com.jeanchampemont.wtfdyum.service.AdminService) Autowired(org.springframework.beans.factory.annotation.Autowired) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) RequestMethod(org.springframework.web.bind.annotation.RequestMethod) Controller(org.springframework.stereotype.Controller) Collectors(java.util.stream.Collectors) SessionManager(com.jeanchampemont.wtfdyum.utils.SessionManager) ModelAndView(org.springframework.web.servlet.ModelAndView) Collectors.toMap(java.util.stream.Collectors.toMap) AuthenticationService(com.jeanchampemont.wtfdyum.service.AuthenticationService) TwitterService(com.jeanchampemont.wtfdyum.service.TwitterService) Map(java.util.Map) Feature(com.jeanchampemont.wtfdyum.dto.Feature) WTFDYUMException(com.jeanchampemont.wtfdyum.utils.WTFDYUMException) ModelAndView(org.springframework.web.servlet.ModelAndView) Collectors.toMap(java.util.stream.Collectors.toMap) Map(java.util.Map) Secured(com.jeanchampemont.wtfdyum.security.Secured) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 2 with Secured

use of com.jeanchampemont.wtfdyum.security.Secured in project WTFDYUM by jchampemont.

the class UserController method index.

@RequestMapping(method = RequestMethod.GET)
@Secured
public ModelAndView index() {
    final ModelAndView result = new ModelAndView("user/index");
    final Long userId = authenticationService.getCurrentUserId();
    try {
        result.getModel().put("user", twitterService.getUser(SessionManager.getPrincipal(), userId));
    } catch (final WTFDYUMException e) {
        authenticationService.logOut();
        return new ModelAndView("redirect:/");
    }
    result.getModel().put("events", userService.getRecentEvents(userId, 10));
    result.getModel().put("availableFeatures", Feature.values());
    final Map<String, Boolean> featuresStatus = new HashMap<>();
    for (final Feature f : Feature.values()) {
        featuresStatus.put(f.name(), featureService.isEnabled(userId, f));
    }
    result.getModel().put("featuresStatus", featuresStatus);
    return result;
}
Also used : HashMap(java.util.HashMap) WTFDYUMException(com.jeanchampemont.wtfdyum.utils.WTFDYUMException) ModelAndView(org.springframework.web.servlet.ModelAndView) Feature(com.jeanchampemont.wtfdyum.dto.Feature) Secured(com.jeanchampemont.wtfdyum.security.Secured) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

Feature (com.jeanchampemont.wtfdyum.dto.Feature)2 Secured (com.jeanchampemont.wtfdyum.security.Secured)2 WTFDYUMException (com.jeanchampemont.wtfdyum.utils.WTFDYUMException)2 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)2 ModelAndView (org.springframework.web.servlet.ModelAndView)2 AdminService (com.jeanchampemont.wtfdyum.service.AdminService)1 AuthenticationService (com.jeanchampemont.wtfdyum.service.AuthenticationService)1 PrincipalService (com.jeanchampemont.wtfdyum.service.PrincipalService)1 TwitterService (com.jeanchampemont.wtfdyum.service.TwitterService)1 SessionManager (com.jeanchampemont.wtfdyum.utils.SessionManager)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Collectors (java.util.stream.Collectors)1 Collectors.toMap (java.util.stream.Collectors.toMap)1 Autowired (org.springframework.beans.factory.annotation.Autowired)1 Controller (org.springframework.stereotype.Controller)1 RequestMethod (org.springframework.web.bind.annotation.RequestMethod)1