2 * Copyright (c) 2010-2023 Contributors to the openHAB project
4 * See the NOTICE file(s) distributed with this work for additional
7 * This program and the accompanying materials are made available under the
8 * terms of the Eclipse Public License 2.0 which is available at
9 * http://www.eclipse.org/legal/epl-2.0
11 * SPDX-License-Identifier: EPL-2.0
13 package org.openhab.binding.ihc.internal.ws.services;
15 import org.openhab.binding.ihc.internal.ws.datatypes.WSLoginResult;
16 import org.openhab.binding.ihc.internal.ws.exeptions.IhcExecption;
17 import org.openhab.binding.ihc.internal.ws.http.IhcConnectionPool;
18 import org.slf4j.Logger;
19 import org.slf4j.LoggerFactory;
22 * Class to handle IHC / ELKO LS Controller's authentication service.
24 * Communication to controller need to be authenticated. On successful
25 * authentication Controller returns session id which need to be used further
28 * @author Pauli Anttila - Initial contribution
30 public class IhcAuthenticationService extends IhcBaseService {
31 private final Logger logger = LoggerFactory.getLogger(IhcAuthenticationService.class);
33 public IhcAuthenticationService(String host, int timeout, IhcConnectionPool ihcConnectionPool) {
34 super(ihcConnectionPool, timeout, host, "AuthenticationService");
37 public WSLoginResult authenticate(String username, String password, String application) throws IhcExecption {
38 logger.debug("Authenticate");
41 final String soapQuery =
43 <?xml version="1.0" encoding="UTF-8"?>
44 <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
46 <authenticate1 xmlns="utcs">
47 <password>%s</password>
48 <username>%s</username>
49 <application>%s</application>
56 String query = String.format(soapQuery, password, username, application);
57 String response = sendSoapQuery(null, query);
58 return new WSLoginResult().parseXMLData(response);