int main(int argc, char *argv[]) { const char* prop_file = "../../config/OpenSSOAgentBootstrap.properties"; const char* config_file = "../../config/OpenSSOAgentConfiguration.properties"; am_status_t status = AM_FAILURE; am_properties_t prop = AM_PROPERTIES_NULL; am_auth_context_t auth_ctx = NULL; am_sso_token_handle_t sso_handle = NULL; const char *ssoTokenID = NULL; char *user = NULL; char* org_name = NULL; char* auth_module = "LDAP"; char *pw = NULL; int j; char c; int usage = 0; boolean_t agentInitialized = B_FALSE; boolean_t dispatch_listener = B_FALSE; /* dispatch listener in a */ /* seperate thread */ for (j=1; j < argc; j++) { if (*argv[j]=='-') { c = argv[j][1]; switch (c) { case 'u': user = (j <= argc-1) ? argv[++j] : NULL; break; case 'p': pw = (j <= argc-1) ? argv[++j] : NULL; break; case 'o': org_name = (j < argc-1) ? argv[++j] : NULL; break; case 'f': prop_file = (j <= argc-1) ? argv[++j] : NULL; break; case 'c': config_file = (j <= argc-1) ? argv[++j] : NULL; break; case 's': ssoTokenID = (j <= argc-1) ? argv[++j] : NULL; break; case 'm': auth_module = (j < argc-1) ? argv[++j] : NULL; break; case 'd': dispatch_listener = B_TRUE; break; default: usage++; break; } if (usage) break; } else { usage++; break; } } if (usage || (NULL==ssoTokenID && (NULL==org_name) && (NULL==user || NULL==pw))) { Usage(argv); return EXIT_FAILURE; } am_web_init(prop_file, config_file); am_agent_init(&agentInitialized); // initialize sso status = am_properties_create(&prop); fail_on_error(status, "am_properties_create"); status = am_properties_load( prop, prop_file ); fail_on_error(status, "am_properties_load"); status = am_log_init(prop); fail_on_error(status, "am_log_init"); status = am_sso_init(prop); fail_on_error(status, "am_sso_init"); // login to get a sso token ID if (NULL == ssoTokenID) { auth_login(prop, user, pw, org_name, &auth_ctx, &ssoTokenID, auth_module); } else { am_log_log(AM_LOG_ALL_MODULES, AM_LOG_INFO, "SSO Token ID is %s.", ssoTokenID); } // create sso token handle status = AM_FAILURE; status = am_sso_create_sso_token_handle(&sso_handle, ssoTokenID, B_FALSE); fail_on_error(status, "am_sso_create_sso_token_handle"); printf("Created sso token handle for %s.\n", ssoTokenID); status = am_sso_destroy_sso_token_handle(sso_handle); fail_on_error(status, "am_sso_destroy_sso_token_handle"); sso_handle = NULL; // call it again to see if found in cache (check log) status = am_sso_create_sso_token_handle(&sso_handle, ssoTokenID, B_FALSE); fail_on_error(status, "am_sso_create_sso_token_handle (again)"); printf("Created sso token handle again for %s.\n", ssoTokenID); // test interfaces for sso_handle test_interfaces(sso_handle, ssoTokenID); // test listeners and notification test_listeners(sso_handle, ssoTokenID, dispatch_listener); // test invalidate. printf("Invalidating token..\n"); status = am_sso_invalidate_token(sso_handle); printf("am_sso_invalidate_token returned %s.\n", am_status_to_name(status)); // session should now be invalid. printf("IsValid=%s.\n", am_sso_is_valid_token(sso_handle)?"true":"false"); // add listener should now fail. status = am_sso_add_sso_token_listener(sso_handle, listener_func_one, NULL, dispatch_listener); printf("am_sso_add_sso_token_listener() returned %s.\n", am_status_to_name(status)); // destroy auth context status = am_auth_destroy_auth_context(auth_ctx); printf("am_auth_destroy_auth_context returned %s.\n", am_status_to_name(status)); // destroy sso token handle (free the memory) printf("Deleting token..\n"); status = am_sso_destroy_sso_token_handle(sso_handle); printf("am_sso_destroy_sso_token_handle() returned %s.\n", am_status_to_name(status)); printf("Cleaning up..\n"); (void)am_cleanup(); am_properties_destroy(prop); printf("Done.\n"); return EXIT_SUCCESS; } /* end of main procedure */
int main(int argc, char *argv[]) { const char* prop_file = "../../config/OpenSSOAgentBootstrap.properties"; am_status_t status = AM_FAILURE; am_properties_t prop = AM_PROPERTIES_NULL; const char *user_token_id = NULL; const char *log_name = NULL; const char *log_message = NULL; const char *logged_by_token_id = NULL; const char *log_module = "TestModule"; const char *loggingservice = "loggingservice"; int j; char c; char *serverUrl = NULL; const char *loggingUrl = NULL; int usage = 0; for (j=1; j < argc; j++) { if (*argv[j]=='-') { c = argv[j][1]; switch (c) { case 'f': prop_file = (j <= argc-1) ? argv[++j] : NULL; break; case 'u': user_token_id = (j <= argc-1) ? argv[++j] : NULL; break; case 'n': log_name = (j <= argc-1) ? argv[++j] : NULL; break; case 'l': logged_by_token_id = (j <= argc-1) ? argv[++j] : NULL; break; case 'm': log_message = (j <= argc-1) ? argv[++j] : NULL; break; case 'd': log_module = (j <= argc-1) ? argv[++j] : NULL; break; default: usage++; break; } if (usage) { break; } } // end if } //end for if (usage || prop_file == NULL || user_token_id == NULL || log_name == NULL || logged_by_token_id == NULL || log_message == NULL || log_module == NULL) { Usage(argv); exit(0); } status = am_properties_create(&prop); fail_on_error(status, "am_properties_create"); status = am_properties_load(prop, prop_file); fail_on_error(status, "am_properties_load"); status = am_log_init(prop); fail_on_error(status, "am_log_init"); serverUrl = (char *) malloc(512); memset(serverUrl,0,512); do_remote_logging(serverUrl, prop, user_token_id, log_name, log_message, logged_by_token_id, log_module); if (serverUrl != NULL) { free(serverUrl); } exit(0); }
void am_log_init_worker(int id, int status) { #ifdef _WIN32 am_log_init(id, status); #endif }
void test_logging(void** state) { am_log_init(AM_SUCCESS); AM_LOG_ALWAYS(getpid(), "Hello world"); }