List of usage examples for org.springframework.security.core Authentication isAuthenticated
boolean isAuthenticated();
AuthenticationManager
. From source file:org.apache.atlas.web.filters.AtlasKnoxSSOAuthenticationFilter.java
/** * Do not try to validate JWT if user already authenticated via other * provider// w ww . j a v a 2 s. c o m * * @return true, if JWT validation required */ private boolean isAuthenticated() { Authentication existingAuth = SecurityContextHolder.getContext().getAuthentication(); return !(!(existingAuth != null && existingAuth.isAuthenticated()) || existingAuth instanceof SSOAuthentication); }
From source file:org.apache.atlas.web.security.AtlasADAuthenticationProvider.java
@Override public Authentication authenticate(Authentication authentication) { Authentication auth = getADBindAuthentication(authentication); if (auth != null && auth.isAuthenticated()) { return auth; } else {/* w ww . j a va2s . c o m*/ auth = getADAuthentication(authentication); if (auth != null && auth.isAuthenticated()) { return auth; } } if (auth == null) { throw new AtlasAuthenticationException("AD Authentication Failed"); } return auth; }
From source file:org.apache.atlas.web.security.AtlasAuthenticationProvider.java
@Override public Authentication authenticate(Authentication authentication) throws AuthenticationException { if (ssoEnabled) { if (authentication != null) { authentication = getSSOAuthentication(authentication); if (authentication != null && authentication.isAuthenticated()) { return authentication; }/*from w w w . jav a 2 s . c o m*/ } } else { if (ldapType.equalsIgnoreCase("LDAP")) { try { authentication = ldapAuthenticationProvider.authenticate(authentication); } catch (Exception ex) { LOG.error("Error while LDAP authentication", ex); } } else if (ldapType.equalsIgnoreCase("AD")) { try { authentication = adAuthenticationProvider.authenticate(authentication); } catch (Exception ex) { LOG.error("Error while AD authentication", ex); } } else if (pamAuthenticationEnabled) { try { authentication = pamAuthenticationProvider.authenticate(authentication); } catch (Exception ex) { LOG.error("Error while PAM authentication", ex); } } } if (authentication != null) { if (authentication.isAuthenticated()) { return authentication; } else if (fileAuthenticationMethodEnabled) { // If the LDAP/AD/PAM authentication fails try the local filebased login method authentication = fileAuthenticationProvider.authenticate(authentication); if (authentication != null && authentication.isAuthenticated()) { return authentication; } } } LOG.error("Authentication failed."); throw new AtlasAuthenticationException("Authentication failed."); }
From source file:org.apache.atlas.web.security.AtlasLdapAuthenticationProvider.java
@Override public Authentication authenticate(Authentication authentication) throws AuthenticationException { try {/*w ww . j a va 2s . c om*/ authentication = getLdapBindAuthentication(authentication); if (authentication != null && authentication.isAuthenticated()) { return authentication; } else { authentication = getLdapAuthentication(authentication); if (authentication != null && authentication.isAuthenticated()) { return authentication; } } } catch (Exception e) { throw new AtlasAuthenticationException(e.getMessage(), e.getCause()); } return authentication; }
From source file:org.apache.atlas.web.security.AtlasPamAuthenticationProvider.java
@Override public Authentication authenticate(Authentication authentication) throws AuthenticationException { Authentication auth = getPamAuthentication(authentication); if (auth != null && auth.isAuthenticated()) { return auth; } else {/*from ww w . j ava 2 s .co m*/ throw new AtlasAuthenticationException("PAM Authentication Failed"); } }
From source file:org.apache.atlas.web.security.FileAuthenticationTest.java
@Test public void testValidUserLogin() { when(authentication.getName()).thenReturn("admin"); when(authentication.getCredentials()).thenReturn("admin"); Authentication auth = authProvider.authenticate(authentication); LOG.debug(" {}", auth); Assert.assertTrue(auth.isAuthenticated()); }
From source file:org.apache.atlas.web.security.FileAuthenticationTest.java
@Test public void testUserRoleMapping() { when(authentication.getName()).thenReturn("admin"); when(authentication.getCredentials()).thenReturn("admin"); Authentication auth = authProvider.authenticate(authentication); LOG.debug(" {}", auth); Assert.assertTrue(auth.isAuthenticated()); Collection<? extends GrantedAuthority> authorities = auth.getAuthorities(); String role = ""; for (GrantedAuthority gauth : authorities) { role = gauth.getAuthority();//from w ww.j a v a 2 s. c o m } Assert.assertTrue("ADMIN".equals(role)); }
From source file:org.apache.camel.component.spring.security.SpringSecurityAuthorizationPolicy.java
private Authentication authenticateIfRequired(Authentication authentication) { if (authentication.isAuthenticated() && !alwaysReauthenticate) { if (LOG.isDebugEnabled()) { LOG.debug("Previously Authenticated: " + authentication); }//w ww .jav a 2 s. c o m return authentication; } authentication = authenticationManager.authenticate(authentication); if (LOG.isDebugEnabled()) { LOG.debug("Successfully Authenticated: " + authentication); } return authentication; }
From source file:org.apache.nifi.kerberos.KerberosProvider.java
@Override public final AuthenticationResponse authenticate(final LoginCredentials credentials) throws InvalidLoginCredentialsException, IdentityAccessException { if (provider == null) { throw new IdentityAccessException("The Kerberos authentication provider is not initialized."); }//from www .j a v a2 s.c o m try { // Perform the authentication final UsernamePasswordAuthenticationToken token = new UsernamePasswordAuthenticationToken( credentials.getUsername(), credentials.getPassword()); logger.debug("Created authentication token for principal {} with name {} and is authenticated {}", token.getPrincipal(), token.getName(), token.isAuthenticated()); final Authentication authentication = provider.authenticate(token); logger.debug( "Ran provider.authenticate() and returned authentication for " + "principal {} with name {} and is authenticated {}", authentication.getPrincipal(), authentication.getName(), authentication.isAuthenticated()); return new AuthenticationResponse(authentication.getName(), credentials.getUsername(), expiration, issuer); } catch (final AuthenticationException e) { throw new InvalidLoginCredentialsException(e.getMessage(), e); } }
From source file:org.apache.nifi.registry.web.security.authentication.kerberos.KerberosIdentityProvider.java
@Override public AuthenticationResponse authenticate(AuthenticationRequest authenticationRequest) throws InvalidCredentialsException, IdentityAccessException { if (provider == null) { throw new IdentityAccessException("The Kerberos authentication provider is not initialized."); }/* www. j a v a 2s . c o m*/ try { // perform the authentication final String username = authenticationRequest.getUsername(); final Object credentials = authenticationRequest.getCredentials(); final String password = credentials != null && credentials instanceof String ? (String) credentials : null; // perform the authentication final UsernamePasswordAuthenticationToken token = new UsernamePasswordAuthenticationToken(username, credentials); logger.debug("Created authentication token " + token.toString()); final Authentication authentication = provider.authenticate(token); logger.debug( "Ran provider.authenticate(token) and returned authentication for " + "principal={} with name={} and isAuthenticated={}", authentication.getPrincipal(), authentication.getName(), authentication.isAuthenticated()); return new AuthenticationResponse(authentication.getName(), username, expiration, issuer); } catch (final AuthenticationException e) { throw new InvalidCredentialsException(e.getMessage(), e); } }