You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users-cn@cloudstack.apache.org by fengjianjian <fe...@chinaskycloud.com> on 2012/12/26 02:05:40 UTC

答复: 也请教大家一个api的问题

参数列表必须经过按参数名的字母表顺序排序

-----邮件原件-----
发件人: Gavin Lee [mailto:gavin.lxh@gmail.com] 
发送时间: 2012年12月25日 22:41
收件人: cloudstack-users-cn@incubator.apache.org
主题: Re: 也请教大家一个api的问题

通过8096端口是直接调用API了, 没有鉴权和认证的过程, 你可以去掉请求中的apiKey和signature再试试,结果一样,
使用这种方式需要自己保证安全性.全局配置端口默认为0, 表示不通过直接API调用提供服务.

通过8080端口访问是需要提供APIKey和Signature,
其中Signature是由SecretKey及请求的参数一起通过HmacSHA1编码得到的,每一个请求都会有一个单独的Signature,
因些安全性很好, 下列是代码片段:
Mac mac = Mac.getInstance("HmacSHA1");

SecretKeySpec keySpec = new SecretKeySpec(secretkey.getBytes(),
"HmacSHA1");

mac.init(keySpec);

mac.update(request.getBytes());
byte[] encryptedBytes =
mac.doFinal();
//System.out.println("HmacSHA1 hash: " + encryptedBytes);

return Base64.encodeBase64String(encryptedBytes);

需要注意的是第二种最终仍然统一调用到API Server提供的服务.





2012/12/25 Royal Yang <ra...@gmail.com>:
> 请问大家请求
>
> http://localhost:8096?apiKey=aaaa&command=listRouters&response=json&st
> ate=Running&signature=aaaaa
> "
>
> 和请求
> http://localhost:8080/client/api?apiKey=aaaa&command= listRouters& 
> response=json&state=Running &signature=aaaaa"
>
> 有啥区别?
>
> 为啥我用上面的url就能获取到正确的vrouter信息,后者就列不出?(apikey和signatrue已编辑)



--
Gavin

Re: 答复: 也请教大家一个api的问题

Posted by Royal Yang <ra...@gmail.com>.
多谢楼上两位的回答。
Gavin说的我明白。虽然直接请求8096但是结果还是和请求8080的时候不一样。详细情况是这样的,当时router有三个处于启动状态,两台isolated
network,一台shared network的vrouter,关闭两台isolated vrouter之后,再通过8080调用api
listRouters(‘state’: ’Running‘)的时候返回的就是空了。通过8096调用的时候就能返回那个还没关闭的vrouter。

在 2012年12月26日上午9:05,fengjianjian <fe...@chinaskycloud.com>写道:

> 参数列表必须经过按参数名的字母表顺序排序
>
> -----邮件原件-----
> 发件人: Gavin Lee [mailto:gavin.lxh@gmail.com]
> 发送时间: 2012年12月25日 22:41
> 收件人: cloudstack-users-cn@incubator.apache.org
> 主题: Re: 也请教大家一个api的问题
>
> 通过8096端口是直接调用API了, 没有鉴权和认证的过程, 你可以去掉请求中的apiKey和signature再试试,结果一样,
> 使用这种方式需要自己保证安全性.全局配置端口默认为0, 表示不通过直接API调用提供服务.
>
> 通过8080端口访问是需要提供APIKey和Signature,
> 其中Signature是由SecretKey及请求的参数一起通过HmacSHA1编码得到的,每一个请求都会有一个单独的Signature,
> 因些安全性很好, 下列是代码片段:
> Mac mac = Mac.getInstance("HmacSHA1");
>
> SecretKeySpec keySpec = new SecretKeySpec(secretkey.getBytes(),
> "HmacSHA1");
>
> mac.init(keySpec);
>
> mac.update(request.getBytes());
> byte[] encryptedBytes =
> mac.doFinal();
> //System.out.println("HmacSHA1 hash: " + encryptedBytes);
>
> return Base64.encodeBase64String(encryptedBytes);
>
> 需要注意的是第二种最终仍然统一调用到API Server提供的服务.
>
>
>
>
>
> 2012/12/25 Royal Yang <ra...@gmail.com>:
> > 请问大家请求
> >
> > http://localhost:8096?apiKey=aaaa&command=listRouters&response=json&st
> > ate=Running&signature=aaaaa
> > "
> >
> > 和请求
> > http://localhost:8080/client/api?apiKey=aaaa&command= listRouters&
> > response=json&state=Running &signature=aaaaa"
> >
> > 有啥区别?
> >
> > 为啥我用上面的url就能获取到正确的vrouter信息,后者就列不出?(apikey和signatrue已编辑)
>
>
>
> --
> Gavin
>