2 * (C) Copyright 2006-2007 Nuxeo SAS (http://nuxeo.com/) and contributors.
4 * All rights reserved. This program and the accompanying materials
5 * are made available under the terms of the GNU Lesser General Public License
6 * (LGPL) version 2.1 which accompanies this distribution, and is available at
7 * http://www.gnu.org/licenses/lgpl.html
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
15 * Nuxeo - initial API and implementation
17 * $Id: JOOoConvertPluginImpl.java 18651 2007-05-13 20:28:53Z sfermigier $
20 package org.collectionspace.hello.services.nuxeo;
21 import java.security.MessageDigest;
22 import java.security.NoSuchAlgorithmException;
23 import java.util.Date;
24 import java.util.HashMap;
26 import java.util.Random;
28 import com.noelios.restlet.util.Base64;
30 public class PortalSSOAuthenticationProvider {
32 private static final String TOKEN_SEP = ":";
34 private static final String TS_HEADER = "NX_TS";
36 private static final String RANDOM_HEADER = "NX_RD";
38 private static final String TOKEN_HEADER = "NX_TOKEN";
40 private static final String USER_HEADER = "NX_USER";
42 public static Map<String, String> getHeaders(String secretKey,
45 Map<String, String> headers = new HashMap<String, String>();
47 Date timestamp = new Date();
48 int randomData = new Random(timestamp.getTime()).nextInt();
50 String clearToken = timestamp.getTime() + TOKEN_SEP + randomData
51 + TOKEN_SEP + secretKey + TOKEN_SEP + userName;
56 hashedToken = MessageDigest.getInstance("MD5").digest(
57 clearToken.getBytes());
58 } catch (NoSuchAlgorithmException e) {
62 String base64HashedToken = Base64.encodeBytes(hashedToken);
64 headers.put(TS_HEADER, String.valueOf(timestamp.getTime()));
65 headers.put(RANDOM_HEADER, String.valueOf(randomData));
66 headers.put(TOKEN_HEADER, base64HashedToken);
67 headers.put(USER_HEADER, userName);