List of usage examples for org.springframework.security.core Authentication getName
public String getName();
From source file:cherry.sqlman.tool.clause.SqlClauseControllerImpl.java
private void initializeForm(SqlClauseForm form, Integer ref, Authentication auth) { if (ref != null) { SqlMetadataForm mdForm = metadataService.findById(ref, auth.getName()); if (mdForm != null) { SqlClauseForm f = clauseService.findById(ref); if (f != null) { form.setDatabaseName(f.getDatabaseName()); form.setSelect(f.getSelect()); form.setFrom(f.getFrom()); form.setWhere(f.getWhere()); form.setGroupBy(f.getGroupBy()); form.setHaving(f.getHaving()); form.setOrderBy(f.getOrderBy()); form.setParamMap(f.getParamMap()); form.setLockVersion(f.getLockVersion()); return; }// w ww .j a v a 2 s .c o m } } form.setDatabaseName(dataSourceDef.getDefaultName()); }
From source file:de.blizzy.documentr.web.access.UserController.java
@RequestMapping(value = "/delete/{loginName:" + DocumentrConstants.USER_LOGIN_NAME_PATTERN + "}", method = RequestMethod.GET) @PreAuthorize("hasApplicationPermission(ADMIN) and !isAdmin(#loginName)") public String deleteUser(@PathVariable String loginName, Authentication authentication) throws IOException { User user = userStore.getUser(authentication.getName()); userStore.deleteUser(loginName, user); return "redirect:/users"; //$NON-NLS-1$ }
From source file:org.jasig.springframework.security.portlet.authentication.PortletAuthenticationProcessingFilterTest.java
@Test public void userIsReauthenticatedIfPrincipalChangesAndCheckForPrincipalChangesIsSet() throws Exception { MockRenderRequest request = new MockRenderRequest(); MockRenderResponse response = new MockRenderResponse(); FilterChain chain = mock(FilterChain.class); PortletAuthenticationProcessingFilter filter = new PortletAuthenticationProcessingFilter(); filter.setAuthenticationManager(createAuthenticationManager()); filter.setAuthenticationDetailsSource(createAuthenticationDetailsSource()); filter.setCheckForPrincipalChanges(true); filter.afterPropertiesSet();/*ww w .ja va 2s. c o m*/ request.setRemoteUser("cat"); filter.doFilter(request, response, chain); request = new MockRenderRequest(); request.setRemoteUser("dog"); filter.doFilter(request, response, chain); Authentication dog = SecurityContextHolder.getContext().getAuthentication(); assertNotNull(dog); assertEquals("dog", dog.getName()); // Make sure authentication doesn't occur every time (i.e. if the header *doesn't change) filter.setAuthenticationManager(mock(AuthenticationManager.class)); filter.doFilter(request, response, chain); assertSame(dog, SecurityContextHolder.getContext().getAuthentication()); }
From source file:com.mothsoft.alexis.web.security.TermsOfServiceFilter.java
@Override protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain chain) throws ServletException, IOException { final HttpSession session = request.getSession(false); final Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); if (authentication == null || !authentication.isAuthenticated() || ANONYMOUS_USER.equals(authentication.getName()) || isStaticContent(request)) { chain.doFilter(request, response); return;// w w w.jav a 2 s . c om } if (session.getAttribute(TOS_KEY) == null) { final UserAuthenticationDetails details = (UserAuthenticationDetails) SecurityContextHolder.getContext() .getAuthentication().getPrincipal(); final Long userId = details.getUserId(); final User user = this.userService.getUser(userId); if (user.getTosAcceptDate() != null) { session.setAttribute(TOS_KEY, user.getTosAcceptDate()); } } if (session.getAttribute(TOS_KEY) == null && !request.getRequestURI().equals(TERMS_OF_SERVICE_URI)) { response.sendRedirect(TERMS_OF_SERVICE_URI); return; } chain.doFilter(request, response); }
From source file:uk.ac.ebi.emma.manager.AbstractManager.java
protected Session getCurrentSession() { if (username == null) { SecurityContext securityContext = SecurityContextHolder.getContext(); if (securityContext == null) throw new RuntimeException("AbstractManager.getCurrentSession(): securityContext is null."); Authentication authentication = securityContext.getAuthentication(); if (authentication == null) throw new RuntimeException("AbstractManager.getCurrentSession(): authentication is null."); String name = authentication.getName(); if (name == null) throw new RuntimeException("AbstractManager.getCurrentSession(): name is null."); username = name;/* w ww.ja va 2 s .c o m*/ } return sessionFactory.getCurrentSession(); }
From source file:org.ligoj.app.http.security.RestAuthenticationProviderTest.java
@Test public void authenticateMixedCase() { httpServer.stubFor(post(urlPathEqualTo("/")).willReturn(aResponse().withStatus(HttpStatus.SC_NO_CONTENT))); httpServer.start();// w w w . j a va 2 s . c o m final Authentication authentication = authenticate("http://localhost", "jUniT"); Assertions.assertNotNull(authentication); Assertions.assertEquals("junit", authentication.getName()); Assertions.assertEquals("junit", authentication.getPrincipal().toString()); }
From source file:fr.univrouen.poste.web.ProfilChoiceController.java
@RequestMapping public String profilChoice(@RequestParam(required = false) String profil) { Authentication auth = SecurityContextHolder.getContext().getAuthentication(); List<GrantedAuthority> authorities = new ArrayList<GrantedAuthority>(auth.getAuthorities()); if (profil != null) { logger.info(auth.getName() + " a slectionn le profil " + profil); if ("membre".equals(profil)) { authorities.remove(new GrantedAuthorityImpl("ROLE_CANDIDAT")); }/*w ww. j a va2 s .c o m*/ if ("candidat".equals(profil)) { authorities.remove(new GrantedAuthorityImpl("ROLE_MEMBRE")); } auth = new UsernamePasswordAuthenticationToken(auth.getPrincipal(), auth.getCredentials(), authorities); SecurityContextHolder.getContext().setAuthentication(auth); } if (auth.getAuthorities().contains(new GrantedAuthorityImpl("ROLE_CANDIDAT")) && auth.getAuthorities().contains(new GrantedAuthorityImpl("ROLE_MEMBRE"))) { return "profilChoice"; } else { return "index"; } }
From source file:com.castlemock.web.basis.service.ServiceProcessorImpl.java
/** * Get the current logged in user username * @return The username of the current logged in user * @see User// w w w . java2 s. co m */ protected String getLoggedInUsername() { final Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); if (authentication == null) { return UNKNOWN_USER; } return authentication.getName(); }
From source file:it.geosolutions.geostore.services.rest.SecurityTest.java
protected void springAuthenticationTest() { doAutoLogin("admin", "admin", null); assertNotNull(SecurityContextHolder.getContext()); assertNotNull(SecurityContextHolder.getContext().getAuthentication()); final Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); authentication.getName(); assertEquals("admin", authentication.getCredentials()); Object principal = authentication.getPrincipal(); assertNotNull(principal);/* w w w . j a v a 2 s. co m*/ if (principal instanceof User) { User user = (User) principal; assertEquals("admin", user.getName()); } else if (principal instanceof LdapUserDetailsImpl) { LdapUserDetailsImpl userDetails = (LdapUserDetailsImpl) principal; assertEquals("uid=admin,ou=people,dc=geosolutions,dc=it", userDetails.getDn()); } assertEquals(authentication.getAuthorities().size(), 1); for (GrantedAuthority authority : authentication.getAuthorities()) { assertEquals("ROLE_ADMIN", authority.getAuthority()); } }
From source file:com.cruz.sec.config.MyAuthenticationProvider.java
@Override public Authentication authenticate(Authentication authentication) throws AuthenticationException { System.out.println("Entrando a la verificacin del usuario"); System.out.println("Nombre de usuario: " + authentication.getName()); UserDetails userDetails = (UserDetails) this.customJDBCDaoImpl.loadUserByUsername(authentication.getName()); if (userDetails.isEnabled()) { Object salt = null;// w w w. j a v a 2 s.c o m if (this.saltSource != null) { salt = saltSource.getSalt(userDetails); } if (shaPasswordEncoder.isPasswordValid(userDetails.getPassword(), authentication.getCredentials().toString(), salt)) { //Verifico si el usuario ya tiene una sesin abierta, si es as la cierro y le creo su nueva instancia verifUserInSession(userDetails.getUsername()); return new UsernamePasswordAuthenticationToken(userDetails, null, userDetails.getAuthorities()); } throw new BadCredentialsException("Bad credentials"); } else { throw new DisabledException("User disabled"); } }