@Component("login")
public class LoginLogic {
private Login login;
public String efetuarLogin(HttpServletRequest req, HttpServletResponse res)throws ServletException, IOException ,AplicacaoException{
LoginRepository loginRepository = RepositoryFactory.getInstance().getLoginRepository();
try {
boolean retorno = loginRepository.efetuarLogin(req);
if (retorno == false) {
return "invalid";
}
return "ok";
} catch (Exception e) {
throw new AplicacaoException (e);
}
}
public void validateEfetuarLogin(ValidationErrors errors,HttpServletRequest req){
LoginRepository loginRepository = RepositoryFactory.getInstance().getLoginRepository();
try {
boolean retorno = loginRepository.efetuarLogin(req);
if (req.getParameter("loginTxt").isEmpty() ||req.getParameter("loginTxt") == null )
errors.add(new Message("Login", "Login está vazio!"));
if (req.getParameter("senhaTxt").isEmpty() || req.getParameter("senhaTxt") == null)
errors.add(new Message("senha", "Senha está vazia!"));
if (retorno == false && !req.getParameter("senhaTxt").isEmpty() && !req.getParameter("loginTxt").isEmpty())
errors.add(new Message("Usuario","Login e senha são inválidos!"));
} catch (Exception e) {
// TODO: Logger
}
}
}
public class LoginRepository extends Repository {
LoginDAO loginDAO = DAOFactory.getInstance().getLoginDao();
public boolean efetuarLogin(HttpServletRequest req) throws Exception {
return loginDAO.efetuarLogin(req);
}
}
public class LoginDAO {
private final static String hostname = "XXX.XX.XX.XX";
private final static String domain = "XX.XXX.XXX;";
private static String userName = null;
private static String pass = null;
public boolean efetuarLogin (HttpServletRequest req) throws Exception {
userName = req.getParameter("loginTxt");
pass = req.getParameter("senhaTxt");
try {
UniAddress dc = UniAddress.getByName(hostname);
NtlmPasswordAuthentication auth = new NtlmPasswordAuthentication(domain+userName+":"+pass);
SmbSession.logon(dc,auth);
return true;
} catch(SmbAuthException e) {
//Login inválido
e.printStackTrace();
return false;
}
}
}
<form method="post" action="/SRV/login.efetuarLogin.logic">
<table width="100%" cellspacing="1" align="center" class="table_form" >
<tr>
<th>Login:</th>
<td>
<input type="text" name="loginTxt" id="loginTxt" size="20" maxlength="20"/>
</td>
<th>Senha:</th>
<td>
<input type="password" name="senhaTxt" id="senhaTxt" size="20" maxlength="10"/>
</td>
</tr>
<tr>
<td colspan="6" align="right">
</td>
</tr>
<tr>
<td colspan="6" align="right">
<input type="submit" value="Pesquisar" class="input_submit"/>