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

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

Introduction

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

Prototype

Object getDetails();

Source Link

Document

Stores additional details about the authentication request.

Usage

From source file:de.pksoftware.springstrap.core.service.AccountServiceBase.java

/**
 * Triggered on account login./* ww w  . ja  v  a 2s.  c o  m*/
 * @param event The Spring interactive authentication event.
 * TODO implement lastLoginIp and lastVisitIp
 */
@Override
@Transactional
public void onApplicationEvent(InteractiveAuthenticationSuccessEvent event) {
    Authentication userAuth = event.getAuthentication();

    logger.info("Authenticated using {}", userAuth);

    String remoteAddress = null;

    WebAuthenticationDetails details = (WebAuthenticationDetails) userAuth.getDetails();
    if (null != details) {
        remoteAddress = details.getRemoteAddress();
    } else {
        logger.warn("Cannot determine remote address!");
    }

    IAccount account = (IAccount) userAuth.getPrincipal();

    ZonedDateTime now = ZonedDateTime.now();

    ZonedDateTime lastLoginDate = account.getLastLoginDate();
    String lastLoginIp = account.getLastLoginIp();

    if (null != lastLoginDate) {
        account.setLastVisitDate(lastLoginDate);
    }

    if (null != lastLoginIp) {
        account.setLastVisitIp(lastLoginIp);
    }

    account.setLastLoginDate(now);
    account.setLastLoginIp(remoteAddress);

    this.saveAccount(account);

    logger.info("SUCCESSFUL Authentication with {}", account);
}

From source file:org.jasig.springframework.security.portlet.authentication.PrimaryAttributePortletAuthenticationValidator.java

@Override
public boolean validate(Authentication authentication, PortletRequest request) {

    //get current request value
    String currentValue = preAuthenticationDetailsSource.getPrimaryUserAttribute(request);

    //get cached value
    final PrimaryAttributePortletAuthenticationDetails authenticationDetails = (PrimaryAttributePortletAuthenticationDetails) authentication
            .getDetails();/*from ww w .  j a v  a 2s .  c  o  m*/
    String cachedValue = authenticationDetails.getPrimaryAttribute();

    //return if those values changed or not
    return StringUtils.equals(currentValue, cachedValue);
}

From source file:ph.fingra.statisticsweb.service.MemberServiceImpl.java

public void update(Member member) {
    if (!StringUtils.isEmpty(member.getPassword())) {
        member.setPassword(passwordEncoder.encode(member.getPassword()));
    }//from   w  w  w.ja  v  a2 s .  c o m
    memberDao.update(member);
    UserDetails newPrincipal = new FingraphUser(get(member.getMemberid()));
    Authentication currentAuth = SecurityContextHolder.getContext().getAuthentication();
    UsernamePasswordAuthenticationToken newAuth = new UsernamePasswordAuthenticationToken(newPrincipal,
            currentAuth.getCredentials(), newPrincipal.getAuthorities());
    newAuth.setDetails(currentAuth.getDetails());
    SecurityContextHolder.getContext().setAuthentication(newAuth);
}

From source file:com.cfitzarl.cfjwed.core.security.CsrfValidatingFilter.java

@Override
public void doFilter(ServletRequest servletRequest, ServletResponse servletresponse, FilterChain chain)
        throws IOException, ServletException {
    HttpServletRequest request = (HttpServletRequest) servletRequest;
    HttpServletResponse response = (HttpServletResponse) servletresponse;

    Authentication authentication = SecurityContextWrapper.getAuthentication();
    String csrfToken = request.getHeader(SessionConstant.CSRF_TOKEN);

    if (!EXCLUDED_METHODS.contains(request.getMethod())) {
        if ((authentication != null) && (authentication instanceof UsernamePasswordAuthenticationToken)) {
            if (!authentication.getDetails().equals(csrfToken)) {
                throw new UnauthorizedException("Invalid or missing CSRF token");
            }// w  w w.j  a va2s  .c  om
        }
    }

    chain.doFilter(servletRequest, servletresponse);
}

From source file:com.vivastream.security.oauth2.provider.DynamoDBUserDetailsManager.java

protected Authentication createNewAuthentication(UserDetails user, Authentication currentAuth,
        String newPassword) {//from ww w .  ja v  a  2 s .com

    UsernamePasswordAuthenticationToken newAuthentication = new UsernamePasswordAuthenticationToken(user, null,
            user.getAuthorities());
    newAuthentication.setDetails(currentAuth.getDetails());

    return newAuthentication;
}

