private synchronized SSPToken getAuthenticationToken ( boolean forceUpdate ) throws MalformedURLException , RestClientException { if ( authenticationToken != null && ! authenticationToken . hasExpired ( ) && ! forceUpdate ) { return authenticationToken ; } String authString = getClientId ( ) + ":" + getClientSecret ( ) ; String authentication = new Base64 ( ) . encodeToString ( authString . getBytes ( ) ) ; HttpHeaders headers = new HttpHeaders ( ) ; headers . add ( AUTHORIZATION , BASIC + " " + authentication ) ; // form encode the grant_type... MultiValueMap < String , String > form = new LinkedMultiValueMap <> ( ) ; form . add ( GRANT_TYPE , CLIENT_CREDENTIALS ) ; HttpEntity < MultiValueMap < String , String > > request = new HttpEntity <> ( form , headers ) ; URL authURL = getAuthenticationURL ( ) ; authenticationToken = restTemplate . postForObject ( authURL . toExternalForm ( ) , request , SSPToken . class ) ; return authenticationToken ; }
Get the authentication token to use .