extern "C" am_status_t am_policy_init(am_properties_t policy_config_params) { Log::ModuleId logID = Log::addModule(AM_POLICY_SERVICE); am_status_t status = AM_SUCCESS; if (policy_config_params) { const Properties& propertiesRef = *reinterpret_cast<Properties *>(policy_config_params); try { if(enginePtr == NULL) { am_sso_init(policy_config_params); // Now try creating the policy engine. enginePtr = new PolicyEngine(propertiesRef); } else { Log::log(logID, Log::LOG_DEBUG, "Policy Service already initialized"); } } catch (const InternalException exc) { status = exc.getStatusCode(); Log::log(logID, Log::LOG_ERROR, exc); } catch (const std::bad_alloc& exc) { status = AM_NO_MEMORY; Log::log(logID, Log::LOG_ERROR, exc); } catch(std::exception &ex) { Log::log(enginePtr->getModuleID(), Log::LOG_ERROR, ex); return AM_FAILURE; } catch (...) { status = AM_FAILURE; Log::log(logID, Log::LOG_ERROR, "Unknown exception encountered."); } #if defined(USE_STATIC_NSPR) if (AM_SUCCESS != status) { PR_Cleanup(); } #endif } else { Log::log(logID, Log::LOG_DEBUG, "am_policy_init(): " "One or more invalid parameters is invalid."); status = AM_INVALID_ARGUMENT; } return status; }
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 */