List of usage examples for org.springframework.security.core Authentication isAuthenticated
boolean isAuthenticated();
AuthenticationManager
. From source file:org.ng200.openolympus.SpringSecurityAuditorAware.java
@Override public User getCurrentAuditor() { final Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); if (authentication == null || !authentication.isAuthenticated()) { return null; }/*from ww w .ja v a 2s.c om*/ return this.userService.getUserByUsername(((Principal) authentication.getPrincipal()).getName()); }
From source file:eu.cloud4soa.frontend.commons.server.security.C4sSubjectImpl.java
@Override public boolean isLoggedIn() { Authentication authentication = getAuthentication(); return authentication.isAuthenticated() && authentication instanceof C4sUserAuthentication; }
From source file:org.ff4j.security.test.FlipSecurityTests2.java
@Test public void testIsAuthenticatedAndAuthorized() { // check authentication Authentication auth = SecurityContextHolder.getContext().getAuthentication(); Assert.assertTrue(auth.isAuthenticated()); // autorized because role ROLE_USER Assert.assertTrue(ff4j.check("first")); // not autorized because bad credential Assert.assertFalse(ff4j.check("third")); }
From source file:org.apache.nifi.minifi.c2.security.authentication.X509AuthenticationFilter.java
private void authenticateIfPossible(ServletRequest request) { if (!request.isSecure()) { return;/* w w w . j a v a2s .c o m*/ } X509Certificate[] certs = (X509Certificate[]) request.getAttribute("javax.servlet.request.X509Certificate"); if (certs == null || certs.length == 0) { if (logger.isDebugEnabled()) { logger.debug( "Unable to get certificates in request from " + HttpRequestUtil.getClientString(request)); } return; } Authentication authentication = authenticationManager.authenticate(new X509AuthenticationToken(certs)); if (authentication.isAuthenticated()) { SecurityContextHolder.getContext().setAuthentication(authentication); } }
From source file:de.uni_koeln.spinfo.maalr.login.LoginManager.java
public Authentication authenticate(Authentication authentication) throws AuthenticationException { if (authentication.isAuthenticated()) { return authentication; }/*w w w . j a va2 s .c o m*/ return login(authentication.getName(), (String) authentication.getCredentials()); }
From source file:org.ff4j.security.test.FlipSecurityTests.java
@Test public void testIsAuthenticatedAndAuthorized() { // check authentication Authentication auth = SecurityContextHolder.getContext().getAuthentication(); Assert.assertTrue(auth.isAuthenticated()); Assert.assertEquals("user1", ff4j.getAuthorizationsManager().getCurrentUserName()); // init//from w w w. j a va2s. co m // not autorized because bad credential Assert.assertFalse(ff4j.check("third")); // autorized because role ROLE_USER Assert.assertTrue(ff4j.check("first")); }
From source file:org.juiser.spring.security.user.SecurityContextUser.java
protected Authentication getValidAuthentication() { SecurityContext ctx = getSecurityContext(); if (ctx != null) { Authentication authc = ctx.getAuthentication(); if (authc != null && !(authc instanceof AnonymousAuthenticationToken) && authc.isAuthenticated()) { return authc; }/*w w w . j a v a 2 s.c o m*/ } return null; }
From source file:uk.co.caprica.bootlace.data.UsernameAuditor.java
@Override public String getCurrentAuditor() { logger.debug("getCurrentAuditor()"); Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); String result;//from w w w . ja va 2 s . c o m if (authentication != null && authentication.isAuthenticated()) { result = authentication.getName(); } else { result = null; } logger.debug("result={}", result); return result; }
From source file:ar.com.zauber.commons.auth.acegi.AbstractAcegiAuthenticationUserMapper.java
/** @return the username of the current session */ protected String getUsername() { final SecurityContext context = SecurityContextHolder.getContext(); String ret = null;/*from w ww .ja v a2 s .com*/ final Authentication auth = context.getAuthentication(); if (auth != null) { if (auth.isAuthenticated()) { final Object o = auth.getPrincipal(); if (o instanceof String) { ret = (String) o; } else { ret = ((UserDetails) auth.getPrincipal()).getUsername(); } Validate.notNull(ret); } else { throw new IllegalStateException("someone didn't " + "authenticate the user. Shame on ...!!"); } } return ret; }
From source file:com.hp.autonomy.frontend.configuration.authentication.IdolPreAuthenticatedAuthenticationProviderTest.java
@Test public void authenticateWithExistingUser() { when(userService.getUser(SAMPLE_USER, true)).thenReturn(new UserRoles(SAMPLE_USER)); final Authentication communityAuthentication = authenticationProvider.authenticate(authentication); assertTrue(communityAuthentication.isAuthenticated()); assertThat(communityAuthentication.getAuthorities(), hasSize(2)); }