Search in sources :

Example 6 with Session

use of com.xensource.xenapi.Session in project cloudstack by apache.

the class XenServerConnectionPool method loginWithPassword.

protected Session loginWithPassword(Connection conn, String username, Queue<String> password, String version) throws BadServerResponse, XenAPIException, XmlRpcException {
    Session s = null;
    boolean logged_in = false;
    Exception ex = null;
    while (!logged_in) {
        try {
            s = Session.loginWithPassword(conn, username, password.peek(), APIVersion.latest().toString());
            logged_in = true;
        } catch (BadServerResponse e) {
            logged_in = false;
            ex = e;
        } catch (XenAPIException e) {
            logged_in = false;
            ex = e;
        } catch (XmlRpcException e) {
            logged_in = false;
            ex = e;
        }
        if (logged_in && conn != null) {
            break;
        } else {
            if (password.size() > 1) {
                password.remove();
                continue;
            } else {
                // the last password did not work leave it and flag error
                if (ex instanceof BadServerResponse) {
                    throw (BadServerResponse) ex;
                } else if (ex instanceof XmlRpcException) {
                    throw (XmlRpcException) ex;
                } else if (ex instanceof Types.SessionAuthenticationFailed) {
                    throw (Types.SessionAuthenticationFailed) ex;
                } else if (ex instanceof XenAPIException) {
                    throw (XenAPIException) ex;
                }
            }
        }
    }
    return s;
}
Also used : BadServerResponse(com.xensource.xenapi.Types.BadServerResponse) XenAPIException(com.xensource.xenapi.Types.XenAPIException) XmlRpcException(org.apache.xmlrpc.XmlRpcException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) XenAPIException(com.xensource.xenapi.Types.XenAPIException) IOException(java.io.IOException) KeyManagementException(java.security.KeyManagementException) FileNotFoundException(java.io.FileNotFoundException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) XmlRpcClientException(org.apache.xmlrpc.client.XmlRpcClientException) XmlRpcException(org.apache.xmlrpc.XmlRpcException) Session(com.xensource.xenapi.Session) SSLSession(javax.net.ssl.SSLSession)

Aggregations

CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)6 Session (com.xensource.xenapi.Session)6 XenAPIException (com.xensource.xenapi.Types.XenAPIException)6 FileNotFoundException (java.io.FileNotFoundException)6 IOException (java.io.IOException)6 KeyManagementException (java.security.KeyManagementException)6 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)6 SSLSession (javax.net.ssl.SSLSession)6 XmlRpcException (org.apache.xmlrpc.XmlRpcException)6 XmlRpcClientException (org.apache.xmlrpc.client.XmlRpcClientException)6 BadServerResponse (com.xensource.xenapi.Types.BadServerResponse)4 Connection (com.xensource.xenapi.Connection)2 Host (com.xensource.xenapi.Host)2 Types (com.xensource.xenapi.Types)2 HttpsURLConnection (javax.net.ssl.HttpsURLConnection)2