Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package edu.ncsu.csc.itrust.action;
import edu.ncsu.csc.itrust.beans.SecurityQA;
import edu.ncsu.csc.itrust.dao.DAOFactory;
import edu.ncsu.csc.itrust.dao.mysql.AuthDAO;
import edu.ncsu.csc.itrust.exception.ITrustException;
import edu.ncsu.csc.itrust.validate.SecurityQAValidator;
/**
* Handles setting and retrieving the security questions/answers for users Used by
* patient/editMyDemographics.jsp, staff/editMyDemographics.jsp, staff/editPersonnell.jsp
*
*
*/
public class SetSecurityQuestionAction {
private AuthDAO authDAO;
private long loggedInMID;
/**
* Sets up defaults
*
* @param factory The DAOFactory used to create the DAOs used in this action.
* @param rLoggedInMID The MID of the user who is setting their security question.
* @throws ITrustException
*/
public SetSecurityQuestionAction(DAOFactory factory, long rLoggedInMID) throws ITrustException {
this.authDAO = factory.getAuthDAO();
loggedInMID = checkMID(rLoggedInMID);
}
/**
* Updates information in the database from the information held in the SecurityQA bean passed as a param
*
* @param a
* SecurityQuestionBean that holds new information
* @throws Exception
*/
public void updateInformation(SecurityQA a) throws Exception {
SecurityQAValidator sqav = new SecurityQAValidator();
sqav.validate(a);
authDAO.setSecurityQuestionAnswer(a.getQuestion(), a.getAnswer(), loggedInMID);
}
/**
* Returns a SecurityQA bean holding the security info for the currently logged in user
*
* @return SecurityQA for loggedInMid
* @throws ITrustException
*/
public SecurityQA retrieveInformation() throws ITrustException {
SecurityQA toRet = new SecurityQA();
toRet.setAnswer(authDAO.getSecurityAnswer(loggedInMID));
toRet.setQuestion(authDAO.getSecurityQuestion(loggedInMID));
return toRet;
}
/**
* Checks to make sure the MID exists in iTrust
*
* @param mid MID to check
* @return returns the MID if the user is valid, otherwise, throws an exception
* @throws ITrustException
*/
private long checkMID(long mid) throws ITrustException {
if (!authDAO.checkUserExists(mid))
throw new ITrustException("MID " + mid + " is not a user!");
return mid;
}
}