BrightSide Workbench Full Report + Source Code
AllianceAuthentication.java
Go to the documentation of this file.
1 /*
2  * TurrĂ³ i Cutiller Foundation. License notice.
3  * Copyright (C) 2022 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.alliance.auth;
20 
21 import java.security.NoSuchAlgorithmException;
22 import java.util.logging.Level;
23 import java.util.logging.Logger;
24 import org.turro.string.Strings;
25 import org.turro.alliance.contact.AllianceContact;
26 import org.turro.alliance.db.AlliancePU;
27 import org.turro.alliance.db.entities.AxContact;
28 import org.turro.alliance.service.AxConstants;
29 import org.turro.alliance.service.AxClient;
30 import org.turro.crypto.Digest;
31 import org.turro.external.ElephantAuthentication;
32 import org.turro.external.IElephantAuthentication;
33 import org.turro.plugin.contacts.IContact;
34 import org.turro.sql.SqlClause;
35 import org.turro.ws.WsMember;
36 import org.turro.ws.service.server.Clients;
37 
44 
45  @Override
46  public boolean requiresProcedence() {
47  return !Clients.getMembers(AxClient.CLIENT_SERVICE).isEmpty();
48  }
49 
50  @Override
51  public boolean accepts(Object extra) {
52  WsMember member = (WsMember) extra;
53  return (member != null) && (member.getService().equals(AxClient.CLIENT_SERVICE));
54  }
55 
56  @Override
57  public IContact doLogin(String login, String pass, Object extra) {
58  WsMember member = (WsMember) extra;
59  if(!Strings.isBlank(pass)) try {
60  AxContact contact = SqlClause.select("c").from("AxContact c")
61  .where().equal("c.contactId.memberId", member.getMemberId())
62  .and().equal("c.active", true)
63  .and().equal("c.email", login)
64  .and().equal("c.passdig", Digest.sha256(pass).hexString())
65  .dao(new AlliancePU())
66  .singleResult(AxContact.class);
67  if(contact != null) {
68  return new AllianceContact(contact);
69  }
70  } catch (NoSuchAlgorithmException ex) {
71  Logger.getLogger(AllianceAuthentication.class.getName()).log(Level.SEVERE, null, ex);
72  }
73  return null;
74  }
75 
76 }
IContact doLogin(String login, String pass, Object extra)
static AxContact from(long memberId, String contactId)
Definition: AxContact.java:162
static final String CLIENT_SERVICE
Definition: AxClient.java:58