安全管理接口
登录eSight
接口功能
根据用户名、密码以及IP地址登录eSight,返回登录成功后的openid(标识登录会话的唯一ID)。
分级网管场景下,调用/rest/openapi/sm/session接口所使用的用户必须都是上级网管用户。
URI路径
/rest/openapi/sm/session
访问方法
PUT
参数说明
参数名 |
必选/可选 |
参数位置 |
参数类型 |
参数说明 |
---|---|---|---|---|
userid |
必选 |
请求实体参数列表 |
String |
待登录的用户名。 |
value |
必选 |
请求实体参数列表 |
String |
用户密码。 |
ipaddr |
可选 |
请求实体参数列表 |
String |
用户的IP地址。 说明:
该IP地址为备用IP地址;优先使用请求消息中的IP地址,若在请求消息中获取失败就使用该IP地址。 |
返回结果
字段名 |
类型 |
说明 |
---|---|---|
code |
int |
操作返回码。可以是如下值之一:
|
data |
Object |
登录成功后返回的openid。 |
description |
String |
接口调用结果的描述信息。 |
注意事项
- 缺省情况下,用户登录后,如果持续30分钟没有操作,openid会自动失效。
- 登录成功后返回的openid,已经与调用该登录接口的客户端IP地址绑定。此openid在有效期内不能在其他IP地址所在的客户端使用,否则认证时会被拒绝。
使用示例
package com.huawei.nms.openapi.demo.sm; import java.util.ArrayList; import java.util.List; import org.apache.http.HttpResponse; import org.apache.http.message.BasicNameValuePair; import com.huawei.nms.openapi.demo.global.GlobalVar; import com.huawei.nms.openapi.demo.global.NewHttpsAccess; import net.sf.json.JSONObject; /* * log in */ public class Login { public static void main(String[] args) throws Exception { login(); } public static void login() throws Exception { //set the URL and method final String openidURL = "/rest/openapi/sm/session"; final String method = "PUT"; //set parameters List<BasicNameValuePair> bodys = new ArrayList<BasicNameValuePair>(); bodys.add(new BasicNameValuePair("userid", GlobalVar.GLOBAL_USERNAME)); bodys.add(new BasicNameValuePair("value", GlobalVar.GLOBAL_USERVALUE)); bodys.add(new BasicNameValuePair("ipaddr", GlobalVar.GLOBAL_USERIP)); //send the request HttpResponse response = NewHttpsAccess.access(GlobalVar.GLOBAL_IP, GlobalVar.GLOBAL_PORT, openidURL, method, null, bodys); //get the result final String ret = NewHttpsAccess.getResult(response); System.out.println(ret); //resolve the result and get the openid final JSONObject jObject = JSONObject.fromObject(ret); if (null == jObject) { System.out.println("Login failed."); return; } if ("0".equals(String.valueOf(jObject.get("code")))) { final String openid = String.valueOf(jObject.get("data")); GlobalVar.globalOpenid = openid; } } }
执行结果如下:
{ "code" : 0, "data" : "89965ad0cb924a932cda461d749288368b54b91bd4260b84", "description" : "Operation success." }
退出eSight
接口功能
根据参数openid退出该次登录。
URI路径
/rest/openapi/sm/session
访问方法
DELETE
参数说明
返回结果
字段名 |
类型 |
说明 |
---|---|---|
code |
int |
操作返回码。可以是如下值之一:
|
data |
Object |
此处为null。 |
description |
String |
接口调用结果的描述信息。 |
注意事项
无。
使用示例
package com.huawei.nms.openapi.demo.sm; import org.apache.http.HttpResponse; import org.apache.http.message.BasicNameValuePair; import com.huawei.nms.openapi.demo.global.GlobalVar; import com.huawei.nms.openapi.demo.global.NewHttpsAccess; import com.huawei.nms.openapi.demo.global.NewRosSecurity; /** * LogOut */ public class Logout { public static void main(String[] args) throws Exception { Logout test = new Logout(); test.logoutTest(); } public void logoutTest() throws Exception { Login.login(); //set the URL and method String openidURL = "/rest/openapi/sm/session"; String method = "DELETE"; //set headers BasicNameValuePair[] headers = NewRosSecurity.getRosHttpHeader(openidURL, method); //set parameters BasicNameValuePair[] parameters = { new BasicNameValuePair("openid", GlobalVar.globalOpenid) }; //send the request HttpResponse response = NewHttpsAccess.access(GlobalVar.GLOBAL_IP, GlobalVar.GLOBAL_PORT, openidURL, method, headers, parameters); //get the result String ret = NewHttpsAccess.getResult(response); System.out.println(ret); } }
执行结果如下:
{ "code":0, "data":null, "description":"Operation success." }
查询角色列表
接口功能
查询网管系统中的角色列表。
OpenAPI用户调用此接口前需具备“用户管理”操作权限。
URI路径
/rest/openapi/role/detail
访问方法
GET
参数说明
参数名 |
必选/可选 |
参数位置 |
参数类型 |
参数说明 |
---|---|---|---|---|
openid |
必选 |
请求消息头 |
String |
会话标识,用于Open API的鉴权。 说明:
该参数由第三方调用安全管理的登录接口获取openid。 |
返回结果
字段名 |
类型 |
说明 |
---|---|---|
code |
int |
操作返回码。可以是如下值之一:
|
data |
List<Map<String, Object>> |
角色信息列表。 |
description |
String |
接口调用结果的描述信息。 |
data中的Map<String, Object>对象包含以下字段:
字段名 |
类型 |
说明 |
---|---|---|
roleName |
String |
角色名称 。 |
roleDescription |
String |
角色描述 。 |
roleAssociatedUsers |
List<String> |
角色关联的用户名称列表。 |
roleCreateTime |
String |
角色创建时间,与网管服务器时区一致。 |
isDefault |
int |
是否为网管系统缺省角色。可以是如下值之一:
|
注意事项
此接口在基于摘要认证时无法调用。
使用示例
package com.huawei.nms.openapi.demo.sm; import org.apache.http.HttpResponse; import org.apache.http.message.BasicNameValuePair; import com.huawei.nms.openapi.demo.global.GlobalVar; import com.huawei.nms.openapi.demo.global.NewHttpsAccess; import com.huawei.nms.openapi.demo.global.NewRosSecurity; /** * query role list */ public class QueryRoles { /** * Open API URI */ private static final String QUERY_ROLES_URI = "/rest/openapi/role/detail"; /** * main entry * * @param args console arguments * @throws Exception exception */ public static void main(String[] args) throws Exception { Login.login(); queryRoles(); } /** * query example * * @throws Exception exception */ public static void queryRoles() throws Exception { //set the URL and method String openidURI = QUERY_ROLES_URI; String method = "GET"; //set headers BasicNameValuePair[] headers = NewRosSecurity.getRosHttpHeader(openidURI, method); //set parameters BasicNameValuePair[] parameters = null; //send the request HttpResponse response = NewHttpsAccess.access(GlobalVar.GLOBAL_IP, GlobalVar.GLOBAL_PORT, openidURI, method, headers, parameters); //get the result String body = NewHttpsAccess.getResult(response); System.out.println(body); } }
执行结果如下:
{ "code": 0, "data": [{ "roleDescription": "管理员角色", "isDefault": 1, "roleCreateTime": "2015-04-08 10:29:11", "roleAssociatedUsers": ["admin"], "roleName": "Administrators" }, { "roleDescription": "", "isDefault": 0, "roleCreateTime": "2015-04-08 10:44:12", "roleAssociatedUsers": ["openapi"], "roleName": "eSDK" }, { "roleDescription": "具有各特性查询的权限,不具有安全管理员的权限", "isDefault": 0, "roleCreateTime": "2015-04-08 00:00:00", "roleAssociatedUsers": [], "roleName": "Monitor" }, { "roleDescription": "Openapi用户组拥有调用Open API接口的操作权限", "isDefault": 1, "roleCreateTime": "2015-04-08 10:29:34", "roleAssociatedUsers": [], "roleName": "Openapi用户组" }, { "roleDescription": "具有各特性配置和查询的权限,不具有安全管理员的权限", "isDefault": 0, "roleCreateTime": "2015-04-08 00:00:00", "roleAssociatedUsers": [], "roleName": "Operator" }, { "roleDescription": "具有用户/角色管理、日志管理等权限", "isDefault": 0, "roleCreateTime": "2015-04-08 00:00:00", "roleAssociatedUsers": [], "roleName": "Security" }], "description": "Operation success." }
创建角色
接口功能
根据角色名创建角色。
该接口需要配合“同步用户”功能使用,即在同步用户时需要同步角色,OpenAPI用户调用此接口前需具备“用户管理”操作权限。
URI路径
/rest/openapi/role
访问方法
PUT
参数说明
参数名 |
必选/可选 |
参数位置 |
参数类型 |
参数说明 |
---|---|---|---|---|
openid |
必选 |
请求消息头 |
String |
会话标识,用于Open API的鉴权。 说明:
该参数由第三方调用安全管理的登录接口获取openid。 |
roleName |
必选 |
请求实体参数列表 |
String |
待创建的角色名。 说明:
角色名必须满足以下规范:
|
返回结果
字段名 |
类型 |
说明 |
---|---|---|
code |
int |
操作返回码。可以是如下值之一:
|
data |
list |
此处为null。 |
description |
String |
接口调用结果的描述信息。 |
注意事项
此接口在基于摘要认证时无法调用。
使用示例
package com.huawei.nms.openapi.demo.sm; import org.apache.http.HttpResponse; import org.apache.http.message.BasicNameValuePair; import com.huawei.nms.openapi.demo.global.GlobalVar; import com.huawei.nms.openapi.demo.global.NewHttpsAccess; import com.huawei.nms.openapi.demo.global.NewRosSecurity; /** * Create a Role */ public class AddRole { private static final String SM_Role = "/rest/openapi/role"; public static void main(String[] args) throws Exception { Login.login(); addRole(); } public static void addRole() throws Exception { //set the URL and method String openidURL = SM_Role; String method = "PUT"; //set headers BasicNameValuePair[] headers = NewRosSecurity.getRosHttpHeader(openidURL, method); //set parameters BasicNameValuePair[] bodys = { new BasicNameValuePair("roleName", "role01") }; //send the request HttpResponse response = NewHttpsAccess.access(GlobalVar.GLOBAL_IP, GlobalVar.GLOBAL_PORT, openidURL, method, headers, bodys); //get the result String body = NewHttpsAccess.getResult(response); System.out.println(body); } }
执行结果如下:
{ "data":null, "description":"Operation success.", "code":0 }
删除角色
接口功能
根据角色名删除角色。
OpenAPI用户调用此接口前需具备“用户管理”操作权限。
URI路径
/rest/openapi/role
访问方法
DELETE
参数说明
参数名 |
必选/可选 |
参数位置 |
参数类型 |
参数说明 |
---|---|---|---|---|
openid |
必选 |
请求消息头 |
String |
会话标识,用于Open API的鉴权。 说明:
该参数由第三方调用安全管理的登录接口获取openid。 |
roleName |
必选 |
URL参数列表 |
String |
待删除的角色名。 |
返回结果
字段名 |
类型 |
说明 |
---|---|---|
code |
int |
操作返回码。可以是如下值之一:
|
data |
list |
此处为null。 |
description |
String |
接口调用结果的描述信息。 |
注意事项
此接口在基于摘要认证时无法调用。
使用示例
package com.huawei.nms.openapi.demo.sm; import org.apache.http.HttpResponse; import org.apache.http.message.BasicNameValuePair; import com.huawei.nms.openapi.demo.global.GlobalVar; import com.huawei.nms.openapi.demo.global.NewHttpsAccess; import com.huawei.nms.openapi.demo.global.NewRosSecurity; /** * Delete a Role */ public class DeleteRole { private static final String SM_Role = "/rest/openapi/role"; public static void main(String[] args) throws Exception { Login.login(); deleteRole(); } public static void deleteRole() throws Exception { //set the URL and method String openidURL = SM_Role; String method = "DELETE"; //set headers BasicNameValuePair[] headers = NewRosSecurity.getRosHttpHeader(openidURL, method); //set parameters BasicNameValuePair[] parameters = { new BasicNameValuePair("roleName", "role01") }; //send the request HttpResponse response = NewHttpsAccess.access(GlobalVar.GLOBAL_IP, GlobalVar.GLOBAL_PORT, openidURL, method, headers, parameters); //get the result String body = NewHttpsAccess.getResult(response); System.out.println(body); } }
执行结果如下:
{ "data":null, "description":"Operation success.", "code":0 }
查询用户列表
接口功能
查询网管系统中的用户列表。
OpenAPI用户调用此接口前需具备“用户管理”操作权限。
URI路径
/rest/openapi/user
访问方法
GET
参数说明
参数名 |
必选/可选 |
参数位置 |
参数类型 |
参数说明 |
---|---|---|---|---|
openid |
必选 |
请求消息头 |
String |
会话标识,用于Open API的鉴权。 说明:
该参数由第三方调用安全管理的登录接口获取openid。 |
返回结果
字段名 |
类型 |
说明 |
---|---|---|
code |
int |
操作返回码。可以是如下值之一:
|
data |
List<Map<String, Object>> |
用户信息列表。 |
description |
String |
接口调用结果的描述信息。 |
data中的Map<String, Object>对象包含以下字段:
字段名 |
类型 |
说明 |
---|---|---|
userID |
String |
用户名称 。 |
userDescription |
String |
用户描述 。 |
userStatus |
int |
用户状态。可以是如下值之一:
|
userCreateTime |
String |
用户创建时间,与网管服务器时区一致。 |
userAssociatedRoles |
List<String> |
用户绑定的角色名称列表。 |
isDefault |
int |
是否为网管系统缺省用户 。可以是如下值之一:
|
注意事项
此接口在基于摘要认证时无法调用。
使用示例
package com.huawei.nms.openapi.demo.sm; import org.apache.http.HttpResponse; import org.apache.http.message.BasicNameValuePair; import com.huawei.nms.openapi.demo.global.GlobalVar; import com.huawei.nms.openapi.demo.global.NewHttpsAccess; import com.huawei.nms.openapi.demo.global.NewRosSecurity; /** * query user list */ public class QueryUsers { /** * Open API URI */ private static final String QUERY_USERS_URI = "/rest/openapi/user"; /** * main entry * * @param args console arguments * @throws Exception exception */ public static void main(String[] args) throws Exception { Login.login(); queryUsers(); } /** * query example * * @throws Exception exception */ public static void queryUsers() throws Exception { //set the URL and method String openidURI = QUERY_USERS_URI; String method = "GET"; //set headers BasicNameValuePair[] headers = NewRosSecurity.getRosHttpHeader(openidURI, method); //set parameters BasicNameValuePair[] parameters = null; //send the request HttpResponse response = NewHttpsAccess.access(GlobalVar.GLOBAL_IP, GlobalVar.GLOBAL_PORT, openidURI, method, headers, parameters); //get the result String body = NewHttpsAccess.getResult(response); System.out.println(body); } }
执行结果如下:
{ "code": 0, "data": [{ "userID": "admin", "isDefault": 1, "userAssociatedRoles": ["Administrators"], "userStatus": 1, "userDescription": "管理员", "userCreateTime": "2015-04-08 10:29:12" }, { "userID": "openapi", "isDefault": 0, "userAssociatedRoles": ["eSDK","Openapi user group"], "userStatus": 1, "userDescription": "", "userCreateTime": "2015-04-08 10:39:25" }], "description": "Operation success." }
同步用户
接口功能
SSO场景下,eSight作为SSO Client端提供该接口供第三方调用,第三方从SSO Server端获取用户至SSO Client端。
- 登录时用于验证的用户名/密码是存储在SSO Server端的。
- 第三方调用该接口后在SSO Client端创建的用户,仅用于在SSO Client端分配角色,其对应的密码在SSO Client端是随机生成的,不能进行修改也不需要修改。
- OpenAPI用户调用此接口前需具备“用户管理”操作权限。
URI路径
/rest/openapi/user
访问方法
PUT
参数说明
参数名 |
必选/可选 |
参数位置 |
参数类型 |
参数说明 |
---|---|---|---|---|
openid |
必选 |
请求消息头 |
String |
会话标识,用于Open API的鉴权。 说明:
该参数由第三方调用安全管理的登录接口获取openid。 |
userid |
必选 |
请求实体参数列表 |
String |
待同步的用户名。 说明:
用户名必须满足以下规范:
|
返回结果
字段名 |
类型 |
说明 |
---|---|---|
code |
int |
操作返回码。可以是如下值之一:
|
data |
list |
此处为null。 |
description |
String |
接口调用结果的描述信息。 |
注意事项
此接口在基于摘要认证时无法调用。
使用示例
package com.huawei.nms.openapi.demo.sm; import org.apache.http.HttpResponse; import org.apache.http.message.BasicNameValuePair; import com.huawei.nms.openapi.demo.global.GlobalVar; import com.huawei.nms.openapi.demo.global.NewHttpsAccess; import com.huawei.nms.openapi.demo.global.NewRosSecurity; /** * Create a User */ public class AddUser { private static final String SM_USER = "/rest/openapi/user"; public static void main(String[] args) throws Exception { Login.login(); addUser(); } public static void addUser() throws Exception { //set the URL and method String openidURL = SM_USER; String method = "PUT"; //set headers BasicNameValuePair[] headers = NewRosSecurity.getRosHttpHeader(openidURL, method); //set parameters BasicNameValuePair[] bodys = { new BasicNameValuePair("userid", "user01") }; //send the request HttpResponse response = NewHttpsAccess.access(GlobalVar.GLOBAL_IP, GlobalVar.GLOBAL_PORT, openidURL, method, headers, bodys); //get the result String body = NewHttpsAccess.getResult(response); System.out.println(body); } }
执行结果如下:
{ "data":null, "description":"Operation success.", "code":0 }
删除用户
接口功能
根据用户名删除用户。
OpenAPI用户调用此接口前需具备“用户管理”操作权限。
URI路径
/rest/openapi/user
访问方法
DELETE
参数说明
参数名 |
必选/可选 |
参数位置 |
参数类型 |
参数说明 |
---|---|---|---|---|
openid |
必选 |
请求消息头 |
String |
会话标识,用于Open API的鉴权。 说明:
该参数由第三方调用安全管理的登录接口获取openid。 |
userid |
必选 |
URL参数列表 |
String |
待删除的用户名。 |
返回结果
字段名 |
类型 |
说明 |
---|---|---|
code |
int |
操作返回码。可以是如下值之一:
|
data |
list |
此处为null。 |
description |
String |
接口调用结果的描述信息。 |
注意事项
此接口在基于摘要认证时无法调用。
使用示例
package com.huawei.nms.openapi.demo.sm; import org.apache.http.HttpResponse; import org.apache.http.message.BasicNameValuePair; import com.huawei.nms.openapi.demo.global.GlobalVar; import com.huawei.nms.openapi.demo.global.NewHttpsAccess; import com.huawei.nms.openapi.demo.global.NewRosSecurity; /** * Delete a User */ public class DeleteUser { private static final String SM_USER = "/rest/openapi/user"; public static void main(String[] args) throws Exception { Login.login(); deleteUser(); } public static void deleteUser() throws Exception { //set the URL and method String openidURL = SM_USER; String method = "DELETE"; //set headers BasicNameValuePair[] headers = NewRosSecurity.getRosHttpHeader(openidURL, method); //set parameters BasicNameValuePair[] parameters = { new BasicNameValuePair("userid", "user01") }; //send the request HttpResponse response = NewHttpsAccess.access(GlobalVar.GLOBAL_IP, GlobalVar.GLOBAL_PORT, openidURL, method, headers, parameters); //get the result String body = NewHttpsAccess.getResult(response); System.out.println(body); } }
执行结果如下:
{ "data":null, "description":"Operation success.", "code":0 }
更新用户角色关系
接口功能
根据用户名更新用户的角色关系。
OpenAPI用户调用此接口前需具备“用户管理”操作权限。
URI路径
/rest/openapi/user
访问方法
POST
参数说明
参数名 |
必选/可选 |
参数位置 |
参数类型 |
参数说明 |
---|---|---|---|---|
openid |
必选 |
请求消息头 |
String |
会话标识,用于Open API的鉴权。 说明:
该参数由第三方调用安全管理的登录接口获取openid。 |
userid |
必选 |
请求实体参数列表 |
String |
用户名。 |
roleName |
必选 |
请求实体参数列表 |
String |
角色名。 说明:
若是多个角色名,各个角色名之间使用“;”隔开。 |
返回结果
字段名 |
类型 |
说明 |
---|---|---|
code |
int |
操作返回码。可以是如下值之一:
|
data |
list |
此处为null。 |
description |
String |
接口调用结果的描述信息。 |
注意事项
- 只要有一个角色不存在,则该更新操作全部失败。
- 此接口在基于摘要认证时无法调用。
使用示例
package com.huawei.nms.openapi.demo.sm; import org.apache.http.HttpResponse; import org.apache.http.message.BasicNameValuePair; import com.huawei.nms.openapi.demo.global.GlobalVar; import com.huawei.nms.openapi.demo.global.NewHttpsAccess; import com.huawei.nms.openapi.demo.global.NewRosSecurity; /** * Update User Role Relationships */ public class UpdateUserRoleRelation { private static final String SM_USER = "/rest/openapi/user"; public static void main(String[] args) throws Exception { Login.login(); update(); } public static void update() throws Exception { //set the URL and method String openidURL = SM_USER; String method = "POST"; //set headers BasicNameValuePair[] headers = NewRosSecurity.getRosHttpHeader(openidURL, method); //set parameters BasicNameValuePair[] bodys = { new BasicNameValuePair("userid", "user01"), new BasicNameValuePair("roleName", "role01") }; //send the request HttpResponse response = NewHttpsAccess.access(GlobalVar.GLOBAL_IP, GlobalVar.GLOBAL_PORT, openidURL, method, headers, bodys); //get the result String body = NewHttpsAccess.getResult(response); System.out.println(body); } }
执行结果如下:
{ "data":null, "description":"Operation success.", "code":0 }
分页查询审计日志
接口功能
根据日志类型、日志起始时间、日志结束时间等分页查询审计日志(包括安全日志、系统日志、操作日志以及操作日志详细信息)。
URI路径
/rest/openapi/omslogs
访问方法
GET
参数说明
参数名 |
必选/可选 |
参数位置 |
参数类型 |
参数说明 |
---|---|---|---|---|
openid |
必选 |
请求消息头 |
String |
会话标识,用于Open API的鉴权。 说明:
该参数由第三方调用安全管理的登录接口获取openid。 |
type |
可选 |
URL参数列表 |
String |
查询的日志类型。可以是如下值之一:
|
startTime |
可选 |
URL参数列表 |
String |
日志起始时间,为UTC时间,精确到秒。默认为前一天的当前时间。 说明:
|
endTime |
可选 |
URL参数列表 |
String |
日志结束时间,为UTC时间,精确到秒。默认为当前时间。 说明:
|
pageSize |
可选 |
URL参数列表 |
int |
分页查询的每页记录数,支持1~100条,默认值20条。 说明:
pageSize小于1或大于100时,使用默认值20。 |
pageNo |
可选 |
URL参数列表 |
int |
分页查询的第几页,从1开始,默认取第1页。 说明:
|
optSN |
可选 |
URL参数列表 |
String |
日志流水号。 说明:
当type="operationDetail"时,optSN不能为空;当type为其他值时,optSN不起作用。 |
返回结果
字段名 |
类型 |
说明 |
---|---|---|
code |
int |
操作返回码。可以是如下值之一:
|
data |
List<AuditLogdapter> |
日志列表。 |
description |
String |
接口调用结果的描述信息。 |
pageSize |
int |
当前页的记录数。 |
totalPage |
int |
符合查询条件的记录总页数。 |
currentPage |
int |
当前页,从1开始。 |
List<AuditLogdapter>对象包含以下字段:
字段名 |
类型 |
说明 |
---|---|---|
auditType |
String |
日志类型。可以是如下值之一:
|
sn |
int |
日志流水号。 |
baseInfo |
String |
日志的操作名称。 |
source |
String |
日志来源。 |
dateTime |
long |
操作发生的时间(UTC时间,精确到毫秒)。 |
level |
String |
日志级别。可以是如下值之一:
|
targetObj |
String |
操作对象。 |
userId |
String |
发起操作的用户名。 |
detail |
String |
日志详细信息。 |
terminal |
String |
发起操作的客户端IP地址。 |
result |
String |
操作结果。可以是如下值之一:
|
注意事项
若查询所有类型的审计日志,查询结果依次按日志类型、时间排序。日志类型排序顺序依次为:安全日志、系统日志、操作日志。
使用示例
package com.huawei.nms.openapi.demo.sm; import org.apache.http.HttpResponse; import org.apache.http.message.BasicNameValuePair; import com.huawei.nms.openapi.demo.global.GlobalVar; import com.huawei.nms.openapi.demo.global.NewHttpsAccess; import com.huawei.nms.openapi.demo.global.NewRosSecurity; /** * Query all Audit logs */ public class QueryLogs { private static final String SM_LOG = "/rest/openapi/omslogs"; public static void main(String[] args) throws Exception { Login.login(); GetLogTest(); } public static void GetLogTest() throws Exception { //set the URL and method String openidURL = SM_LOG; String method = "GET"; //set headers BasicNameValuePair[] headers = NewRosSecurity.getRosHttpHeader(openidURL, method); //set parameters BasicNameValuePair[] parameters = { new BasicNameValuePair("type", ""), new BasicNameValuePair("pageSize", "20") }; //send the request HttpResponse response = NewHttpsAccess.access(GlobalVar.GLOBAL_IP, GlobalVar.GLOBAL_PORT, openidURL, method, headers, parameters); //get the result String body = NewHttpsAccess.getResult(response); System.out.println(body); } }
执行结果如下:
{ "code":0, "data": [ { "auditType":"securityLog", "sn":23, "baseInfo":"用户退出系统", "source":"安全管理", "dateTime":1386674982205, "level":"MINOR", "targetObj":"LocalNMS", "userId":"admin", "detail":"用户退出系统", "terminal":"10.66.98.118", "result":"SUCCESSFUL" } ], "description":"Get security log success.", "pageSize":20, "totalPage":1, "currentPage":1 }
查询网管系统信息
接口功能
查询网管系统信息,应用于对接上级管理系统以呈现基本信息、适配接口等场景。
URI路径
/rest/openapi/systemInfo
访问方法
GET
参数说明
参数名 |
必选/可选 |
参数位置 |
参数类型 |
参数说明 |
---|---|---|---|---|
openid |
必选 |
请求消息头 |
String |
会话标识,用于Open API的鉴权。 说明:
该参数由第三方调用安全管理的登录接口获取openid。 |
返回结果
字段名 |
类型 |
说明 |
---|---|---|
code |
int |
操作返回码。可以是如下值之一:
|
data |
List<Map<String, Object>> |
系统信息列表。 |
description |
String |
接口调用结果的描述信息。 |
data中的Map<String, Object>对象包含以下字段:
字段名 |
类型 |
说明 |
---|---|---|
systemID |
String |
系统标识。 |
systemName |
String |
系统名称。 |
systemVersion |
String |
系统版本号。可通过ros.web.notification.xml文件中platform.version-file项配置版本文件位置。 |
systemVendor |
String |
系统厂商,固定为“Huawei”。 |
systemOS |
String |
系统部署服务器安装的操作系统类型。 |
systemDB |
String |
系统数据库类型。 |
systemUptime |
String |
系统运行历时。 |
- 操作系统和数据库信息仅显示基本名称,不显示详细的配置信息。
- 系统标识可在“eSight安装目录/AppBase/etc/oms.ros/ros.web.notification.xml”文件中的platform.id项配置。如果文件不存在,则默认为“HuaweiPlatform”。
- 系统名称可在“eSight安装目录/AppBase/etc/oms.ros/ros.web.notification.xml”文件中的platform.name项配置。如果文件不存在,则默认为“HuaweiPlatform”。
- 系统版本号文件可在“eSight安装目录/AppBase/etc/oms.ros/ros.web.notification.xml”文件中的platform.version-file项配置。如果文件不存在,则默认为“iEMP V100R002C30”。
注意事项
无。
使用示例
package com.huawei.nms.openapi.demo.sm; import org.apache.http.HttpResponse; import org.apache.http.message.BasicNameValuePair; import com.huawei.nms.openapi.demo.global.GlobalVar; import com.huawei.nms.openapi.demo.global.NewHttpsAccess; import com.huawei.nms.openapi.demo.global.NewRosSecurity; /** * query system information */ public class QuerySystemInfo { /** * Open API URI */ private static final String QUERY_SYSTEM_INFO_URI = "/rest/openapi/systemInfo"; /** * main entry * * @param args console arguments * @throws Exception exception */ public static void main(String[] args) throws Exception { Login.login(); querySystemInfo(); } /** * query example * * @throws Exception exception */ public static void querySystemInfo() throws Exception { //set the URL and method String openidURI = QUERY_SYSTEM_INFO_URI; String method = "GET"; //set headers BasicNameValuePair[] headers = NewRosSecurity.getRosHttpHeader(openidURI, method); //set parameters BasicNameValuePair[] parameters = null; //send the request HttpResponse response = NewHttpsAccess.access(GlobalVar.GLOBAL_IP, GlobalVar.GLOBAL_PORT, openidURI, method, headers, parameters); //get the result String body = NewHttpsAccess.getResult(response); System.out.println(body); } }
执行结果如下:
{
"code": 0,
"data": [{
"systemOS": "Windows Server 2008 R2",
"systemVersion": "eSight V100R002C30B040",
"systemName": "HuaweiPlatform",
"systemVendor": "Huawei",
"systemID": "HuaweiPlatform",
"systemDB": "mysq",
"systemUptime": "0 Day(s) 00 Hour(s) 05 Minute(s) 38 Second(s)"
}],
"description": "Operation success."
}
查询所有的角色名称
接口功能
查询网管系统中所有的角色名称列表。
OpenAPI用户调用此接口前需具备“用户管理”操作权限。
URI路径
/rest/openapi/role
访问方法
GET
参数说明
参数名 |
必选/可选 |
参数位置 |
参数类型 |
参数说明 |
---|---|---|---|---|
openid |
必选 |
请求消息头 |
String |
会话标识,用于Open API的鉴权。 说明:
该参数由第三方调用安全管理的登录接口获取openid。 |
返回结果
字段名 |
类型 |
说明 |
---|---|---|
code |
int |
操作返回码。可以是如下值之一:
|
data |
List<String> |
角色名列表。 |
description |
String |
接口调用结果的描述信息。 |
注意事项
此接口在基于摘要认证时无法调用。
使用示例
package com.huawei.nms.openapi.demo.sm; import org.apache.http.HttpResponse; import org.apache.http.message.BasicNameValuePair; import com.huawei.nms.openapi.demo.global.GlobalVar; import com.huawei.nms.openapi.demo.global.NewHttpsAccess; import com.huawei.nms.openapi.demo.global.NewRosSecurity; /** * query role list */ public class QueryRoles { /** * Open API URI */ private static final String QUERY_ROLES_URI = "/rest/openapi/role"; public static void main(String[] args) throws Exception { Login.login(); queryRoles(); } public static void queryRoles() throws Exception { //set the URL and method String openidURI = QUERY_ROLES_URI; String method = "GET"; //set headers BasicNameValuePair[] headers = NewRosSecurity.getRosHttpHeader(openidURI, method); //set parameters BasicNameValuePair[] parameters = null; //send the request HttpResponse response = NewHttpsAccess.access(GlobalVar.GLOBAL_IP, GlobalVar.GLOBAL_PORT, openidURI, method, headers, parameters); //get the result String body = NewHttpsAccess.getResult(response); System.out.println(body); } }
执行结果如下:
{ "code" : 0, "data" : [{ "Administrators", "Open API用户组" }], "description" : "Operation success." }
第三方认证登录eSight
接口功能
根据用户名、密码、IP地址、inParam进行第三方本地库验证后登录eSight,返回登录成功后的openid(标识登录会话的唯一ID)。
URI路径
/rest/openapi/sm/sessionext
访问方法
PUT
参数说明
参数名 |
必选/可选 |
参数位置 |
参数类型 |
参数说明 |
---|---|---|---|---|
userid |
必选 |
请求实体参数列表 |
String |
待登录的用户名。 |
value |
必选 |
请求实体参数列表 |
String |
用户密码。 |
ipaddr |
可选 |
请求实体参数列表 |
String |
用户的IP地址。 说明:
该IP地址为备用IP地址;优先使用请求消息中的IP地址,若在请求消息中获取失败就使用该IP地址。 |
inParam |
可选 |
请求实体参数列表 |
String |
产品侧本地库校验时带入的参数。 说明:
inParam参数的内容,由产品侧本地库的校验逻辑决定。 |
返回结果
字段名 |
类型 |
说明 |
---|---|---|
code |
int |
操作返回码。可以是如下值之一:
|
data |
Object |
登录成功后返回的openid。 |
description |
String |
接口调用结果的描述信息。 |
注意事项
- 缺省情况下,用户登录后,如果持续30分钟没有操作,openid会自动失效。
- 登录成功后返回的openid,已经与调用该登录接口的客户端IP地址绑定。此openid在有效期内不能在其他IP地址所在的客户端使用,否则认证时会被拒绝。
使用示例
package com.huawei.nms.openapi.demo.sm; import java.util.ArrayList; import java.util.List; import net.sf.json.JSONObject; import org.apache.http.HttpResponse; import org.apache.http.message.BasicNameValuePair; import com.huawei.nms.openapi.demo.global.GlobalVar; import com.huawei.nms.openapi.demo.global.NewHttpsAccess; /** * Third-party Certified login */ public class ThirdAuthLogin { public static void main(String[] args) throws Exception { login(); } private static void login() throws Exception { // set the URL final String openidURL = "/rest/openapi/sm/sessionext"; final String method = "PUT"; // set parameters List<BasicNameValuePair> bodys = new ArrayList<BasicNameValuePair>(); bodys.add(new BasicNameValuePair("userid", GlobalVar.GLOBAL_USERNAME)); bodys.add(new BasicNameValuePair("value", GlobalVar.GLOBAL_USERVALUE)); bodys.add(new BasicNameValuePair("ipaddr", GlobalVar.GLOBAL_USERIP)); bodys.add(new BasicNameValuePair("inParam", "123")); // send the request final HttpResponse response = NewHttpsAccess.access(GlobalVar.GLOBAL_IP, GlobalVar.GLOBAL_PORT, openidURL, method, null, bodys); // get the result final String ret = NewHttpsAccess.getResult(response); System.out.println(ret); // resolve the result and get the openid final JSONObject jObject = JSONObject.fromObject(ret); if (null == jObject) { System.out.println("Login failed."); return; } if ("0".equals(String.valueOf(jObject.get("code")))) { final String openid = String.valueOf(jObject.get("data")); GlobalVar.globalOpenid = openid; } } }
执行结果如下:
{ "code" : 0, "data" : "1d5e59d2d9cf69ca611018f6b2398302f963c5c4a0ef8157", "description" : "Operation success." }