View Javadoc

1   /*
2    * SymmetricDS is an open source database synchronization solution.
3    *   
4    * Copyright (C) Dave Michels <dmichels2@users.sourceforge.net>,
5    *
6    * This library is free software; you can redistribute it and/or
7    * modify it under the terms of the GNU Lesser General Public
8    * License as published by the Free Software Foundation; either
9    * version 3 of the License, or (at your option) any later version.
10   *
11   * This library is distributed in the hope that it will be useful,
12   * but WITHOUT ANY WARRANTY; without even the implied warranty of
13   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14   * Lesser General Public License for more details.
15   *
16   * You should have received a copy of the GNU Lesser General Public
17   * License along with this library; if not, see
18   * <http://www.gnu.org/licenses/>.
19   */
20  
21  package org.jumpmind.symmetric.security.inet;
22  
23  import java.net.UnknownHostException;
24  import java.util.ArrayList;
25  import java.util.List;
26  
27  /***
28   * @author dmichels
29   */
30  public class InetAddressAuthorizerCompiler implements IInetAddressAuthorizerCompiler
31  {
32      Inet4AddressAuthorizerCompiler inet4Compiler = new Inet4AddressAuthorizerCompiler();
33  
34      Inet6AddressAuthorizerCompiler inet6Compiler = new Inet6AddressAuthorizerCompiler();
35  
36      /*
37       * (non-Javadoc)
38       * 
39       * @see org.jumpmind.symmetric.security.inet.IInetAddressFilterCompiler#compile(java.lang.String[])
40       */
41      public List<IRawInetAddressAuthorizer> compile(final String[] addresses) throws UnknownHostException
42      {
43          final List<String> inet4Addrs = new ArrayList<String>();
44          final List<String> inet6Addrs = new ArrayList<String>();
45          for (final String filter : addresses)
46          {
47              // check IPv4 or IPv6
48              if (filter.contains(":"))
49              {
50                  inet6Addrs.add(filter);
51              }
52              else
53              {
54                  inet4Addrs.add(filter);
55              }
56          }
57          final List<IRawInetAddressAuthorizer> rawFilters = inet4Compiler.compile(inet4Addrs
58              .toArray(new String[inet4Addrs.size()]));
59          rawFilters.addAll(inet6Compiler.compile(inet6Addrs.toArray(new String[inet6Addrs.size()])));
60  
61          return rawFilters;
62      }
63  
64  }