List of usage examples for org.springframework.security.core.context SecurityContextHolder getContext
public static SecurityContext getContext()
SecurityContext
. From source file:com.vdenotaris.spring.boot.security.saml.web.contollers.SSOController.java
@RequestMapping(value = "/idpSelection", method = RequestMethod.GET) public String idpSelection(HttpServletRequest request, Model model) { if (!(SecurityContextHolder.getContext().getAuthentication() instanceof AnonymousAuthenticationToken)) { LOG.warn("The current user is already logged."); return "redirect:/landing"; } else {//from ww w. j a v a 2 s. c o m if (isForwarded(request)) { Set<String> idps = metadata.getIDPEntityNames(); for (String idp : idps) LOG.info("Configured Identity Provider for SSO: " + idp); model.addAttribute("idps", idps); return "saml/idpselection"; } else { LOG.warn("Direct accesses to '/idpSelection' route are not allowed"); return "redirect:/"; } } }
From source file:org.italiangrid.storm.webdav.server.LogRequestFilter.java
@Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { chain.doFilter(request, response);/* w w w. j a v a2 s . c o m*/ SecurityContext ctxt = SecurityContextHolder.getContext(); HttpServletRequest req = (HttpServletRequest) request; HttpServletResponse res = (HttpServletResponse) response; String resMsg = String.format("%s %s %s %d [user:<%s>, authorities:<%s>]", req.getRemoteAddr(), req.getMethod(), req.getRequestURI(), res.getStatus(), ctxt.getAuthentication().getName(), ctxt.getAuthentication().getAuthorities()); log.info(resMsg); }
From source file:nl.surfnet.coin.selfservice.control.BaseControllerTest.java
@Before public void setUp() throws Exception { baseController = new TestController(); MockitoAnnotations.initMocks(this); SecurityContextHolder.getContext().setAuthentication(getAuthentication()); }
From source file:org.trustedanalytics.platformoperations.security.UserRoleVerifier.java
public boolean verifyIsAdmin() { if (userManagementOperations .getUserModel(/*from w ww . ja va 2 s . co m*/ "bearer " + tokenExtractor.apply(SecurityContextHolder.getContext().getAuthentication())) .getRole().equals(UserRole.ADMIN)) return true; throw new AccessDeniedException("You do not have permission to perform this action!"); }
From source file:de.tudarmstadt.ukp.clarin.webanno.webapp.home.security.LogoutPanel.java
@SuppressWarnings("serial") private void initialize() { add(new Label("username").setDefaultModel( new Model<String>(SecurityContextHolder.getContext().getAuthentication().getName()))); add(new Link("logout") { @Override/*from w w w. jav a 2s. c o m*/ public void onClick() { AuthenticatedWebSession.get().signOut(); setResponsePage(getApplication().getHomePage()); } }); }
From source file:com.morevaadin.vaadin7.springsecurity.ui.MainView.java
@Override public void navigateTo(String fragmentParameters) { String user = SecurityContextHolder.getContext().getAuthentication().getName(); label.setValue("Welcome to " + user); }
From source file:it.geosolutions.opensdi.operations.UserOperation.java
/** * Obtain run time directory//from w w w . j a v a 2 s . co m * * @return default directory if differentDirectoryByUser it's disabled or user * directory otherwise */ public String getRunTimeDir() { String dir = null; if (Boolean.TRUE.equals(differentDirectoryByUser)) { String username = SecurityContextHolder.getContext().getAuthentication().getName(); dir = GeoBatchRunInfoUtils.getRunDir(getDefaultBaseDir(), username); } else { dir = getDefaultBaseDir(); } return dir; }
From source file:jp.xet.uncommons.web.UsernameLogFilter.java
@Override protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException { SecurityContext ctx = SecurityContextHolder.getContext(); Authentication auth = ctx.getAuthentication(); boolean successfulRegistration = false; if (auth != null) { String username = auth.getName(); successfulRegistration = registerUsername(username); }//from w w w . j a va2 s .c om try { filterChain.doFilter(request, response); } finally { if (successfulRegistration) { MDC.remove(USER_KEY); } } }
From source file:com.sasav.blackjack.controller.AccountController.java
@RequestMapping(value = "/deposit", method = RequestMethod.POST) public ModelAndView deposit(AccountTransaction deposit) { Authentication auth = SecurityContextHolder.getContext().getAuthentication(); String login = auth.getName(); accountMaster.depositUserAccount(login, deposit.getAmount()); ModelAndView mv = new ModelAndView("redirect:game"); return mv;/* w w w.j av a 2 s.co m*/ }
From source file:org.unidle.social.SignInAdapterImpl.java
@Override public String signIn(final String userId, final Connection<?> connection, final NativeWebRequest request) { final Authentication authentication = new UsernamePasswordAuthenticationToken(userId, null); SecurityContextHolder.getContext().setAuthentication(authentication); final Cookie cookie = new Cookie(LAST_LOGIN_SOURCE.getName(), connection.createData().getProviderId()); cookie.setMaxAge(LAST_LOGIN_SOURCE.getMaxAgeAs(SECONDS)); cookie.setPath("/"); request.getNativeResponse(HttpServletResponse.class).addCookie(cookie); return null;//from w ww. j a va2 s . co m }