1 /* 2 * Cloud Foundry 2012.02.03 Beta 3 * Copyright (c) [2009-2012] VMware, Inc. All Rights Reserved. 4 * 5 * This product is licensed to you under the Apache License, Version 2.0 (the "License"). 6 * You may not use this product except in compliance with the License. 7 * 8 * This product includes a number of subcomponents with 9 * separate copyright notices and license terms. Your use of these 10 * subcomponents is subject to the terms and conditions of the 11 * subcomponent's license, as noted in the LICENSE file. 12 */ 13 package org.springframework.security.oauth2.provider.token; 14 15 import java.util.Map; 16 17 import org.springframework.security.oauth2.common.OAuth2AccessToken; 18 import org.springframework.security.oauth2.provider.OAuth2Authentication; 19 20 /** 21 * Converter interface for token service implementations that store authentication data inside the token. 22 * 23 * @author Dave Syer 24 * 25 */ 26 public interface AccessTokenConverter { 27 28 final String AUD = "aud"; 29 30 final String CLIENT_ID = "client_id"; 31 32 final String EXP = "exp"; 33 34 final String JTI = "jti"; 35 36 final String GRANT_TYPE = "grant_type"; 37 38 final String ATI = "ati"; 39 40 final String SCOPE = OAuth2AccessToken.SCOPE; 41 42 final String AUTHORITIES = "authorities"; 43 44 /** 45 * @param token an access token 46 * @param authentication the current OAuth authentication 47 * 48 * @return a map representation of the token suitable for a JSON response 49 * 50 */ 51 Map<String, ?> convertAccessToken(OAuth2AccessToken token, OAuth2Authentication authentication); 52 53 /** 54 * Recover an access token from the converted value. Half the inverse of 55 * {@link #convertAccessToken(OAuth2AccessToken, OAuth2Authentication)}. 56 * 57 * @param value the token value 58 * @param map information decoded from an access token 59 * @return an access token 60 */ 61 OAuth2AccessToken extractAccessToken(String value, Map<String, ?> map); 62 63 /** 64 * Recover an {@link OAuth2Authentication} from the converted access token. Half the inverse of 65 * {@link #convertAccessToken(OAuth2AccessToken, OAuth2Authentication)}. 66 * 67 * @param map information decoded from an access token 68 * @return an authentication representing the client and user (if there is one) 69 */ 70 OAuth2Authentication extractAuthentication(Map<String, ?> map); 71 72 }