4
I have Java Web application, but I want to do the following:
When I log into my application with a certain user then I need to do some operations, such as saving some information in the database, only I want that at the time of doing this insertion I capture which user did this insertion, I want to get the usual. How can I do that?
Code of the button I insert:
<p:commandLink id="btn_save_users_modal"
action="#{messageBean.insert()}"
styleClass="btn btn-success"
update=":message_form"
validateClient="true">
<i class="fa fa-check fa-fw" /> #{bundle['system.ui.label.save']}
</p:commandLink>
Method below messageBean.insert()
makes the insertion:
public void insert() {
try {
messageFacade.save(message);
} catch (Exception e) {
e.printStackTrace();
}
}
Here, for example, I want to insert this object of mine message
and along with the user I just logged into my page.
I want to know which user did this insertion according to each user who logs in to my page.
This is my login() method, when right on the page makes some validations.
public String doLogin() {
// Força a JVM para pt-BR, assim a formatação numérica fica no formato
// brasileiro
Locale.setDefault(new Locale("pt", "BR"));
// Validações
if (this.username == null || this.username.equals("")) {
MessageGrowl.warn(
MessageProperties.getString("message.loginVazio"), false);
} else if (this.password == null || this.password.equals("")) {
MessageGrowl
.warn(MessageProperties.getString("message.passwordVazio"),
false);
} else {
// String hashedPassword = SecurityUtils.getHashedString(password);
this.loggedUser = loginUserFacade.getValideUser(username,password);
if (this.loggedUser != null) {
isAuthenticated = true;
redirectIfAlreadyLogged();
}
else {
MessageGrowl.error(MessageProperties
.getString("login.autenticacao"));
clear();
}
}
return "";
}
Ivan, post your login code to the system and remember to hide any information that might compromise your application’s security.
– Maicon Carraro
Why do you want to do an Audit on your system ? If that is your question follow link. https://michelzanini.wordpress.com/2008/09/22/aop-na-pratica/
– Luã Govinda Mendes Souza
I edited my question by putting the login method()
– Ivan