BrightSide Workbench Full Report + Source Code
SSOIdentity.java
Go to the documentation of this file.
1 /*
2  * TurrĂ³ i Cutiller Foundation. License notice.
3  * Copyright (C) 2019 Lluis TurrĂ³ Cutiller <http://www.turro.org/>
4  *
5  * This program is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU Affero General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU Affero General Public License for more details.
14  *
15  * You should have received a copy of the GNU Affero General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  */
18 
19 package org.turro.elephant.entities.db;
20 
21 import com.jayway.jsonpath.JsonPath;
22 import java.nio.charset.StandardCharsets;
23 import java.util.Date;
24 import javax.persistence.Column;
25 import javax.persistence.Entity;
26 import javax.persistence.Id;
27 import javax.persistence.Lob;
28 import javax.persistence.Temporal;
29 import org.turro.string.Strings;
30 import org.turro.action.Contacts;
31 import org.turro.elephant.sso.ISSOIdentity;
32 import org.turro.log.WebLoggers;
33 import org.turro.plugin.contacts.IContact;
34 
39 @Entity
40 public class SSOIdentity implements java.io.Serializable, ISSOIdentity {
41 
42  @Id
43  private String clientAssertion;
44 
45  private byte[] clientId;
46 
47  private String idContact;
48 
49  @Temporal(value = javax.persistence.TemporalType.TIMESTAMP)
50  private java.util.Date dateUsed;
51 
52  @Lob
53  @Column(length=512)
54  private String details;
55 
56  private String remoteIp;
57 
58  @Lob
59  @Column(length=2048)
60  private String geoIp;
61 
62  @Override
63  public byte[] getClientAssertion() {
64  return clientAssertion.getBytes(StandardCharsets.UTF_8);
65  }
66 
67  public void setClientAssertion(byte[] clientAssertion) {
68  this.clientAssertion = new String(clientAssertion, StandardCharsets.UTF_8);
69  }
70 
71  @Override
72  public byte[] getClientId() {
73  return clientId;
74  }
75 
76  public void setClientId(byte[] clientId) {
77  this.clientId = clientId;
78  }
79 
80  @Override
81  public String getIdContact() {
82  return idContact;
83  }
84 
85  public void setIdContact(String idContact) {
86  this.idContact = idContact;
87  }
88 
89  @Override
90  public Date getDateUsed() {
91  return dateUsed;
92  }
93 
94  public void setDateUsed(Date dateUsed) {
95  this.dateUsed = dateUsed;
96  }
97 
98  @Override
99  public String getDetails() {
100  return details;
101  }
102 
103  public void setDetails(String details) {
104  this.details = details;
105  }
106 
107  @Override
108  public String getRemoteIp() {
109  return remoteIp;
110  }
111 
112  public void setRemoteIp(String remoteIp) {
113  this.remoteIp = remoteIp;
114  }
115 
116  @Override
117  public String getGeoIp() {
118  return geoIp;
119  }
120 
121  public void setGeoIp(String geoIp) {
122  this.geoIp = geoIp;
123  }
124 
125  /* JSON Helpers */
126 
127  public Object readGeo(String path) {
128  try {
129  return (Strings.isBlank(geoIp) || geoIp.contains("error")) ? "" : JsonPath.read(geoIp, path);
130  } catch (Exception ex) {
131  WebLoggers.info(this).exception(ex).log();
132  return "";
133  }
134  }
135 
138  private transient IContact _contact;
139 
140  @Override
141  public IContact getContact() {
142  if(_contact == null) {
143  _contact = Contacts.getContactById(idContact);
144  }
145  return _contact;
146  }
147 
148  public void setContact(IContact contact) {
149  _contact = contact;
150  idContact = _contact != null ? _contact.getId() : null;
151  }
152 
153 }
static IContact getContactById(String id)
Definition: Contacts.java:72
void setClientAssertion(byte[] clientAssertion)
WebLoggers exception(Throwable throwable)
Definition: WebLoggers.java:29
static WebLoggers info(Object entity)
Definition: WebLoggers.java:43