You are here: Authorization > loginByContact

Customer Contact Login by User ID and Password

Description

You can use this Web service in your application to configure customer/end user login by contact e-mail ID and password. The output parameters are sessionId and entID.

On login by e-mailID and password, a contact can view details of all the entitlements created for the customer. For a complete list of operations that the customer can perform after login, refer to Sentinel Cloud EMS User's Guide.

Default Protocol Method Type URI
HTTPS POST loginByContact.xml

Post Parameters

Parameter Description Valid Values Optional
emailId E-mail ID of the contact. String No
password Login password associated with the contact. String No

Sample Code

import java.io.IOException;
import java.io.InputStream;
import java.security.Principal;
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.protocol.ClientContext;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.protocol.BasicHttpContext;
import org.apache.http.protocol.HTTP;
import org.apache.http.protocol.HttpContext;
import org.apache.http.NameValuePair;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.params.BasicHttpParams;
import org.apache.http.params.HttpParams;
public class EMSSample {
        private static DefaultHttpClient httpclient = new DefaultHttpClient();
        private static Principal principal = null;
        private static String server;
        private static String sslServer;
        private static String trustStore;
        private static String trustStorePass;
        private static String emsWSDemoFile = "emsWSDemo.properties";
        public static void loadPropertiesFile()throws Exception
        {
                Properties properties = new Properties();
                InputStream file = Thread.currentThread().getContextClassLoader().getResourceAsStream(emsWSDemoFile);
                if(file == null)
                {
                        throw new Exception("unable to load file '" + emsWSDemoFile + "'");
                }
                properties.load(file);
                server = properties.getProperty("server");
                sslServer = properties.getProperty("sslServer");
                trustStore = properties.getProperty("trustStore");
                trustStorePass = properties.getProperty("trustStorePass");
                System.setProperty("javax.net.ssl.trustStore", trustStore);
                System.setProperty("javax.net.ssl.trustStorePassword", trustStorePass);
        }
        public static boolean loginByContact() throws Exception{
                loadPropertiesFile();
                HttpContext context = new BasicHttpContext();
                HttpPost post = new HttpPost(
                                "https://localhost:8443/ems/3.6/loginByContact.xml");
                List<NameValuePair> nvps = new ArrayList<NameValuePair>();
                nvps.add(new BasicNameValuePair("emailId", ""));
                nvps.add(new BasicNameValuePair("password", ""));
                post.setEntity(new UrlEncodedFormEntity(nvps, HTTP.UTF_8));
                HttpResponse emsResponse = httpclient.execute(post, context);
                HttpEntity entity = emsResponse.getEntity();
                byte[] b = null;
                if (entity != null) {
                        long l = entity.getContentLength();
                        b = new byte[(int) l];
                        entity.getContent().read(b);
                        entity.consumeContent();
                }
                principal = (Principal) context
                .getAttribute(ClientContext.USER_TOKEN);
                String loginResult = new String(b);
                if (loginResult.indexOf("\"stat\":\"ok\"")>0)
                        return true;
                else
                        return false;
        }
}

Sample Response

<?xml version="1.0" encoding="UTF-8"?>
<emsResponse>
   <entIds>
      <entId>98</entId>
      <entId>97</entId>
      <entId>90</entId>
   </entIds>
   <sessionId>B9902FF8008931D71882BCD51E71A85F</sessionId>
   <stat>ok</stat>
</emsResponse>
See Also:

Output Format for Failure

Error Codes

Error Code Description
214 Password cannot be blank.
216 Email id cannot be blank.
217 Email Id or Password is incorrect, please retry to login.
218 Your account has been disabled. Please contact Administrator!
1081 Invalid Web service version provided
1084 No Web service version provided
1088 The EMS system is running on HTTPS. Please provide the correct Web service URL.