19 package org.turro.auth;
21 import java.io.IOException;
22 import java.util.logging.Level;
23 import java.util.logging.Logger;
24 import javax.servlet.ServletContext;
25 import javax.servlet.http.HttpServletRequest;
26 import javax.servlet.http.HttpServletResponse;
27 import org.turro.string.Strings;
28 import org.turro.action.Actions;
29 import org.turro.elephant.context.ElephantContext;
30 import org.turro.elephant.context.ElephantProperties;
31 import org.turro.elephant.direct.DirectContent;
32 import org.turro.elephant.direct.DirectContents;
33 import org.turro.elephant.direct.IDirectContent;
34 import org.turro.http.ElephantPost;
35 import org.turro.http.ElephantResponse;
36 import org.turro.http.ElephantResponseType;
37 import org.turro.plugin.contacts.IContact;
43 @DirectContent(identifier=
"authentication")
47 LOGOUT_URL =
"/logout",
48 AUTH_URL =
"/authurl";
50 public static String
getAccessURL(String domain, String email, String redir) {
53 if(!email.contains(
"@")) {
54 email = mapName(email);
60 return domain +
"?" + er.
message;
62 }
catch (IOException ex) {
70 if(contact !=
null && contact.
isValid()) {
72 (redir !=
null ?
"?redir=" + redir :
"");
79 String remoteIP = request.getRemoteAddr();
80 if(
"127.0.0.1".equals(remoteIP))
return true;
82 Logger.getLogger(
AuthActions.class.getName()).log(Level.INFO, remoteIP +
" trust checked");
88 public static String
mapName(String name) {
90 Logger.getLogger(
AuthActions.class.getName()).log(Level.INFO, name +
" mapped");
93 Logger.getLogger(
AuthActions.class.getName()).log(Level.INFO, name +
" not found");
104 return getIdentifier().equals(
id);
108 public boolean myTurn(HttpServletRequest request) {
113 public void execute(ServletContext context, HttpServletRequest request, HttpServletResponse response) {
115 String redir = request.getParameter(
"redir");
118 }
catch (IOException ex) {
122 if(isTrustedSource(request)) {
124 String url = createAccessURL(request);
125 if(!Strings.isBlank(url)) {
129 }
catch (IOException ex) {
136 private static String createAccessURL(HttpServletRequest request) {
138 String email = request.getParameter(
"email"),
139 redir = request.getParameter(
"redir");
141 }
catch (Exception ex) {
142 Logger.getLogger(AuthActions.class.getName()).log(Level.SEVERE, ElephantContext.logMsg(
null), ex);
static String createAction(String email, String redir)
static String getAccessURL(String domain, String email, String redir)
static String mapName(String name)
boolean myTurn(HttpServletRequest request)
static String createLogoutURL(String redir)
void execute(ServletContext context, HttpServletRequest request, HttpServletResponse response)
static boolean isTrustedSource(HttpServletRequest request)
static String getIdentifier()
static void doLogout(String redir)
static IContact getLoggedIContact()
static String logMsg(String msg)
static boolean containsContextProperty(String context, String property)
static String getContextProperty(String context, String property)
static boolean isYourTurn(HttpServletRequest request, String path)
static String createURL(String server, String id)
static String createRelativeURL(String id)
ElephantResponse doPost()
void addParameter(String name, String value)
static boolean isCorrect(ElephantResponse er)
static void writeToResponse(HttpServletResponse response, ElephantResponseType type, String message, String code)