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

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

Introduction

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

Prototype

public Object getSource() 

Source Link

Document

The object on which the Event initially occurred.

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 w ww .  j  av  a  2s.  c  om*/
    }
}