private String getSSOUrl ( int port ) throws SFException , SnowflakeSQLException { try { String serverUrl = loginInput . getServerUrl ( ) ; String authenticator = loginInput . getAuthenticator ( ) ; URIBuilder fedUriBuilder = new URIBuilder ( serverUrl ) ; fedUriBuilder . setPath ( SessionUtil . SF_PATH_AUTHENTICATOR_REQUEST ) ; URI fedUrlUri = fedUriBuilder . build ( ) ; HttpPost postRequest = this . handlers . build ( fedUrlUri ) ; ClientAuthnDTO authnData = new ClientAuthnDTO ( ) ; Map < String , Object > data = new HashMap <> ( ) ; data . put ( ClientAuthnParameter . AUTHENTICATOR . name ( ) , authenticator ) ; data . put ( ClientAuthnParameter . ACCOUNT_NAME . name ( ) , loginInput . getAccountName ( ) ) ; data . put ( ClientAuthnParameter . LOGIN_NAME . name ( ) , loginInput . getUserName ( ) ) ; data . put ( ClientAuthnParameter . BROWSER_MODE_REDIRECT_PORT . name ( ) , Integer . toString ( port ) ) ; data . put ( ClientAuthnParameter . CLIENT_APP_ID . name ( ) , loginInput . getAppId ( ) ) ; data . put ( ClientAuthnParameter . CLIENT_APP_VERSION . name ( ) , loginInput . getAppVersion ( ) ) ; authnData . setData ( data ) ; String json = mapper . writeValueAsString ( authnData ) ; // attach the login info json body to the post request StringEntity input = new StringEntity ( json , Charset . forName ( "UTF-8" ) ) ; input . setContentType ( "application/json" ) ; postRequest . setEntity ( input ) ; postRequest . addHeader ( "accept" , "application/json" ) ; String theString = HttpUtil . executeRequest ( postRequest , loginInput . getLoginTimeout ( ) , 0 , null ) ; logger . debug ( "authenticator-request response: {}" , theString ) ; // general method, same as with data binding JsonNode jsonNode = mapper . readTree ( theString ) ; // check the success field first if ( ! jsonNode . path ( "success" ) . asBoolean ( ) ) { logger . debug ( "response = {}" , theString ) ; String errorCode = jsonNode . path ( "code" ) . asText ( ) ; throw new SnowflakeSQLException ( SqlState . SQLCLIENT_UNABLE_TO_ESTABLISH_SQLCONNECTION , new Integer ( errorCode ) , jsonNode . path ( "message" ) . asText ( ) ) ; } JsonNode dataNode = jsonNode . path ( "data" ) ; // session token is in the data field of the returned json response this . proofKey = dataNode . path ( "proofKey" ) . asText ( ) ; return dataNode . path ( "ssoUrl" ) . asText ( ) ; } catch ( IOException | URISyntaxException ex ) { throw new SFException ( ex , ErrorCode . NETWORK_ERROR , ex . getMessage ( ) ) ; } }
Gets SSO URL and proof key