⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 userauthprovider.cpp

📁 Pegasus is an open-source implementationof the DMTF CIM and WBEM standards. It is designed to be por
💻 CPP
📖 第 1 页 / 共 2 页
字号:
    }    else    {        PEG_METHOD_EXIT();        throw PEGASUS_CIM_EXCEPTION(            CIM_ERR_NOT_FOUND, myInstance.getClassName().getString());    }    // complete processing the request    handler.complete();    PEG_METHOD_EXIT();    return;}//// Modify instance based on modifiedInstance.//void UserAuthProvider::modifyInstance(    const OperationContext & context,    const CIMObjectPath & instanceReference,    const CIMInstance& modifiedIns,    const Boolean includeQualifiers,    const CIMPropertyList & propertyList,    ResponseHandler & handler){    PEG_METHOD_ENTER(TRC_USER_MANAGER,"UserAuthProvider::modifyInstance");    //    // get userName    //    String user;    try    {        IdentityContainer container = context.get(IdentityContainer::NAME);        user= container.getUserName();    }    catch (...)    {        user= String::EMPTY;    }    //    // verify user authorizations    //    if ( user != String::EMPTY || user != "" )    {        _verifyAuthorization(user);    }    //    // check if the class name requested is PG_Authorization    //    if (!instanceReference.getClassName().equal (CLASS_NAME_PG_AUTHORIZATION))    {        PEG_METHOD_EXIT();        throw PEGASUS_CIM_EXCEPTION (            CIM_ERR_NOT_SUPPORTED, instanceReference.getClassName().getString());    }    CIMInstance newInstance = modifiedIns;    // begin processing the request    handler.processing();    try    {        //        // Get the user name from the instance        //        String userNameStr;        String namespaceStr;        String authorizationStr;        Uint32 pos = modifiedIns.findProperty ( PROPERTY_NAME_USERNAME );        CIMProperty prop = (CIMProperty)newInstance.getProperty(pos);        prop.getValue().get(userNameStr);        //        // Get the namespace from the instance        //        pos = modifiedIns.findProperty ( PROPERTY_NAME_NAMESPACE );        prop = (CIMProperty)newInstance.getProperty(pos);        prop.getValue().get(namespaceStr);        //        // Get the authorization from the instance        //        pos = modifiedIns.findProperty ( PROPERTY_NAME_AUTHORIZATION );        prop = (CIMProperty)newInstance.getProperty(pos);        prop.getValue().get(authorizationStr);        //        // ATTN: Note that the following is a hack, because        // modifyInstance() in repository does not like        // the hostname and namespace included in the CIMObjectPath        // passed to it as a parameter.        //        CIMObjectPath ref("", CIMNamespaceName (),            modifiedIns.getClassName(), instanceReference.getKeyBindings());        CIMInstance newModifiedIns = modifiedIns.clone ();        newModifiedIns.setPath (ref);        //        // call modifyInstances of the repository        //        _repository->modifyInstance(            instanceReference.getNameSpace(), newModifiedIns);        //        // set authorization in the UserManager        //        _userManager->setAuthorization(            userNameStr, namespaceStr, authorizationStr );    }    catch(Exception& e)    {        PEG_METHOD_EXIT();        throw PEGASUS_CIM_EXCEPTION(CIM_ERR_FAILED, e.getMessage());    }    // complete processing the request    handler.complete();    PEG_METHOD_EXIT();    return;}//// Enumerates instances.//void UserAuthProvider::enumerateInstances(    const OperationContext & context,    const CIMObjectPath & ref,    const Boolean includeQualifiers,    const Boolean includeClassOrigin,    const CIMPropertyList& propertyList,    InstanceResponseHandler & handler){    PEG_METHOD_ENTER(TRC_USER_MANAGER,"UserAuthProvider::enumerateInstances");    Array<CIMInstance> instanceArray;    Array<CIMInstance> namedInstances;    //    // get userName    //    String user;    try    {        IdentityContainer container = context.get(IdentityContainer::NAME);        user= container.getUserName();    }    catch (...)    {        user= String::EMPTY;    }    //    // verify user authorizations    //    if ( user != String::EMPTY || user != "" )    {        _verifyAuthorization(user);    }    //    // check if the class name requested is PG_Authorization    //    if (!ref.getClassName().equal (CLASS_NAME_PG_AUTHORIZATION))    {        PEG_METHOD_EXIT();        throw PEGASUS_CIM_EXCEPTION (CIM_ERR_NOT_SUPPORTED,            ref.getClassName().getString());    }    // begin processing the request    handler.processing();    try    {        //        // call enumerateInstancesForClass of the repository        //        namedInstances = _repository->enumerateInstancesForClass(            ref.getNameSpace(), ref.getClassName());    }    catch(Exception& e)    {        PEG_METHOD_EXIT();        throw PEGASUS_CIM_EXCEPTION(CIM_ERR_FAILED, e.getMessage());    }    for(Uint32 i = 0, n = namedInstances.size(); i < n; i++)    {        handler.deliver(namedInstances[i]);    }    // complete processing the request    handler.complete();    PEG_METHOD_EXIT();    return;}//// Enumerates all the user names.//void UserAuthProvider::enumerateInstanceNames(    const OperationContext & context,    const CIMObjectPath & classReference,    ObjectPathResponseHandler & handler){    PEG_METHOD_ENTER(TRC_USER_MANAGER,"UserAuthProvider::enumerateInstanceNames");    Array<CIMObjectPath> instanceRefs;    Array<String>       userNames;    Array<CIMKeyBinding>   keyBindings;    CIMKeyBinding          kb;    String            hostName;    //    // get userName    //    String user;    try    {        IdentityContainer container = context.get(IdentityContainer::NAME);        user= container.getUserName();    }    catch (...)    {        user= String::EMPTY;    }    //    // verify user authorizations    //    if ( user != String::EMPTY || user != "" )    {        _verifyAuthorization(user);    }    const CIMName& className = classReference.getClassName();    const CIMNamespaceName& nameSpace = classReference.getNameSpace();    // begin processing the request    handler.processing();#ifndef PEGASUS_NO_PASSWORDFILE    //    // check if the class name requested is PG_User    //    if (className.equal (CLASS_NAME_PG_USER))    {        try        {            hostName.assign(System::getHostName());            _userManager->getAllUserNames(userNames);            Uint32 size = userNames.size();            for (Uint32 i = 0; i < size; i++)            {                keyBindings.append(CIMKeyBinding(PROPERTY_NAME_USERNAME, userNames[i],                   CIMKeyBinding::STRING));                //                // Convert instance names to References                //                CIMObjectPath ref(hostName, nameSpace, className, keyBindings);                handler.deliver(ref);                keyBindings.clear();            }        }        catch( const CIMException& )        {            handler.complete();            PEG_METHOD_EXIT();            throw;        }        catch(const Exception& e)        {            PEG_METHOD_EXIT();            throw PEGASUS_CIM_EXCEPTION(CIM_ERR_FAILED, e.getMessage());        }    }    //    // check if the class name requested is PG_Authorization    //    else if (className.equal (CLASS_NAME_PG_AUTHORIZATION))#else    if (className.equal (CLASS_NAME_PG_AUTHORIZATION))#endif    {        try        {            //            // call enumerateInstanceNamesForClass of the repository            //            instanceRefs = _repository->enumerateInstanceNamesForClass(                nameSpace, className);            handler.deliver(instanceRefs);        }        catch ( CIMException &e )        {            PEG_METHOD_EXIT();            throw PEGASUS_CIM_EXCEPTION(CIM_ERR_FAILED, e.getMessage());        }    }    else    {        handler.complete();        PEG_METHOD_EXIT();        throw PEGASUS_CIM_EXCEPTION (CIM_ERR_NOT_SUPPORTED,            className.getString());    }    // complete processing the request    handler.complete();    PEG_METHOD_EXIT();    return;}//// Invoke Method, used to modify user's password//void UserAuthProvider::invokeMethod(    const OperationContext & context,    const CIMObjectPath & ref,    const CIMName & methodName,    const Array<CIMParamValue> & inParams,    MethodResultResponseHandler & handler){    PEG_METHOD_ENTER(TRC_USER_MANAGER,"UserAuthProvider::invokeMethod");    //    // get userName    //    String user;    try    {        IdentityContainer container = context.get(IdentityContainer::NAME);        user= container.getUserName();    }    catch (...)    {        user= String::EMPTY;    }    //    // verify user authorizations    //    if ( user != String::EMPTY || user != "" )    {        _verifyAuthorization(user);    }#ifndef PEGASUS_NO_PASSWORDFILE    String            userName;    String            password;    String            newPassword;    Array<CIMKeyBinding>     kbArray;    // Begin processing the request    handler.processing();    // Check if the class name is PG_USER    if (!ref.getClassName().equal (CLASS_NAME_PG_USER))    {        handler.complete();            throw PEGASUS_CIM_EXCEPTION (CIM_ERR_NOT_SUPPORTED,                ref.getClassName().getString());    }    // Check if the method name is correct    if (!methodName.equal (METHOD_NAME_MODIFY_PASSWORD))    {        handler.complete();        PEG_METHOD_EXIT();	//l10n        //throw PEGASUS_CIM_EXCEPTION (            //CIM_ERR_FAILED,           //"Unsupported method name, " + methodName.getString());	MessageLoaderParms parms("ControlProviders.UserAuthProvider.UNSUPPORTED_METHOD_NAME",						 "Unsupported method name, $0",						 methodName.getString());	throw PEGASUS_CIM_EXCEPTION_L(CIM_ERR_FAILED,parms);    }    // Check if all the input parameters are passed.    if ( inParams.size() < 2 )    {        handler.complete();        PEG_METHOD_EXIT();	//l10n       //     throw PEGASUS_CIM_EXCEPTION( CIM_ERR_INVALID_PARAMETER,         //                           "Input parameters are not valid.");	MessageLoaderParms parms("ControlProviders.UserAuthProvider.INPUT_PARAMETERS_NOT_VALID",						 "Input parameters are not valid.");	throw PEGASUS_CIM_EXCEPTION_L( CIM_ERR_INVALID_PARAMETER, parms);    }    try    {        kbArray = ref.getKeyBindings();        if ( !kbArray.size() )        {            PEG_METHOD_EXIT();	    //l10n            //throw PEGASUS_CIM_EXCEPTION( CIM_ERR_INVALID_PARAMETER,              //       "Unable to find Key Property Username");	    MessageLoaderParms parms("ControlProviders.UserAuthProvider.UNABLE_TO_FIND_KEY_PROPERTY_USERNAME",	    						 "Unable to find Key Property Username");	    throw PEGASUS_CIM_EXCEPTION_L( CIM_ERR_INVALID_PARAMETER,parms);        }        //        // Get the user name        //        if ( kbArray[0].getName() == PROPERTY_NAME_USERNAME )        {            userName = kbArray[0].getValue();        }        else        {            PEG_METHOD_EXIT();            MessageLoaderParms parms(                "ControlProviders.UserAuthProvider.UNEXPECTED_KEY_PROPERTY",                "Unexpected key property");            throw PEGASUS_CIM_EXCEPTION_L(CIM_ERR_INVALID_PARAMETER, parms);        }        //        // Get the old and the new password params        //        for ( Uint32 i=0; i < 2; i++)        {            //            // check the param name            //            if ( inParams[i].getParameterName() == OLD_PASSWORD )            {                inParams[i].getValue().get(password);            }            if ( inParams[i].getParameterName() == NEW_PASSWORD )            {                inParams[i].getValue().get(newPassword);            }        }        // Modify the user's password in User Manager        _userManager->modifyUser(            userName,            password,            newPassword);    }    catch ( const CIMException& )    {        handler.complete();        PEG_METHOD_EXIT();        throw;    }    catch (const Exception& e)    {        handler.complete();        PEG_METHOD_EXIT();        throw PEGASUS_CIM_EXCEPTION(CIM_ERR_FAILED, e.getMessage());    }    // Return zero as there is no error    Uint32 retCode = 0;    handler.deliver(CIMValue(retCode));    // complete processing the request    handler.complete();    PEG_METHOD_EXIT();    return;#else    PEG_METHOD_EXIT();    throw PEGASUS_CIM_EXCEPTION (CIM_ERR_NOT_SUPPORTED,        ref.getClassName().getString());#endif}PEGASUS_NAMESPACE_END

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -