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:com.github.djabry.platform.vaadin.account.LoginAction.java

public void login(String username, String password) {
    security.login(username, password);//from  w  w w.jav  a  2 s .  c  o  m

    AccountEvent accountEvent = new AccountEvent();

    Authentication authentication = security.getAuthentication();
    if (authentication != null) {
        accountEvent.setAuthenticated(authentication.isAuthenticated());
    }

    UI.getCurrent().getNavigator().navigateTo(HomeView.VIEW_NAME);
    eventBus.publish(EventScope.SESSION, this, accountEvent);

}

From source file:fr.mycellar.interfaces.web.security.SecurityContextTokenRepository.java

public Token newToken(SecurityContext context) {
    Authentication auth = context.getAuthentication();
    if ((auth != null) && auth.isAuthenticated() && !(auth instanceof AnonymousAuthenticationToken)) {
        return keyBasedPersistenceTokenService.allocateToken(context.getAuthentication().getName());
    }/* ww w  . j  av  a 2s .  c  o  m*/
    return null;
}

From source file:ar.com.zauber.commons.auth.acegi.AbstractAcegiAuthenticationUserMapper.java

/** @see AuthenticationUserMapper#getRoles() */
public Set<String> getRoles() {
    final SecurityContext context = SecurityContextHolder.getContext();
    final Authentication auth = context.getAuthentication();
    final Set<String> ret = new HashSet<String>();
    if (auth.isAuthenticated()) {
        final Collection<GrantedAuthority> roles = auth.getAuthorities();
        for (final GrantedAuthority role : roles) {
            ret.add(role.getAuthority());
        }//from  w w w  .  j a va 2 s.c om
    }

    return ret;
}

From source file:io.galeb.core.entity.security.SpringSecurityAuditorAware.java

@Override
public String getCurrentAuditor() {

    Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
    String currentUser = "anonymousUser";

    if (authentication != null && authentication.isAuthenticated()) {
        Object principal = authentication.getPrincipal();
        if (principal instanceof UserDetails) {
            currentUser = ((UserDetails) principal).getUsername();
        } else {//  w ww  . j a va2s  . co  m
            currentUser = principal.toString();
        }
    }

    return currentUser;
}

From source file:no.dusken.momus.authentication.UserLoginServiceImpl.java

private boolean isAuthenticated(Authentication authentication) {
    return authentication != null && !(authentication instanceof AnonymousAuthenticationToken)
            && authentication.isAuthenticated();
}

From source file:org.meruvian.yama.service.DefaultSessionCredential.java

@Override
public org.meruvian.yama.repository.user.User getCurrentUser() {
    Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
    if (authentication == null || !authentication.isAuthenticated()) {
        return null;
    }/* w w w .jav  a2s.c om*/

    if (authentication.getPrincipal() instanceof DefaultUserDetails) {
        DefaultUserDetails user = (DefaultUserDetails) authentication.getPrincipal();
        return user.getUser();
    }

    return null;
}

From source file:de.tudarmstadt.ukp.csniper.webapp.security.SpringAuthenticatedWebSession.java

public SpringAuthenticatedWebSession(Request request) {
    super(request);
    injectDependencies();/*from w  w  w. jav  a  2s.  co  m*/
    ensureDependenciesNotNull();

    Authentication auth = SecurityContextHolder.getContext().getAuthentication();
    if (auth != null) {
        signIn(auth.isAuthenticated());
    }
}

From source file:com.jiwhiz.JiwhizBlogRestApiTestApplication.java

@Bean
public AuditorAware<String> auditorAware() {
    return new AuditorAware<String>() {
        public String getCurrentAuditor() {
            Authentication authentication = SecurityContextHolder.getContext().getAuthentication();

            if (authentication == null || !authentication.isAuthenticated()) {
                return null;
            }//from  w  w  w  .j  a  va 2s .  c o m

            return authentication.getName();
        }
    };
}

From source file:com.thesoftwareguild.flightmaster.debugging.AuthenticationEventListener.java

@Override
public void onApplicationEvent(AbstractAuthenticationEvent authenticationEvent) {
    if (authenticationEvent instanceof InteractiveAuthenticationSuccessEvent) {
        // ignores to prevent duplicate logging with AuthenticationSuccessEvent
        return;/*from  w  w w  .j  a v  a  2s .  com*/
    }
    Authentication authentication = authenticationEvent.getAuthentication();
    String auditMessage = "Login attempt with username: " + authentication.getName() + "\t\tSuccess: "
            + authentication.isAuthenticated();
    logger.info(auditMessage);
}

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

public void testPasswordAuthenticate() throws Exception {
    UsernamePasswordAuthenticationToken userAuth = new UsernamePasswordAuthenticationToken("username",
            "password");
    OAuth2Authentication auth = new OAuth2Authentication(request, userAuth);
    Authentication authentication = authenticationManager.authenticate(auth);
    //false since we don't authenticate the user yet
    assertFalse(authentication.isAuthenticated());
}