commit | author | age
|
5bfcdd
|
1 |
/* |
U |
2 |
* To change this license header, choose License Headers in Project Properties. |
|
3 |
* To change this template file, choose Tools | Templates |
|
4 |
* and open the template in the editor. |
|
5 |
*/ |
|
6 |
package de.uhilger.wbx.web; |
|
7 |
|
|
8 |
import java.io.IOException; |
|
9 |
import java.security.Principal; |
|
10 |
import java.util.logging.Level; |
|
11 |
import java.util.logging.Logger; |
|
12 |
import javax.servlet.http.HttpServletRequest; |
|
13 |
import org.apache.catalina.servlets.DefaultServlet; |
|
14 |
|
|
15 |
/** |
|
16 |
* |
|
17 |
* @author ulrich |
|
18 |
*/ |
|
19 |
public class WbxServlet extends DefaultServlet { |
|
20 |
|
|
21 |
protected static final Logger logger = Logger.getLogger(WbxServlet.class.getName()); |
|
22 |
protected static final String HOME_CTX = "/home"; |
|
23 |
|
|
24 |
|
|
25 |
protected String getUrlUser(HttpServletRequest request, String userName) throws IOException { |
|
26 |
String result = ""; |
|
27 |
String requestUrlStr = request.getRequestURL().toString(); |
|
28 |
String contextPath = request.getContextPath(); |
|
29 |
if(contextPath != null && requestUrlStr != null && userName != null) { |
|
30 |
int start = requestUrlStr.indexOf(contextPath); |
|
31 |
start += contextPath.length(); |
|
32 |
start++; |
|
33 |
int end = start + userName.length(); |
|
34 |
try { |
|
35 |
result = requestUrlStr.substring(start, end); |
|
36 |
} catch(Exception ex) { |
|
37 |
logger.log(Level.SEVERE, ex.getLocalizedMessage(), ex); |
|
38 |
} |
|
39 |
} |
|
40 |
return result; |
|
41 |
} |
|
42 |
|
|
43 |
protected String getUserName(HttpServletRequest hr) { |
|
44 |
String userName = null; |
|
45 |
Object p = hr.getUserPrincipal(); |
|
46 |
if (p instanceof Principal) { |
|
47 |
userName = ((Principal) p).getName(); |
|
48 |
} |
|
49 |
return userName; |
|
50 |
} |
|
51 |
|
|
52 |
} |