23 from rapp_utilities
import RappUtilities
24 from rapp_exceptions
import RappError
26 from rapp_platform_ros_communications.srv
import (
27 addStoreTokenToDeviceSrv,
28 addStoreTokenToDeviceSrvRequest,
29 getUserOntologyAliasSrv,
30 getUserOntologyAliasSrvRequest,
31 registerUserOntologyAliasSrv,
32 registerUserOntologyAliasSrvRequest,
34 checkIfUserExistsSrvRequest,
36 getUserLanguageSrvRequest,
38 getUserPasswordSrvRequest,
39 getUsernameAssociatedWithApplicationTokenSrv,
40 getUsernameAssociatedWithApplicationTokenSrvRequest,
41 createNewPlatformUserSrv,
42 createNewPlatformUserSrvRequest,
43 createNewApplicationTokenSrv,
44 createNewApplicationTokenSrvRequest,
45 checkActiveApplicationTokenSrv,
46 checkActiveApplicationTokenSrvRequest,
47 checkActiveRobotSessionSrv,
48 checkActiveRobotSessionSrvRequest,
50 validateUserRoleSrvRequest,
51 validateExistingPlatformDeviceTokenSrv,
52 validateExistingPlatformDeviceTokenSrvRequest
62 user_exists_topic = rospy.get_param(
63 "rapp_mysql_wrapper_check_if_user_exists_service_topic")
64 if not user_exists_topic:
65 RappUtilities.rapp_print(
66 'rapp_mysql_wrapper_check_if_user_exists_service_topic ' +
68 rospy.wait_for_service(user_exists_topic)
73 rospy.ServiceProxy(user_exists_topic, checkIfUserExistsSrv,
76 get_passwd_topic = rospy.get_param(
77 "rapp_mysql_wrapper_get_user_password_service_topic")
78 if not get_passwd_topic:
79 RappUtilities.rapp_print(
80 'rapp_mysql_wrapper_get_user_password_service_topic ' +
82 rospy.wait_for_service(get_passwd_topic)
87 rospy.ServiceProxy(get_passwd_topic, getUserPasswordSrv,
90 verify_appl_token_topic = rospy.get_param(
91 "rapp_mysql_wrapper_check_active_" +
92 "application_token_service_topic")
93 if not verify_appl_token_topic:
94 RappUtilities.rapp_print(
95 "rapp_mysql_wrapper_check_active_" +
96 "application_token_service_topic NOT FOUND",
'ERROR')
97 rospy.wait_for_service(verify_appl_token_topic)
102 verify_appl_token_topic, checkActiveApplicationTokenSrv,
105 get_token_user_topic = rospy.get_param(
106 "rapp_mysql_wrapper_get_username_associated_" +
107 "with_application_token_service_topic")
108 if not get_token_user_topic:
109 RappUtilities.rapp_print(
110 'rapp_mysql_wrapper_get_username_associated_with' +
111 '_application_token_service_topic NOT FOUND',
'ERROR')
112 rospy.wait_for_service(get_token_user_topic)
117 get_token_user_topic, getUsernameAssociatedWithApplicationTokenSrv,
120 verify_robot_session_topic = rospy.get_param(
121 "rapp_mysql_wrapper_check_active_" +
122 "robot_session_service_topic")
123 if not verify_robot_session_topic:
124 RappUtilities.rapp_print(
125 "rapp_mysql_wrapper_check_active_" +
126 "robot_session_service_topic NOT FOUND",
'ERROR')
127 rospy.wait_for_service(verify_robot_session_topic)
132 verify_robot_session_topic, checkActiveRobotSessionSrv,
135 add_new_user_topic = rospy.get_param(
136 "rapp_mysql_wrapper_create_new_platform_user_service_topic")
137 if not add_new_user_topic:
138 RappUtilities.rapp_print(
139 'rapp_mysql_wrapper_create_new_platform_user_service_topic ' +
140 'NOT FOUND',
'ERROR')
141 rospy.wait_for_service(add_new_user_topic)
146 rospy.ServiceProxy(add_new_user_topic, createNewPlatformUserSrv,
149 create_new_appl_token_topic = rospy.get_param(
150 "rapp_mysql_wrapper_create_new_application_token_service_topic")
151 if not create_new_appl_token_topic:
152 RappUtilities.rapp_print(
153 'rapp_mysql_wrapper_create_new_application_token_' +
154 'create_new_appl_token_topic NOT FOUND',
'ERROR')
155 rospy.wait_for_service(create_new_appl_token_topic)
160 create_new_appl_token_topic, createNewApplicationTokenSrv,
163 add_store_token_to_device_topic = rospy.get_param(
164 "rapp_mysql_wrapper_add_store_token_to_device_topic")
165 if not add_store_token_to_device_topic:
166 RappUtilities.rapp_print(
167 'rapp_mysql_wrapper_add_store_token_to_device_topic NOT FOUND',
169 rospy.wait_for_service(add_store_token_to_device_topic)
174 add_store_token_to_device_topic, addStoreTokenToDeviceSrv,
177 validate_user_role_topic = rospy.get_param(
178 "rapp_mysql_wrapper_validate_user_role_topic")
179 if not validate_user_role_topic:
180 RappUtilities.rapp_print(
181 'rapp_mysql_wrapper_validate_user_role_topic NOT FOUND',
183 rospy.wait_for_service(validate_user_role_topic)
188 validate_user_role_topic, validateUserRoleSrv,
191 validate_existing_device_topic = rospy.get_param(
192 "rapp_mysql_wrapper_validate_existing_platform_device_token_topic")
193 if not validate_existing_device_topic:
194 RappUtilities.rapp_print(
195 'rapp_mysql_wrapper_validate_' +
196 'existing_platform_device_token_topic NOT FOUND',
198 rospy.wait_for_service(validate_existing_device_topic)
203 validate_existing_device_topic,
204 validateExistingPlatformDeviceTokenSrv, persistent=
True)
222 req = validateExistingPlatformDeviceTokenSrvRequest()
223 req.device_token = device_token
226 return response.success
234 req = checkIfUserExistsSrvRequest()
235 req.username = username
239 return response.user_exists
251 req = getUserPasswordSrvRequest()
252 req.username = username
256 return response.password
258 raise RappError(
'Wrong credentials')
267 req = checkActiveApplicationTokenSrvRequest()
268 req.application_token = application_token
272 return response.application_token_exists
282 req = getUsernameAssociatedWithApplicationTokenSrvRequest()
283 req.application_token = app_token
286 return response.username
296 req = checkActiveRobotSessionSrvRequest()
297 req.username = username
298 req.device_token = store_token
302 return response.application_token_exists
317 req = createNewPlatformUserSrvRequest()
318 req.username = username
319 req.password = password
320 req.creator_username = creator
321 req.language = language
325 RappUtilities.rapp_print(
'Succesfully wrote new user',
'DEBUG')
327 RappUtilities.rapp_print(response.error,
'ERROR')
328 msg =
'Could not write new user to the database'
329 RappUtilities.rapp_print(msg,
'ERROR')
340 req = createNewApplicationTokenSrvRequest()
341 req.username = username
342 req.store_token = store_token
343 req.application_token = appl_token
347 RappUtilities.rapp_print(
'Succesfully wrote new token',
'DEBUG')
349 msg =
'Could not write new application token to the database'
350 RappUtilities.rapp_print(msg,
'ERROR')
359 req = addStoreTokenToDeviceSrvRequest()
360 req.store_token = store_token
364 RappUtilities.rapp_print(
'Succesfully wrote new token',
'DEBUG')
366 RappUtilities.rapp_print(res.error,
'ERROR')
367 msg =
'Could not write store token to the database'
368 RappUtilities.rapp_print(msg,
'ERROR')
377 req = validateUserRoleSrvRequest()
378 req.username = username
382 RappUtilities.rapp_print(
'Proper user role',
'DEBUG')
385 msg =
'Invalid user role'
386 RappUtilities.rapp_print(msg,
'ERROR')
def verify_active_robot_session
Check if there is an active session (token) for the specified user and store_token (device_token) ...
_verify_appl_token_proxy
Service proxy to query database for application token validity.
def verify_active_application_token
Check if the application_token is active/valid.
_username_exists_proxy
Service proxy to query database for user existance.
_validate_existing_device_token_proxy
Service proxy to query the database for a device token.
_add_new_user_proxy
Service proxy to add new user to the database.
Handles database functions for authentication manager.
_validate_user_role_proxy
Service proxy to query the database for the user's role.
def add_new_user
Write new user to the platform database.
_add_store_token_to_device_proxy
Service proxy to add new device token from store to the database.
def get_token_user
Retrieve username associated with application_token from platform database.
def write_new_application_token
Write new token to the platform database.
def verify_platform_device_token
Verify that the device token exists in platform database.
_get_user_passwd_proxy
Service proxy to query database for user password.
_create_new_app_token_proxy
Service proxy to add new application token to the database.
def add_store_token_to_device
Write store token the device table.
def __init__
ROS Service initializations.
def validate_user_role
Check if user has an admin/root role.
def get_user_password
Retrieve user's password from platform database.
def verify_store_device_token
Verify that the device token exists in store database.
def username_exists
Verify that username exists in platform database.
_get_token_user_proxy
Service proxy to query database for the user associated with a token.
_verify_robot_session_proxy
Service proxy to query database for active user session.