@@ -370,6 +370,80 @@ public boolean loginKeystone() throws UnknownHostException, SocketException, IOE
370370
371371 return isLoggedin ;
372372 }
373+
374+ public boolean loginKeystoneV3 () throws UnknownHostException , SocketException , IOException , UnauthorizeException {
375+ isLoggedin = false ;
376+
377+ String tenantNameKeystone = "" ;
378+ String userNameKeystone = username ;
379+ if (username .split (":" ).length >= 2 ) {
380+ tenantNameKeystone = username .split (":" )[0 ];
381+ userNameKeystone = username .split (":" )[1 ];
382+ }
383+
384+ String content = "{\" auth\" : {\" identity\" : {\" methods\" : [\" password\" ],\" password\" : {\" user\" :{\" domain\" : {\" name\" : \" d_Stacksync\" },\" name\" : \" " +userNameKeystone +"\" ,\" password\" : \" " +password +"\" }}},\" scope\" : {\" project\" : {\" domain\" : {\" name\" : \" d_Stacksync\" },\" name\" : \" " +tenantNameKeystone +"\" }}}}" ;
385+ //String content = "{\"auth\": {\"passwordCredentials\": {\"username\": \"" + userNameKeystone + "\", \"password\": \"" + password + "\"}, \"tenantName\":\"" + tenantNameKeystone + "\"}}";
386+
387+ HttpPost method = new HttpPost (authenticationURL );
388+ method .getParams ().setIntParameter ("http.socket.timeout" , connectionTimeOut );
389+ method .setHeader ("Content-type" , "application/json" );
390+
391+ InputStream stream = new ByteArrayInputStream (content .getBytes ("UTF-8" ));
392+ InputStreamEntity entity = new InputStreamEntity (stream , content .getBytes ("UTF-8" ).length );
393+ method .setEntity (entity );
394+
395+ stream .close ();
396+
397+ FilesResponse response = new FilesResponse (client .execute (method ));
398+
399+ if (response .getStatusCode () == 401 ) {
400+ throw new UnauthorizeException ("Incorrect user/password." , response .getResponseHeaders (), response .getStatusLine ());
401+ }
402+
403+ InputStream in = response .getResponseBodyAsStream ();
404+ String outString = IOUtils .toString (in , "UTF-8" );
405+ in .close ();
406+
407+ Header header = response .getResponseHeaders ("X-Subject-Token" )[0 ];
408+ authToken = header .getValue ();
409+
410+ JsonElement jelement = new JsonParser ().parse (outString );
411+ JsonObject jobject = jelement .getAsJsonObject ();
412+
413+ //jobject = jelement.getAsJsonObject();
414+ jobject = jobject .getAsJsonObject ("token" );
415+
416+ JsonArray jarray = jobject .getAsJsonArray ("catalog" );
417+
418+ for (JsonElement serviceCatalog : jarray ) {
419+ JsonObject jsonLineItem = serviceCatalog .getAsJsonObject ();
420+
421+ String value = jsonLineItem .get ("type" ).getAsString ();
422+
423+ if (value .compareTo ("object-store" ) == 0 ) {
424+ JsonArray jarray2 = jsonLineItem .getAsJsonArray ("endpoints" );
425+
426+ for (JsonElement endpoint : jarray2 ) {
427+ JsonObject endpointObject = endpoint .getAsJsonObject ();
428+ String publicURL = endpointObject .get ("interface" ).getAsString ();
429+ if (publicURL .compareTo ("public" ) == 0 ) {
430+ storageURL = endpointObject .get ("url" ).getAsString ();
431+ isLoggedin = true ;
432+ cdnManagementURL = "" ;
433+
434+ break ;
435+ }
436+ }
437+ }
438+ }
439+
440+ logger .debug ("storageURL: " + storageURL );
441+ logger .debug ("authToken: " + authToken );
442+ logger .debug ("cdnManagementURL:" + cdnManagementURL );
443+ logger .debug ("ConnectionManager:" + client .getConnectionManager ());
444+
445+ return isLoggedin ;
446+ }
373447
374448 /**
375449 * Log in to CloudFiles. This method performs the authentication and sets up
0 commit comments