?? server.cc
字號:
/* * A Bank factory that creates Account objects */#include <fstream.h>#include "account.h"#include <mico/security/security.h>#include <mico/security/securitylevel1.h>#include <mico/security/securitylevel2.h>using namespace std;CORBA::ORB_var orb;CORBA::Object_var securitymanager;SecurityLevel2::SecurityManager_var secman;/* * Implementation of the Account */class Account_impl : virtual public POA_Account{public: Account_impl (); void deposit (CORBA::ULong); void withdraw (CORBA::ULong); CORBA::Long balance ();private: CORBA::Long bal;};Account_impl::Account_impl (){ bal = 0;}voidAccount_impl::deposit (CORBA::ULong amount){ bal += amount;}voidAccount_impl::withdraw (CORBA::ULong amount){ // Get SecurityCurrent CORBA::Object_var securitycurrent; SecurityLevel2::Current_var seccur; securitycurrent = orb->resolve_initial_references ("SecurityCurrent"); assert (!CORBA::is_nil (securitycurrent)); seccur = SecurityLevel2::Current::_narrow(securitycurrent); assert (!CORBA::is_nil (seccur)); SecurityLevel2::ReceivedCredentials_var rc = seccur->received_credentials(); Security::CredentialsType cred_type = rc->credentials_type(); if ( cred_type == Security::SecOwnCredentials ) cout << "SecOwnCredentials\n"; if ( cred_type == Security::SecReceivedCredentials ) cout << "SecReceivedCredentials\n"; if ( cred_type == Security::SecTargetCredentials ) cout << "SecTargetCredentials\n"; // Get Security Features cout << "Security Features:\n"; if (rc->get_security_feature(Security::SecDirectionBoth,Security::SecNoDelegation )) cout << "SecNoDelegation\n"; if (rc->get_security_feature(Security::SecDirectionBoth,Security::SecSimpleDelegation )) cout << "SecSimpleDelegation\n"; if (rc->get_security_feature(Security::SecDirectionBoth,Security::SecCompositeDelegation )) cout << "SecCompositeDelegation\n"; if (rc->get_security_feature(Security::SecDirectionBoth,Security::SecNoProtection )) cout << "SecNoProtection\n"; if (rc->get_security_feature(Security::SecDirectionBoth,Security::SecIntegrity)) cout << "SecIntegrity\n"; if (rc->get_security_feature(Security::SecDirectionBoth,Security::SecConfidentiality)) cout << "SecConfidentiality\n"; if (rc->get_security_feature(Security::SecDirectionBoth,Security::SecIntegrityAndConfidentiality)) cout << "SecIntegrityAndConfidentiality\n"; if (rc->get_security_feature(Security::SecDirectionBoth,Security::SecDetectReplay)) cout << "SecDetectReplay\n"; if (rc->get_security_feature(Security::SecDirectionBoth,Security::SecDetectMisordering)) cout << "SecDetectMisordering\n"; if (rc->get_security_feature(Security::SecDirectionBoth,Security::SecEstablishTrustInTarget)) cout << "SecEstablishTrustInTarget\n"; if (rc->get_security_feature(Security::SecDirectionBoth,Security::SecEstablishTrustInClient)) cout << "SecEstablishTrustInClient\n"; Security::ExtensibleFamily fam; fam.family_definer = 0; fam.family = 1; Security::AttributeType at; at.attribute_family = fam; at.attribute_type = Security::AccessId; Security::AttributeTypeList atl; atl.length(0); // atl[0]=at; Security::AttributeList_var al = rc->get_attributes( atl ); cout << "Received credentials" << (*al).length() << " attributes\n"; for (CORBA::ULong ctr = 0; ctr < (*al).length(); ctr++) { cout << (*al)[ctr].attribute_type.attribute_family.family << " " << (*al)[ctr].attribute_type.attribute_type << " " << &(*al)[ctr].value[0] << " " << &(*al)[ctr].defining_authority[0] << endl; }cout << "///////////////////////////////////////////////////////////////////////////\n"; SecurityLevel2::CredentialsList* accept_creds = rc -> accepting_credentials(); SecurityLevel2::Credentials_var cred = (*accept_creds)[0]; // get the attributes from the initiating_credentials of tc al = cred -> get_attributes(atl);// and print them cout << "Associating credentials " << (*al).length() << " attributes\n"; for (CORBA::ULong ctr = 0; ctr < (*al).length(); ctr++) { cout << "family = " << (*al)[ctr].attribute_type.attribute_family.family << " " << "type = " << (*al)[ctr].attribute_type.attribute_type << " " << &(*al)[ctr].value[0] << " " << &(*al)[ctr].defining_authority[0] << endl; } cout << "///////////////////////////////////////////////////////////////////////////\n"; Security::AssociationOptions opt_used = rc -> association_options_used(); cout << "Association_options_used (received credentials)\n" ; if (Security::NoDelegation == (opt_used & Security::NoDelegation)) cout << "NoDelegaion\n"; if (Security::SimpleDelegation == (opt_used & Security::SimpleDelegation)) cout << "SimpleDelegation\n"; if (Security::CompositeDelegation == (opt_used & Security::CompositeDelegation)) cout << "CompositeDelegation\n"; if (Security::NoProtection == (opt_used & Security::NoProtection)) cout << "NoProtection\n"; if (Security::Integrity == (opt_used & Security::Integrity)) cout << "Integrity\n"; if (Security::Confidentiality == (opt_used & Security::Confidentiality)) cout << "Confidentiality\n"; if (Security::DetectReplay == (opt_used & Security::DetectReplay)) cout << "DetectReplay\n"; if (Security::DetectMisordering == (opt_used & Security::DetectMisordering)) cout << "DetectMisordering\n"; if (Security::EstablishTrustInTarget == (opt_used & Security::EstablishTrustInTarget)) cout << "EstablishTrustInTarget\n"; if (Security::EstablishTrustInClient == (opt_used & Security::EstablishTrustInClient)) cout << "EstablishTrustInClient\n"; cout << "///////////////////////////////////////////////////////////////////////////\n"; bal -= amount;}CORBA::LongAccount_impl::balance (){ return bal;}/* * Implementation of the Bank */class Bank_impl : virtual public POA_Bank{public: Account_ptr create ();};Account_ptrBank_impl::create (){ /* * Create a new account (which is never deleted) */ Account_impl * ai = new Account_impl; /* * Obtain a reference using _this. This implicitely activates the * account servant (the RootPOA, which is the object's _default_POA, * has the IMPLICIT_ACTIVATION policy) */ Account_ptr aref = ai->_this (); assert (!CORBA::is_nil (aref)); /* * Return the reference */ return aref;}intmain (int argc, char *argv[]){ /* * Initialize the ORB */ cout << "Start Bank server\n"; orb = CORBA::ORB_init (argc, argv, "mico-local-orb"); // Check for security service // Are the values correct? CORBA::ServiceType service_type = CORBA::Security; CORBA::ServiceInformation_var service_information = new CORBA::ServiceInformation; if (orb->get_service_information(service_type, service_information)) { cout << "Security Service exists\n"; CORBA::ULong opt_len = service_information->service_options.length(); cout << opt_len << " Service Options:= "; for ( CORBA::ULong i = 0; i < opt_len; i++) { cout << service_information->service_options[i] << " "; } cout << endl; CORBA::ULong det_len = service_information->service_details.length(); cout << det_len << " Service Details:\n"; for ( CORBA::ULong i = 0; i < det_len; i++) { cout << "Type= " << service_information->service_details[i].service_detail_type << " "; for ( CORBA::ULong j = 0; j < service_information->service_details[i].service_detail.length(); j++) { cout << (unsigned char)service_information->service_details[i].service_detail[j]; } cout << endl; } } else { cout << "No Security Service available\n"; assert(0); } /* * Obtain a reference to the RootPOA and its Manager */ PortableServer::POA_var poa; CORBA::Object_var poaobj = orb->resolve_initial_references ("RootPOA"); poa = PortableServer::POA::_narrow (poaobj); PortableServer::POAManager_var mgr = poa->the_POAManager(); // Get SecurityManager
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -