Skip to content

Commit

Permalink
Sspi (#60)
Browse files Browse the repository at this point in the history
* sspi support

* sspi support

* javaparms
  • Loading branch information
tomweber-sas authored Sep 12, 2017
1 parent 4be0434 commit 2278c4b
Show file tree
Hide file tree
Showing 5 changed files with 107 additions and 59 deletions.
Binary file modified saspy/java/pyiom/saspy2j.class
Binary file not shown.
69 changes: 43 additions & 26 deletions saspy/java/pyiom/saspy2j.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import com.sas.services.connection.ConnectionFactoryInterface;
import com.sas.services.connection.ConnectionFactoryManager;
import com.sas.services.connection.ConnectionInterface;
import com.sas.services.connection.Credential;
import com.sas.services.connection.ManualConnectionFactoryConfiguration;
import com.sas.services.connection.Server;

Expand Down Expand Up @@ -70,11 +71,12 @@ public static void main(String[] args) throws InterruptedException, IOException,
int idx = 0;
boolean fndeol;
boolean zero = false;
boolean spn = false;
boolean failed = false;

String[] iomhosts;
int hosts = 0;

BufferedReader inp;
BufferedWriter outp;
BufferedWriter errp;
Expand Down Expand Up @@ -113,6 +115,8 @@ else if (args[x].equalsIgnoreCase("-appname"))
appName = args[x + 1];
else if (args[x].equalsIgnoreCase("-zero"))
zero = true;
else if (args[x].equalsIgnoreCase("-spn"))
spn = true;
}

try {
Expand Down Expand Up @@ -144,35 +148,48 @@ else if (args[x].equalsIgnoreCase("-zero"))
}

} else {
omrpw = inp.readLine();
if (! spn)
omrpw = inp.readLine();
iomhosts = iomhost.split(";");
hosts = iomhosts.length;
for (int i=0; i < hosts; i++)
{
try {
server = new BridgeServer(Server.CLSID_SAS, iomhosts[i], iomport);
if (appName != "")
server.setServerName(appName.replace("\'", ""));
//server.setOption(SASURI.applicationNameKey, appName);
ConnectionFactoryConfiguration cxfConfig = new ManualConnectionFactoryConfiguration(server);
ConnectionFactoryManager cxfManager = new ConnectionFactoryManager();
ConnectionFactoryInterface cxf = cxfManager.getFactory(cxfConfig);
// ConnectionFactoryAdminInterface admin =
// cxf.getAdminInterface();
if (timeout > 0)
cx = cxf.getConnection(omruser, omrpw, timeout);
else
cx = cxf.getConnection(omruser, omrpw);
break;
} catch (ConnectionFactoryException e) {
String msg = e.getMessage();
System.out.print(msg+"\n");
errp.write(msg+"\n");
errp.flush();
if (i+1 < hosts)
continue;
failed = true;
}
try {
server = new BridgeServer(Server.CLSID_SAS, iomhosts[i], iomport);
if (appName != "")
server.setServerName(appName.replace("\'", ""));
//server.setOption(SASURI.applicationNameKey, appName);
server.setOption(SASURI.applicationNameKey, "SASPy");

if (spn)
{
server.setSecurityPackage(Server.SECURITY_PACKAGE_NEGOTIATE);
//server.setSPN("");
}
ConnectionFactoryConfiguration cxfConfig = new ManualConnectionFactoryConfiguration(server);
ConnectionFactoryManager cxfManager = new ConnectionFactoryManager();
ConnectionFactoryInterface cxf = cxfManager.getFactory(cxfConfig);
// ConnectionFactoryAdminInterface admin =
// cxf.getAdminInterface();
if (spn)
{
Credential cred = SecurityPackageCredential.getInstance();
cx = cxf.getConnection(cred);
}
else if (timeout > 0)
cx = cxf.getConnection(omruser, omrpw, timeout);
else
cx = cxf.getConnection(omruser, omrpw);
break;
} catch (ConnectionFactoryException e) {
String msg = e.getMessage();
System.out.print(msg+"\n");
errp.write(msg+"\n");
errp.flush();
if (i+1 < hosts)
continue;
failed = true;
}
}
}

Expand Down
Binary file modified saspy/java/saspyiom.jar
Binary file not shown.
8 changes: 8 additions & 0 deletions saspy/sascfg.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@
# 'encoding' - This is the python encoding value that matches the SAS session encoding of the IOM server you are connecting to
# 'classpath' - [REQUIRED] classpath to IOM client jars and saspy client jar.
# 'appserver' - name ofphysical workspace server (when more than one app server defined in OMR) i.e.: 'SASApp - Workspace Server'
# 'sspi' - boolean. use IWA instead of user/pw to connect to the IOM workspace server


# build out a local classpath variable to use below for Linux clients
Expand Down Expand Up @@ -172,6 +173,13 @@
'classpath' : cpW
}

winiomIWA = {'java' : 'java',
'iomhost' : 'windows.iom.host',
'iomport' : 8591,
'encoding' : 'windows-1252',
'classpath' : cpW,
'sspi' : True
}

