-
Notifications
You must be signed in to change notification settings - Fork 41
Expand file tree
/
Copy pathRegistrationHandlerServlet.java
More file actions
78 lines (66 loc) · 3.08 KB
/
RegistrationHandlerServlet.java
File metadata and controls
78 lines (66 loc) · 3.08 KB
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
72
73
74
75
76
77
78
/****************************************************************************
The Original Code is TEAM Engine.
The Initial Developer of the Original Code is Northrop Grumman Corporation
jointly with The National Technology Alliance. Portions created by
Northrop Grumman Corporation are Copyright (C) 2005-2006, Northrop
Grumman Corporation. All Rights Reserved.
Contributor(s): No additional contributors to date
****************************************************************************/
package com.occamlab.te.web;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.occamlab.te.realm.PasswordStorage;
import java.io.File;
import java.io.FileOutputStream;
import java.io.PrintStream;
/**
* Handles requests to register new users.
*
*/
public class RegistrationHandlerServlet extends HttpServlet {
private static final long serialVersionUID = 7428127065308163495L;
Config conf;
public void init() throws ServletException {
conf = new Config();
}
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException {
try {
String username = request.getParameter("username");
String password = request.getParameter("password");
String hashedPassword = PasswordStorage.createHash(password);
String email = request.getParameter("email");
String firstName = request.getParameter("firstName");
String lastName = request.getParameter("lastName");
String organization = request.getParameter("organization");
File userDir = new File(conf.getUsersDir(), username);
if (userDir.exists()) {
String url = "register.jsp?error=duplicate&username=" + username;
if (email != null) {
url += "&email=" + email;
}
response.sendRedirect(url);
} else {
userDir.mkdirs();
File xmlfile = new File(userDir, "user.xml");
PrintStream out = new PrintStream(new FileOutputStream(xmlfile));
out.println("<user>");
out.println(" <name>" + username + "</name>");
out.println(" <roles>");
out.println(" <name>user</name>");
out.println(" </roles>");
out.println(" <password>" + hashedPassword + "</password>");
out.println(" <email>" + email + "</email>");
out.println(" <firstName>" + firstName + "</firstName>");
out.println(" <lastName>" + lastName + "</lastName>");
out.println(" <organization>" + organization + "</organization>");
out.println("</user>");
out.close();
response.sendRedirect("registered.jsp");
}
} catch (Exception e) {
throw new ServletException(e);
}
}
}