安全错误坚持在Azure中的数据与Android应用 [英] Security error to persist data in Azure with an Android app

查看:210
本文介绍了安全错误坚持在Azure中的数据与Android应用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

显然,这是一个安全问题,而是从网站上下载的例子正常工作(待办事项),我的应用程序更简单,不工作,因为我真的不明白,我查了图书馆,宣言,code ,一切似乎是正确的。我究竟做错了什么?
我对前面这个问题的一个悬而未决的问题,但现在我认为我最能说明问题。

错误:未经授权


  

完整的错误:
  错误行为
   com.microsoft.windowsazure.mobileservices.MobileServiceException:处理请求时出错。
    在com.microsoft.windowsazure.mobileservices.MobileServiceConnection $ 1.onNext
    在com.microsoft.windowsazure.mobileservices.MobileServiceClient $ 4.handleRequest
    在com.microsoft.windowsazure.mobileservices.MobileServiceConnection.start
    在com.microsoft.windowsazure.mobileservices.RequestAsyncTask.doInBackground
    在com.microsoft.windowsazure.mobileservices.RequestAsyncTask.doInBackground
    在android.os.AsyncTask $ 2.call
    在java.util.concurrent.FutureTask中$ Sync.innerRun
    在java.util.concurrent.FutureTask.run
    在android.os.AsyncTask $ SerialExecutor $ 1.run
    在java.util.concurrent.ThreadPoolExecutor.runWorker
    在java.util.concurrent.ThreadPoolExecutor中的$ Worker.run
    在java.lang.Thread.run
   com.microsoft.windowsazure.mobileservices.MobileServiceException:产生的原因:
  code:401,错误:错误:未授权}
   在com.microsoft.windowsazure.mobileservices.MobileServiceConnection $ 1.onNext


我的code下载:<一href=\"https://skydrive.live.com/embed?cid=3CF3FC770FC59E9B&resid=3CF3FC770FC59E9B!1277&authkey=ADQMeBtUVTTIjtE%22\" rel=\"nofollow\">https://skydrive.live.com/embed?cid=3CF3FC770FC59E9B&resid=3CF3FC770FC59E9B!1277&authkey=ADQMeBtUVTTIjtE%22

 包com.bn7.rota;
进口java.net.MalformedURLException;进口com.bn7.rota.Item;
进口com.microsoft.windowsazure.mobileservices *。
进口android.os.Bundle;
进口android.app.Activity;
进口android.util.Log;
进口android.view.Menu;公共类MainActivity延伸活动{
    私人MobileServiceClient mClient;    @覆盖
    保护无效的onCreate(捆绑savedInstanceState){
        super.onCreate(savedInstanceState);
        的setContentView(R.layout.activity_main);
        尝试{
             mClient =新MobileServiceClient(
                    https://bn7.azure-mobile.net/
                    hCzcrsFYhkGmxPvQDNxyqBXjZwjXlK99
                    这个
                    );
            项目项目=新的项目();
            item.IdPhone =真棒项目;
            item.DateTimePhone =2013年4月2日8时27分32秒;
            item.LatitudePhone = -43;
            item.LongetudePhone = -23;
            item.Active = FALSE;
            mClient.getTable(Item.class).insert(项目,新TableOperationCallback&LT;项目&GT;(){
                 公共无效onCompleted(项目实体,异常例外,ServiceFilterResponse响应){
                    如果(例外== NULL){
                         //插入成功
                                            }其他{
                         //将失败
                        Log.d(插入失败,* - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - *);
                        Log.d(插入失败,活动中的错误,除外);
                        Log.d(插入失败,* - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - *);
                    }
                 }
            });
        }赶上(MalformedURLException的E){
            Log.d(MalformedURLException的,e.toString());
        }
}
    @覆盖
    公共布尔onCreateOptionsMenu(菜单菜单){
        //充气菜单;如果是present这增加了项目操作栏。
        。getMenuInflater()膨胀(R.menu.activity_main,菜单);
        返回true;
    }}
包com.bn7.rota;公共类项目{
    公众诠释标识;
    公共字符串IdPhone;
    公共字符串DateTimePhone;
    公共双LatitudePhone;
    公共双LongetudePhone;
    公共布尔活跃;
    }&LT; XML版本=1.0编码=UTF-8&GT?;
&LT;清单的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
    包=com.bn7.rota
    安卓版code =1
    机器人:=的versionName1.0&GT;    &LT;用途-SDK
        安卓的minSdkVersion =10
        机器人:targetSdkVersion =17/&GT;
        &LT;使用许可权的android:NAME =android.permission.INTERNET对/&GT;
        &lt;应用
        机器人:allowBackup =真
        机器人:图标=@绘制/ ic_launcher
        机器人:标签=@字符串/ APP_NAME
        机器人:主题=@风格/ AppTheme&GT;
        &LT;活动
            机器人:名字=com.bn7.rota.MainActivity
            机器人:标签=@字符串/ APP_NAME&GT;
            &所述;意图滤光器&gt;
                &lt;作用机器人:名字=android.intent.action.MAIN/&GT;                &LT;类机器人:名字=android.intent.category.LAUNCHER/&GT;
            &所述; /意图滤光器&gt;
        &LT; /活性GT;
    &LT; /用途&gt;&LT; /清单&GT;


