001: /*
002: * JOSSO: Java Open Single Sign-On
003: *
004: * Copyright 2004-2008, Atricore, Inc.
005: *
006: * This is free software; you can redistribute it and/or modify it
007: * under the terms of the GNU Lesser General Public License as
008: * published by the Free Software Foundation; either version 2.1 of
009: * the License, or (at your option) any later version.
010: *
011: * This software is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * Lesser General Public License for more details.
015: *
016: * You should have received a copy of the GNU Lesser General Public
017: * License along with this software; if not, write to the Free
018: * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
019: * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
020: */
021: package org.josso.gateway;
022:
023: import org.apache.commons.logging.Log;
024: import org.apache.commons.logging.LogFactory;
025: import org.josso.SecurityDomain;
026: import org.josso.gateway.identity.exceptions.NoSuchUserException;
027: import org.josso.gateway.session.SSOSession;
028: import org.josso.gateway.session.exceptions.NoSuchSessionException;
029: import org.josso.gateway.session.service.SSOSessionManager;
030:
031: import javax.management.MBeanException;
032: import javax.management.RuntimeOperationsException;
033: import java.io.IOException;
034: import java.io.InputStream;
035: import java.util.ArrayList;
036: import java.util.Collection;
037: import java.util.Iterator;
038: import java.util.Properties;
039:
040: /**
041: * TODO : Add class description.
042: *
043: * @author <a href="mailto:sgonzalez@josso.org">Sebastian Gonzalez Oyuela</a>
044: * @version $Id: SSOGatewayInfo.java 508 2008-02-18 13:32:29Z sgonzalez $
045: */
046: public class SSOGatewayInfo {
047:
048: private static final Log logger = LogFactory
049: .getLog(SSOGatewayInfo.class);
050:
051: private SecurityDomain domain;
052:
053: private Properties props;
054:
055: public SSOGatewayInfo(SecurityDomain domain) throws MBeanException,
056: RuntimeOperationsException {
057: super ();
058: this .domain = domain;
059: props = new Properties();
060: InputStream in = getClass().getResourceAsStream(
061: "/org/josso/josso.properties");
062: try {
063: props.load(in);
064: } catch (IOException e) {
065: logger.warn(e.getMessage(), e);
066: }
067: }
068:
069: public String getVersion() {
070: return props.getProperty("version");
071: }
072:
073: public String getFullName() {
074: return props.getProperty("fullname");
075: }
076:
077: public String getName() {
078: return props.getProperty("name");
079: }
080:
081: /**
082: * This is not realy used ...
083: *
084: * @deprecated this is not realy used by JOSSO.
085: */
086: public Long getMaxSessionCount() {
087: return new Long(1000);
088: }
089:
090: public Long getSessionCount() {
091: try {
092: return new Long(domain.getSessionManager()
093: .getSessionCount());
094: } catch (Exception e) {
095: logger.error(e.getMessage(), e);
096: }
097:
098: return new Long(0);
099: }
100:
101: public void invalidateAll() {
102: try {
103: domain.getSessionManager().invalidateAll();
104: } catch (Exception e) {
105: logger.error(e.getMessage(), e);
106: }
107: }
108:
109: public void invalidateUserSessions(String username) {
110: try {
111: SSOSessionManager sm = domain.getSessionManager();
112: Collection sessions = sm.getUserSessions(username);
113: for (Iterator iterator = sessions.iterator(); iterator
114: .hasNext();) {
115: SSOSession session = (SSOSession) iterator.next();
116: try {
117: sm.invalidate(session.getId());
118: } catch (NoSuchSessionException e) {
119: logger.warn("Alrady invalidated : "
120: + session.getId());
121: }
122: }
123: } catch (Exception e) {
124: logger.error(e.getMessage(), e);
125: }
126: }
127:
128: public void invalidateSession(String sessionId) {
129: try {
130: domain.getSessionManager().invalidate(sessionId);
131: } catch (Exception e) {
132: logger.error(e.getMessage(), e);
133: }
134: }
135:
136: public boolean userExists(String username) {
137: try {
138: domain.getIdentityManager().userExists(username);
139: return true;
140: } catch (NoSuchUserException e) {
141: return false;
142:
143: } catch (Exception e) {
144: logger.error(e.getMessage(), e);
145: }
146: return false;
147: }
148:
149: public void checkValidSessions() {
150: try {
151: domain.getSessionManager().checkValidSessions();
152: } catch (Exception e) {
153: logger.error(e.getMessage(), e);
154: }
155: }
156:
157: public Collection listUserSessions(String username) {
158: try {
159: return domain.getSessionManager().getUserSessions(username);
160: } catch (Exception e) {
161: logger.error(e.getMessage(), e);
162: }
163:
164: return new ArrayList(0);
165:
166: }
167:
168: public Collection listSessions() {
169:
170: try {
171: return domain.getSessionManager().getSessions();
172: } catch (Exception e) {
173: logger.error(e.getMessage(), e);
174: }
175:
176: return new ArrayList(0);
177: }
178:
179: }
|