Skip to main content

Code for Authorization Example

Here is the code for the authentication example. Create the class using your IDE.


Class SecurityTutorial.AuthorizationExample
{
ClassMethod CreateTestData()
{
    Set ^TestData = "MyInitialData"
}

ClassMethod HelloUser()
{
    Write "User ", $Username
}

ClassMethod UpdateTestData()
{
    Set ^TestData = "MyUpdatedData"
}

ClassMethod ReadTestData() As %String
{
    Return ^TestData
}

ClassMethod ProtectedMethod() As %String
{
    If ($System.Security.Check("ProtectedMethod","U"))
    {
        Return $Username
    }
    Else
    {
        Return "Error: Insufficient Privileges"
    }
}

}
FeedbackOpens in a new tab