Skip to content

Commit d8979cd

Browse files
committed
Add role to socket web application to access current database
1 parent c84c136 commit d8979cd

1 file changed

Lines changed: 27 additions & 5 deletions

File tree

export/WebTerminal/Installer.xml

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<Export generator="Cache" version="25" zv="Cache for Windows (x86-64) 2015.1.1 (Build 505U)" ts="2016-02-13 14:41:00">
2+
<Export generator="Cache" version="25" zv="Cache for Windows (x86-64) 2015.1.1 (Build 505U)" ts="2016-02-15 12:28:08">
33
<Class name="WebTerminal.Installer">
44
<Description>
55
Importing this class will install Cache WEB Terminal properly.</Description>
66
<Super>%Projection.AbstractProjection</Super>
7-
<TimeChanged>63961,52835.903719</TimeChanged>
7+
<TimeChanged>63963,44872.55628</TimeChanged>
88
<TimeCreated>63890,71053.144208</TimeCreated>
99
<DependsOn>Common,Engine,Router,StaticContent,Autocomplete,Trace</DependsOn>
1010

@@ -72,6 +72,7 @@ This method is invoked when a class is compiled.</Description>
7272
write !, "Installing WebTerminal application to " _ $NAMESPACE
7373
set ns = $NAMESPACE // ought to be package home namespace!
7474
set ^WebTerminal("HomeNamespace") = ns
75+
set dbdir = $$$defdir
7576
zn:ns'="%SYS" "%SYS"
7677
do ##class(Security.System).GetInstallationSecuritySetting(.security)
7778
set cspProperties("AutheEnabled") = 32 // password by default, 64 for no password
@@ -83,7 +84,7 @@ This method is invoked when a class is compiled.</Description>
8384
set cspProperties("AutheEnabled") = 64
8485
set cspProperties("Description") = "An application representing the open socket for /terminal application. Required since 2016.* Cache versions changed WebSocket behavior. PLEASE LEAVE THIS APPLICATION UNAUTHENTICATED, but do not worry: the socket won't accept anyone without the key."
8586
set cspProperties("DispatchClass") = ""
86-
set cspProperties("MatchRoles")=":%DB_CACHESYS" //:%DB_USER"
87+
set cspProperties("MatchRoles")=":%DB_CACHESYS:" _ ..GetDBRole(dbdir)
8788
do ..RegisterWebApplication("/terminalsocket", .cspProperties)
8889
set status = ##Class(Config.Namespaces).Get("%All")
8990
if ($$$ISERR(status)) { // no namespace %All
@@ -132,8 +133,9 @@ This method is invoked when a class is 'uncompiled'.</Description>
132133
write !, "Uninstalling WebTerminal application from " _ $NAMESPACE
133134
set ns = $NAMESPACE // has to be package home namespace!
134135
if ($get(^WebTerminal("HomeNamespace")) = "") {
135-
write "Terminal home namespace is not defined! Uninstalling will be skipped."
136-
quit '$$$OK
136+
set msg = "Terminal home namespace is not defined! Uninstalling will be skipped."
137+
set msg = msg _ $C(10,12) _ "Set ^WebTerminal(""HomeNamespace"") global equal to home namespace"
138+
quit $$$ERROR($$$GeneralError, msg)
137139
} else {
138140
set ns = ^WebTerminal("HomeNamespace")
139141
}
@@ -158,5 +160,25 @@ This method is invoked when a class is 'uncompiled'.</Description>
158160
QUIT $$$OK
159161
]]></Implementation>
160162
</Method>
163+
164+
<Method name="GetDBRole">
165+
<ClassMethod>1</ClassMethod>
166+
<FormalSpec>directory:%String</FormalSpec>
167+
<ReturnType>%String</ReturnType>
168+
<Implementation><![CDATA[
169+
quit:'$d(directory) ""
170+
new $NAMESPACE
171+
set $Namespace = "%SYS"
172+
#dim db As SYS.Database
173+
set db=##class(SYS.Database).%OpenId(directory)
174+
if $Isobject(db) {
175+
set resource = db.ResourceName
176+
set role = resource // I'm assuming that default role exists
177+
} else {
178+
set role = ""
179+
}
180+
quit role
181+
]]></Implementation>
182+
</Method>
161183
</Class>
162184
</Export>

0 commit comments

Comments
 (0)