From source file:eu.freme.broker.security.AuthenticationFilter.java

private void processUsernamePasswordAuthentication(HttpServletResponse httpResponse, Optional<String> username,
        Optional<String> password) throws IOException {
    Authentication resultOfAuthentication = tryToAuthenticateWithUsernameAndPassword(username, password);
    SecurityContextHolder.getContext().setAuthentication(resultOfAuthentication);
    httpResponse.setStatus(HttpServletResponse.SC_OK);
    Token token = (Token) resultOfAuthentication.getDetails();
    TokenResponse tokenResponse = new TokenResponse(token.getToken());
    String tokenJsonResponse = new ObjectMapper().writeValueAsString(tokenResponse);
    httpResponse.addHeader("Content-Type", "application/json");
    httpResponse.getWriter().print(tokenJsonResponse);
}

From source file:org.xaloon.wicket.security.spring.SpringSecurityFacade.java

private AuthenticationToken authenticateInternal(AbstractAuthenticationToken authenticationRequestToken) {
    boolean authenticated = false;
    String name = authenticationRequestToken.getName();
    String errorMessage = null;/*from  ww  w .j a va  2  s  .co  m*/
    try {
        Authentication authentication = authenticationManager.authenticate(authenticationRequestToken);
        authenticated = authentication.isAuthenticated();
        if (authenticated && authentication.getDetails() == null) {
            // Try to load user details. Copy information into new token
            UsernamePasswordAuthenticationToken authenticationWithDetails = new UsernamePasswordAuthenticationToken(
                    authentication.getPrincipal(), authentication.getCredentials(),
                    authentication.getAuthorities());
            authenticationWithDetails.setDetails(userDao.getUserByUsername(authentication.getName()));
            authentication = authenticationWithDetails;
        }
        SecurityContextHolder.getContext().setAuthentication(authentication);
        name = authentication.getName();
    } catch (AuthenticationException e) {
        if (LOGGER.isWarnEnabled()) {
            LOGGER.warn("User " + name + " failed to login. Reason: ", e);
        }
        authenticated = false;
        errorMessage = e.getMessage();
    }
    if (authenticated) {
        return new AuthenticationToken(name, new ArrayList<AuthenticationAttribute>());
    }
    return new AuthenticationToken(name, errorMessage);
}

From source file:nl.surfnet.mujina.spring.SAMLResponseAuthenticationProvider.java

@Override
public Authentication authenticate(Authentication submitted) throws AuthenticationException {

    logger.debug("attempting to authenticate: {}", submitted);

    User user = assertionConsumer.consume((Response) submitted.getPrincipal());

    SAMLAuthenticationToken authenticated = new SAMLAuthenticationToken(user,
            (String) submitted.getCredentials(), user.getAuthorities());

    authenticated.setDetails(submitted.getDetails());

    logger.debug("Returning with authentication token of {}", authenticated);

    return authenticated;

}

From source file:nl.surfnet.spring.security.opensaml.SAMLResponseAuthenticationProvider.java

public Authentication authenticate(Authentication submitted) throws AuthenticationException {

    logger.debug("attempting to authenticate: {}", submitted);

    UserDetails user = assertionConsumer.consume((Response) submitted.getPrincipal());

    SAMLAuthenticationToken authenticated = new SAMLAuthenticationToken(user,
            (String) submitted.getCredentials(), user.getAuthorities());

    authenticated.setDetails(submitted.getDetails());

    logger.debug("Returning with authentication token of {}", authenticated);

    return authenticated;

}

From source file:es.mdef.clientmanager.ui.GestionClientesUI.java

private String getNombreUsuario() {
    String nombre = "";
    SecurityContext context = SecurityContextHolder.getContext();
    Authentication authentication = context.getAuthentication();
    if (authentication != null && authentication.isAuthenticated()
            && !authentication.getAuthorities().contains(new SimpleGrantedAuthority("ROLE_ANONYMOUS"))) {
        UserDetail userDetail = (UserDetail) authentication.getDetails();
        nombre = userDetail.getAppUser().getUserName();
    }// w  w w  .  j  a v  a 2 s.  com
    return nombre;
}