How to add a role to a web applicaiton programmatically?

Primary tabs

Replies

I was very interested in this question! Looking at this really great post here, there was some documentation I wanted to look at but it's giving me access errors :( hoping to read up on the security package documentation soon!

Hello @Evgeny Shvarov ,

I tested the following code in an Iris terminal to add %DB_%DEFAULT role, It seems to work :

Write !,"Current user roles : ",$Roles
Zn "%SYS"
Set tSc = ##class(Security.Applications).Get("/csp/user",.p)
Write !,"Get application : ",$SYSTEM.Status.GetOneErrorText(tSc)
Set p("MatchRoles")=p("MatchRoles")_":%DB_%DEFAULT"
Set tSc = ##class(Security.Applications).Modify("/csp/user",.p)
Write !,"Modify application : ",$SYSTEM.Status.GetOneErrorText(tSc)
Kill p


 

If you are using %INSTALLER, you can use GRANT to assign a role:

<CSPApplication
   Url="/api/pivotsubscriptionsunsubscribe"
   Directory="${CSPDIR}"
   DispatchClass="PivotSubscriptions.UI.Unsubscribe"
   Grant="PivotSubscriptionsUnsubscribe"
   AuthenticationMethods="64"
/>

I have tested and confirmed that this does add the Application Role.