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.2.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 AppServerManager appServerManager; 046 private String appServerID; 047 private String appServerBaseURL; 048 private SessionManager sessionManager; 049 private KeyManagerChannelManager keyManagerChannelManager; 050 051 public AppServer(AppServerManager appServerManager, String appServerID, String appServerBaseURL) 052 { 053 if (appServerManager == null) 054 throw new IllegalArgumentException("appServerManager == null"); 055 056 // if (appServerID == null) // this is now allowed! the appServerID will be assigned when putting this into the AppServerManager. 057 // throw new IllegalArgumentException("appServerID == null"); 058 059 if (appServerBaseURL == null) 060 throw new IllegalArgumentException("appServerBaseURL == null"); 061 062 this.appServerManager = appServerManager; 063 this.appServerID = appServerID; 064 this.appServerBaseURL = appServerBaseURL; 065 this.sessionManager = new SessionManager(appServerManager.getKeyStore()); 066 this.keyManagerChannelManager = new KeyManagerChannelManager(sessionManager, appServerBaseURL); 067 } 068 069 public String getAppServerID() { 070 return appServerID; 071 } 072 073 public void setAppServerID(String appServerID) 074 { 075 if (this.appServerID != null && !this.appServerID.equals(appServerID)) 076 throw new IllegalArgumentException("this.appServerID is already assigned and new value differs from old value! Cannot modify it afterwards!"); 077 078 this.appServerID = appServerID; 079 } 080 081 public String getAppServerBaseURL() { 082 return appServerBaseURL; 083 } 084 085 public AppServerManager getAppServerManager() { 086 return appServerManager; 087 } 088 089 public SessionManager getSessionManager() { 090 return sessionManager; 091 } 092 093 public KeyManagerChannelManager getKeyManagerChannelManager() { 094 return keyManagerChannelManager; 095 } 096 }