01: /*
02: * CoadunationLib: The coaduntion implementation library.
03: * Copyright (C) 2006 Rift IT Contracting
04: *
05: * This library is free software; you can redistribute it and/or
06: * modify it under the terms of the GNU Lesser General Public
07: * License as published by the Free Software Foundation; either
08: * version 2.1 of the License, or (at your option) any later version.
09: *
10: * This library is distributed in the hope that it will be useful,
11: * but WITHOUT ANY WARRANTY; without even the implied warranty of
12: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13: * Lesser General Public License for more details.
14: *
15: * You should have received a copy of the GNU Lesser General Public
16: * License along with this library; if not, write to the Free Software
17: * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18: *
19: * ClientInterceptor.java
20: *
21: * This object is responsible for supplying the authentication information on
22: * the client side of a connection for the request onto a server.
23: */
24:
25: // package path
26: package com.rift.coad.lib.interceptor;
27:
28: // the thread permission container
29: import com.rift.coad.lib.security.ThreadsPermissionContainer;
30: import com.rift.coad.lib.security.ThreadPermissionSession;
31: import com.rift.coad.lib.interceptor.credentials.Credential;
32: import com.rift.coad.lib.interceptor.credentials.Session;
33:
34: /**
35: * This object is responsible for supplying the authentication information on
36: * the client side of a connection for the request onto a server.
37: *
38: * @author Brett Chaldecott
39: */
40: public class ClientInterceptor {
41:
42: // the classes private member variables
43: private ThreadsPermissionContainer permissionContainer = null;
44:
45: /**
46: * Creates a new instance of ClientInterceptor
47: */
48: protected ClientInterceptor(
49: ThreadsPermissionContainer permissionContainer) {
50: this .permissionContainer = permissionContainer;
51: }
52:
53: /**
54: * This method retrieves the threads session credentials.
55: *
56: * @return The credentials for this session.
57: * @exception InterceptorException
58: */
59: public Credential getSessionCredential()
60: throws InterceptorException {
61: try {
62: ThreadPermissionSession permission = permissionContainer
63: .getSession();
64: Session session = new Session(permission.getUser()
65: .getName(), permission.getUser().getSessionId(),
66: permission.getPrincipals());
67: return session;
68: } catch (Exception ex) {
69: throw new InterceptorException(
70: "Failed to retrieve the session credentials : "
71: + ex.getMessage(), ex);
72: }
73: }
74:
75: }
|