BrightSide Workbench Full Report + Source Code
DefaultContact.java
Go to the documentation of this file.
1 /*
2  * TurrĂ³ i Cutiller Foundation. License notice.
3  * Copyright (C) 2011 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 package org.turro.contacts.util;
19 
20 import java.io.Serializable;
21 import java.util.ArrayList;
22 import java.util.Collection;
23 import java.util.Collections;
24 import java.util.Date;
25 import java.util.HashMap;
26 import java.util.List;
27 import java.util.Locale;
28 import java.util.Map;
29 import java.util.Objects;
30 import java.util.Optional;
31 import java.util.Set;
32 import java.util.logging.Level;
33 import java.util.logging.Logger;
34 import org.turro.string.Strings;
35 import org.turro.action.Plugins;
36 import org.turro.actor.Actors;
37 import org.turro.annotation.ElephantContact;
38 import org.turro.auth.Authentication;
39 import org.turro.collections.KeyValueMap;
40 import org.turro.contacts.BusinessRelation;
41 import org.turro.contacts.Comment;
42 import org.turro.contacts.Connector;
43 import org.turro.contacts.Contact;
44 import org.turro.contacts.ContactType;
45 import org.turro.contacts.Syndication;
46 import org.turro.contacts.db.ContactsPU;
47 import org.turro.contacts.relation.FuzzyRelationTypes;
48 import org.turro.contacts.relation.Relations;
49 import org.turro.contacts.zul.menu.ContactMenu;
50 import org.turro.elephant.context.Application;
51 import org.turro.elephant.context.ElephantContext;
52 import org.turro.elephant.db.WhereClause;
53 import org.turro.elephant.security.IUser;
54 import org.turro.entities.ContactEntities;
55 import org.turro.entities.Faces;
56 import org.turro.file.util.FileAttach;
57 import org.turro.i18n.Locales;
58 import org.turro.jpa.Dao;
59 import org.turro.plugin.contacts.CompoundId;
60 import org.turro.plugin.contacts.IContact;
61 import org.turro.plugin.contacts.IProfile;
62 import org.turro.plugin.contacts.IRelations;
63 import org.turro.security.ContactPermissions;
64 import org.turro.security.FlatPermissions;
65 import org.turro.security.Permissions;
66 import org.turro.security.SocialGroups;
67 import org.turro.string.Words;
68 import org.turro.util.CompareUtil;
69 
74 @ElephantContact(priority=1)
75 public class DefaultContact implements IContact, Serializable, Comparable<IContact> {
76 
77  protected Contact contact = null;
78 
79  public DefaultContact() {
80  }
81 
82  public DefaultContact(Object object) {
83  this.contact = (Contact) object;
84  }
85 
86  public DefaultContact(Contact contact) {
87  this.contact = contact;
88  }
89 
90  @Override
91  public Object loadById(String id) {
92  setContact(null);
93  if(!Strings.isBlank(id)) {
94  setContact(new ContactsPU().find(Contact.class, id));
95  }
96  return contact;
97  }
98 
102  @Override
103  public Object loadByLogin(String login) {
104  setContact((Contact) new ContactsPU().getSingleResultOrNull(
105  "select c from Contact as c where c.login = ? or c.id = ?",
106  new String[] { login, login }));
107  return contact;
108  }
109 
110  @Override
111  public Object loadLogged(Application app) {
112  IUser user = app.getConstructor().getUser();
113  if(user instanceof IContact) {
114  setContact((Contact) ((IContact) user).getContact());
115  return user;
116  } else {
117  return user != null ? loadByLogin(app.getConstructor().getUser().getId()) : null;
118  }
119  }
120 
121  @Override
122  public Object getContact() {
123  return contact;
124  }
125 
126  @Override
127  public void setContact(Object contact) {
128  this.contact = (Contact) contact;
129  //_roles = null;
130  _syndications = null;
131  }
132 
133  @Override
134  public String getId() {
135  return contact != null ? contact.getId() : null;
136  }
137 
138  @Override
139  public String getGlobalId() {
140  return contact != null ? contact.getGlobalIdentifier() : null;
141  }
142 
143  @Override
144  public String getGrouping() {
145  return contact != null ? contact.getGrouping() : null;
146  }
147 
148  @Override
149  public String getDeepGrouping() {
150  Contact business = contact;
151  while(business != null) {
152  if(!Strings.isBlank(business.getGrouping())) {
153  return business.getGrouping();
154  }
155  business = business.getBusiness();
156  }
157  return null;
158  }
159 
160  @Override
161  public String getLogin() {
162  return contact != null ? contact.getLogin() : null;
163  }
164 
165  @Override
166  public String getName() {
167  return contact != null ? contact.getName().trim() : "";
168  }
169 
170  @Override
171  public String getFriendly() {
172  return contact != null ? contact.getFriendly().trim() : "";
173  }
174 
175  @Override
176  public String getFormal() {
177  return contact != null ? contact.getFormal().trim() : "";
178  }
179 
180  @Override
181  public String getFullName() {
182  return contact != null ? contact.getFullName().trim() : "";
183  }
184 
185  @Override
186  public String getTradeName() {
187  return contact != null ? contact.getTradeName().trim() : "";
188  }
189 
190  @Override
191  public String getEmail() {
192  return getConnector(IUser.CONNECTOR_EMAIL);
193  }
194 
195  @Override
196  public Locale getLocale() {
197  return contact != null ? contact.getLocale() : null;
198  }
199 
200  @Override
201  public String getConnector(String id) {
202  if(contact != null) {
203  for(Connector connector : contact.getConnectors()) {
204  if(id.equalsIgnoreCase(connector.getDescription())) {
205  return connector.getValue();
206  }
207  }
208  }
209  return null;
210  }
211 
212  @Override
213  public List<String> getConnectorList(String id) {
214  ArrayList<String> list = new ArrayList<>();
215  if(contact != null) {
216  for(Connector connector : contact.getConnectors()) {
217  if(id.equalsIgnoreCase(connector.getDescription())) {
218  list.add(connector.getValue());
219  }
220  }
221  }
222  return list;
223  }
224 
225  /* Relations */
226 
227  private IRelations _companies, _staff;
228 
229  @Override
231  if(_companies == null) _companies = Relations.companies(this);
232  return _companies;
233  }
234 
235  @Override
237  if(_staff == null) _staff = Relations.staff(this);
238  return _staff;
239  }
240 
241  @Override
242  public List<IContact> getRelations(String id) {
243  List<IContact> list = new ArrayList<>();
244  if(contact != null) {
245  for(BusinessRelation relation : contact.getBusinessSet()) {
246  if(id.equalsIgnoreCase(relation.getDescription())) {
247  list.add(relation.getBusiness().getIContact());
248  }
249  }
250  }
251  return list;
252  }
253 
254  @Override
255  public List<IContact> getRelations() {
256  List<IContact> list = new ArrayList<>();
257  if(contact != null) {
258  for(BusinessRelation relation : contact.getBusinessSet()) {
259  list.add(relation.getBusiness().getIContact());
260  }
261  for(BusinessRelation relation : contact.getWorkerSet()) {
262  list.add(relation.getContact().getIContact());
263  }
264  }
265  return list;
266  }
267 
268  @Override
270  if(contact != null) {
271  Contact b = contact.getBusiness();
272  if(b != null) {
273  return b.getIContact();
274  }
275  }
276  return null;
277  }
278 
279  @Override
280  public List<IContact> getBusinessList() {
281  org.turro.plugin.contacts.ContactList list = new org.turro.plugin.contacts.ContactList();
282  if(contact != null) {
283  for(Contact c : contact.getBusinessList()) {
284  if(!c.getId().equals(contact.getId())) {
285  list.add(c.getIContact());
286  }
287  }
288  }
289  return list;
290  }
291 
292  @Override
293  public List<IContact> getCoworkers() {
294  org.turro.plugin.contacts.ContactList list = new org.turro.plugin.contacts.ContactList();
295  if(contact != null) {
296  for(Contact c : contact.getCoworkers()) {
297  if(!c.getId().equals(contact.getId())) {
298  list.add(c.getIContact());
299  }
300  }
301  }
302  return list;
303  }
304 
305  @Override
306  public List<IContact> getCoworkers(IContact business) {
307  org.turro.plugin.contacts.ContactList list = new org.turro.plugin.contacts.ContactList();
308  if(contact != null) {
309  for(Contact c : contact.getCoworkers((Contact) business.getContact())) {
310  if(!c.getId().equals(contact.getId())) {
311  list.add(c.getIContact());
312  }
313  }
314  }
315  return list;
316  }
317 
318  @Override
319  public boolean isInBusiness(IContact worker) {
320  return getCoworkers().contains(worker);
321  }
322 
323  @Override
324  public void setConnector(String id, String value) {
325  if(contact != null) {
326  for(Connector connector : contact.getConnectors()) {
327  if(id.equalsIgnoreCase(connector.getDescription())) {
328  connector.setValue(value);
329  return;
330  }
331  }
332  Connector connector = new Connector();
333  connector.setOwner(contact.getOwner());
334  connector.setOnlyOwner(false);
335  connector.setContact(contact);
336  connector.setDescription(id);
337  connector.setValue(value);
338  contact.getConnectors().add(connector);
339  }
340  }
341 
342  @Override
343  public void setName(String value) {
344  if(contact != null) {
345  contact.setName(value);
346  contact.getComplexName().setFull(value);
347  }
348  }
349 
350  @Override
351  public void setPassword(String newValue, String repeatValue) {
352  if(newValue != null && newValue.trim().length() > 0 && newValue.equals(repeatValue)) {
353  try {
354  contact.setPass1(ElephantContext.encrypt(newValue));
355  } catch (Exception ex) {
356  Logger.getLogger(DefaultContact.class.getName()).log(Level.SEVERE, ElephantContext.logMsg(null), ex);
357  }
358  }
359  }
360 
361  @Override
362  public void applyChanges() {
363  try {
364  new org.turro.contacts.form.ContactWrapper(contact).save();
365  } catch (Exception ex) {
366  Logger.getLogger(DefaultContact.class.getName()).log(Level.SEVERE, ElephantContext.logMsg(null), ex);
367  }
368  }
369 
370  @Override
371  public boolean isValid() {
372  return contact != null;
373  }
374 
375  @Override
376  public boolean checkPassword(String password) {
377  try {
378  return ElephantContext.encrypt(password).equals(contact.getPass1());
379  } catch (Exception ex) {
380  Logger.getLogger(DefaultContact.class.getName()).log(Level.SEVERE, ElephantContext.logMsg(null), ex);
381  }
382  return false;
383  }
384 
385  public boolean checkPassword2(String password) {
386  try {
387  return ElephantContext.encrypt(password).equals(contact.getPass2());
388  } catch (Exception ex) {
389  Logger.getLogger(DefaultContact.class.getName()).log(Level.SEVERE, ElephantContext.logMsg(null), ex);
390  }
391  return false;
392  }
393 
394  @Override
395  public String getCommentValue(String key) {
396  String comment = null, lang = key + Application.getUsedLocale();
397  for(Comment c : contact.getComments()) {
398  if(!Strings.isBlank(c.getComment()) && c.getComment().startsWith(lang)) {
399  comment = c.getComment().substring(lang.length());
400  break;
401  }
402  }
403  if(org.turro.string.Strings.isBlank(comment)) {
404  lang = key + "#";
405  for(Comment c : contact.getComments()) {
406  if(!Strings.isBlank(c.getComment()) && c.getComment().startsWith(lang)) {
407  comment = c.getComment().substring(lang.length());
408  break;
409  }
410  }
411  }
412  return comment;
413  }
414 
415  @Override
416  public Object getObject(String key) {
417  return contact.getObject(key);
418  }
419 
420  @Override
421  public void setObject(String key, Serializable value) {
422  contact.setObject(key, value);
423  }
424 
425  @Override
426  public boolean isWebUser() {
427  return contact == null ? false : (!contact.isDeactivated() && contact.isWebUser());
428  }
429 
430  @Override
431  public boolean isWebapp() {
432  return contact == null ? false : contact.isWebapp();
433  }
434 
435  @Override
436  public boolean isUserMenu() {
437  return contact == null ? false : contact.isUserMenu();
438  }
439 
440  @Override
441  public boolean isDeactivated() {
442  return contact == null ? true : contact.isDeactivated();
443  }
444 
445  private ArrayList<String> _syndications = null;
446 
447  @Override
448  public List<String> getSyndications() {
449  if(_syndications == null) {
450  _syndications = new ArrayList<>();
451  for(Syndication s : contact.getSyndications()) {
452  _syndications.add(s.getName());
453  }
454  }
455  return _syndications;
456  }
457 
458  private FlatPermissions _permissions = null;
459 
460  @Override
462  if(_permissions == null) {
463  _permissions = new ContactPermissions(this);
464  }
465  return _permissions;
466  }
467 
468  @Override
469  public void resetPermissions() {
470  _permissions = null;
471  }
472 
473  @Override
474  public IUser getAsUser() {
475  return this;
476  }
477 
478  @Override
479  public boolean acceptsLang(String lang) {
480  return Locales.checkLanguage(contact.getLocale(), lang);
481  }
482 
483  @Override
484  public List<IContact> loadByPartialName(String name) {
485  return loadByPartialName(name, null);
486  }
487 
488  @Override
489  public List<IContact> loadByPartialName(String name, KeyValueMap kvm) {
490  ArrayList<IContact> list = new ArrayList<IContact>();
491  if(name != null && name.trim().length() > 2) {
492  ContactEntities ce = new ContactEntities();
493  for(Contact c : ((Collection<Contact>) ce.getEntitites("contact", name, 0, kvm))) {
494  list.add(c.getIContact());
495  }
496  }
497  return list;
498  }
499 
500  @Override
501  public IContact loadByName(String name) {
503  "select c from Contact as c where c.name = ?",
504  new String[] { name });
505  return c == null ? null : c.getIContact();
506  }
507 
508  @Override
509  public IContact loadByEmail(String email) {
511  "select c.contact from Connector as c where c.description = ? and c.value = ?",
512  new String[] { IUser.CONNECTOR_EMAIL, email });
513  return (c == null || c.isDeactivated()) ? null : c.getIContact();
514  }
515 
516  public static String fullName(String contactId) {
517  Object o = new ContactsPU().getSingleResult(
518  "select name from Contact contact " +
519  "where contact.id = ?",
520  new Object[] {
521  contactId
522  });
523  return (String) o;
524  }
525 
526  @Override
527  public void setAttribute(String key, Object value) {
528  contact.setAttribute(key, value);
529  }
530 
531  @Override
532  public Object getAttribute(String key) {
533  return contact.getAttribute(key);
534  }
535 
536  @Override
537  public List<IContact> getBySyndication(String syndication) {
538  ArrayList<IContact> list = new ArrayList<>();
539  if(!Strings.isBlank(syndication)) {
540  if("hhrr".equals(syndication)) {
541  list.addAll(getHHRR());
542  } else if("student".equals(syndication)) {
543  list.addAll(getStudents());
544  } else {
545  for(Contact c : (List<Contact>) new ContactsPU().getResultList(
546  "select s.contact from Syndication as s where s.name = ?",
547  new String[] { syndication })) {
548  list.add(c.getIContact());
549  }
550  }
551  }
552  return list;
553  }
554 
555  @Override
556  public List<IContact> getByRole(String role) {
557  ArrayList<IContact> list = new ArrayList<>();
558  if(!Strings.isBlank(role)) {
559  List<String> syndicationNames = List.copyOf(Permissions.getSecurityGroupIdsBy(role));
560  WhereClause wc = new WhereClause();
561  wc.addClause("select distinct syndication.contact from Syndication as syndication");
562  wc.addClause("where syndication.name in (:syndicationNames)");
563  wc.addNamedValue("syndicationNames", syndicationNames);
564  for(Contact c : (List<Contact>) new ContactsPU().getResultList(wc)) {
565  list.add(c.getIContact());
566  }
567  }
568  return list;
569  }
570 
571  @Override
572  public List<IContact> getByGrouping(String grouping) {
573  return getByGrouping(Collections.singletonList(grouping));
574  }
575 
576  @Override
577  public List<IContact> getByGrouping(List<String> groupings) {
578  ArrayList<IContact> list = new ArrayList<>();
579  if(groupings != null && !groupings.isEmpty()) {
580  WhereClause wc = new WhereClause();
581  wc.addClause("select contact from Contact as contact");
582  wc.addClause("where contact.grouping in (:groupings)");
583  wc.addNamedValue("groupings", groupings);
584  for(Contact c : (List<Contact>) new ContactsPU().getResultList(wc)) {
585  list.add(c.getIContact());
586  }
587  }
588  return list;
589  }
590 
591  @Override
592  public List<IContact> getCompanies() {
593  ArrayList<IContact> list = new ArrayList<>();
594  WhereClause wc = new WhereClause();
595  wc.addClause("select contact from Contact as contact");
596  wc.addClause("where contact.type = :type");
598  for(Contact c : (List<Contact>) new ContactsPU().getResultList(wc)) {
599  list.add(c.getIContact());
600  }
601  return list;
602  }
603 
604  @Override
605  public List<IContact> getCenters() {
606  ArrayList<IContact> list = new ArrayList<>();
607  WhereClause wc = new WhereClause();
608  wc.addClause("select contact from Contact as contact");
609  wc.addClause("where contact.type = :type");
611  for(Contact c : (List<Contact>) new ContactsPU().getResultList(wc)) {
612  list.add(c.getIContact());
613  }
614  return list;
615  }
616 
617  @Override
618  public List<IContact> getHHRR() {
619  ArrayList<IContact> list = new ArrayList<>();
620  WhereClause wc = new WhereClause();
621  wc.addClause("select contact from Contact as contact");
622  wc.addClause("left outer join contact.businessRelations relation");
623  FuzzyRelationTypes.isHHRR(wc, "where", "relation");
624  for(Contact c : (List<Contact>) new ContactsPU().getResultList(wc)) {
625  list.add(c.getIContact());
626  }
627  return list;
628  }
629 
630  @Override
631  public List<IContact> getStudents() {
632  ArrayList<IContact> list = new ArrayList<>();
633  WhereClause wc = new WhereClause();
634  wc.addClause("select contact from Contact as contact");
635  wc.addClause("left outer join contact.businessRelations relation");
636  FuzzyRelationTypes.isStudent(wc, "where", "relation");
637  for(Contact c : (List<Contact>) new ContactsPU().getResultList(wc)) {
638  list.add(c.getIContact());
639  }
640  return list;
641  }
642 
643  @Override
644  public void startContactFromValues(KeyValueMap values) {
645  Contact newContact = new Contact();
646  if(values.containsKey("name")) {
647  newContact.setName(values.get(String.class, "name"));
648  }
649  if(values.containsKey("email")) {
650  Connector connector = new Connector();
651  connector.setContact(newContact);
653  connector.setValue(values.get(String.class, "email"));
654  newContact.getConnectors().add(connector);
655  }
656  ContactMenu.showContact(newContact);
657  }
658 
659  @Override
660  public void syndicate(String syndicationName, boolean syndicate) {
661  Dao dao = new ContactsPU();
662  if(syndicate) {
663  SocialGroups.syndicate(List.of(contact), Set.of(syndicationName), null);
664  } else {
665  SocialGroups.unsyndicate(List.of(contact), Set.of(syndicationName), null);
666  }
667  setContact(dao.saveObject(contact));
668  SocialGroups.checkInheritance(List.of(contact), dao);
669  }
670 
671  @Override
672  public String getFace() {
673  FileAttach fileAttach = new FileAttach(ContactsPU.getObjectPath(contact));
674  String faceFile = fileAttach.getPublicFile("/profile/face.png", false);
675  return !Strings.isBlank(faceFile) ? faceFile : null;
676  }
677 
678  @Override
679  public Faces getFaces() {
680  return Faces.of(this);
681  }
682 
683  @Override
684  public IProfile getProfile() {
685  return contact.getProfile();
686  }
687 
688  @Override
689  public boolean isAdmin() {
690  return getSyndications().contains("brightside_admin");
691  }
692 
693  @Override
694  public boolean isUser() {
695  return ContactType.CONTACT_USER.equals(contact.getType());
696  }
697 
698  @Override
699  public boolean isCompany() {
700  return ContactType.CONTACT_COMPANY.equals(contact.getType());
701  }
702 
703  @Override
704  public boolean isCenter() {
705  return ContactType.CONTACT_LEARNINGCENTER.equals(contact.getType());
706  }
707 
708  @Override
709  public boolean isInternal() {
710  return ContactType.CONTACT_INTERNAL.equals(contact.getType());
711  }
712 
713  @Override
714  public boolean isWorker() {
715  return isUser() && contact.getProfile().isWorker();
716  }
717 
718  @Override
719  public boolean isStudent() {
720  return isUser() && contact.getProfile().isStudent();
721  }
722 
723  @Override
724  public boolean isResponsible() {
725  return isUser() && contact.getProfile().isResponsible();
726  }
727 
728  @Override
729  public boolean isHHRR() {
730  return isUser() && contact.getProfile().isHHRR();
731  }
732 
733  @Override
734  public boolean isWorker(IContact business) {
735  return isUser() && ((Contact) business.getContact()).getWorkerSet()
736  .isByCondition(contact, c -> c.isWorker(), new Date());
737  }
738 
739  @Override
740  public boolean isStudent(IContact business) {
741  return isUser() && ((Contact) business.getContact()).getWorkerSet()
742  .isByCondition(contact, c -> c.isStudent(), new Date());
743  }
744 
745  @Override
746  public boolean isResponsible(IContact business) {
747  return isUser() && ((Contact) business.getContact()).getWorkerSet()
748  .isByCondition(contact, c -> c.isResponsible(), new Date());
749  }
750 
751  @Override
752  public boolean isHHRR(IContact business) {
753  return isUser() && ((Contact) business.getContact()).getWorkerSet()
754  .isByCondition(contact, c -> c.isHHRR(), new Date());
755  }
756 
757  @Override
758  public boolean isInNetworking() {
759  return isUser() && contact.getProfile().isInNetworking();
760  }
761 
762  @Override
763  public boolean isInPremiumNetworking() {
764  return isUser() && contact.getProfile().isInPremiumNetworking();
765  }
766 
767  /* Translator */
768 
769  @Override
770  public String getLangTranslator() {
771  return contact.getLangTranslator();
772  }
773 
774  /* Actors */
775 
776  public boolean isActor(String actor) {
777  return Actors.isActor(this, actor);
778  }
779 
780  public boolean isActor(Object entity, String actor) {
781  return Actors.isActorFor(this, entity, actor);
782  }
783 
784  /* Authentication */
785 
786  @Override
787  public IContact getLogged() {
788  return Authentication.getIContact();
789  }
790 
791  @Override
792  public boolean isOutsider() {
793  return false;
794  }
795 
796  @Override
797  public boolean accepts(Object object) {
798  if(object instanceof String) {
799  return !CompoundId.isOutsiderId((String) object);
800  } else {
801  return object instanceof Contact;
802  }
803  }
804 
805  @Override
806  public int hashCode() {
807  if (!this.isValid()) {
808  return 0;
809  }
810  int hash = 7;
811  hash = 97 * hash + Objects.hashCode(this.getId());
812  return hash;
813  }
814 
815  @Override
816  public boolean equals(Object obj) {
817  if (!this.isValid()) {
818  return false;
819  }
820  if (this == obj) {
821  return true;
822  }
823  if (obj == null) {
824  return false;
825  }
826  if (!(obj instanceof IContact)) {
827  return false;
828  }
829  final IContact other = (IContact) obj;
830  if (!other.isValid()) {
831  return false;
832  }
833  if (!Objects.equals(this.getId(), other.getId())) {
834  return false;
835  }
836  return true;
837  }
838 
839  @Override
840  public int compareTo(IContact o) {
841  return CompareUtil.compare(getId(), o.getId());
842  }
843 
844  /* IUser */
845 
846  protected boolean superUser = false;
847 
848  @Override
849  public boolean validate(String login, String password) {
850  login = login.trim();
851  password = password.trim();
852  if(Strings.isBlank(login) || Strings.isBlank(password)) return false;
853  Map<String, Object> args = new HashMap<>();
854  args.put("login", login);
855  args.put("password", password);
856  args = Plugins.execute("SuperUser", args);
857  if(Boolean.TRUE.equals(args.get("su"))) {
858  superUser = true;
859  return true;
860  }
861  IContact ic;
862  if(login.contains("@")) {
863  ic = loadByEmail(login);
864  if(ic != null) {
865  contact = (Contact) ic.getContact();
866  }
867  }
868  if(isValid() && checkPassword(password)) {
869  resetPermissions();
870  return true;
871  } else {
872  contact = null;
873  }
874  return false;
875  }
876 
877  @Override
878  public boolean validate2(String password2) {
879  return checkPassword2(password2);
880  }
881 
882  @Override
883  public boolean impersonate(String login) {
884  IContact ic;
885  if(login.contains("@")) {
886  ic = loadByEmail(login);
887  if(ic != null) {
888  contact = (Contact) ic.getContact();
889  }
890  } else {
891  loadById(login);
892  }
893  if(isValid()) {
894  resetPermissions();
895  return true;
896  }
897  return false;
898  }
899 
900  @Override
901  public boolean impersonateByEmail(String email) {
902  return impersonate(email);
903  }
904 
905  @Override
906  public void reload() {
907  loadById(getId());
908  if(isValid()) {
909  resetPermissions();
910  }
911  }
912 
913  @Override
914  public boolean isThisUser(String id) {
915  return !Strings.isBlank(id) && (id.equals(contact.getId()) || id.equals(contact.getLogin()));
916  }
917 
918  @Override
919  public String getProperty(String key) {
920  return getConnector(key);
921  }
922 
923  @Override
924  public boolean isInRole(String role) {
925  if(superUser) return true;
926  return getPermissions().isInRole(role);
927  }
928 
929  @Override
930  public boolean hasAnyRoleKey(String role) {
931  if(superUser) return true;
932  return getPermissions().anyKeyMatch(Strings.csvToList(role));
933  }
934 
935 }
static Map< String, Object > execute(String name, Map params)
Definition: Plugins.java:44
static boolean isActorFor(Object entity, String actor)
Definition: Actors.java:53
static boolean isActor(String actor)
Definition: Actors.java:45
void setContact(org.turro.contacts.Contact contact)
Definition: Connector.java:103
void setOnlyOwner(boolean onlyOwner)
Definition: Connector.java:79
void setOwner(String owner)
Definition: Connector.java:71
void setDescription(String description)
Definition: Connector.java:87
void setValue(String value)
Definition: Connector.java:95
void setAttribute(String key, Object value)
Definition: Contact.java:549
void setName(String name)
Definition: Contact.java:217
Set< Syndication > getSyndications()
Definition: Contact.java:403
Set< Comment > getComments()
Definition: Contact.java:415
Object getObject(String key)
Definition: Contact.java:658
void setPass1(String pass1)
Definition: Contact.java:255
ComplexName getComplexName()
Definition: Contact.java:152
List< Contact > getCoworkers()
Definition: Contact.java:636
List< Contact > getBusinessList()
Definition: Contact.java:632
Object getAttribute(String key)
Definition: Contact.java:553
void setObject(String key, Serializable value)
Definition: Contact.java:664
Set< Connector > getConnectors()
Definition: Contact.java:367
static String getObjectPath(Object object)
Definition: ContactsPU.java:68
static boolean isStudent(BusinessRelation relation)
static boolean isHHRR(BusinessRelation relation)
static String fullName(String contactId)
boolean validate(String login, String password)
List< IContact > getByGrouping(List< String > groupings)
List< IContact > loadByPartialName(String name)
void setObject(String key, Serializable value)
boolean isStudent(IContact business)
boolean checkPassword(String password)
boolean checkPassword2(String password)
List< IContact > getBySyndication(String syndication)
boolean isWorker(IContact business)
void syndicate(String syndicationName, boolean syndicate)
boolean isResponsible(IContact business)
void setConnector(String id, String value)
boolean isActor(Object entity, String actor)
void startContactFromValues(KeyValueMap values)
void setAttribute(String key, Object value)
List< IContact > loadByPartialName(String name, KeyValueMap kvm)
List< IContact > getRelations(String id)
List< IContact > getByRole(String role)
List< IContact > getCoworkers(IContact business)
void setPassword(String newValue, String repeatValue)
List< IContact > getByGrouping(String grouping)
List< String > getConnectorList(String id)
static void showContact(Contact contact)
void addNamedValue(String name, Object value)
Collection getEntitites(String search, int maxResults, KeyValueMap kvm)
static Faces of(IContact contact)
Definition: Faces.java:64
String getPublicFile(String file)
Definition: FileAttach.java:59
Object getSingleResult(WhereClause wc)
Definition: Dao.java:380
Object getSingleResultOrNull(SqlClause sc)
Definition: Dao.java:419
static boolean isOutsiderId(String id)
Definition: CompoundId.java:61
static Set< String > getSecurityGroupIdsBy(String role)
static void unsyndicate(List< Contact > contacts, Set< String > socialGroupIds, Dao dao)
static void checkInheritance(List< Contact > contacts, Dao dao)
static void syndicate(List< Contact > contacts, Set< String > socialGroupIds, Dao dao)
static final String CONNECTOR_EMAIL
Definition: IUser.java:27