package art.servers.transactionsserver.model.access;
import art.library.interop.InteropParameters;
import art.library.interop.InteropResponse;
import art.library.interop.serialization.Serialization;
import art.library.interop.serialization.SerializationException;
import art.library.model.devices.Device;
import art.library.model.devices.user.User;
import art.library.model.devices.user.UserIdentification;
import art.library.model.devices.user.UserInformation;
import art.library.model.devices.user.UserPermission;
import art.library.net.ldap.LDAP;
import art.library.utils.licence.Licence;
import art.library.utils.password.PasswordGenerator;
import art.servers.transactionsserver.Shared;
import art.servers.transactionsserver.controller.ListenerImplementation;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.stream.Collectors;
public class ModelUsers
{
public ModelUsers() throws Exception
{
}
// name: "language" class: name: "lGroup" class: name: "language" class: name: "lGroup" class: InteropParameters
* String
* String[]
* @return InteropResponse
* UserIdentification[]
* @throws SerializationException
*/
@SuppressWarnings("unchecked")
public InteropResponse getUsersIdentification(InteropParameters parameters) throws SerializationException
{
String language = (String)parameters.getParameterValue("language");
ListInteropParameters
* String
* String[]
* @return InteropResponse
* UserInformation[]
* @throws SerializationException
*/
@SuppressWarnings("unchecked")
public InteropResponse getUsersInformation(InteropParameters parameters) throws SerializationException
{
String language = (String)parameters.getParameterValue("language");
ListInteropParameters
*
name: "get" class: getUserLdap
*
name: "language" class: String
*
name: "username" class: String
* @return InteropResponse
* UserInformation
* @throws SerializationException
*/
public InteropResponse getUserLdap(InteropParameters parameters) throws SerializationException
{
String language = (String)parameters.getParameterValue("language");
try
{
Shared.println("ModelUsers", "1.GetUserLDAP: " + Shared.getConfiguration().lldapServer);
if ((Shared.getConfiguration().lldapServer == null) || (Shared.getConfiguration().lldapServer.length <= 0))
{
return new InteropResponse(Shared.getMessage("Information:") + " " + Shared.getMessage("art.servers.transactionsserver.ldap.json not defined"));
}
String username = (String)parameters.getParameterValue("username");
String usernameDecrypt;
try
{
usernameDecrypt = Licence.decrypt(username);
} catch (Exception e)
{
usernameDecrypt = username;
username = Licence.encrypt(username);
}
Shared.println("ModelUsers", "2.GetUserLDAP username: " + usernameDecrypt + " - " + username);
LDAP ldap = new LDAP(Arrays.asList(Shared.getConfiguration().lldapServer));
Shared.println("ModelUsers", "GetUserLdap: LDAP: " + ldap);
if (ldap.userExists(usernameDecrypt))
{
Shared.println("ModelUsers", "GetUserLdap: LDAP user exists: " + usernameDecrypt);
art.library.net.ldap.User ldapUser = ldap.getUser(usernameDecrypt);
//GET ARTIC USER
User user = null;
try
{
user = (User) Shared.getModel().getDevice(username);
}
catch (Exception e)
{
Shared.println("ModelUsers", "GetUserLdap: LDAP user exists, user ARTIC ex: " + e.toString());
UserInformation userInformation = new UserInformation();
userInformation.setIdentifier(username);
userInformation.group = ldapUser.department;
userInformation.name = ldapUser.displayName;
userInformation.company = ldapUser.company;
userInformation.phone = ldapUser.telephoneNumber;
userInformation.address = ldapUser.userPrincipalName;
userInformation.description = ldapUser.employeeID;
userInformation.password = Licence.encrypt(PasswordGenerator.generatePassword(8));
List