Written by

Senior Startups and Community Programs Manager at InterSystems Corporation
Question Evgeny Shvarov · Mar 20, 2020

How to add a role to a web applicaiton programmatically?

Hi developers!

I have an existing CSP app and I want to add a role to it. How can I make it programmatically?

Comments

David Crawford · Mar 22, 2020

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!

0
Lorenzo Scalese · Mar 22, 2020

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
0
sween  May 12, 2021 to Lorenzo Scalese

^^^ Bacon Saver, thank you.

0
Peter Steiwer · Mar 23, 2020

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.

0