001    /*
002     * Cumulus4j - Securing your data in the cloud - http://cumulus4j.org
003     * Copyright (C) 2011 NightLabs Consulting GmbH
004     *
005     * This program is free software: you can redistribute it and/or modify
006     * it under the terms of the GNU Affero General Public License as
007     * published by the Free Software Foundation, either version 3 of the
008     * License, or (at your option) any later version.
009     *
010     * This program is distributed in the hope that it will be useful,
011     * but WITHOUT ANY WARRANTY; without even the implied warranty of
012     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
013     * GNU Affero General Public License for more details.
014     *
015     * You should have received a copy of the GNU Affero General Public License
016     * along with this program.  If not, see <http://www.gnu.org/licenses/>.
017     */
018    package org.cumulus4j.keymanager;
019    
020    import org.cumulus4j.keymanager.channel.KeyManagerChannelManager;
021    
022    /**
023     * <p>
024     * An <code>AppServer</code> represents a logical application server. This logical application server
025     * might be a cluster/cloud consisting of many physical machines.
026     * </p>
027     * <p>
028     * An <code>AppServer</code> knows how to contact the application server (or more precisely the key-manager-channel-REST-service
029     * running on this application server) in order to establish a communication channel. See
030     * <a target="_blank" href="http://cumulus4j.org/1.0.0/documentation/deployment-scenarios.html">Deployment scenarios</a>.
031     * </p>
032     * <p>
033     * Since {@link Session}s are managed per <code>AppServer</code> (in case one single key-store is used for multiple
034     * application servers), this serves as a scope for sessions (thus every <code>AppServer</code> has one instance of
035     * {@link SessionManager}).
036     * </p>
037     * <p>
038     * This is not API! Use the classes and interfaces provided by <code>org.cumulus4j.keymanager.api</code> instead.
039     * </p>
040     *
041     * @author Marco หงุ่ยตระกูล-Schulze - marco at nightlabs dot de
042     */
043    public class AppServer
044    {
045            private static final long serialVersionUID = 1L;
046    
047            private AppServerManager appServerManager;
048            private String appServerID;
049            private String appServerBaseURL;
050            private SessionManager sessionManager;
051            private KeyManagerChannelManager keyManagerChannelManager;
052    
053            public AppServer(AppServerManager appServerManager, String appServerID, String appServerBaseURL)
054            {
055                    if (appServerManager == null)
056                            throw new IllegalArgumentException("appServerManager == null");
057    
058    //              if (appServerID == null) // this is now allowed! the appServerID will be assigned when putting this into the AppServerManager.
059    //                      throw new IllegalArgumentException("appServerID == null");
060    
061                    if (appServerBaseURL == null)
062                            throw new IllegalArgumentException("appServerBaseURL == null");
063    
064                    this.appServerManager = appServerManager;
065                    this.appServerID = appServerID;
066                    this.appServerBaseURL = appServerBaseURL;
067                    this.sessionManager = new SessionManager(appServerManager.getKeyStore());
068                    this.keyManagerChannelManager = new KeyManagerChannelManager(sessionManager, appServerBaseURL);
069            }
070    
071            public String getAppServerID() {
072                    return appServerID;
073            }
074    
075            public void setAppServerID(String appServerID)
076            {
077                    if (this.appServerID != null && !this.appServerID.equals(appServerID))
078                            throw new IllegalArgumentException("this.appServerID is already assigned and new value differs from old value! Cannot modify it afterwards!");
079    
080                    this.appServerID = appServerID;
081            }
082    
083            public String getAppServerBaseURL() {
084                    return appServerBaseURL;
085            }
086    
087            public AppServerManager getAppServerManager() {
088                    return appServerManager;
089            }
090    
091            public SessionManager getSessionManager() {
092                    return sessionManager;
093            }
094    
095            public KeyManagerChannelManager getKeyManagerChannelManager() {
096                    return keyManagerChannelManager;
097            }
098    }