BrightSide Workbench Full Report + Source Code
SSOVM.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.sso;
20 
21 import java.util.List;
22 import org.turro.auth.Authentication;
23 import org.turro.elephant.db.ElephantPU;
24 import org.turro.elephant.db.WhereClause;
25 import org.turro.elephant.entities.db.SSOIdentity;
26 import org.turro.jpa.Dao;
27 import org.turro.plugin.contacts.IContact;
28 import org.zkoss.bind.annotation.BindingParam;
29 import org.zkoss.bind.annotation.Command;
30 import org.zkoss.bind.annotation.ExecutionArgParam;
31 import org.zkoss.bind.annotation.Init;
32 import org.zkoss.bind.annotation.NotifyChange;
33 
38 public class SSOVM {
39 
40  private IContact contact = Authentication.getIContact();
41 
42  @Init
43  public void init(@ExecutionArgParam("contact") IContact contact) {
44  if(contact != null) this.contact = contact;
45  }
46 
47  @Command
48  @NotifyChange("*")
49  public void delete(@BindingParam("entity") Object entity) {
50  if(entity instanceof SSOIdentity) {
51  getDao().deleteObject(entity);
52  }
53  }
54 
55  public List<SSOIdentity> getModel() {
56  WhereClause wc = new WhereClause();
57  wc.addClause("select sso from SSOIdentity as sso");
58  wc.addClause("where idContact = :idContact");
59  wc.addNamedValue("idContact", contact.getId());
60  return getDao().getResultList(wc);
61  }
62 
63  public String getIcon(SSOIdentity identity) {
64  String userAgent = identity.getDetails().toLowerCase();
65  if (userAgent.contains("windows")) {
66  return "windows";
67  } else if (userAgent.contains("mac")) {
68  return "apple";
69  } else if (userAgent.contains("x11") || userAgent.contains("ubuntu")) {
70  return "linux";
71  } else if (userAgent.contains("android")) {
72  return "android";
73  } else if (userAgent.contains("iphone")) {
74  return "apple";
75  } else {
76  return "question";
77  }
78  }
79 
80  /* Dao */
81 
82  private Dao _dao;
83 
84  private Dao getDao() {
85  if(_dao == null) {
86  _dao = new ElephantPU();
87  }
88  return _dao;
89  }
90 
91 }
void addNamedValue(String name, Object value)
void deleteObject(Object obj)
Definition: Dao.java:162
List< SSOIdentity > getModel()
Definition: SSOVM.java:55
void delete(@BindingParam("entity") Object entity)
Definition: SSOVM.java:49
void init(@ExecutionArgParam("contact") IContact contact)
Definition: SSOVM.java:43
String getIcon(SSOIdentity identity)
Definition: SSOVM.java:63