コード例 #1
0
//
// 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)
    {
        _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();

    //
    // call enumerateInstancesForClass of the repository
    //
    namedInstances = _repository->enumerateInstancesForClass(
        ref.getNameSpace(), ref.getClassName());

    for(Uint32 i = 0, n = namedInstances.size(); i < n; i++)
    {
        handler.deliver(namedInstances[i]);
    }

    // complete processing the request
    handler.complete();

    PEG_METHOD_EXIT();
    return;
}
コード例 #2
0
//
// 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)
    {
        _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();

    //
    // 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);

    // complete processing the request
    handler.complete();

    PEG_METHOD_EXIT();
}
コード例 #3
0
//
// Deletes the specified instance.
//
void UserAuthProvider::deleteInstance(
    const OperationContext & context,
    const CIMObjectPath& myInstance,
    ResponseHandler & handler)
{
    CIMValue                userName ;
    String                  userNameStr;
    String                  namespaceStr;
    Array<CIMKeyBinding>       kbArray;

    PEG_METHOD_ENTER(TRC_USER_MANAGER,"UserAuthProvider::deleteInstance");

    //
    // 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)
    {
        _verifyAuthorization(user);
    }

    // begin processing the request
    handler.processing();

#ifndef PEGASUS_NO_PASSWORDFILE
    //
    // check if the class name requested is PG_User
    //
    if (myInstance.getClassName().equal (CLASS_NAME_PG_USER))
    {
        //
        // Get the user name from the instance
        //
        kbArray = myInstance.getKeyBindings();
        if (!kbArray.size())
        {
            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);
        }
        if (kbArray[0].getName() == PROPERTY_NAME_USERNAME)
        {
            userNameStr = kbArray[0].getValue();
        }
        else
        {
            MessageLoaderParms parms(
                "ControlProviders.UserAuthProvider.UNEXPECTED_KEY_PROPERTY",
                "Unexpected Key property");
            throw PEGASUS_CIM_EXCEPTION_L(CIM_ERR_INVALID_PARAMETER, parms);
        }

        //
        // Remove the user from User Manager
        //
        _userManager->removeUser(userNameStr);
    }
    //
    // check if the class name requested is PG_Authorization
    //
    else if (myInstance.getClassName().equal (CLASS_NAME_PG_AUTHORIZATION))
#else
    if (myInstance.getClassName().equal (CLASS_NAME_PG_AUTHORIZATION))
