diff --git a/applications/osgviewer/osgviewer.cpp b/applications/osgviewer/osgviewer.cpp index d790d3873..0d7919687 100644 --- a/applications/osgviewer/osgviewer.cpp +++ b/applications/osgviewer/osgviewer.cpp @@ -74,14 +74,10 @@ int main(int argc, char** argv) std::string url, username, password; while(arguments.read("--login",url, username, password)) { - if (!osgDB::Registry::instance()->getAuthenticationMap()) - { - osgDB::Registry::instance()->setAuthenticationMap(new osgDB::AuthenticationMap); - osgDB::Registry::instance()->getAuthenticationMap()->addAuthenticationDetails( - url, - new osgDB::AuthenticationDetails(username, password) - ); - } + osgDB::Registry::instance()->getOrCreateAuthenticationMap()->addAuthenticationDetails( + url, + new osgDB::AuthenticationDetails(username, password) + ); } std::string device; diff --git a/include/osgDB/Registry b/include/osgDB/Registry index 62d4ac884..87076dc81 100644 --- a/include/osgDB/Registry +++ b/include/osgDB/Registry @@ -366,6 +366,13 @@ class OSGDB_EXPORT Registry : public osg::Referenced /** Set the password map to be used by plugins when access files from secure locations.*/ void setAuthenticationMap(AuthenticationMap* authenticationMap) { _authenticationMap = authenticationMap; } + /** Get the password map to be used by plugins when access files from secure locations. Create a AuthenticationMap if one isn't already assigned.*/ + AuthenticationMap* getOrCreateAuthenticationMap() + { + if (!_authenticationMap) _authenticationMap = new AuthenticationMap; + return _authenticationMap.get(); + } + /** Get the password map to be used by plugins when access files from secure locations.*/ AuthenticationMap* getAuthenticationMap() { return _authenticationMap.get(); }