Example #1
0
  public Node(HazelcastInstanceImpl hazelcastInstance, Config config, NodeContext nodeContext) {
    this.hazelcastInstance = hazelcastInstance;
    this.config = config;
    this.configClassLoader = config.getClassLoader();
    this.groupProperties = new GroupProperties(config);
    this.buildInfo = BuildInfoProvider.getBuildInfo();

    String loggingType = groupProperties.getString(GroupProperty.LOGGING_TYPE);
    loggingService =
        new LoggingServiceImpl(config.getGroupConfig().getName(), loggingType, buildInfo);
    final AddressPicker addressPicker = nodeContext.createAddressPicker(this);
    try {
      addressPicker.pickAddress();
    } catch (Throwable e) {
      throw ExceptionUtil.rethrow(e);
    }

    final ServerSocketChannel serverSocketChannel = addressPicker.getServerSocketChannel();
    try {
      address = addressPicker.getPublicAddress();
      final Map<String, Object> memberAttributes =
          findMemberAttributes(config.getMemberAttributeConfig().asReadOnly());
      localMember =
          new MemberImpl(
              address, true, createMemberUuid(address), hazelcastInstance, memberAttributes);
      loggingService.setThisMember(localMember);
      logger = loggingService.getLogger(Node.class.getName());
      hazelcastThreadGroup =
          new HazelcastThreadGroup(hazelcastInstance.getName(), logger, configClassLoader);
      nodeExtension = NodeExtensionFactory.create(configClassLoader);
      nodeExtension.beforeStart(this);

      serializationService = nodeExtension.createSerializationService();
      securityContext =
          config.getSecurityConfig().isEnabled() ? nodeExtension.getSecurityContext() : null;

      nodeEngine = new NodeEngineImpl(this);

      clientEngine = new ClientEngineImpl(this);
      connectionManager = nodeContext.createConnectionManager(this, serverSocketChannel);
      partitionService = new InternalPartitionServiceImpl(this);
      clusterService = new ClusterServiceImpl(this);
      textCommandService = new TextCommandServiceImpl(this);
      nodeExtension.printNodeInfo(this);
      multicastService =
          createMulticastService(addressPicker.getBindAddress(), this, config, logger);
      discoveryService = createDiscoveryService(config);
      initializeListeners(config);
      joiner = nodeContext.createJoiner(this);
    } catch (Throwable e) {
      try {
        serverSocketChannel.close();
      } catch (Throwable ignored) {
      }
      throw ExceptionUtil.rethrow(e);
    }
  }
  private static Config createConfig(String licenceKey) {
    Config config = new Config();
    config.setLicenseKey(licenceKey);
    config.setProperty("hazelcast.wait.seconds.before.join", "0");
    SecurityInterceptorConfig securityInterceptorConfig = new SecurityInterceptorConfig();
    securityInterceptorConfig.setClassName(MySecurityInterceptor.class.getName());
    SecurityConfig securityConfig = config.getSecurityConfig();
    securityConfig.setEnabled(true).addSecurityInterceptorConfig(securityInterceptorConfig);

    // when you enable security all client requests are denied, so we need to give permission first
    // security-interceptor will be run after checking this permission
    PermissionConfig permissionConfig =
        new PermissionConfig(PermissionConfig.PermissionType.ALL, "", null);
    securityConfig.addClientPermissionConfig(permissionConfig);
    return config;
  }
  @Test
  public void testSecurityInterceptorConfig() {
    String xml =
        HAZELCAST_START_TAG
            + "<security enabled=\"true\">"
            + "<security-interceptors>"
            + "<interceptor class-name=\"foo\"/>"
            + "<interceptor class-name=\"bar\"/>"
            + "</security-interceptors>"
            + "</security>"
            + "</hazelcast>";

    final Config config = buildConfig(xml);
    final SecurityConfig securityConfig = config.getSecurityConfig();
    final List<SecurityInterceptorConfig> interceptorConfigs =
        securityConfig.getSecurityInterceptorConfigs();
    assertEquals(2, interceptorConfigs.size());
    assertEquals("foo", interceptorConfigs.get(0).className);
    assertEquals("bar", interceptorConfigs.get(1).className);
  }
  @Test
  public void testSecurityInterceptorConfig() {
    String xml =
        "<hazelcast xmlns=\"http://www.hazelcast.com/schema/config\">"
            + "<security enabled=\"true\">"
            + "<security-interceptors>"
            + "<interceptor class-name=\"foo\"/>"
            + "<interceptor class-name=\"bar\"/>"
            + "</security-interceptors>"
            + "</security>"
            + "</hazelcast>";

    ByteArrayInputStream bis = new ByteArrayInputStream(xml.getBytes());
    XmlConfigBuilder configBuilder = new XmlConfigBuilder(bis);

    final Config config = configBuilder.build();
    final SecurityConfig securityConfig = config.getSecurityConfig();
    final List<SecurityInterceptorConfig> interceptorConfigs =
        securityConfig.getSecurityInterceptorConfigs();
    assertEquals(2, interceptorConfigs.size());
    assertEquals("foo", interceptorConfigs.get(0).className);
    assertEquals("bar", interceptorConfigs.get(1).className);
  }
