vicker313 tech blog

November 5, 2010

Restrict IP coming to Tomcat Service

Filed under: Tomcat — Tags: , — vicker313 @ 8:24 pm

We can restrict incoming connection by IP address in Tomcat, for example we only allow connection from IP 10.10.10.* to access. We only need to add a valve tag in the context:

<Context>
<Valve className="org.apache.catalina.valves.RemoteAddrValve" allow="192\.168\.56\..*" deny="192\.168\.56\.1"/>
</Context>

It is quite straight forward: allow attribute to allow what IP pattern to go through, while deny is to block. The value of the attribute use regular expression. Another example of regular expression, 192.168.*.* need to set as 192\.168\..*\..*.

2 ways to do this: either you want to implement the restriction to all the applications, or to particular application. If you want to apply to all applications, put the tag in TOMCAT_HOME/conf/context.xml.

If you only want to apply the restriction to particular application, put the tag in TOMCAT_HOME/conf/catalina/locahost/<webapp>.xml. The name of the file follow the name of your web application. Create the file if it is not exist.

Enable or Disable All Constraints in MSSQL

Filed under: MSSQL — Tags: , — vicker313 @ 8:11 pm

There is no method provided by MSSQL to enable or disable all constraints of table in a go. However we can create a simple procedure to archive this goal. Use script below to create the procedure:

CREATE PROCEDURE sp_ConstraintState
@TblName VARCHAR(128),
@State BIT = 1
AS
DECLARE @SQLState VARCHAR(500)
IF @State = 0
BEGIN
SET @SQLState = 'ALTER TABLE '+ @TblName + ' NOCHECK CONSTRAINT ALL'
END
ELSE
BEGIN
SET @SQLState = 'ALTER TABLE ' + @TblName + ' CHECK CONSTRAINT ALL'
END
EXEC (@SQLState)
go

To execute the procedure, run script below:

sp_MsForEachTable 'sp_ConstraintState ''?'', 0'

sp_MsForEachTable is system defined procedure in MSSQL, to run the procedure created above in each table. o at the back is to disable, 1 is for enable.

Create a free website or blog at WordPress.com.