2 * ***************************************************************
4 * Copyright 2016 Samsung Electronics All Rights Reserved.
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
18 * ****************************************************************
21 package org.iotivity.service.easysetup.mediator;
23 import android.util.Log;
25 import org.iotivity.service.easysetup.mediator.enums.OAUTH_TOKENTYPE;
27 import org.iotivity.base.OcException;
28 import org.iotivity.base.OcRepresentation;
31 * This class contains cloud server properties to be delivered to Enrollee
33 public class CloudProp {
34 private static final String TAG = CloudProp.class.getName();
35 protected OcRepresentation mRep = null;
36 protected String mCloudID = null;
37 protected int mCredID ;
43 mRep = new OcRepresentation();
47 public void setCloudProp(String authCode, String authProvider, String ciServer)
53 if(authProvider == null)
62 mRep.setValue(ESConstants.OC_RSRVD_ES_AUTHCODE, authCode);
63 mRep.setValue(ESConstants.OC_RSRVD_ES_AUTHPROVIDER, authProvider);
64 mRep.setValue(ESConstants.OC_RSRVD_ES_CISERVER, ciServer);
65 } catch (OcException e) {
66 Log.e(TAG, "setCloudProp is failed.");
70 public void setCloudPropWithAccessToken(String accessToken, OAUTH_TOKENTYPE tokenType,
71 String authProvider, String ciServer)
73 if(accessToken == null)
77 if(authProvider == null)
86 mRep.setValue(ESConstants.OC_RSRVD_ES_ACCESSTOKEN, accessToken);
87 mRep.setValue(ESConstants.OC_RSRVD_ES_ACCESSTOKEN_TYPE, tokenType.getValue());
88 mRep.setValue(ESConstants.OC_RSRVD_ES_AUTHPROVIDER, authProvider);
89 mRep.setValue(ESConstants.OC_RSRVD_ES_CISERVER, ciServer);
90 } catch (OcException e) {
91 Log.e(TAG, "setCloudPropWithAccessToken is failed.");
95 public void setCloudID(String cloudID)
100 public void setCredID(int credID)
105 * This method returns the authCode used for the first registration to IoTivity cloud
106 * @return AuthCode for sign-up to IoTivity cloud
108 public String getAuthCode()
117 if (mRep.hasAttribute(ESConstants.OC_RSRVD_ES_AUTHCODE))
118 return mRep.getValue(ESConstants.OC_RSRVD_ES_AUTHCODE);
120 catch (OcException e)
122 Log.e(TAG, "getAuthCode is failed.");
128 * This method returns the auth provider which issued the given AuthCode
129 * @return Auth provider which issued the given AuthCode
131 public String getAuthProvider()
140 if (mRep.hasAttribute(ESConstants.OC_RSRVD_ES_AUTHPROVIDER))
141 return mRep.getValue(ESConstants.OC_RSRVD_ES_AUTHPROVIDER);
143 catch (OcException e)
145 Log.e(TAG, "getAuthProvider is failed.");
151 * This method returns the Cloud Interface server's URL to be registered
152 * @return CI server's URL to be registered
154 public String getCiServer()
163 if (mRep.hasAttribute(ESConstants.OC_RSRVD_ES_CISERVER))
164 return mRep.getValue(ESConstants.OC_RSRVD_ES_CISERVER);
166 catch (OcException e)
168 Log.e(TAG, "getCiServer is failed.");
174 * This method returns the Cloud Interface server's UUID
175 * @return CI server's UUID
177 public String getCloudID()
183 * This method returns the Cloud Certificate's Cred ID
184 * @return CI server's Credential ID of Certificate
186 public int getCredID()
192 * This method returns an accessToken used for the first registration to IoTivity cloud
193 * @return accessToken for sign-up to IoTivity cloud
195 public String getAccessToken()
204 if (mRep.hasAttribute(ESConstants.OC_RSRVD_ES_ACCESSTOKEN))
205 return mRep.getValue(ESConstants.OC_RSRVD_ES_ACCESSTOKEN);
207 catch (OcException e)
209 Log.e(TAG, "getAccessToken is failed.");
215 * This method returns an access token type
216 * @return tokenType of access token
218 public OAUTH_TOKENTYPE getAccessTokenType()
227 if (mRep.hasAttribute(ESConstants.OC_RSRVD_ES_ACCESSTOKEN_TYPE))
228 return OAUTH_TOKENTYPE.fromInt((int)mRep.getValue(ESConstants.OC_RSRVD_ES_ACCESSTOKEN_TYPE));
230 catch (OcException e)
232 Log.e(TAG, "getAccessTokenType is failed.");
234 return OAUTH_TOKENTYPE.NONE_OAUTH_TOKENTYPE;
237 public OcRepresentation toOCRepresentation()