tomcat是使用VALV的機制達成(類似filter),預設並無開啟,
若要開啟則須 修改conf\server.xml,找到
pattern="common" resolveHosts="false"/>
把前後包夾的註解符號拿掉後,存檔,重啟tomcat,便會在log目錄裡面看到
localhost_access_log.開頭的紀錄檔了。
INSERT INTO JBPM_ID_GROUP VALUES(2,'G','admin','security-role',NULL);
INSERT INTO JBPM_ID_GROUP VALUES(3,'G','user','security-role',NULL);
INSERT INTO JBPM_ID_GROUP VALUES(5,'G','manager','security-role',NULL);
INSERT INTO JBPM_ID_USER VALUES(1,'U','user','user@sample.domain','user');
INSERT INTO JBPM_ID_USER VALUES(2,'U','manager','manager@sample.domain','manager');
INSERT INTO JBPM_ID_USER VALUES(3,'U','admin','admin@sample.domain','admin');
INSERT INTO JBPM_ID_MEMBERSHIP VALUES(5,'M',NULL,NULL,1,3);
INSERT INTO JBPM_ID_MEMBERSHIP VALUES(6,'M',NULL,NULL,2,3);
INSERT INTO JBPM_ID_MEMBERSHIP VALUES(7,'M',NULL,NULL,3,3);
INSERT INTO JBPM_ID_MEMBERSHIP VALUES(8,'M',NULL,NULL,3,2);
INSERT INTO JBPM_ID_MEMBERSHIP VALUES(9,'M',NULL,NULL,2,2);
INSERT INTO JBPM_ID_MEMBERSHIP VALUES(10,'M',NULL,NULL,2,5);
....略....
<security-role>
<role-name>admin</role-name>
</security-role>
<security-role>
<role-name>user</role-name>
</security-role>
<security-role>
<role-name>participant</role-name>
</security-role>
....略....
<security-constraint>
<web-resource-collection>
<web-resource-name>Secure Area</web-resource-name>
<url-pattern>/app/*</url-pattern>
<http-method>GET</http-method>
<http-method>POST</http-method>
</web-resource-collection>
<auth-constraint>
<role-name>user</role-name>
<role-name>admin</role-name>
<role-name>participant</role-name>
</auth-constraint>
</security-constraint>
....略....
import java.io.IOException;
import java.io.PushbackInputStream;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import sun.nio.cs.StreamDecoder;
public class UnicodeInputStreamReader extends InputStreamReader {
private static final int BOM_SIZE = 4;
private final StreamDecoder decoder;
private PushbackInputStream pushBack;
private String encode;
private String defaultEnc;
public UnicodeInputStreamReader(InputStream input, String defaultEnc) throws UnsupportedEncodingException {
super(input);
try {
this.defaultEnc = defaultEnc;
this.pushBack = new PushbackInputStream(input, BOM_SIZE);
init();
} catch (Exception e) {
e.printStackTrace();
}
this.decoder = StreamDecoder.forInputStreamReader(this.pushBack, this, this.encode);
}
private void init() throws IOException {
byte[] bom = new byte[BOM_SIZE];
int n, unread;
// 初始讀取一次
n = this.pushBack.read(bom, 0, bom.length);
// 比對表頭
if ( (bom[0] == (byte) 0x00) && (bom[1] == (byte) 0x00) && (bom[2] == (byte) 0xFE) && (bom[3] == (byte) 0xFF) ) {
this.encode = "UTF-32BE";
unread = n - 4;
} else if ( (bom[0] == (byte) 0xFF) && (bom[1] == (byte) 0xFE) && (bom[2] == (byte) 0x00) && (bom[3] == (byte) 0x00) ) {
this.encode = "UTF-32LE";
unread = n - 4;
} else if ( (bom[0] == (byte) 0xEF) && (bom[1] == (byte) 0xBB) && (bom[2] == (byte) 0xBF) ) {
this.encode = "UTF-8";
unread = n - 3;
} else if ( (bom[0] == (byte) 0xFE) && (bom[1] == (byte) 0xFF) ) {
this.encode = "UTF-16BE";
unread = n - 2;
} else if ( (bom[0] == (byte) 0xFF) && (bom[1] == (byte) 0xFE) ) {
this.encode = "UTF-16LE";
unread = n - 2;
} else {
// 如果沒有找到任何表頭, 則退回長度等於原先總長
this.encode = this.defaultEnc;
unread = n;
}
// System.out.println("has BOM=" + ((unread == n) ? false : true) + ", encode=" + encode + ", read=" + n + ", unread=" + unread);
// 計算應該退回多少byte
if ( unread > 0 ) {
this.pushBack.unread(bom, (n - unread), unread);
}
}
public String getEncoding() {
return this.encode;
}
public int read() throws IOException {
return this.decoder.read();
}
public int read(char cbuf[], int offset, int length) throws IOException {
return this.decoder.read(cbuf, offset, length);
}
public boolean ready() throws IOException {
return this.decoder.ready();
}
public void close() throws IOException {
this.decoder.close();
}
}
import java.io.IOException;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
public class UTF8OutputStreamWriter extends OutputStreamWriter{
public UTF8OutputStreamWriter(OutputStream pos) throws IOException{
super(pos,"UTF-8");
// write UTF8 BOM mark if file is empty
final byte[] bom = new byte[] { (byte)0xEF, (byte)0xBB, (byte)0xBF };
pos.write(bom);
}
public UTF8OutputStreamWriter(OutputStream pos,String pencoding) throws IOException{
this(pos);
}
}