#endif
    {
        //
        // Get the user name and namespace from the instance
        //
        kbArray = myInstance.getKeyBindings();
        for (Uint32 i = 0; i < kbArray.size(); i++)
        {
            if ( kbArray[i].getName() == PROPERTY_NAME_USERNAME )
            {
                userNameStr = kbArray[i].getValue();
            }
            else if ( kbArray[i].getName() == PROPERTY_NAME_NAMESPACE )
            {
                namespaceStr = kbArray[i].getValue();
            }
        }

        if ( !userNameStr.size() )
        {
            PEG_METHOD_EXIT();
            MessageLoaderParms parms("ControlProviders.UserAuthProvider."
                                        "USERNAME_PROPERTY_CANNOT_BE_EMPTY",
                                        "Username property can not be empty.");
            throw PEGASUS_CIM_EXCEPTION_L(CIM_ERR_INVALID_PARAMETER,parms);
        }
        else if ( !namespaceStr.size() )
        {
            PEG_METHOD_EXIT();
            MessageLoaderParms parms("ControlProviders.UserAuthProvider."
                                         "NAMESPACE_PROPERTY_CANNOT_BE_EMPTY",
                                     "Namespace property can not be empty.");
            throw PEGASUS_CIM_EXCEPTION_L(CIM_ERR_INVALID_PARAMETER,parms);
        }

        //
        // ATTN: Note that the following is a hack, because
        // deleteInstance() in repository does not like
        // the hostname and namespace included in the CIMObjectPath
        // passed to it as a parameter.
        //
        CIMObjectPath ref("", CIMNamespaceName (),
            myInstance.getClassName(), myInstance.getKeyBindings());

        _repository->deleteInstance(myInstance.getNameSpace(), ref);

        //
        // remove authorization in the UserManager
        //
        _userManager->removeAuthorization(userNameStr, namespaceStr);
    }
    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;
}
コード例 #4
0
//
// Creates a new instance.
//
void UserAuthProvider::createInstance(
    const OperationContext & context,
    const CIMObjectPath & instanceReference,
    const CIMInstance & myInstance,
    ObjectPathResponseHandler & handler)
{
    PEG_METHOD_ENTER(TRC_USER_MANAGER,"UserAuthProvider::createInstance");

    CIMValue    userName;
    CIMValue    password;
    String      userNameStr;
    String      passwordStr;
    String      namespaceStr;
    String      authorizationStr;
    Boolean     authAlreadyExists = false;
    //
    // get userName
    //
    String user;
    try
    {
        const IdentityContainer container =
            context.get(IdentityContainer::NAME);
        user= container.getUserName();
    }
    catch (...)
    {
        user= String::EMPTY;
    }

    //
    // verify user authorizations
    //
    if (user != String::EMPTY)
    {
        _verifyAuthorization(user);
    }

    CIMInstance          modifiedInst = myInstance;

    // begin processing the request
    handler.processing();

#ifndef PEGASUS_NO_PASSWORDFILE
    //
    // check if the class name requested is PG_User
    //
    if (CLASS_NAME_PG_USER.equal(instanceReference.getClassName()))
    {
        //
        // Get the user name from the instance
        //
        Uint32 pos = myInstance.findProperty(PROPERTY_NAME_USERNAME);
        CIMProperty prop = (CIMProperty)modifiedInst.getProperty(pos);
        userName = prop.getValue();
        userName.get(userNameStr);

        //
        // Get the password from the instance
        //
        pos = myInstance.findProperty (PROPERTY_NAME_PASSWORD);
        prop = (CIMProperty) modifiedInst.getProperty(pos);
        password = prop.getValue();
        password.get(passwordStr);

        //
        // Add the user to the User Manager
        //
        _userManager->addUser(userNameStr, passwordStr);
    }
    //
    // check if the class name requested is PG_Authorization
    //
    else if (instanceReference.getClassName().equal
        (CLASS_NAME_PG_AUTHORIZATION))
#else
    if (instanceReference.getClassName().equal (CLASS_NAME_PG_AUTHORIZATION))
#endif
    {
        try
        {
            //
            // Get the user name from the instance
            //
            Uint32 pos = myInstance.findProperty ( PROPERTY_NAME_USERNAME );
            CIMProperty prop = (CIMProperty)modifiedInst.getProperty(pos);
            prop.getValue().get(userNameStr);

            //
            // Get the namespace from the instance
            //
            pos = myInstance.findProperty ( PROPERTY_NAME_NAMESPACE );
            prop = (CIMProperty)modifiedInst.getProperty(pos);
            prop.getValue().get(namespaceStr);

            //
            // Get the authorization from the instance
            //
            pos = myInstance.findProperty ( PROPERTY_NAME_AUTHORIZATION );
            prop = (CIMProperty)modifiedInst.getProperty(pos);
            prop.getValue().get(authorizationStr);

            //
            // Check if the user is a valid system user
            //
            if ( !System::isSystemUser( userNameStr.getCString() ) )
            {
                InvalidSystemUser isu(userNameStr);
                throw isu;
            }

#ifndef PEGASUS_NO_PASSWORDFILE
            //
            // check if the user is a valid CIM user
            //
            if ( !_userManager->verifyCIMUser( userNameStr ) )
            {
                InvalidUser iu(userNameStr);
                throw iu;
            }
#endif

            try
            {
                _userManager->getAuthorization(userNameStr, namespaceStr);
                authAlreadyExists = true;
            }
            catch(...)
            {
                //if authorization does not exist, It will be created 
                //If exist, exception is thrown later
            }
            if (!authAlreadyExists)
            {
            _repository->createInstance(
                instanceReference.getNameSpace(), myInstance);

            //
            // set authorization in the UserManager
            //
            _userManager->setAuthorization(
                userNameStr, namespaceStr, authorizationStr );
        }
        }
        catch ( InvalidUser &iu )
        {
            PEG_METHOD_EXIT();
            throw PEGASUS_CIM_EXCEPTION(
                CIM_ERR_INVALID_PARAMETER, iu.getMessage());
        }
        catch ( InvalidSystemUser &isu )
        {
            PEG_METHOD_EXIT();
            throw PEGASUS_CIM_EXCEPTION(
                CIM_ERR_INVALID_PARAMETER, isu.getMessage());
        }
        catch ( InvalidNamespace &ins )
        {
            PEG_METHOD_EXIT();
            throw PEGASUS_CIM_EXCEPTION(
                CIM_ERR_INVALID_PARAMETER, ins.getMessage());
        }
        catch ( CIMException &e )
        {
            PEG_METHOD_EXIT();
            throw PEGASUS_CIM_EXCEPTION(CIM_ERR_FAILED, e.getMessage());
        }
        catch ( Exception &e )
        {
            PEG_METHOD_EXIT();
            throw PEGASUS_CIM_EXCEPTION(CIM_ERR_FAILED, e.getMessage());
        }
    }
    else
    {
        PEG_METHOD_EXIT();
        throw PEGASUS_CIM_EXCEPTION (CIM_ERR_NOT_SUPPORTED,
                                 instanceReference.getClassName().getString());
    }
    if (authAlreadyExists)
    {
        throw PEGASUS_CIM_EXCEPTION(
            CIM_ERR_ALREADY_EXISTS,
            userNameStr);
    }

    handler.deliver(instanceReference);

    // complete processing the request
    handler.complete();

    PEG_METHOD_EXIT();
    return;
}
コード例 #5
0
//------------------------------------------------------------------------------
// Constructor to set context
//------------------------------------------------------------------------------
NTPProviderSecurity::NTPProviderSecurity(const OperationContext & context)
{
    IdentityContainer container(context.get(IdentityContainer::NAME));
    secUsername.assign(container.getUserName());
}
コード例 #6
0
void EnableIndicationsResponseHandler::deliver(const OperationContext & context, const CIMIndication & cimIndication)
{
    if(cimIndication.isUninitialized())
    {
        MessageLoaderParms message(
            "Common.Exception.UNINITIALIZED_OBJECT_EXCEPTION",
            "The object is not initialized.");

        throw CIMException(CIM_ERR_FAILED, message);
    }

    // ATTN: temporarily convert indication to instance
    CIMInstance cimInstance(cimIndication);

    //  Get list of subscription instance names from context
    Array<CIMObjectPath> subscriptionInstanceNames;

    try
    {
        SubscriptionInstanceNamesContainer container =
            context.get(SubscriptionInstanceNamesContainer::NAME);

        subscriptionInstanceNames = container.getInstanceNames();
    }
    catch(Exception &)
    {
        subscriptionInstanceNames.clear();
    }

    // l10n
    ContentLanguages contentLangs;

    try
    {
        // Get the Content-Language for this indication.  The provider
        // does not have to add specify a language for the indication.
        ContentLanguageListContainer langContainer =
            context.get(ContentLanguageListContainer::NAME);

        contentLangs = langContainer.getLanguages();
    }
    catch(Exception &)
    {
        // The provider did not explicitly set a Content-Language for
        // the indication.  Fall back to the lang set in this object.
        contentLangs = getLanguages();
    }
    // l10n -end

    // create message
    // l10n
    CIMProcessIndicationRequestMessage * request =
        new CIMProcessIndicationRequestMessage(
        XmlWriter::getNextMessageId(),
        cimInstance.getPath().getNameSpace(),
        cimInstance,
        subscriptionInstanceNames,
        _provider,
        QueueIdStack());  // Must be filled in by the callback function

    request->operationContext = context;

    try
    {
        request->operationContext.set(ContentLanguageListContainer(contentLangs));
    }
    catch(Exception &)
    {
        request->operationContext.insert(ContentLanguageListContainer(contentLangs));
    }

    _indicationCallback(request);
}