Example usage for org.springframework.security.access.event AuthorizedEvent getAuthentication

List of usage examples for org.springframework.security.access.event AuthorizedEvent getAuthentication

Introduction

In this page you can find the example usage for org.springframework.security.access.event AuthorizedEvent getAuthentication.

Prototype

public Authentication getAuthentication() 

Source Link

Usage

From source file:com.muk.security.AuthEventListener.java

@Override
public void onApplicationEvent(AuthorizedEvent event) {
    final Exchange exchange = (Exchange) event.getSource();

    if (!RestConstants.Rest.anonymousToken.equals(event.getAuthentication().getName())
            && exchange.getIn().getHeader(HttpHeaders.AUTHORIZATION, String.class) != null) {
        final Authentication currentAuthentication = event.getAuthentication();
        final String currentTokenRepresentation = (String) currentAuthentication.getCredentials();
        final String incomingTokenRepresentation = StringUtils
                .substringAfter(exchange.getIn().getHeader(HttpHeaders.AUTHORIZATION, String.class), "Bearer ");

        if (!currentTokenRepresentation.equals(incomingTokenRepresentation)) {
            exchange.getOut().getHeaders().put(RestConstants.Headers.refreshToken, currentTokenRepresentation);
        }//from   ww w  .ja v  a2  s.  c  o  m
    }
}