| 5110 |
mandeep.dh |
1 |
/**
|
|
|
2 |
*
|
|
|
3 |
*/
|
|
|
4 |
package in.shop2020.inventory.controllers;
|
|
|
5 |
|
|
|
6 |
import in.shop2020.serving.auth.InventoryAuthorizingRealm;
|
|
|
7 |
import in.shop2020.thrift.clients.HelperClient;
|
|
|
8 |
import in.shop2020.utils.HelperService.Client;
|
|
|
9 |
|
|
|
10 |
import org.apache.shiro.SecurityUtils;
|
|
|
11 |
import org.apache.shiro.crypto.hash.Sha256Hash;
|
|
|
12 |
import org.apache.struts2.convention.annotation.Result;
|
|
|
13 |
import org.apache.thrift.TException;
|
|
|
14 |
|
|
|
15 |
/**
|
|
|
16 |
* @author mandeep
|
|
|
17 |
* This class manages all the login related updates for a user.
|
|
|
18 |
*/
|
|
|
19 |
@Result(name="loginPage", location="/login.html")
|
|
|
20 |
public class LoginController extends BaseController {
|
|
|
21 |
|
|
|
22 |
/**
|
|
|
23 |
*
|
|
|
24 |
*/
|
|
|
25 |
private static final long serialVersionUID = 1L;
|
|
|
26 |
|
|
|
27 |
private String password;
|
|
|
28 |
|
|
|
29 |
public String updatePassword() throws TException
|
|
|
30 |
{
|
|
|
31 |
Client helperClient = new HelperClient().getClient();
|
|
|
32 |
helperClient.updatePasswordForAgent(SecurityUtils.getSubject().getPrincipal().toString(), new Sha256Hash(password).toHex());
|
|
|
33 |
addActionMessage("Password changed successfully!");
|
|
|
34 |
|
|
|
35 |
// Dummy call to reload agents
|
|
|
36 |
InventoryAuthorizingRealm.getAgent(-1);
|
|
|
37 |
return INDEX;
|
|
|
38 |
}
|
|
|
39 |
|
|
|
40 |
public String logout()
|
|
|
41 |
{
|
|
|
42 |
log.info("Logging out!");
|
|
|
43 |
SecurityUtils.getSubject().logout();
|
|
|
44 |
return "loginPage";
|
|
|
45 |
}
|
|
|
46 |
|
|
|
47 |
public String getPassword() {
|
|
|
48 |
return password;
|
|
|
49 |
}
|
|
|
50 |
|
|
|
51 |
public void setPassword(String password) {
|
|
|
52 |
this.password = password;
|
|
|
53 |
}
|
|
|
54 |
|
|
|
55 |
public static void main(String[] args) {
|
|
|
56 |
if (args != null && args.length != 0) {
|
|
|
57 |
System.out.println(new Sha256Hash(args[0]).toHex());
|
|
|
58 |
}
|
|
|
59 |
}
|
|
|
60 |
}
|