# Future - for the HTTP access method to connect to the Compute Service
# This access method is not available yet.
Expand Down
89 changes: 56 additions & 33 deletions saspy/sasioiom.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ def __init__(self, **kwargs):
self.authkey = cfg.get('authkey', '')
self.timeout = cfg.get('timeout', None)
self.appserver = cfg.get('appserver', '')
self.sspi = cfg.get('sspi', False)
self.javaparms = cfg.get('javaparms', '')

try:
self.outopts = getattr(SAScfg, "SAS_output_options")
Expand Down Expand Up @@ -124,6 +126,13 @@ def __init__(self, **kwargs):
else:
self.omrpw = inomrpw

insspi = kwargs.get('sspi', False)
if insspi:
if lock and self.sspi:
print("Parameter 'sspi' passed to SAS_session was ignored due to configuration restriction.")
else:
self.sspi = insspi

incp = kwargs.get('classpath', '')
if len(incp) > 0:
if lock and len(self.classpath):
Expand Down Expand Up @@ -154,6 +163,13 @@ def __init__(self, **kwargs):
if not self.encoding:
self.encoding = 'utf-8'

injparms = kwargs.get('javaparms', '')
if len(injparms) > 0:
if lock:
print("Parameter 'javaparms' passed to SAS_session was ignored due to configuration restriction.")
else:
self.javaparms = injparms

return

def _prompt(self, prompt, pw=False):
Expand Down Expand Up @@ -251,36 +267,39 @@ def _startsas(self):
Will use HTML5 for this SASsession.""")
self.sascfg.output = 'html5'

user = self.sascfg.omruser
pw = self.sascfg.omrpw
found = False
if self.sascfg.authkey:
if os.name == 'nt':
pwf = os.path.expanduser('~')+os.sep+'_authinfo'
else:
pwf = os.path.expanduser('~')+os.sep+'.authinfo'
try:
fid = open(pwf, mode='r')
for line in fid:
if line.startswith(self.sascfg.authkey):
user = line.partition('user')[2].lstrip().partition(' ')[0].partition('\n')[0]
pw = line.partition('password')[2].lstrip().partition(' ')[0].partition('\n')[0]
found = True
fid.close()
except OSError as e:
print('Error trying to read authinfo file:'+pwf+'\n'+str(e))
pass
except:
pass

if not found:
print('Did not find key '+self.sascfg.authkey+' in authinfo file:'+pwf+'\n')

while len(user) == 0:
user = self.sascfg._prompt("Please enter the IOM user id: ")

if not self.sascfg.sspi:
user = self.sascfg.omruser
pw = self.sascfg.omrpw
found = False
if self.sascfg.authkey:
if os.name == 'nt':
pwf = os.path.expanduser('~')+os.sep+'_authinfo'
else:
pwf = os.path.expanduser('~')+os.sep+'.authinfo'
try:
fid = open(pwf, mode='r')
for line in fid:
if line.startswith(self.sascfg.authkey):
user = line.partition('user')[2].lstrip().partition(' ')[0].partition('\n')[0]
pw = line.partition('password')[2].lstrip().partition(' ')[0].partition('\n')[0]
found = True
fid.close()
except OSError as e:
print('Error trying to read authinfo file:'+pwf+'\n'+str(e))
pass
except:
pass

if not found:
print('Did not find key '+self.sascfg.authkey+' in authinfo file:'+pwf+'\n')

while len(user) == 0:
user = self.sascfg._prompt("Please enter the IOM user id: ")

pgm = self.sascfg.java
parms = [pgm]
if len(self.sascfg.javaparms) > 0:
parms += self.sascfg.javaparms
parms += ["-classpath", self.sascfg.classpath, "pyiom.saspy2j", "-host", "localhost"]
#parms += ["-classpath", self.sascfg.classpath+":/u/sastpw/tkpy2j", "pyiom.saspy2j_sleep", "-host", "tomspc.na.sas.com"]
parms += ["-stdinport", str(self.sockin.getsockname()[1])]
Expand All @@ -292,7 +311,10 @@ def _startsas(self):
parms += ["-appname", "'"+self.sascfg.appserver+"'"]
if not zero:
parms += ["-iomhost", self.sascfg.iomhost, "-iomport", str(self.sascfg.iomport)]
parms += ["-user", user]
if not self.sascfg.sspi:
parms += ["-user", user]
else:
parms += ["-spn"]
else:
parms += ["-zero"]
parms += ['']
Expand Down Expand Up @@ -414,10 +436,11 @@ def _startsas(self):
self.stderr[0].setblocking(False)

if not zero:
while len(pw) == 0:
pw = self.sascfg._prompt("Please enter the password for IOM user "+self.sascfg.omruser+": ", pw=True)
pw += '\n'
self.stdin[0].send(pw.encode())
if not self.sascfg.sspi:
while len(pw) == 0:
pw = self.sascfg._prompt("Please enter the password for IOM user "+self.sascfg.omruser+": ", pw=True)
pw += '\n'
self.stdin[0].send(pw.encode())

ll = self.submit("options svgtitle='svgtitle'; options validvarname=any pagesize=max nosyntaxcheck; ods graphics on;", "text")

Expand Down

0 comments on commit 2278c4b

Please sign in to comment.