我对Google App Engine端点的安全性有疑问。 我上载的数据存储区中有一个数据,并且该数据只能从Android应用读取。
我这样检索所有数据:
Personendpoint.Builder endpointBuilder = new Personendpoint.Builder(
AndroidHttp.newCompatibleTransport(), new JacksonFactory(), null);
endpointBuilder = CloudEndpointUtils.updateBuilder(endpointBuilder);
CollectionResponsePerson result;
Personendpoint endpoint = endpointBuilder.build();
try {
result = endpoint.listPerson().execute();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
result = null;
}
在我的PersonEndpoint内部,我有:
@Api(name = "personendpoint", namespace = @ApiNamespace(ownerDomain = "test.com", ownerName = "test.com", packagePath = "personmanagement"))
public class PersonEndpoint {
/**
* This method lists all the entities inserted in datastore.
* It uses HTTP GET method and paging support.
*
* @return A CollectionResponse class containing the list of all entities
* persisted and a cursor to the next page.
*/
@SuppressWarnings({ "unchecked", "unused" })
@ApiMethod(name = "listPerson")
public CollectionResponse<Person> listPerson(@Nullable @Named("cursor") String cursorString,
@Nullable @Named("limit") Integer limit)
{
...
}
与此类似,还有方法insertPerson
, removePerson
在这种情况下很危险。 攻击者可以轻松触发这些方法并从我的数据存储中删除数据。 如何保护它?
我只允许用户从数据存储中获取数据。 谢谢。
我建议您使用OAuth进行身份验证来保护端点。 除此之外,您还有责任检查经过身份验证的用户的角色和权限,并过滤将与其他Web应用程序一样管理的数据。
您可以在web.xml中轻松实施安全约束。
<security-constraint>
<web-resource-collection>
<web-resource-name>personmanagement</web-resource-name>
<url-pattern>/personmanagement/*</url-pattern>
</web-resource-collection>
<auth-constraint>
<role-name>*</role-name>
</auth-constraint>
</security-constraint>
这将强制用户通过其Google帐户进行身份验证以访问URL: <role-name>*</role-name>
。 如果只希望应用程序管理员能够访问URL(可以在云控制台中添加管理员),则可以使用<role-name>admin</role-name>
。
查看文档: https : //developers.google.com/appengine/docs/java/config/webxml?hl= fr# Security_and_Authentication