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.cocoon.auth.impl;
18:
19: import java.io.Serializable;
20: import java.util.ArrayList;
21: import java.util.List;
22:
23: import org.apache.cocoon.auth.User;
24:
25: /**
26: * This class keeps track of the number of applications a user is logged into
27: * using the same security handler.
28: *
29: * @version $Id: LoginInfo.java 433543 2006-08-22 06:22:54Z crossley $
30: */
31: public class LoginInfo implements Serializable {
32:
33: /** Number of applications using the security handler. */
34: protected int counter;
35: /** The corresponding user. */
36: protected final User user;
37: /** The applications the user is logged in to. */
38: protected List applications = new ArrayList();
39:
40: /**
41: * Instantiate new info object.
42: * @param aUser The user object returned by the security handler.
43: */
44: public LoginInfo(final User aUser) {
45: this .user = aUser;
46: }
47:
48: /**
49: * Notification of another application using the handler.
50: * @param appName The application name.
51: */
52: public void incUsageCounter(final String appName) {
53: this .counter++;
54: this .applications.add(appName);
55: }
56:
57: /**
58: * Notification of an application that is not using the handler anymore.
59: * @param appName The application name.
60: */
61: public void decUsageCounter(final String appName) {
62: this .applications.remove(appName);
63: this .counter--;
64: }
65:
66: /**
67: * Is the handler used by any application.
68: * @return true if it's used, otherwise false.
69: */
70: public boolean isUsed() {
71: return (this .counter > 0);
72: }
73:
74: /**
75: * Return the corresponding user.
76: * @return The user generated by the security handler.
77: */
78: public User getUser() {
79: return this .user;
80: }
81:
82: /**
83: * Return the list of all applications.
84: * @return The list containing all applications this user is logged in to.
85: */
86: public List getApplications() {
87: return this.applications;
88: }
89: }
|