http 403 认证失败-keytool生成证书,上传到azure中,但仍旧,显示认证失败

问题描述

keytool生成证书,上传到azure中,但仍旧,显示认证失败
 public class TestClient {
    private static ComputeManagementClient computeManagementClient;
    private static ManagementClient client;
    private static URI uri;
    private static String subscriptionId;
    private static String keyStoreLocation;
    private static String keyStorePassword;
    private static KeyStoreType  keyStoreType;
    public static Configuration createConfiguration() throws IOException,URISyntaxException{
        uri = new URI("https://management.core.windows.net/");
        subscriptionId="1dd1940e-9979-476c-a5dc-79a7d31686fd";
        keyStoreLocation="C:\Program Files\Java\jdk1.8.0_40\bin\AzureKeyStore.jks";
        keyStorePassword="123456";
        keyStoreType= KeyStoreType.fromString("jks");
        Configuration configuration = ManagementConfiguration.configure(uri,  subscriptionId,
                keyStoreLocation,  keyStorePassword,keyStoreType);
        configuration.setProperty("testprefix.com.microsoft.windowsazure.services.core.Configuration.connectTimeout","3");
        configuration.setProperty("testprefix.com.microsoft.windowsazure.services.core.Configuration.readTimeout","7");
        return configuration;
    }                                                                                                                                                      

    /**
     * https://management.core.windows.net/1dd1940e-9979-476c-a5dc-79a7d31686fd/services/resourceextensions
     * @param args
     * @throws Exception
     */
    public static void main(String[] args) throws Exception {
        computeManagementClient = ComputeManagementService.create(createConfiguration());
        client = ManagementService.create(createConfiguration());
        // get the list of regions
        LocationsListResponse response = client.getLocationsOperations().list();
        ArrayList<LocationsListResponse.Location> locations = response.getLocations();
        // write them out
        for( int i=0; i<locations.size(); i++){
            System.out.println(locations.get(i).getDisplayName());
        }                                                                                                                                                  

        HostedServiceListResponse hostedServiceListResponse = computeManagementClient.getHostedServicesOperations().list();
        System.out.println("statusCode:"+hostedServiceListResponse.getStatusCode());                                                                       

        VirtualMachineExtensionListResponse virtualMachineExtensionListResponse = computeManagementClient.getVirtualMachineExtensionsOperations().list();
        System.out.println("................response........................");
        System.out.println("requestId:" + virtualMachineExtensionListResponse.getRequestId());
        System.out.println("statusCode:"+virtualMachineExtensionListResponse.getStatusCode());
        ArrayList<VirtualMachineExtensionListResponse.ResourceExtension> list= virtualMachineExtensionListResponse.getResourceExtensions();
        if( list != null && !list.isEmpty() ){
            for( VirtualMachineExtensionListResponse.ResourceExtension resourceExtension : list){
                System.out.println("resourceExtension:"+resourceExtension.getName());
            }
        }                                                                                                                                                  

    }
}                                                                                                                                                          

但依然报http 403错误
This XML file does not appear to have any style information associated with it. The document tree is shown below.

ForbiddenError

The server failed to authenticate the request. Verify that the certificate is valid and is associated with this subscription.

解决方案

您好,看起来您使用的是Azure Management Library for Java,请问您使用的是China Azure还是Global Azure?
我不确定您的访问终结点是中国版Azure还是Global,因此,我建议您可以使用Gaurav Mantri这种方式去访问您的证书:

//Get key
 private static KeyStore getKeyStore(String keyStoreName, String password) throws IOException
{
    KeyStore ks = null;
    FileInputStream fis = null;
    try {
        ks = KeyStore.getInstance("JKS");
        char[] passwordArray = password.toCharArray();
        fis = new java.io.FileInputStream(keyStoreName);
        ks.load(fis, passwordArray);
        fis.close();

    } catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    finally {
        if (fis != null) {
            fis.close();
        }
    }
    return ks;
}

// Get SSLSocketFactory

private static SSLSocketFactory getSSLSocketFactory(String keyStoreName, String password) throws UnrecoverableKeyException, KeyStoreException, NoSuchAlgorithmException, KeyManagementException, IOException {
    KeyStore ks = getKeyStore(keyStoreName, password);
    KeyManagerFactory keyManagerFactory = KeyManagerFactory.getInstance("SunX509");
    keyManagerFactory.init(ks, password.toCharArray());

      SSLContext context = SSLContext.getInstance("TLS");
      context.init(keyManagerFactory.getKeyManagers(), null, new SecureRandom());

      return context.getSocketFactory();
}
//

//You can use it in this method
private static String processGetRequest(URL url, String keyStore, String keyStorePassword) throws UnrecoverableKeyException, KeyManagementException, KeyStoreException, NoSuchAlgorithmException, IOException {
        SSLSocketFactory sslFactory = getSSLSocketFactory(keyStore, keyStorePassword);
        HttpsURLConnection con = (HttpsURLConnection) url.openConnection();
        con.setSSLSocketFactory(sslFactory);
        con.setRequestMethod("GET");
        con.addRequestProperty("x-ms-version", "2012-03-01");
        InputStream responseStream = (InputStream) con.getContent();
        String response = getStringFromInputStream(responseStream);
        responseStream.close();
        return response;
    }

