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
14 package org.springframework.security.oauth2.provider.token;
15
16 import java.util.Map;
17
18 import org.springframework.security.core.Authentication;
19
20 /**
21 * Utility interface for converting a user authentication to and from a Map.
22 *
23 * @author Dave Syer
24 *
25 */
26 public interface UserAuthenticationConverter {
27
28 final String AUTHORITIES = AccessTokenConverter.AUTHORITIES;
29
30 final String USERNAME = "user_name";
31
32 /**
33 * Extract information about the user to be used in an access token (i.e. for resource servers).
34 *
35 * @param userAuthentication an authentication representing a user
36 * @return a map of key values representing the unique information about the user
37 */
38 Map<String, ?> convertUserAuthentication(Authentication userAuthentication);
39
40 /**
41 * Inverse of {@link #convertUserAuthentication(Authentication)}. Extracts an Authentication from a map.
42 *
43 * @param map a map of user information
44 * @return an Authentication representing the user or null if there is none
45 */
46 Authentication extractAuthentication(Map<String, ?> map);
47
48 }