List of usage examples for org.springframework.security.core.context SecurityContextHolder getContext
public static SecurityContext getContext()
SecurityContext
. From source file:com.orange.clara.cloud.servicedbdumper.config.UaaConfig.java
@Bean @Scope(value = "session", proxyMode = ScopedProxyMode.TARGET_CLASS) public OAuth2AccessToken getOAuth2AccessToken() { if (!(SecurityContextHolder.getContext().getAuthentication() instanceof OAuth2Authentication)) { return null; }//from w ww . jav a2 s.co m OAuth2Authentication oAuth2Authentication = (OAuth2Authentication) SecurityContextHolder.getContext() .getAuthentication(); final OAuth2AuthenticationDetails details = (OAuth2AuthenticationDetails) oAuth2Authentication.getDetails(); return new DefaultOAuth2AccessToken(details.getTokenValue()); }
From source file:com.tcloud.bee.key.server.mvc.controller.HomeController.java
/** * Simple controller for "/" that returns a Thymeleaf view. *///from w ww . ja v a2 s.co m @RequestMapping(value = "/", method = RequestMethod.GET) public String home(Locale locale, Model model) { logger.info("Welcome home! the client locale is " + locale.toString()); Authentication auth = SecurityContextHolder.getContext().getAuthentication(); logger.trace("Authentication principal: {}", auth.getPrincipal()); logger.trace("Authentication name: {}", auth.getName()); Date date = new Date(); DateFormat dateFormat = DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.LONG, locale); String formattedDate = dateFormat.format(date); model.addAttribute("serverTime", formattedDate); // model.addAttribute("echoService", echoService); model.addAttribute("someItems", new String[] { "one", "two", "three" }); return "home"; }
From source file:CRM.web.MishaSecurityController.java
@RequestMapping(value = "/403", method = RequestMethod.GET) public ModelAndView accessDenied() { ModelAndView model = new ModelAndView(); Authentication auth = SecurityContextHolder.getContext().getAuthentication(); if (!(auth instanceof AnonymousAuthenticationToken)) { UserDetails userDetail = (UserDetails) auth.getPrincipal(); System.out.println(userDetail); model.addObject("username", userDetail.getUsername()); }// ww w. j av a 2s .co m model.setViewName("403"); return model; }
From source file:de.pksoftware.springstrap.basic.service.BasicSecurityService.java
/** * Get the UserDetails of the current logged in Account. * @return/*from w ww .jav a 2 s . c o m*/ */ public static IAccount getCurrentUserDetails() { SecurityContext securityContext = SecurityContextHolder.getContext(); Authentication auth = securityContext.getAuthentication(); if (null != auth && !(auth instanceof AnonymousAuthenticationToken)) { return (IAccount) auth.getPrincipal(); } return null; }
From source file:net.paulgray.bbrest.security.CourseFilter.java
public void doFilter(ServletRequest request, ServletResponse response, FilterChain fc) throws IOException, ServletException { Logger.getLogger(CourseFilter.class.getName()).log(Level.INFO, "Calling Course Filter..."); String url = ((HttpServletRequest) request).getRequestURL().toString(); String course = getCourseIdFromUrl(url); Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); User user = (User) authentication.getDetails(); Id userId = BlackboardUtilities.getIdFromPk(user.getId(), blackboard.data.user.User.class); Id courseId = BlackboardUtilities.getIdFromPk(course, blackboard.data.course.Course.class); if (!SecurityUtil.userHasEntitlement(userId, courseId, new Entitlement("course.VIEW"))) { throw new AccessDeniedException( "Context user: '" + user.getUsername() + "' does not have access to view course: " + courseId); }/* www . j a v a 2s . com*/ }
From source file:com.orange.clara.cloud.servicedbdumper.security.AccessManager.java
protected SecurityContext getSecurityContextHolder() { return SecurityContextHolder.getContext(); }
From source file:org.obp.web.LoginController.java
@RequestMapping("/logoff") public String logout(ModelMap model) { model.addAttribute("loggedOut", true); logService.logUserLoggedOut(SecurityContextHolder.getContext().getAuthentication().getName()); return "login"; }
From source file:com.acme.portal.PortalController.java
@RequestMapping(value = "/info/user", method = RequestMethod.GET) public String handlerUserInfoRequest(Model model) { KeycloakAuthenticationToken authentication = (KeycloakAuthenticationToken) SecurityContextHolder .getContext().getAuthentication(); IDToken token = authentication.getAccount().getKeycloakSecurityContext().getIdToken(); model.addAttribute("token", token); model.addAttribute("claims", token.getOtherClaims()); return "info"; }
From source file:org.cloudfoundry.identity.uaa.security.DefaultSecurityContextAccessor.java
@Override public boolean isUser() { Authentication a = SecurityContextHolder.getContext().getAuthentication(); if (a instanceof OAuth2Authentication) { return !isClient(); }//from w w w .j av a2s. c o m if (a instanceof UaaAuthentication) { return true; } return false; }
From source file:org.jblogcms.core.security.controller.SecurityController.java
@RequestMapping(value = "/signout", method = RequestMethod.GET) public String signout(HttpServletRequest request, HttpServletResponse response) { Authentication auth = SecurityContextHolder.getContext().getAuthentication(); if (auth != null) { new SecurityContextLogoutHandler().logout(request, response, auth); }/*from w w w . j av a 2 s .c o m*/ return "redirect:/login"; }