也可以参考这篇文章:http://gauravmantri.com/2013/08/25/consuming-windows-azure-service-management-api-in-java/
也建议您使用Fiddle去抓获下真正的错误信息。
Regards,
Will

如果您想进一步了解Windows Azure, Windows Azure 官网欢迎您的访问

解决方案二:

Hi,

需要补充的是,如果使用的是中国版的Azure我们还需要多出一项工作,CNNIC颁发的证书没有导入JDK的KeyStore,因此不被JDK所信任,我们需要通过程序的方式将其导入,具体参考这篇文章:http://blog.csdn.net/faye0412/article/details/6883879

Best Regards,
Jambor
如果您想进一步了解Windows Azure, Windows Azure 官网欢迎您的访问

时间: 2024-08-08 14:54:25

http 403 认证失败-keytool生成证书,上传到azure中,但仍旧,显示认证失败的相关文章

app store 注册账号生成证书上传app完整的教程

app store为开发者提供四种类型的申请: 个人ios开发者计划$99/年 公司ios开发者计划$99/年 企业ios开发者计划$299/年 高校ios开发者计划免费 在这里主要介绍一下公司ios开发者计划,只有利用个人和公司ios开发者计划证书开发的应用,才能上app store.企业开发者计划主要是为本公司开发软件,并安装到本公司的硬件设备上,不能上app store.下面主要介绍一下公司ios开发者计划的申请. 申请帐号: 打开连接:http://developer.apple.com

Tomcat服务器配置https双向认证(使用keytool生成证书)

一,HTTPS原理 1,HTTP.HTTPS.SSL.TLS介绍与相互关系 (1)HTTP:平时浏览网页时候使用的一种协议.HTTP协议传输的数据都是未加密的(明文),因此使用HTTP协议传输隐私信息非常不安全. (2)HTTPS:为了保证隐私数据能加密传输,采用SSL/TLS协议用于对HTTP协议传输的数据进行加密,也就是HTTPS. (3)SSL:SSL(Secure Sockets Layer)协议是由网景公司设计,后被IETF定义在RFC 6101中.目前的版本是3.0. (4)TLS:

java代码怎么写用命令行调用keytool生成证书

问题描述 java代码怎么写用命令行调用keytool生成证书 java代码怎么写用命令行调用keytool生成证书,最好具体一点,有注释最好 解决方案 http://blog.csdn.net/prstaxy/article/details/30050175http://blog.chinaunix.net/uid-17102734-id-2830223.html 解决方案二: java 调用 keytool 生成keystore 和 cer 证书Java调用命令行java调用命令行

ios 推送证书上传后 为什么还是提示注册失败呢?Error=3000

问题描述 **ios 推送证书上传后 为什么还是提示注册失败呢?Error=3000** 解决方案 推送证书跟注册没关系.你可以百度去搜error 3000,网上有解决的办法.

struts2 文件上传时,某次上传失败之后的所有上传都返回input,不跳到action

问题描述 在做文件上传时,不加限制上传任意类型文件都成功,但是如果加了"allowedTypes"限制文件类型后,上传正确类型成功,上传错误类型失败,这些都是理所当然的结果.问题是上传错误类型失败后,再上传正确的文件,也跳转到input视图,不经过action.如限制只能上传gif格式文件,第一次上传gif图片返回success:第二次上传非gif文件,返回input:第三次上传gif文件,还是返回input,怎么解决?代码如下:jsp页面: <s:form action =&q

php-PHP上传图片问题上传到C的图片无法显示

问题描述 PHP上传图片问题上传到C的图片无法显示 PHP 上传图片为什么上传到C盘图片无法显示上传到其他盘图片可以显示呢? 代码哪个地方写错了?请指正.... 前端代码: <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> 文件上传 上传文件的用户名: 后端代码; <?php $usename

java-Java实现自动识别文件夹中图片路径?上传到网站中的 源码,很急

问题描述 Java实现自动识别文件夹中图片路径?上传到网站中的 源码,很急 Java实现自动识别文件夹中图片路径,上传到网站中的 源码,比如,我有一个文件夹,里面有许多图片,需要发布到一个网站 解决方案 你直接复制到服务器不必这个快??? 解决方案二: 这个发布到服务器不是把地址发布到服务器,而是把图片上传的服务器,服务器没有C盘D盘什么的,它是图片上传到服务其的一个指定地址,在把这个地址存入类中对应的数据库字段中,在通过掉用这个地址获得图片,如果是在本地就可以通过String name=fil

filezilla-用FileZilla客户端新建站点,上传war包中的网站之后怎么利用页面打开?

问题描述 用FileZilla客户端新建站点,上传war包中的网站之后怎么利用页面打开? 我上传了之后成功了,但是不知道怎么在网页中打开,而且,我新建站点,上传的时候还提示我是否覆盖 解决方案 http://blog.csdn.net/wy818/article/details/7240294

上传到ftp的视频不显示画面

问题描述 上传到ftp的视频不显示画面 上传到ftp的视频 复制相关链接到网站时 视频有的可以显示画面,有的却显示不出来 你知道是为什么吗 解决方案 您好,请贴出连接地址 解决方案二: 有可能是你的连接地址写错了. 解决方案三: 可能传输的时候丢包了吧