The following code sample shows how you might use the am_sso_get_property() and am_sso_set_property() functions. For additional information, see am_sso_get_property() and am_sso_set_property().
/* initialize sso as in previous sample */
am_status_t status = NULL;
am_sso_token_handle_t sso_handle = NULL;
char *session_status = NULL;
am_string_set_t principal_set = NULL;
/* create sso token handle */
status = am_sso_create_sso_token_handle(&sso_handle, sso_token_id, false);
if (status != AM_SUCCESS) {
printf("Failed getting sso token handle for sso token id %s.
\\n", sso_token_id);
return 1;
}
/* check if session is valid */
session_status = am_sso_is_valid_token(sso_handle) ? "Valid" : "Invalid";
printf("Session state is %s\\n", session_status);
/* check if session is valid using validate. This also updates the handle with
/*info from the server */
status = am_sso_validate_token(sso_handle);
if (status == AM_SUCCESS) {
printf("Session state is valid.\\n");
} else if (status == AM_INVALID_SESSION) {
printf("Session status is invalid.\\n");
} else {
printf("Error validating sso token.\\n");
return 1;
}
/* get info on the session */
printf("SSO Token ID is %s.\\n", am_sso_get_sso_token_id(sso_handle));
printf("Auth type is %s.\\n", am_sso_get_auth_type(sso_handle));
printf("Auth level is %d.\\n", am_sso_get_auth_level(sso_handle));
printf("Idle time is %d.\\n", am_sso_get_idle_time(sso_handle));
printf("Max Idle time is %d.\\n", am_sso_get_max_idle_time(sso_handle));
printf("Time left is %d.\\n", am_sso_get_time_left(sso_handle));
printf("Max session time is %d.\\n", am_sso_get_max_session_time(sso_handle));
printf("Principal is %s.\\n", am_sso_get_principal(sso_handle));
printf("Host is %s.\\n", am_sso_get_host(sso_handle));
principal_set = am_sso_get_principal_set(sso_handle);
if (principal_set == NULL) {
printf("ERROR: Principal set is NULL!\\n");
}else {
printf("Principal set size %d.\\n", principal_set->size);
for (i = 0; i < principal_set->size; i++) {
printf("Principal[%d] = %s.\\n", i, principal_set->strings[i]);
}
am_string_set_destroy(principal_set);
}
/* get "HOST" property on the session. Same as am_sso_get_host(). */
printf("Host is %s.\\n", am_sso_get_property(sso_handle, "HOST"));
/* set a application defined property and get it back */
status = am_sso_set_property(sso_handle, "AppPropName", "AppPropValue");
if (status != AM_SUCCESS) {
printf("Error setting property.\\n");
return 1;
}
printf("AppPropName value is %s.\\n", am_sso_get_property
(sso_handle, "AppPropName");
/* refresh token, idle time should be 0 after refresh */
status = am_sso_refresh_token(sso_handle);
if (status != AM_SUCCESS) {
printf("Error refreshing token !\\n");
return 1;
}
printf("After refresh, idle time is %d.\\n", am_sso_get_idle_time(sso_handle));
/* end this session abruptly. am_auth_logout() is the right way
/* to end session */
status = am_sso_invalidate_token(sso_handle);
if (status != AM_SUCCESS) {
printf("Error invalidating token.\\n");
return 1;
}
/* we are done with sso token handle. free memory for sso handle. */
status = am_sso_destroy_sso_token_handle(sso_handle);
if (status != AM_SUCCESS) {
printf("Failed to free sso token handle.\\n");
return 1;
}
/* call am_cleanup, and other cleanup routines as in previous sample */