解决方案

你得到的未经授权的错误表明您不必在表上执行操作的权限。如果你的操作的权限(在门户网站)都设置为与应用中的关键任何人,那么你发送了不正确的应用的关键。如果它被设置为只有认证用户,你需要成为一个身份验证的用户(与移动服务)为它工作。如果它被设置为仅脚本和管理员,那么你要么送过来的主密钥在页眉或来自不同的脚本访问表。

Apparently it's a security issue, but the example downloaded from the website works correctly (ToDo), my application is simpler, does not work, because I really do not understand, I checked the libraries, the manifesto, code, everything seems to be correct. What am I doing wrong? I have an open question on this problem earlier, but now I think I can best describe the problem

Error : Unauthorized

Complete error: Error in activity com.microsoft.windowsazure.mobileservices.MobileServiceException: Error while processing request. at com.microsoft.windowsazure.mobileservices.MobileServiceConnection$1.onNext at com.microsoft.windowsazure.mobileservices.MobileServiceClient$4.handleRequest at com.microsoft.windowsazure.mobileservices.MobileServiceConnection.start at com.microsoft.windowsazure.mobileservices.RequestAsyncTask.doInBackground at com.microsoft.windowsazure.mobileservices.RequestAsyncTask.doInBackground at android.os.AsyncTask$2.call at java.util.concurrent.FutureTask$Sync.innerRun at java.util.concurrent.FutureTask.run at android.os.AsyncTask$SerialExecutor$1.run at java.util.concurrent.ThreadPoolExecutor.runWorker at java.util.concurrent.ThreadPoolExecutor$Worker.run at java.lang.Thread.run Caused by: com.microsoft.windowsazure.mobileservices.MobileServiceException: code":401,"error":"Error: Unauthorized"} at com.microsoft.windowsazure.mobileservices.MobileServiceConnection$1.onNext

My Code for download : https://skydrive.live.com/embed?cid=3CF3FC770FC59E9B&resid=3CF3FC770FC59E9B!1277&authkey=ADQMeBtUVTTIjtE%22

package com.bn7.rota;
import java.net.MalformedURLException;

import com.bn7.rota.Item;
import com.microsoft.windowsazure.mobileservices.*;
import android.os.Bundle;
import android.app.Activity;
import android.util.Log;
import android.view.Menu;

public class MainActivity extends Activity {
    private MobileServiceClient mClient;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        try {
             mClient = new MobileServiceClient( 
                    "https://bn7.azure-mobile.net/", 
                    "hCzcrsFYhkGmxPvQDNxyqBXjZwjXlK99", 
                    this 
                    );
            Item item = new Item(); 
            item.IdPhone = "Awesome item"; 
            item.DateTimePhone = "2013/04/02 08:27:32"; 
            item.LatitudePhone = -43; 
            item.LongetudePhone = -23; 
            item.Active = false; 
            mClient.getTable(Item.class).insert(item, new TableOperationCallback<Item>() {
                 public void onCompleted(Item entity, Exception exception, ServiceFilterResponse response) { 
                    if (exception == null) { 
                         // Insert succeeded 
                                            } else { 
                         // Insert failed
                        Log.d("Insert failed", "*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*");
                        Log.d("Insert failed", "Error in activity", exception);  
                        Log.d("Insert failed", "*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*");
                    } 
                 } 
            });
        } catch (MalformedURLException e) {
            Log.d("MalformedURLException", e.toString());
        }
}


    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.activity_main, menu);
        return true;
    }

}
package com.bn7.rota;

public class Item { 
    public int Id; 
    public String IdPhone;
    public String DateTimePhone;
    public double LatitudePhone;
    public double LongetudePhone;
    public boolean Active;
    }

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.bn7.rota"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="10"
        android:targetSdkVersion="17" />
        <uses-permission android:name="android.permission.INTERNET" />
        <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name="com.bn7.rota.MainActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

解决方案

The Unauthorized error you're getting indicates that you don't have permission to perform the operation on the table. If your operation's permissions (in the portal) are set to "Anybody with the Application Key", then you're sending over the incorrect application key. If it's set to "Only Authenticated Users", you'd need to be an authenticated user (with the Mobile Service) for it to work. If it's set to "Only Scripts and Admins" then you either have to send over your master key in the header or be accessing the table from a different script.

这篇关于安全错误坚持在Azure中的数据与Android应用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