forked from projeto-siga/siga
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'pbdoc/develop' into bugfix/excecao-anexacao
- Loading branch information
Showing
4 changed files
with
106 additions
and
7 deletions.
There are no files selected for viewing
90 changes: 90 additions & 0 deletions
90
siga-base/src/main/java/br/gov/jfrj/siga/base/log/AccessLogger.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
package br.gov.jfrj.siga.base.log; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Enumeration; | ||
import java.util.logging.Logger; | ||
|
||
import javax.servlet.http.HttpServletRequest; | ||
|
||
import br.gov.jfrj.siga.model.ContextoPersistencia; | ||
|
||
public class AccessLogger { | ||
|
||
private static final Logger logger = Logger.getLogger(AccessLogger.class.getName()); | ||
|
||
private static final ArrayList<String> atributosOcultos = new ArrayList<String>() { | ||
{ | ||
add("meusDelegados"); | ||
add("meusTitulares"); | ||
add("identidadeCadastrante"); | ||
} | ||
}; | ||
|
||
|
||
public static void logAcesso(HttpServletRequest httpReq, String sigla) { | ||
|
||
StringBuffer caminho = httpReq.getRequestURL(); | ||
String parametros = httpReq.getQueryString() == null ? "" : "?" + httpReq.getQueryString(); | ||
caminho.append(parametros); | ||
|
||
StringBuffer requestInfo = new StringBuffer(); | ||
|
||
requestInfo.append("\n\n ----- Detalhes do Acesso -----\n"); | ||
|
||
requestInfo.append("\nURL: "); | ||
requestInfo.append(caminho); | ||
requestInfo.append("\n"); | ||
|
||
requestInfo.append("Método: "); | ||
requestInfo.append(httpReq.getMethod()); | ||
requestInfo.append("\n"); | ||
|
||
requestInfo.append("Session ID: "); | ||
requestInfo.append(httpReq.getRequestedSessionId() == null ? "indefinido" : httpReq.getRequestedSessionId()); | ||
requestInfo.append("\n"); | ||
|
||
requestInfo.append("User Principal: "); | ||
requestInfo.append(ContextoPersistencia.getUserPrincipal() == null ? "indefinido": ContextoPersistencia.getUserPrincipal()); | ||
requestInfo.append("\n"); | ||
|
||
requestInfo.append("Thread ID: "); | ||
requestInfo.append(Thread.currentThread().getId()); | ||
requestInfo.append("\n"); | ||
|
||
requestInfo.append("Thread Name: "); | ||
requestInfo.append(Thread.currentThread().getName()); | ||
requestInfo.append("\n"); | ||
|
||
requestInfo.append("Remote Host: "); | ||
requestInfo.append(httpReq.getRemoteHost()); | ||
requestInfo.append("\n"); | ||
|
||
requestInfo.append("Sigla: "); | ||
requestInfo.append(sigla); | ||
requestInfo.append("\n"); | ||
|
||
requestInfo.append("Atributos: \n"); | ||
Enumeration<String> attrs = httpReq.getAttributeNames(); | ||
while (attrs.hasMoreElements()) { | ||
String name = attrs.nextElement(); | ||
if (name.startsWith("org.jboss.weld") || atributosOcultos.contains(name)) | ||
continue; | ||
requestInfo.append("\t"); | ||
requestInfo.append(name); | ||
requestInfo.append(" : "); | ||
try { | ||
String a = httpReq.getAttribute(name).toString(); | ||
if (a != null && a.length() > 200) | ||
a = "[atributo encurtado] " + a.substring(0, 200) + "..."; | ||
requestInfo.append(a); | ||
} catch (Exception e) { | ||
requestInfo.append("não foi possível determinar: "); | ||
requestInfo.append(e.getMessage()); | ||
} | ||
requestInfo.append("\n"); | ||
} | ||
|
||
logger.info(requestInfo.toString()); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters