In the last article we saw how to create the questions that would hold our login info and the script to handle the actual logon process. In this article we will explore using the DPM object to authenticate our users to decide if they can login or not and take a look at the IsInRole feature.
So , in our MDD in the routing section we have our function called “CheckLogin” and it looks something like this,
Function CheckLogin (sLogin,sPassword,sServer) CheckLogin = true End Function
what we need to do is to change it to look like this,
Function CheckLogin (sLogin,sPassword) Dim oDPMAgent,bAnswer Set oDPMAgent = CreateObject("SPSSMR.DPM.Security.Login.Agent2") oDPMAgent.ConnectToDPMServer("localhost") bAnswer = oDPMAgent.Login(sLogin,sPassword,Null) oDPMAgent.Logout() Set oDPMAgent = null CheckLogin = bAnswer End Function
and to be honest that’s it. If the credentials that you enter allow you to login to server administration then bAnswer will hold a true value. If not it will hold a false value. So is this a good method to use to authenticate , well yes if you want short code and nothing fancy. The other method that we will explore in the next article will perhaps show us something that is more feature rich , anyway , let’s explore the “IsInRole” feature. Add a new routing to your existing MDD file , call it “DPMLogin” then copy and paste this code into it.
Dim oDPMAgent,bIsLoggedIn Set oDPMAgent = CreateObject("SPSSMR.DPM.Security.Login.Agent2") oDPMAgent.ConnectToDPMServer("localhost") bIsLoggedIn = oDPMAgent.Login("[USERNAME HERE]","[PASSWORD HERE]",Null) If bIsLoggedIn = False Then debug.MsgBox("NOT LOGGED IN") Goto EndOfSurvey End If If oDPMAgent.IsInRole("[ROLE NAME HERE]") Then debug.MsgBox("I AM IN THIS ROLE") Else debug.MsgBox("I AM NOT IN THIS ROLE") End If EndOfSurvey:
You should notice that once you are logged in you will get one of two messages pop up , if the group exists in Server Administrator and you are part of it , you will get the message “I AM IN THIS ROLE”, anything else will result in the message “I AM NOT IN THIS ROLE”. With this code in mind now , our menu system can become driven from within Administrator and by that I mean , would could add or take away users from specific roles and this would have an automatic effect in what they were able to do inside of our menu system. We will explore this further in future posts.