1 45 package org.openejb.server; 46 47 import java.io.*; 48 import java.net.*; 49 import java.util.*; 50 import org.openejb.*; 51 52 65 public class ServiceAccessController implements ServerService { 66 67 ServerService next; 68 69 InetAddress[] allowedHosts; 70 71 public ServiceAccessController(ServerService next){ 72 this.next = next; 73 } 74 75 82 public void init(Properties props) throws Exception { 83 parseAdminIPs(props); 85 86 next.init(props); 88 } 89 90 public void start() throws ServiceException{ 91 93 next.start(); 95 } 96 97 public void stop() throws ServiceException{ 98 100 next.stop(); 102 } 103 104 public void service(Socket socket) throws ServiceException, IOException{ 105 next.service(socket); 110 } 111 112 public void service(InputStream in, OutputStream out) throws ServiceException, IOException { 113 throw new UnsupportedOperationException ("service(in,out)"); 114 } 115 116 117 public String getName(){ 118 return next.getName(); 119 } 120 121 125 public String getIP(){ 126 return next.getIP(); 127 } 128 129 133 public int getPort(){ 134 return next.getPort(); 135 } 136 137 138 public void checkHostsAuthorization(InetAddress client, InetAddress server) throws SecurityException { 139 boolean authorized = false; 143 144 authorized = client.equals( server ); 148 149 for (int i=0; i < allowedHosts.length && !authorized; i++){ 150 authorized = allowedHosts[i].equals( client ); 151 } 152 153 if ( !authorized ) { 154 throw new SecurityException ("Host "+client.getHostAddress()+" is not authorized to access this service."); 155 } 156 } 157 158 private void parseAdminIPs(Properties props){ 159 try{ 160 161 Vector addresses = new Vector(); 162 163 InetAddress[] localIps = InetAddress.getAllByName("localhost"); 164 for (int i=0; i < localIps.length; i++){ 165 addresses.add( localIps[i] ); 166 } 167 168 String ipString = props.getProperty("only_from"); 169 if (ipString != null) { 170 StringTokenizer st = new StringTokenizer(ipString, " ,"); 171 while (st.hasMoreTokens()) { 172 String address = null; 173 InetAddress ip = null; 174 try{ 175 address = st.nextToken(); 176 ip = InetAddress.getByName(address); 177 addresses.add( ip ); 178 } catch (Exception e){ 179 } 181 } 182 } 183 184 allowedHosts = new InetAddress[ addresses.size() ]; 185 addresses.copyInto( allowedHosts ); 186 187 } catch (Exception e){ 188 } 190 } 191 192 } 193
| Popular Tags
|