Example #5
0
 public Node(HazelcastInstanceImpl hazelcastInstance, Config config, NodeContext nodeContext) {
   this.hazelcastInstance = hazelcastInstance;
   this.threadGroup = hazelcastInstance.threadGroup;
   this.config = config;
   configClassLoader = config.getClassLoader();
   this.groupProperties = new GroupProperties(config);
   SerializationService ss;
   try {
     ss =
         new SerializationServiceBuilder()
             .setClassLoader(configClassLoader)
             .setConfig(config.getSerializationConfig())
             .setManagedContext(hazelcastInstance.managedContext)
             .setHazelcastInstance(hazelcastInstance)
             .build();
   } catch (Exception e) {
     throw ExceptionUtil.rethrow(e);
   }
   serializationService = (SerializationServiceImpl) ss;
   systemLogService = new SystemLogService(groupProperties.SYSTEM_LOG_ENABLED.getBoolean());
   final AddressPicker addressPicker = nodeContext.createAddressPicker(this);
   try {
     addressPicker.pickAddress();
   } catch (Throwable e) {
     throw ExceptionUtil.rethrow(e);
   }
   final ServerSocketChannel serverSocketChannel = addressPicker.getServerSocketChannel();
   address = addressPicker.getPublicAddress();
   localMember = new MemberImpl(address, true, UuidUtil.createMemberUuid(address));
   String loggingType = groupProperties.LOGGING_TYPE.getString();
   loggingService =
       new LoggingServiceImpl(
           systemLogService, config.getGroupConfig().getName(), loggingType, localMember);
   logger = loggingService.getLogger(Node.class.getName());
   initializer = NodeInitializerFactory.create(configClassLoader);
   try {
     initializer.beforeInitialize(this);
   } catch (Throwable e) {
     try {
       serverSocketChannel.close();
     } catch (Throwable ignored) {
     }
     throw ExceptionUtil.rethrow(e);
   }
   securityContext =
       config.getSecurityConfig().isEnabled() ? initializer.getSecurityContext() : null;
   nodeEngine = new NodeEngineImpl(this);
   clientEngine = new ClientEngineImpl(this);
   connectionManager = nodeContext.createConnectionManager(this, serverSocketChannel);
   partitionService = new PartitionServiceImpl(this);
   clusterService = new ClusterServiceImpl(this);
   textCommandService = new TextCommandServiceImpl(this);
   initializer.printNodeInfo(this);
   buildNumber = initializer.getBuildNumber();
   VersionCheck.check(this, initializer.getBuild(), initializer.getVersion());
   JoinConfig join = config.getNetworkConfig().getJoin();
   MulticastService mcService = null;
   try {
     if (join.getMulticastConfig().isEnabled()) {
       MulticastConfig multicastConfig = join.getMulticastConfig();
       MulticastSocket multicastSocket = new MulticastSocket(null);
       multicastSocket.setReuseAddress(true);
       // bind to receive interface
       multicastSocket.bind(new InetSocketAddress(multicastConfig.getMulticastPort()));
       multicastSocket.setTimeToLive(multicastConfig.getMulticastTimeToLive());
       try {
         // set the send interface
         final Address bindAddress = addressPicker.getBindAddress();
         // http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4417033
         // http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6402758
         if (!bindAddress.getInetAddress().isLoopbackAddress()) {
           multicastSocket.setInterface(bindAddress.getInetAddress());
         }
       } catch (Exception e) {
         logger.warning(e);
       }
       multicastSocket.setReceiveBufferSize(64 * 1024);
       multicastSocket.setSendBufferSize(64 * 1024);
       String multicastGroup = System.getProperty("hazelcast.multicast.group");
       if (multicastGroup == null) {
         multicastGroup = multicastConfig.getMulticastGroup();
       }
       multicastConfig.setMulticastGroup(multicastGroup);
       multicastSocket.joinGroup(InetAddress.getByName(multicastGroup));
       multicastSocket.setSoTimeout(1000);
       mcService = new MulticastService(this, multicastSocket);
       mcService.addMulticastListener(new NodeMulticastListener(this));
     }
   } catch (Exception e) {
     logger.severe(e);
   }
   this.multicastService = mcService;
   initializeListeners(config);
   joiner = nodeContext.createJoiner(this);
 }