doc-exports/docs/mrs/api-ref/mrs_02_1080.html
Yang, Tong bd2b57f749 MRS API 2.0.38.SP20 version
Reviewed-by: gtema <artem.goncharov@gmail.com>
Co-authored-by: Yang, Tong <yangtong2@huawei.com>
Co-committed-by: Yang, Tong <yangtong2@huawei.com>
2022-11-16 15:06:08 +00:00

123 lines
9.6 KiB
HTML

<a name="mrs_02_1080"></a><a name="mrs_02_1080"></a>
<h1 class="topictitle1">API Calling Process</h1>
<div id="body8662426"><p id="mrs_02_1080__en-us_topic_0125376234_en-us_topic_0037324630_p8060118">The process for calling an MRS Manager API is as follows:</p>
<ol id="mrs_02_1080__en-us_topic_0125376234_oe72ac1aaa245416c95e87906a35c7ab0"><li id="mrs_02_1080__en-us_topic_0125376234_li175761832122619"><a href="#mrs_02_1080__en-us_topic_0125376234_section1225494452418">Obtaining Request Authentication Information</a><p id="mrs_02_1080__en-us_topic_0125376234_p45354461159">Before you call an API, obtain request authentication information, and fill it in a request header.</p>
</li><li id="mrs_02_1080__en-us_topic_0125376234_l6bf14b1a74164296857966a9457e528a"><a href="mrs_02_0008.html">Obtaining Request Authentication Information</a><p id="mrs_02_1080__en-us_topic_0125376234_a3561df215a5042dca5ee64bc9c7bca7c">Configure request parameters to construct a request. </p>
</li><li id="mrs_02_1080__en-us_topic_0125376234_lc02afc97587f442aa7dfc0b9473fd64c"><a href="mrs_02_0008.html">Sending a Request</a></li><li id="mrs_02_1080__en-us_topic_0125376234_l4c98f47f8b4d444daa6e23ba05d7be0b"><a href="mrs_02_0010.html">Parsing a Response</a></li></ol>
<div class="section" id="mrs_02_1080__en-us_topic_0125376234_section1225494452418"><a name="mrs_02_1080__en-us_topic_0125376234_section1225494452418"></a><a name="en-us_topic_0125376234_section1225494452418"></a><h4 class="sectiontitle">Obtaining Request Authentication Information</h4><p id="mrs_02_1080__en-us_topic_0125376234_p171821635122714"><strong id="mrs_02_1080__b1382564414271">Scenario</strong></p>
</div>
<p id="mrs_02_1080__en-us_topic_0125376234_p65702362716">Currently, CAS can be used for login authentication when an API is called.</p>
<p id="mrs_02_1080__en-us_topic_0125376234_p3570131279">After login authentication, obtain the JSESSIONID of a web request and check the current user using the JSESSIONID.</p>
<p id="mrs_02_1080__en-us_topic_0125376234_p116835282719"><strong id="mrs_02_1080__b16271185911121">Procedure for Calling an API</strong> (Security Cluster)</p>
<ol id="mrs_02_1080__en-us_topic_0125376234_ol12762544142817"><li id="mrs_02_1080__en-us_topic_0125376234_li8762134413282">Send the request <strong id="mrs_02_1080__b749664371316">GET https://</strong><em id="mrs_02_1080__en-us_topic_0125376234_i8174223205116"><strong id="mrs_02_1080__en-us_topic_0125376234_b1431471512539">MRS Manager</strong><strong id="mrs_02_1080__en-us_topic_0125376234_b163161015115314">floating IP</strong></em><strong id="mrs_02_1080__b13664748141310">:20009/cas/login</strong> to obtain <strong id="mrs_02_1080__b84235270684754">casSessionId</strong> and <strong id="mrs_02_1080__b84235270684758">loginTicket</strong> from the CAS login information.<p id="mrs_02_1080__en-us_topic_0125376234_p1976411444283">The following example describes how to obtain <strong id="mrs_02_1080__b84235270684926">casSessionId</strong> and <strong id="mrs_02_1080__b84235270684931">loginTicket</strong> from the response object of the request.</p>
</li></ol>
<pre class="screen" id="mrs_02_1080__en-us_topic_0125376234_screen576420441281">// Obtain the CAS login page.
HttpResponse casLoginPageResponse = getCasLoginPage(casUrl, httpClient);
LOG.info("get cas login page request status is :{} , casLoginPageResponse is :{}.", casLoginPageResponse.getStatusLine(), casLoginPageResponse);
// Obtain <strong id="mrs_02_1080__b84235270684958">casSessionId</strong> and <strong id="mrs_02_1080__b8423527068503">loginTicket</strong>.
String casSessionId = getCasSessionId(casLoginPageResponse);
String loginTicket = getLoginTicket(casLoginPageResponse);
LOG.info("casSessionId = {} , loginTicket = {}.", casSessionId, loginTicket);</pre>
<ol start="2" id="mrs_02_1080__en-us_topic_0125376234_ol2076420444286"><li id="mrs_02_1080__en-us_topic_0125376234_li7764104462816">Send <strong id="mrs_02_1080__b13946184819243">POST https://</strong><em id="mrs_02_1080__en-us_topic_0125376234_i1936715581141">MRS Manager floating IP</em><strong id="mrs_02_1080__b199081754122419">:20009/cas/login?service= https://</strong><em id="mrs_02_1080__en-us_topic_0125376234_i1241016319159">MRS Manager floating IP</em><strong id="mrs_02_1080__b2055341142511">:28443/web/cas_security_check.htm</strong> to initiate a CAS login authentication request. The request body contains the username, password, and the obtained <strong id="mrs_02_1080__b298151519258">loginTicket</strong>. The request header contains <strong id="mrs_02_1080__b159341519142511">casSessionId</strong>. Obtain the authenticated ticket granting cookie (TGC) from the response header.</li></ol>
<pre class="screen" id="mrs_02_1080__en-us_topic_0125376234_screen57651449283">// Authenticate the username and password on the CAS server.
HttpResponse loginPostResponse =
loginCasServer(casUrl, webUrl, userName, password, httpClient, casSessionId, loginTicket, userTLSVersion);
LOG.info("the post response is: {}.", loginPostResponse);
// Obtain the authenticated TGC.
String casTgc = getCASTGC(loginPostResponse);
LOG.info("casTgc = {}.", casTgc);
...
/**
* Log in to the CAS server and verify user information.
* @param casUrl CAS server address
* @param webUrl Web application address
* @param userName Login user name
* @param password Login password
* @param casSessionId CAS session ID
* @param loginTicket CAS login ticket
* @return http client HTTP client
*/
private HttpResponse loginCasServer(String casUrl, String webUrl, String userName, String password,
HttpClient httpClient, String casSessionId, String loginTicket,String userTLSVersion)
{
if (ParamsValidUtil.isEmpty(casUrl, webUrl, userName, password, casSessionId, loginTicket))
{
LOG.error("Invalid input param.");
}
String postUrl = generateCasLoginUrl(casUrl, webUrl);
LOG.info("login cas server URL is : {}.", postUrl);
HttpPost httpPost = new HttpPost(postUrl);
// Parameters contained in the request body
List&lt;BasicNameValuePair&gt; FormData = new ArrayList&lt;BasicNameValuePair&gt;();
FormData.add(new BasicNameValuePair("username", userName));
FormData.add(new BasicNameValuePair("password", password));
FormData.add(new BasicNameValuePair("lt", loginTicket));
FormData.add(new BasicNameValuePair("_eventId", "submit"));
FormData.add(new BasicNameValuePair("submit", "Login"));
HttpResponse response = null;
BufferedReader bufferedReader = null;
// Parameters contained in the request header
httpPost.addHeader("Cookie", CAS_SESSION_ID_STRING + casSessionId);
...
/**
* Generate a complete URL for logging in to CAS.
* After the login is successful, the specified CAS security check page is displayed.
* @param casUrl
* @param webUrl
* @return
*/
private String generateCasLoginUrl(String casUrl, String webUrl)
{
StringBuilder sb = new StringBuilder();
sb.append(casUrl);
sb.append("?service=");
sb.append(webUrl);
sb.append("/cas_security_check.htm");
return sb.toString();
}</pre>
<ol start="3" id="mrs_02_1080__en-us_topic_0125376234_ol1765134415282"><li id="mrs_02_1080__en-us_topic_0125376234_li47651644152812">Send <strong id="mrs_02_1080__b14397950122516">GET https://</strong><em id="mrs_02_1080__en-us_topic_0125376234_i1647144425213">MRS Manager floating IP</em><strong id="mrs_02_1080__b17477156192512">:28443/web/v1/access/login_check</strong> to initiate a web login authentication request. The cookie in the request header contains two TGC obtained in the previous step. After the response is successful, obtain the JSESSIONID of the web request from the cookie in the response header.</li></ol>
<pre class="screen" id="mrs_02_1080__en-us_topic_0125376234_screen20767044132811">/**
* Initiate a request for web application login authentication.
* @param webUrl Web application URL
* @param httpclient http client
* @return response Login verification response object
*/
private HttpResponse webLoginCheck(String webUrl, HttpClient httpclient)
{
//Web login authentication request path
HttpGet loginCheckHttpGet = new HttpGet(webUrl + "/v1/access/login_check");
LOG.info("web login check URL is: {}.", (webUrl + "/v1/access/login_check"));
HttpResponse response = null;
BufferedReader bufferedReader = null;
InputStream inputStream = null;
boolean flag = false;
try
{
response = httpclient.execute(loginCheckHttpGet);
inputStream = response.getEntity().getContent();
bufferedReader = new BufferedReader(new InputStreamReader(inputStream));
String lineContent = "";
lineContent = bufferedReader.readLine();
LOG.info("response content is {} : " + lineContent);
String postResponseState = "";
...</pre>
<div class="note" id="mrs_02_1080__en-us_topic_0125376234_note16133174218393"><img src="public_sys-resources/note_3.0-en-us.png"><span class="notetitle"> </span><div class="notebody"><p id="mrs_02_1080__en-us_topic_0125376234_p139781220155414">For a non-security cluster, you can skip CAS authentication in step 1 and step 2 and directly send the <strong id="mrs_02_1080__b5301532181819">GET https://</strong><em id="mrs_02_1080__en-us_topic_0125376234_i10238935686"><strong id="mrs_02_1080__en-us_topic_0125376234_b24791533184">MRS Manager floating IP</strong></em><strong id="mrs_02_1080__b4600114321814">:28443/web/v1/access/login_check</strong> web login authentication request. And then, you can obtain the <strong id="mrs_02_1080__b19851955111814">FISessionId </strong>of the web request from the cookie of the response header of the response object.</p>
</div></div>
</div>
<div>
<div class="familylinks">
<div class="parentlink"><strong>Parent topic:</strong> <a href="mrs_02_1018.html">API Usage Guide</a></div>
</div>
</div>