我要啦免费统计

Set Up DNS Tunnel Using Iodine

What is DNS Tunneling?

It can be useful when you can connect to a wifi network, but it requires you to log on through a web portal in order to access the Internet. This is very common when you are at a airport or a restaurant where they have wifi network without password, but once you try to access google.com, you will be redirectly to a login page. With DNS Tunneling, you don’t need to login and can still access the Internet.

Requirement

  • A remote server that you have root access
  • A domain name that you can configure its NS record and A record

Read More

Set Up Kafka On Windows (Actually Working)

In this tutorial, I will show how to set up and run Apache Kafka on Windows. Getting Kafka 0.8.1 running on Windows isn’t straightforward if you follow Apache Kafka’s documentation. They are somewhat misleading, and the bat files included in the Kafka package are significantly outdated and could not work properly. However, with correct instructions and updated bat files it’s easy and can be done under 10 minutes.

Kafka comes with two sets of scripts to run Kafka. In the bin folder, the sh files are used to set up Kafka in a Linux environment. In the bin\windows folder, there are also some bat files corresponds to those sh files which are supposed to work in a Windows environment. But these bat files are not well-maintained. For example, Kafka sh scripts merged kafka-list-topic.sh and kafka-create-topic.sh to kafka-topics.sh instead ago; but the windows bat files still uses the old kafka-list-topics.bat and kafka-create-topic.sh. Some say you can use Cygwin to execute the sh scripts in order to run Kafka. However, they are many additional steps involved, and in the end you may not get the desired outcome. With the correct bat files, there is no need to use Cygwin, and only Server JRE is required to run Kafka on Windows.

Step 0: Preparation

Install Java SE Server JRE

You need Java SE Server JRE in order to run Kafka. If you have JDK installed, you already have Server JRE installed, just check if the folder {JRE_PATH}\bin\server exists. If it is not, follow the following steps to install Java SE Server JRE:

  1. Download Java SE Server JRE from http://www.oracle.com/technetwork/java/javase/downloads/index.html

  2. Unpack it to a folder, for example C:\JREServer.

  3. Update the system environment variable PATH to include C:\JREServer\jre\bin, follow this guide provided by Java.

Download Kafka

  1. Download the binaries from http://kafka.apache.org/downloads.html

  2. Unpack it to a folder, for example C:\kafka

    Read More

Redirect After Session Timeout in Spring

Overview

Session management is a crucial part for web applications requires user login. If session is not managed properly, the security of data is directly impacted.

Define session timeout in web.xml

In your Spring configuration file, add the following property:

web.xml
1
2
3
<session-config>
<session-timeout>60</session-timeout>
</session-config>

Change the value in the session-timeout tag to the number of timeout minutes you want to set.

Read More

Load Dojo Modules Conditionally when using Spring Security

Scenario

In a JSP page, I want to load different Dojo modules defined in separate .js files according to the authorization roles determined by Spring Security.

At first glance, it seems that dojo/has fits my need. dojo/has provides feature detection with extensible API. So we can assign difference classes to the body element based on user’s authorization roles, and then define a test for dojo/has, that adds features based on whether the body contains a certain class or not.

Then, we can use

1
2
3
4
require(["dojo/has!feature?package/module:package/other"], function(featureModule){
// If feature is true, package/module loaded
// If feature is false, package/other loaded
});

to load modules conditionally.

However, a vital drawback of this method is that the check is done on the client side, which means the user can modify the body class on the client side to bypass the security mechanism and load the module that the user is not authorized to load. Thus Spring Security taglib is used instead in order to archive the goal.

Read More