Example usage for org.springframework.security.core Authentication isAuthenticated

List of usage examples for org.springframework.security.core Authentication isAuthenticated

Introduction

In this page you can find the example usage for org.springframework.security.core Authentication isAuthenticated.

Prototype

boolean isAuthenticated();

Source Link

Document

Used to indicate to AbstractSecurityInterceptor whether it should present the authentication token to the AuthenticationManager.

Usage

From source file:ch.astina.hesperid.web.services.users.impl.UserServiceImpl.java

public User getCurrentUser() {
    Authentication auth = SecurityContextHolder.getContext().getAuthentication();
    if (auth.isAuthenticated() == false) {
        return null;
    }//from   w  ww .j  a v a2s. co  m
    String username = auth.getName();
    if (username.isEmpty()) {
        return null;
    }
    return userDao.getUserByName(username);
}

From source file:org.taverna.server.master.identity.AuthorityDerivedIDMapper.java

@Override
public String getUsernameForPrincipal(UsernamePrincipal user) {
    Authentication auth = SecurityContextHolder.getContext().getAuthentication();
    if (auth == null || !auth.isAuthenticated())
        return null;
    for (GrantedAuthority authority : auth.getAuthorities()) {
        String token = authority.getAuthority();
        if (token == null)
            continue;
        if (token.startsWith(prefix))
            return token.substring(prefix.length());
    }/*  w ww  . jav a 2s .c  o m*/
    return null;
}

From source file:com.seyren.core.security.AuthenticationTokenFilterTest.java

@Test
public void securityDisabledUserHasPermissionsFilterTest() throws Exception {
    when(seyrenConfig.isSecurityEnabled()).thenReturn(false);
    authenticationTokenFilter.doFilter(servletRequest, servletResponse, filterChain);
    Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
    assertEquals(authentication.isAuthenticated(), true);
}

From source file:org.jtalks.poulpe.security.AclAwareDecisionVoter.java

/**
 * Since SpringSecurity by default thinks of anonymous user as the one that is authenticated, we need to check a bit
 * more. First we check whether she's authenticated by SpringSecurity per se, and then we check whether {@link
 * UserDetails} is created which indicates that it's not an anonymous user.
 *
 * @param authentication to check whether it's an authenticated user and that it's not anonymous
 * @return true if the user is authenticated by SpringSecurity as an existing user, false if it's an anonymous or
 *         not authenticated user/*www  . ja  v  a  2 s  .com*/
 */
private boolean authenticatedAsUser(Authentication authentication) {
    return authentication.isAuthenticated() && authentication.getPrincipal() instanceof UserDetails;
}

From source file:org.cloudfoundry.identity.uaa.authentication.manager.ScopeAuthenticationManagerTest.java

public void testAuthenticate() throws Exception {
    UsernamePasswordAuthenticationToken userAuth = null;
    OAuth2Authentication auth = new OAuth2Authentication(request, userAuth);
    Authentication authentication = authenticationManager.authenticate(auth);
    assertTrue(authentication.isAuthenticated());
}

From source file:org.cloudfoundry.identity.uaa.authentication.manager.ScopeAuthenticationManagerTest.java

public void testPasswordAuthenticateSucceed() throws Exception {
    UsernamePasswordAuthenticationToken userAuth = new UsernamePasswordAuthenticationToken("username",
            "password");
    userAuth.setAuthenticated(true);/*  w w w.  j  a  v  a2s  .c  o m*/
    OAuth2Authentication auth = new OAuth2Authentication(request, userAuth);
    Authentication authentication = authenticationManager.authenticate(auth);
    assertTrue(authentication.isAuthenticated());
}

From source file:org.openeos.services.security.internal.SecurityManagerServiceImpl.java

@Override
public Principal getAuthenticatedPrincipal() {
    Authentication auth = SecurityContextHolder.getContext().getAuthentication();
    if (auth == null || !auth.isAuthenticated()) {
        // TODO/*from w w  w . j a  v a 2  s .  c  o  m*/
        throw new RuntimeException("Actually not user is logged in");
    }

    Object principal = auth.getPrincipal();
    if (principal instanceof InternalUser) {
        InternalUser userDetails = (InternalUser) principal;
        return new PrincipalImpl(userDetails.getId());
    } else {
        throw new RuntimeException("The class of principal is unknown");
    }
}

From source file:org.keycloak.adapters.springsecurity.userdetails.authentication.DirectAccessGrantUserDetailsAuthenticationProviderTest.java

@Ignore
@Test//from w w  w. j a  va2  s. c  o  m
public void testAuthenticate() throws Exception {
    Authentication authentication = provider.authenticate(token);
    assertNotNull(authentication);
    assertTrue(authentication.isAuthenticated());
}

From source file:ch.astina.hesperid.web.services.users.impl.UserServiceImpl.java

public boolean isAuthenticated() {
    Authentication auth = SecurityContextHolder.getContext().getAuthentication();
    return auth != null && auth.isAuthenticated() && auth.getName() != null && auth.getName().isEmpty() == false
            && auth.getName().equals(anonymousUsername) == false;
}

From source file:com.morevaadin.vaadin7.springsecurity.util.ViewChangeSecurityChecker.java

@Override
public boolean isViewChangeAllowed(ViewChangeEvent event) {

    if (event.getNewView() instanceof LoginView) {

        return true;
    }/*from  w ww.j  ava2 s . com*/

    Authentication authentication = SecurityContextHolder.getContext().getAuthentication();

    return authentication == null ? false : authentication.isAuthenticated();
}