01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17: package org.apache.jetspeed.security.activeauthentication;
18:
19: import java.util.List;
20:
21: import org.apache.jetspeed.cache.CacheElement;
22: import org.apache.jetspeed.cache.JetspeedCache;
23:
24: /**
25: * <p>
26: * AuthenticationCacheBeanImpl
27: * </p>
28: * <p>
29: * Short-lived cache implementation to bridge deficiencies in Java Login Modules and general Active Authentication patterns
30: * based on Java login modules. Caches Authentication information across redirects, requests, and threads. The life-time
31: * of this cached authentication information is meant to be very short lived.
32: * </p>
33: * @author <a href="mailto:taylor@apache.org">David Sean Taylor</a>
34: * @version $Id: $
35: *
36: */
37: public class ActiveAuthenticationIdentityProviderImpl implements
38: ActiveAuthenticationIdentityProvider {
39: JetspeedCache cache;
40: List sessionAttributes;
41:
42: public ActiveAuthenticationIdentityProviderImpl(
43: JetspeedCache cache, List sessionAttributes) {
44: this .cache = cache;
45: this .sessionAttributes = sessionAttributes;
46: }
47:
48: public IdentityToken createIdentityToken(String seed) {
49: String token = seed + "-"
50: + String.valueOf(System.currentTimeMillis());
51: return createToken(token);
52: }
53:
54: public IdentityToken createIdentityToken() {
55: String token = String.valueOf(System.currentTimeMillis());
56: return createToken(token);
57: }
58:
59: private IdentityToken createToken(String token) {
60: IdentityToken identityToken = new IdentityTokenImpl(token);
61: CacheElement element = cache
62: .createElement(token, identityToken);
63: cache.put(element);
64: return identityToken;
65: }
66:
67: public void completeAuthenticationEvent(String token) {
68: cache.remove(token);
69: }
70:
71: public List getSessionAttributeNames() {
72: return this.sessionAttributes;
73: }
74:
75: }
|