Commit f449b9dc authored by Ricardo Calheiros de Miranda Cosme's avatar Ricardo Calheiros de Miranda Cosme
Browse files

[OPENBUS-90]

* Alterações necessárias para atender as modificações realizadas pela tarefa OPENBUS-91.
(commit complementar a r84765)



git-svn-id: https://subversion.tecgraf.puc-rio.br/engdist/openbus/trunk@84774 ae0415b3-e90b-0410-900d-d0be9363c56b
parent 8392f0d8
......@@ -19,13 +19,11 @@ class ACSTestSuite: public CxxTest::TestSuite {
private:
Openbus* o ;
services::IAccessControlService* acs ;
common::CredentialManager* credentialManager ;
common::ClientInterceptor* clientInterceptor ;
services::Credential* credential ;
services::Lease* lease ;
char BUFFER[BUFFER_SIZE];
char* OPENBUS_SERVER_HOST;
char* OPENBUS_SERVER_PORT;
unsigned short OPENBUS_SERVER_PORT;
char* OPENBUS_USERNAME;
char* OPENBUS_PASSWORD;
public:
......@@ -47,15 +45,12 @@ class ACSTestSuite: public CxxTest::TestSuite {
lua_getglobal(LuaVM, "OPENBUS_SERVER_HOST");
OPENBUS_SERVER_HOST = (char*) lua_tostring(LuaVM, -1);
lua_getglobal(LuaVM, "OPENBUS_SERVER_PORT");
OPENBUS_SERVER_PORT = (char*) lua_tostring(LuaVM, -1);
OPENBUS_SERVER_PORT = lua_tonumber(LuaVM, -1);
lua_getglobal(LuaVM, "OPENBUS_USERNAME");
OPENBUS_USERNAME = (char*) lua_tostring(LuaVM, -1);
lua_getglobal(LuaVM, "OPENBUS_PASSWORD");
OPENBUS_PASSWORD = (char*) lua_tostring(LuaVM, -1);
lua_pop(LuaVM, 4);
credentialManager = new common::CredentialManager ;
clientInterceptor = new common::ClientInterceptor(credentialManager);
o->setClientInterceptor( clientInterceptor ) ;
} catch ( const char* errmsg ) {
TS_FAIL( errmsg ) ;
} /* try */
......@@ -64,8 +59,7 @@ class ACSTestSuite: public CxxTest::TestSuite {
void testGetACS()
{
try {
sprintf(BUFFER, "corbaloc::%s:%s/ACS", OPENBUS_SERVER_HOST, OPENBUS_SERVER_PORT);
acs = o->getACS( BUFFER, "IDL:openbusidl/acs/IAccessControlService:1.0" ) ;
acs = o->getACS( OPENBUS_SERVER_HOST, OPENBUS_SERVER_PORT ) ;
} catch ( const char* errmsg ) {
TS_FAIL( errmsg ) ;
} /* try */
......@@ -80,14 +74,14 @@ class ACSTestSuite: public CxxTest::TestSuite {
services::Lease* lease2 = new services::Lease() ;
acs->loginByPassword( OPENBUS_USERNAME, OPENBUS_PASSWORD, credential, lease ) ;
acs->loginByPassword( OPENBUS_USERNAME, OPENBUS_PASSWORD, credential2, lease2 ) ;
TS_ASSERT_SAME_DATA( credential->entityName, OPENBUS_USERNAME, 6 ) ;
TS_ASSERT_SAME_DATA( credential2->entityName, OPENBUS_USERNAME, 6 ) ;
TS_ASSERT_SAME_DATA( credential->owner, OPENBUS_USERNAME, 6 ) ;
TS_ASSERT_SAME_DATA( credential2->owner, OPENBUS_USERNAME, 6 ) ;
TS_ASSERT( strcmp( credential2->identifier, credential->identifier ) ) ;
credentialManager->setValue( credential ) ;
o->getCredentialManager()->setValue( credential ) ;
acs->logout( credential ) ;
credentialManager->setValue( credential2 ) ;
o->getCredentialManager()->setValue( credential2 ) ;
acs->logout( credential2 ) ;
credentialManager->invalidate() ;
o->getCredentialManager()->invalidate() ;
TS_ASSERT(!acs->loginByPassword( "INVALID", "INVALID", credential, lease )) ;
TS_ASSERT_SAME_DATA( credential->identifier, "", 0 ) ;
} catch ( const char* errmsg ) {
......@@ -100,10 +94,11 @@ class ACSTestSuite: public CxxTest::TestSuite {
try {
services::Credential* c = new services::Credential ;
acs->loginByPassword( OPENBUS_USERNAME, OPENBUS_PASSWORD, credential, lease ) ;
credentialManager->setValue( credential ) ;
o->getCredentialManager()->setValue( credential ) ;
TS_ASSERT( acs->isValid( credential ) ) ;
c->identifier = "123" ;
c->entityName = OPENBUS_USERNAME ;
c->owner = OPENBUS_USERNAME ;
c->delegate = "";
TS_ASSERT( !acs->isValid( c ) ) ;
acs->logout( credential ) ;
TS_ASSERT_THROWS_ANYTHING( acs->isValid( credential ) ) ;
......@@ -116,7 +111,7 @@ class ACSTestSuite: public CxxTest::TestSuite {
{
try {
acs->loginByPassword( OPENBUS_USERNAME, OPENBUS_PASSWORD, credential, lease ) ;
credentialManager->setValue( credential ) ;
o->getCredentialManager()->setValue( credential ) ;
acs->getRegistryService() ;
} catch ( const char* errmsg ) {
TS_FAIL( errmsg ) ;
......@@ -128,15 +123,16 @@ class ACSTestSuite: public CxxTest::TestSuite {
try {
services::Lease* leaseout = new services::Lease() ;
acs->loginByPassword( OPENBUS_USERNAME, OPENBUS_PASSWORD, credential, lease ) ;
credentialManager->setValue( credential ) ;
o->getCredentialManager()->setValue( credential ) ;
TS_ASSERT( acs->renewLease( credential, leaseout ) ) ;
TS_ASSERT_EQUALS( 30, (int) *leaseout ) ;
services::Credential* s = new services::Credential ;
s->identifier = "" ;
s->entityName = "" ;
s->owner = "" ;
s->delegate = "";
TS_ASSERT( !acs->renewLease( s, leaseout ) ) ;
acs->logout( credential ) ;
credentialManager->invalidate() ;
o->getCredentialManager()->invalidate() ;
} catch ( const char* errmsg ) {
TS_FAIL( errmsg ) ;
} /* try */
......@@ -145,11 +141,12 @@ class ACSTestSuite: public CxxTest::TestSuite {
void testLogout()
{
acs->loginByPassword( OPENBUS_USERNAME, OPENBUS_PASSWORD, credential, lease ) ;
credentialManager->setValue( credential ) ;
o->getCredentialManager()->setValue( credential ) ;
TS_ASSERT( acs->logout( credential ) ) ;
services::Credential* c = new services::Credential ;
c->entityName = OPENBUS_USERNAME ;
c->owner = OPENBUS_USERNAME ;
c->identifier = "dadadsa" ;
c->delegate = "";
TS_ASSERT_THROWS_ANYTHING( acs->logout( c ) ) ;
}
......@@ -160,13 +157,14 @@ class ACSTestSuite: public CxxTest::TestSuite {
void credentialWasDeleted ( services::Credential* aCredential )
{
printf("\nChamando metodo de callback 'credentialWasDeleted'\n");
printf( " credential->entityName=%s\n", aCredential->entityName ) ;
printf( " credential->owner=%s\n", aCredential->owner ) ;
printf( " credential->identifier=%s\n\n", aCredential->identifier ) ;
printf( " credential->delegate=%s\n\n", aCredential->delegate ) ;
}
} ;
services::CredentialIdentifierList* list = new services::CredentialIdentifierList ;
acs->loginByPassword( OPENBUS_USERNAME, OPENBUS_PASSWORD, credential, lease ) ;
credentialManager->setValue( credential ) ;
o->getCredentialManager()->setValue( credential ) ;
credentialObserver* co = new credentialObserver;
list->newmember( credential->identifier ) ;
acs->addObserver( co, list ) ;
......@@ -185,7 +183,7 @@ class ACSTestSuite: public CxxTest::TestSuite {
services::CredentialIdentifierList* list = new services::CredentialIdentifierList ;
services::Credential* c = new services::Credential ;;
acs->loginByPassword( OPENBUS_USERNAME, OPENBUS_PASSWORD, c, lease ) ;
credentialManager->setValue( c ) ;
o->getCredentialManager()->setValue( c ) ;
credentialObserver* co = new credentialObserver ;
list->newmember( c->identifier ) ;
const char* id = acs->addObserver( co, list ) ;
......
......@@ -21,8 +21,6 @@ class RGSTestSuite: public CxxTest::TestSuite {
Openbus* o;
services::IAccessControlService* acs;
services::IRegistryService* rgs;
common::CredentialManager* credentialManager;
common::ClientInterceptor* clientInterceptor;
services::Credential* credential;
services::Lease* lease;
char* RegistryIdentifier;
......@@ -32,7 +30,7 @@ class RGSTestSuite: public CxxTest::TestSuite {
services::PropertyValue* propertyValue;
char BUFFER[BUFFER_SIZE];
char* OPENBUS_SERVER_HOST;
char* OPENBUS_SERVER_PORT;
unsigned short OPENBUS_SERVER_PORT;
char* OPENBUS_USERNAME;
char* OPENBUS_PASSWORD;
public:
......@@ -54,15 +52,12 @@ class RGSTestSuite: public CxxTest::TestSuite {
lua_getglobal(LuaVM, "OPENBUS_SERVER_HOST");
OPENBUS_SERVER_HOST = (char*) lua_tostring(LuaVM, -1);
lua_getglobal(LuaVM, "OPENBUS_SERVER_PORT");
OPENBUS_SERVER_PORT = (char*) lua_tostring(LuaVM, -1);
OPENBUS_SERVER_PORT = lua_tonumber(LuaVM, -1);
lua_getglobal(LuaVM, "OPENBUS_USERNAME");
OPENBUS_USERNAME = (char*) lua_tostring(LuaVM, -1);
lua_getglobal(LuaVM, "OPENBUS_PASSWORD");
OPENBUS_PASSWORD = (char*) lua_tostring(LuaVM, -1);
lua_pop(LuaVM, 4);
credentialManager = new common::CredentialManager;
clientInterceptor = new common::ClientInterceptor(credentialManager);
o->setClientInterceptor(clientInterceptor);
} catch (const char* errmsg) {
TS_FAIL(errmsg);
} /* try */
......@@ -71,12 +66,11 @@ class RGSTestSuite: public CxxTest::TestSuite {
void testGetRGS()
{
try {
sprintf(BUFFER, "corbaloc::%s:%s/ACS", OPENBUS_SERVER_HOST, OPENBUS_SERVER_PORT);
acs = o->getACS(BUFFER, "IDL:openbusidl/acs/IAccessControlService:1.0");
acs = o->getACS(OPENBUS_SERVER_HOST, OPENBUS_SERVER_PORT);
credential = new services::Credential;
lease = new services::Lease;
acs->loginByPassword(OPENBUS_USERNAME, OPENBUS_PASSWORD, credential, lease);
credentialManager->setValue(credential);
o->getCredentialManager()->setValue(credential);
rgs = acs->getRegistryService();
scs::core::IComponent* member = new scs::core::IComponent("scs::core::IComponent Mock");
propertyList = new services::PropertyList;
......
......@@ -19,8 +19,6 @@ class SESTestSuite: public CxxTest::TestSuite {
Openbus* o ;
services::IAccessControlService* acs ;
services::IRegistryService* rgs ;
common::CredentialManager* credentialManager ;
common::ClientInterceptor* clientInterceptor ;
services::Credential* credential ;
services::Lease* lease ;
char* RegistryIdentifier;
......@@ -32,7 +30,7 @@ class SESTestSuite: public CxxTest::TestSuite {
scs::core::IComponent* component ;
char BUFFER[BUFFER_SIZE];
char* OPENBUS_SERVER_HOST;
char* OPENBUS_SERVER_PORT;
unsigned short OPENBUS_SERVER_PORT;
char* OPENBUS_USERNAME;
char* OPENBUS_PASSWORD;
public:
......@@ -54,21 +52,17 @@ class SESTestSuite: public CxxTest::TestSuite {
lua_getglobal(LuaVM, "OPENBUS_SERVER_HOST");
OPENBUS_SERVER_HOST = (char*) lua_tostring(LuaVM, -1);
lua_getglobal(LuaVM, "OPENBUS_SERVER_PORT");
OPENBUS_SERVER_PORT = (char*) lua_tostring(LuaVM, -1);
OPENBUS_SERVER_PORT = lua_tonumber(LuaVM, -1);
lua_getglobal(LuaVM, "OPENBUS_USERNAME");
OPENBUS_USERNAME = (char*) lua_tostring(LuaVM, -1);
lua_getglobal(LuaVM, "OPENBUS_PASSWORD");
OPENBUS_PASSWORD = (char*) lua_tostring(LuaVM, -1);
lua_pop(LuaVM, 4);
credentialManager = new common::CredentialManager ;
clientInterceptor = new common::ClientInterceptor(credentialManager);
o->setClientInterceptor( clientInterceptor ) ;
sprintf(BUFFER, "corbaloc::%s:%s/ACS", OPENBUS_SERVER_HOST, OPENBUS_SERVER_PORT);
acs = o->getACS( BUFFER, "IDL:openbusidl/acs/IAccessControlService:1.0" ) ;
acs = o->getACS(OPENBUS_SERVER_HOST, OPENBUS_SERVER_PORT) ;
credential = new services::Credential() ;
lease = new services::Lease() ;
acs->loginByPassword( OPENBUS_USERNAME, OPENBUS_PASSWORD, credential, lease ) ;
credentialManager->setValue( credential ) ;
o->getCredentialManager()->setValue( credential ) ;
rgs = acs->getRegistryService() ;
services::PropertyList* propertyList = new services::PropertyList;
services::ServiceOffer* serviceOffer = new services::ServiceOffer;
......
......@@ -37,8 +37,11 @@ namespace openbus {
lua_pushstring(LuaVM, "identifier");
lua_pushstring(LuaVM, credential->identifier);
lua_settable(LuaVM, -3);
lua_pushstring(LuaVM, "entityName");
lua_pushstring(LuaVM, credential->entityName);
lua_pushstring(LuaVM, "owner");
lua_pushstring(LuaVM, credential->owner);
lua_settable(LuaVM, -3);
lua_pushstring(LuaVM, "delegate");
lua_pushstring(LuaVM, credential->delegate);
lua_settable(LuaVM, -3);
/* CredentialType */
lua_pushstring(LuaVM, clientInterceptor->credentialType);
......
......@@ -124,6 +124,10 @@ namespace openbus {
#endif
}
common::CredentialManager* Openbus::getCredentialManager() {
return credentialManager;
}
services::IAccessControlService* Openbus::getACS(String host, unsigned short port) {
stringstream corbaloc;
corbaloc << "corbaloc::" << host << ":" << port << "/ACS";
......
......@@ -57,6 +57,7 @@ namespace openbus {
static Openbus* getInstance();
Lua_State* getLuaVM();
void setClientInterceptor(common::ClientInterceptor* clientInterceptor);
common::CredentialManager* getCredentialManager();
services::IAccessControlService* getACS(String host, unsigned short port);
services::IAccessControlService* connect(String host, unsigned short port, String user, String password, \
services::Credential* aCredential, services::Lease* aLease);
......
......@@ -117,14 +117,14 @@ namespace openbus {
#endif
/* quem faz delete desse cara?? */
Credential* c = new Credential ;
lua_getfield( L, -1, "entityName" ) ;
lua_getfield( L, -1, "owner" ) ;
const char * luastring = lua_tolstring( L, -1, &size ) ;
str = new char[ size + 1 ] ;
memcpy( str, luastring, size ) ;
str[ size ] = '\0' ;
c->entityName = str ;
c->owner = str ;
#if VERBOSE
printf( "\t\t[credential->entityName=%s]\n", c->entityName ) ;
printf( "\t\t[credential->owner=%s]\n", c->owner ) ;
#endif
lua_pop( L, 1 ) ;
lua_getfield( L, -1, "identifier" ) ;
......@@ -135,6 +135,16 @@ namespace openbus {
c->identifier = str ;
#if VERBOSE
printf( "\t\t[credential->identifier=%s]\n", c->identifier ) ;
#endif
lua_pop( L, 1 ) ;
lua_getfield( L, -1, "delegate" ) ;
luastring = lua_tolstring( L, -1, &size ) ;
str = new char[ size + 1 ] ;
memcpy( str, luastring, size ) ;
str[ size ] = '\0' ;
c->delegate = str ;
#if VERBOSE
printf( "\t\t[credential->delegate=%s]\n", c->delegate ) ;
#endif
lua_pop( L, 2 ) ;
co->credentialWasDeleted( c ) ;
......@@ -242,8 +252,11 @@ namespace openbus {
lua_pushstring( LuaVM, "identifier" ) ;
lua_pushstring( LuaVM, aCredential->identifier ) ;
lua_settable( LuaVM, -3 ) ;
lua_pushstring( LuaVM, "entityName" ) ;
lua_pushstring( LuaVM, aCredential->entityName ) ;
lua_pushstring( LuaVM, "owner" ) ;
lua_pushstring( LuaVM, aCredential->owner ) ;
lua_settable( LuaVM, -3 ) ;
lua_pushstring( LuaVM, "delegate" ) ;
lua_pushstring( LuaVM, aCredential->delegate ) ;
lua_settable( LuaVM, -3 ) ;
#if VERBOSE
printf( "\t[parametro aCredential empilhado]\n" ) ;
......@@ -354,8 +367,11 @@ namespace openbus {
lua_getfield( LuaVM, -1, "identifier" ) ;
aCredential->identifier = lua_tostring( LuaVM, -1 ) ;
lua_pop( LuaVM, 1 ) ;
lua_getfield( LuaVM, -1, "entityName" ) ;
aCredential->entityName = lua_tostring( LuaVM, -1 ) ;
lua_getfield( LuaVM, -1, "owner" ) ;
aCredential->owner = lua_tostring( LuaVM, -1 ) ;
lua_pop( LuaVM, 1 ) ;
lua_getfield( LuaVM, -1, "delegate" ) ;
aCredential->delegate = lua_tostring( LuaVM, -1 ) ;
#if VERBOSE
printf( "\t[resultado aCredential retirado]\n" ) ;
printf( "\t[Tamanho da pilha de Lua: %d]\n" , lua_gettop( LuaVM ) ) ;
......@@ -440,8 +456,11 @@ namespace openbus {
lua_getfield( LuaVM, -1, "identifier" ) ;
aCredential->identifier = lua_tostring( LuaVM, -1 ) ;
lua_pop( LuaVM, 1 ) ;
lua_getfield( LuaVM, -1, "entityName" ) ;
aCredential->entityName = lua_tostring( LuaVM, -1 ) ;
lua_getfield( LuaVM, -1, "owner" ) ;
aCredential->owner = lua_tostring( LuaVM, -1 ) ;
lua_pop( LuaVM, 1 ) ;
lua_getfield( LuaVM, -1, "delegate" ) ;
aCredential->delegate = lua_tostring( LuaVM, -1 ) ;
#if VERBOSE
printf( "\t[resultado aCredential retirado]\n" ) ;
printf( "\t[Tamanho da pilha de Lua: %d]\n" , lua_gettop( LuaVM ) ) ;
......@@ -542,12 +561,15 @@ namespace openbus {
lua_pushstring( LuaVM, "identifier" ) ;
lua_pushstring( LuaVM, aCredential->identifier ) ;
lua_settable( LuaVM, -3 ) ;
lua_pushstring( LuaVM, "entityName" ) ;
lua_pushstring( LuaVM, aCredential->entityName ) ;
lua_pushstring( LuaVM, "owner" ) ;
lua_pushstring( LuaVM, aCredential->owner ) ;
lua_settable( LuaVM, -3 ) ;
lua_pushstring( LuaVM, "delegate" ) ;
lua_pushstring( LuaVM, aCredential->delegate ) ;
lua_settable( LuaVM, -3 ) ;
#if VERBOSE
printf( "\t[parametro aCredential empilhado\n\t\tidentifier:%s\n\t\tentityName:%s]\n",
aCredential->identifier, aCredential->entityName ) ;
printf( "\t[parametro aCredential empilhado\n\t\tidentifier:%s\n\t\towner:%s\n\t\tdelegate:%s]\n",
aCredential->identifier, aCredential->owner, aCredential->delegate ) ;
printf( "\t[Tamanho da pilha de Lua: %d]\n" , lua_gettop( LuaVM ) ) ;
#endif
#if VERBOSE
......@@ -613,8 +635,11 @@ namespace openbus {
lua_pushstring( LuaVM, "identifier" ) ;
lua_pushstring( LuaVM, aCredential->identifier ) ;
lua_settable( LuaVM, -3 ) ;
lua_pushstring( LuaVM, "entityName" ) ;
lua_pushstring( LuaVM, aCredential->entityName ) ;
lua_pushstring( LuaVM, "owner" ) ;
lua_pushstring( LuaVM, aCredential->owner ) ;
lua_settable( LuaVM, -3 ) ;
lua_pushstring( LuaVM, "delegate" ) ;
lua_pushstring( LuaVM, aCredential->delegate ) ;
lua_settable( LuaVM, -3 ) ;
lua_setglobal( LuaVM , "aCredential" ) ;
lua_getglobal( LuaVM, "aCredential" ) ;
......
......@@ -17,7 +17,8 @@ namespace openbus {
struct Credential {
String identifier ;
String entityName ;
String owner ;
String delegate ;
} ;
typedef Long Lease ;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment