19 package org.turro.sso;
21 import java.io.IOException;
22 import java.nio.charset.StandardCharsets;
23 import java.util.Date;
24 import java.util.logging.Level;
25 import java.util.logging.Logger;
26 import javax.servlet.http.Cookie;
27 import javax.servlet.http.HttpServletRequest;
28 import javax.servlet.http.HttpServletResponse;
29 import org.amic.util.date.CheckDate;
30 import org.apache.commons.codec.DecoderException;
31 import org.turro.elephant.context.ElephantContext;
32 import org.turro.elephant.db.ElephantPU;
33 import org.turro.elephant.db.WhereClause;
34 import org.turro.elephant.entities.db.SSOIdentity;
35 import org.turro.elephant.impl.util.CookieUtil;
36 import org.turro.elephant.sso.IAssertionProvider;
37 import org.turro.elephant.sso.ISSOIdentity;
38 import org.turro.jpa.Dao;
39 import org.turro.plugin.contacts.IContact;
40 import org.turro.sql.SqlClause;
49 private static final int VALID_DAYS = 90;
50 private static final String ASSERTION_ID =
"_elac";
65 if(assertion !=
null) {
69 }
catch (IOException | DecoderException ex) {
78 String details, String remoteIP, String geoIP, HttpServletResponse response) {
79 if(assertion !=
null) {
90 if(identity !=
null) {
97 removeOldAssertions();
115 return SqlClause.select(
"max(geoIp)").from(
"SSOIdentity")
116 .where().equal(
"remoteIp", remoteIP)
117 .dao(
new ElephantPU()).singleResult(String.class);
120 private void removeOldAssertions() {
124 wc.
addNamedValue(
"date",
new CheckDate().addDays(-VALID_DAYS).getDate());
static String logMsg(String msg)
void addClause(String clause)
void addNamedValue(String name, Object value)
void setClientId(byte[] clientId)
void setClientAssertion(byte[] clientAssertion)
void setContact(IContact contact)
static Cookie getCookie(HttpServletRequest request, String name)
static byte[] decryptCookieValue(Cookie cookie)
static void encryptCookie(HttpServletResponse response, String name, byte[] value, String path, int age)
static void deleteCookie(HttpServletResponse response, String name, String path)
int executeUpdate(String query)
void updateAssertion(String details, String remoteIP, String geoIP, HttpServletResponse response, ISSOIdentity identity)
boolean hasAssertion(HttpServletRequest request)
ISSOIdentity getAssertion(HttpServletRequest request)
void killAssertion(HttpServletResponse response)
String getGeoIP(String remoteIP)
void removeAssertion(HttpServletRequest request, HttpServletResponse response, IContact contact)
void setAssertion(byte[] assertion, byte[] clientId, IContact contact, String details, String remoteIP, String geoIP, HttpServletResponse response)
static IElephantSSO getSSO()
byte[] getCurrentId(HttpServletRequest request)
byte[] getClientAssertion()