This project has retired. For details please refer to its
Attic page.
LoginController xref
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.hadoop.chukwa.hicc.rest;
19
20 import java.io.StringWriter;
21 import java.net.URI;
22 import java.net.URISyntaxException;
23
24 import javax.servlet.http.HttpServletRequest;
25 import javax.ws.rs.GET;
26 import javax.ws.rs.POST;
27 import javax.ws.rs.Path;
28 import javax.ws.rs.core.Context;
29 import javax.ws.rs.core.Response;
30
31 import org.apache.hadoop.chukwa.datastore.ChukwaHBaseStore;
32 import org.apache.velocity.Template;
33 import org.apache.velocity.VelocityContext;
34 import org.apache.velocity.app.VelocityEngine;
35
36 import com.sun.jersey.api.client.ClientResponse.Status;
37
38 @Path("/login")
39 public class LoginController {
40 @Context
41 VelocityEngine velocity;
42
43 static {
44 ChukwaHBaseStore.populateDefaults();
45 }
46
47
48
49
50
51
52
53
54
55
56
57 @GET
58 @Path("check")
59 public String login(String buffer) {
60 VelocityContext context = new VelocityContext();
61 StringWriter sw = null;
62 try {
63 Template template = velocity.getTemplate("login.vm");
64 sw = new StringWriter();
65 template.merge(context, sw);
66 } catch (Exception e) {
67 e.printStackTrace();
68 return e.getMessage();
69 }
70 return sw.toString();
71 }
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86 @POST
87 @Path("check")
88 public Response check(@Context HttpServletRequest request) {
89 VelocityContext context = new VelocityContext();
90 if(request.getRemoteUser()!=null) {
91 URI location;
92 try {
93 location = new URI("/hicc/");
94 return Response.temporaryRedirect(location).build();
95 } catch (URISyntaxException e) {
96 }
97 }
98 context.put("invalid", true);
99 Template template = velocity.getTemplate("login.vm");
100 StringWriter sw = new StringWriter();
101 template.merge(context, sw);
102 return Response.status(Status.FORBIDDEN).entity(sw.toString()).build();
103 }
104 }