* LoginAction.java - Use UserDAOImpl type for better source lookup * TermAction.ava - Use obvious serialization version - Implemented add() * UserAction.java - Use more obvious serialization version * TermDAO.java - Renamed listTermById() to getTermById() - Added Javadoc * TermDAOImpl.java - Fixed "FROM term" bug (no SQL, case-sensitive) - saveOrUpdate() now returns boolean (for TermAction) * Term.java - Now imports java.io.Serializable - Added serialization version ID - Use TermDAOImpl type for better source lookup * struts.xml - /doTermAdd now triggers add() - Added basic Term actions * user/nav.jsp - Added /listTerm link to trigger user/termList.jsp * user/termAddForm.jsp - Now functional and reusable for Rename Term * General: - Clean-up: + Renamed Object to ObjectEntity + Source formatting - Added javax.persistence and org.hibernate sources (for Javadoc) - Added PDF documentation generated from OpenDocument Text
/trunk/src/ch/ffhs/webE/action/TermAction.java |
---|
1,15 → 1,20 |
package ch.ffhs.webE.action; |
import java.util.ArrayList; |
import java.util.Date; |
import java.util.List; |
import java.util.Map; |
import javax.servlet.http.HttpServletRequest; |
import org.apache.struts2.StrutsStatics; |
import ch.ffhs.webE.dao.TermDAO; |
import ch.ffhs.webE.dao.TermDAOImpl; |
import ch.ffhs.webE.dao.UserDAOImpl; |
import ch.ffhs.webE.domain.ObjectEntity; |
import ch.ffhs.webE.domain.ObjectType; |
import ch.ffhs.webE.domain.Term; |
import ch.ffhs.webE.domain.User; |
import com.opensymphony.xwork2.Action; |
import com.opensymphony.xwork2.ActionContext; |
23,12 → 28,18 |
*/ |
public class TermAction extends ActionSupport implements ModelDriven<Term> |
{ |
private static final long serialVersionUID = -6659925652584240539L; |
private static final long serialVersionUID = 1L; |
private Term term = new Term(); |
private List<Term> termList = new ArrayList<Term>(); |
private final TermDAO termDAO = new TermDAOImpl(); |
private final TermDAOImpl termDAO = new TermDAOImpl(); |
private final UserDAOImpl userDAO = new UserDAOImpl(); |
/** |
* Session object |
*/ |
Map<String, Object> session = ActionContext.getContext().getSession(); |
/* |
* (non-Javadoc) |
* |
44,14 → 55,23 |
* |
* @return {@link Action#SUCCESS} |
*/ |
public String addOrUpdate() |
public String add() |
{ |
this.termDAO.saveOrUpdate(this.term); |
return Action.SUCCESS; |
User user = this.userDAO.searchUsername((String) this.session |
.get("username")); |
ObjectEntity obj = new ObjectEntity(user, new ObjectType(ObjectType.TERM), |
user, null, new Date(), false, this.term, null, null); |
this.term.setObject(obj); |
if (this.termDAO.saveOrUpdate(this.term)) |
{ |
return Action.SUCCESS; |
} |
return Action.ERROR; |
} |
/** |
* DB query for userList |
* DB query for term list |
* |
* @return SUCCESS |
*/ |
71,13 → 91,14 |
if (id > 0) |
{ |
this.term = this.termDAO.listTermById(id); |
return Action.SUCCESS; |
this.term = this.termDAO.getTermById(id); |
if (this.term != null) |
{ |
return Action.SUCCESS; |
} |
} |
else |
{ |
return Action.ERROR; |
} |
return Action.ERROR; |
} |
/** |
/trunk/src/ch/ffhs/webE/action/LoginAction.java |
---|
2,10 → 2,10 |
import java.util.Map; |
import ch.ffhs.webE.dao.UserDAO; |
import ch.ffhs.webE.dao.UserDAOImpl; |
import ch.ffhs.webE.domain.User; |
import com.opensymphony.xwork2.Action; |
import com.opensymphony.xwork2.ActionContext; |
import com.opensymphony.xwork2.ActionSupport; |
import com.opensymphony.xwork2.ModelDriven; |
13,115 → 13,125 |
public class LoginAction extends ActionSupport implements ModelDriven<User> |
{ |
private static final long serialVersionUID = 1799753056277211344L; |
private User user = new User(); |
private UserDAO userDAO = new UserDAOImpl(); |
private static final long serialVersionUID = 1799753056277211344L; |
private final User user = new User(); |
private final UserDAOImpl userDAO = new UserDAOImpl(); |
// Form fields |
private String userName; |
private String pw; |
/* Form fields */ |
private String userName; |
private String pw; |
// Session Object |
Map<String, Object> session = ActionContext.getContext().getSession(); |
/** |
* JSP session object |
*/ |
Map<String, Object> session = ActionContext.getContext().getSession(); |
public LoginAction() |
{ |
} |
/** |
* |
*/ |
public LoginAction() |
{ |
} |
public String doLogin() |
public String doLogin() |
{ |
// If password or user name are empty, the login fails. |
if ("".equals(this.getUserName()) || "".equals(this.getPw()) |
|| this.getUserName() == null || this.getPw() == null) |
{ |
// If password or user name are empty, the login fails. |
if ("".equals(getUserName()) || "".equals(getPw()) |
|| getUserName() == null || getPw() == null) |
{ |
addFieldError("userName", "Falscher Username oder Passwort"); |
return ERROR; |
} |
String verifiedUser = verifyUser(getUserName(), getPw()); |
if (verifiedUser.equals("failed")) |
{ |
addFieldError("userName", "Falscher Username oder Passwort"); |
return ERROR; |
} |
else |
{ |
// Put user name, password into session |
session.put("username", getUserName()); |
session.put("pw", getPw()); |
return verifiedUser; |
} |
this.addFieldError("userName", "Falscher Username oder Passwort"); |
return Action.ERROR; |
} |
/** |
* Logout ausführen. Zerstört die Daten in der Session |
* @return String |
*/ |
public String doLogout() |
String verifiedUser = this.verifyUser(this.getUserName(), this.getPw()); |
if (verifiedUser.equals("failed")) |
{ |
//Kill Session content |
ActionContext.getContext().getSession().clear(); |
return SUCCESS; |
this.addFieldError("userName", "Falscher Username oder Passwort"); |
return Action.ERROR; |
} |
/** |
* Verify user credentials |
* |
* @param String |
* username: User name |
* @param String |
* password: Password (hashed) |
* @return |
*/ |
public String verifyUser(String username, String password) |
else |
{ |
// DB Query |
User u = userDAO.searchUsername(username); |
// User does not exist |
if (u == null) |
return ERROR; |
// Put user name, password into session |
this.session.put("username", this.getUserName()); |
this.session.put("pw", this.getPw()); |
return verifiedUser; |
} |
} |
// User password does not match |
if (!u.getPassword().equals(password)) |
return ERROR; |
/** |
* Logout ausf�hren. Zerst�rt die Daten in der Session |
* |
* @return String |
*/ |
public String doLogout() |
{ |
// Kill Session content |
ActionContext.getContext().getSession().clear(); |
return Action.SUCCESS; |
} |
// User credentials are fine, check for admin rights |
if (u.isAdmin()) |
{ |
return "admin"; |
} |
else |
{ |
return "user"; |
} |
} |
/** |
* Verify user credentials |
* |
* @param String |
* username: User name |
* @param String |
* password: Password (hashed) |
* @return |
*/ |
public String verifyUser(String username, String password) |
{ |
// DB Query |
User u = this.userDAO.searchUsername(username); |
public String getUserName() |
// User does not exist |
if (u == null) |
{ |
return userName; |
return Action.ERROR; |
} |
public void setUserName(String userName) |
// User password does not match |
if (!u.getPassword().equals(password)) |
{ |
this.userName = userName; |
return Action.ERROR; |
} |
public String getPw() |
// User credentials are fine, check for admin rights |
if (u.isAdmin()) |
{ |
return pw; |
return "admin"; |
} |
public void setPw(String pw) |
else |
{ |
this.pw = pw; |
return "user"; |
} |
} |
@Override |
public User getModel() |
{ |
return user; |
} |
public String getUserName() |
{ |
return this.userName; |
} |
public void setUserName(String userName) |
{ |
this.userName = userName; |
} |
public String getPw() |
{ |
return this.pw; |
} |
public void setPw(String pw) |
{ |
this.pw = pw; |
} |
@Override |
public User getModel() |
{ |
return this.user; |
} |
} |
/trunk/src/ch/ffhs/webE/action/UserAction.java |
---|
5,135 → 5,135 |
import javax.servlet.http.HttpServletRequest; |
import org.apache.struts2.ServletActionContext; |
import org.apache.struts2.StrutsStatics; |
import ch.ffhs.webE.dao.UserDAOImpl; |
import ch.ffhs.webE.domain.User; |
import com.opensymphony.xwork2.Action; |
import com.opensymphony.xwork2.ActionContext; |
import com.opensymphony.xwork2.ActionSupport; |
import com.opensymphony.xwork2.ModelDriven; |
import ch.ffhs.webE.dao.UserDAO; |
import ch.ffhs.webE.dao.UserDAOImpl; |
import ch.ffhs.webE.domain.User; |
public class UserAction extends ActionSupport implements ModelDriven<User> |
{ |
private static final long serialVersionUID = -6659925652584240539L; |
private static final long serialVersionUID = 1L; |
private User user = new User(); |
private List<User> userList = new ArrayList<User>(); |
private UserDAO userDAO = new UserDAOImpl(); |
private User user = new User(); |
private List<User> userList = new ArrayList<User>(); |
private final UserDAOImpl userDAO = new UserDAOImpl(); |
@Override |
public User getModel() |
{ |
return user; |
} |
@Override |
public User getModel() |
{ |
return this.user; |
} |
/** |
* Executes the DB query to save the user |
* |
* @return |
*/ |
public String addOrUpdate() |
/** |
* Executes the DB query to save the user |
* |
* @return |
*/ |
public String addOrUpdate() |
{ |
this.userDAO.saveOrUpdateUser(this.user); |
return Action.SUCCESS; |
} |
/** |
* DB query for userList |
* |
* @return SUCCESS |
*/ |
public String list() |
{ |
this.userList = this.userDAO.listUser(); |
return Action.SUCCESS; |
} |
public String edit() |
{ |
int id = this.getIdParameter(); |
if (id > 0) |
{ |
userDAO.saveOrUpdateUser(user); |
return SUCCESS; |
this.user = this.userDAO.listUserById(id); |
return Action.SUCCESS; |
} |
/** |
* DB query for userList |
* |
* @return SUCCESS |
*/ |
public String list() |
else |
{ |
userList = userDAO.listUser(); |
return SUCCESS; |
return Action.ERROR; |
} |
} |
public String edit() |
/** |
* Gets the ID Parameter for update / delete requests |
* |
* @return int from the ID request. If not set or wrong, it gives back -1 |
*/ |
private int getIdParameter() |
{ |
HttpServletRequest request = (HttpServletRequest) ActionContext |
.getContext().get(StrutsStatics.HTTP_REQUEST); |
int id = -1; |
try |
{ |
int id = getIdParameter(); |
if (id > 0) |
{ |
user = userDAO.listUserById(id); |
return SUCCESS; |
} |
else |
{ |
return ERROR; |
} |
id = Integer.parseInt(request.getParameter("id")); |
} |
/** |
* Gets the ID Parameter for update / delete requests |
* |
* @return int from the ID request. If not set or wrong, it gives back -1 |
*/ |
private int getIdParameter() |
catch (Exception e) |
{ |
HttpServletRequest request = (HttpServletRequest) ActionContext |
.getContext().get(ServletActionContext.HTTP_REQUEST); |
int id = -1; |
try |
{ |
id = Integer.parseInt(request.getParameter("id")); |
} |
catch (Exception e) |
{ |
// TODO: Logging - wrong parameter set |
} |
return id; |
// TODO: Logging - wrong parameter set |
} |
/** |
* deletes a user, gets the ID from the "id" parameter that was submitted |
* with the HTTP request |
* |
* @return String - either SUCCESS or ERROR constant |
*/ |
public String delete() |
{ |
return id; |
} |
int id = getIdParameter(); |
/** |
* deletes a user, gets the ID from the "id" parameter that was submitted with |
* the HTTP request |
* |
* @return String - either SUCCESS or ERROR constant |
*/ |
public String delete() |
{ |
// Check for malicious ID values |
if (id > 0) |
{ |
userDAO.deleteUser(id); |
return SUCCESS; |
} |
else |
{ |
return ERROR; |
} |
} |
int id = this.getIdParameter(); |
/* |
* Standard getters and setters |
*/ |
public User getUser() |
// Check for malicious ID values |
if (id > 0) |
{ |
return user; |
this.userDAO.deleteUser(id); |
return Action.SUCCESS; |
} |
public void setUser(User user) |
else |
{ |
this.user = user; |
return Action.ERROR; |
} |
} |
public List<User> getUserList() |
{ |
return userList; |
} |
/* |
* Standard getters and setters |
*/ |
public void setUserList(List<User> userList) |
{ |
this.userList = userList; |
} |
public User getUser() |
{ |
return this.user; |
} |
public void setUser(User user) |
{ |
this.user = user; |
} |
public List<User> getUserList() |
{ |
return this.userList; |
} |
public void setUserList(List<User> userList) |
{ |
this.userList = userList; |
} |
} |