Changeset 3918 for TI12-security/trunk
- Timestamp:
- 22/05/08 15:07:02 (12 years ago)
- Location:
- TI12-security/trunk/python
- Files:
-
- 20 edited
Legend:
- Unmodified
- Added
- Removed
-
TI12-security/trunk/python/ndg.security.client/ndg/security/client/ssoclient/ssoclient/config/ssoClientMiddleware.py
r3892 r3918 12 12 ''' 13 13 class security: 14 class c lient:15 class sso client:14 class common: 15 class sso: 16 16 cfg = None 17 17 -
TI12-security/trunk/python/ndg.security.client/ndg/security/client/ssoclient/ssoclient/controllers/logout.py
r3892 r3918 9 9 import sys # include in case tracefile is set to sys.stderr 10 10 import base64 # decode the return to address 11 from urlparse import urlsplit, urlunsplit12 11 13 12 from ndg.security.common.SessionMgr import SessionMgrClient … … 32 31 try: 33 32 smClnt = SessionMgrClient(uri=session['ndgSec']['h'], 34 tracefile=g.ndg.security.c lient.ssoclient.cfg.tracefile,35 **g.ndg.security.c lient.ssoclient.cfg.wss)33 tracefile=g.ndg.security.common.sso.cfg.tracefile, 34 **g.ndg.security.common.sso.cfg.wss) 36 35 except Exception, e: 37 36 log.error("logout - creating Session Manager client: %s" % e) -
TI12-security/trunk/python/ndg.security.client/ndg/security/client/ssoclient/ssoclient/lib/base.py
r3892 r3918 51 51 52 52 log.debug('Switching from https to http...') 53 returnToURL = g.ndg.security.c lient.ssoclient.cfg.server + \53 returnToURL = g.ndg.security.common.sso.cfg.server + \ 54 54 self.pathInfo 55 55 … … 67 67 log.debug("Removing security details following logout ...") 68 68 69 returnToURL = g.ndg.security.c lient.ssoclient.cfg.server + \69 returnToURL = g.ndg.security.common.sso.cfg.server + \ 70 70 self.pathInfo 71 71 … … 80 80 # Redirect to cleaned up URL 81 81 h.redirect_to(returnToURL) 82 83 self._OpenIDHandler() 82 84 83 85 … … 97 99 # construct URL picking up setting of server name from config to 98 100 # avoid exposing absolute URL hidden behind mod_proxy see #857 99 c.requestURL = g.ndg.security.c lient.ssoclient.cfg.server + \101 c.requestURL = g.ndg.security.common.sso.cfg.server + \ 100 102 self.pathInfo 101 103 qs = '&'.join(["%s=%s" % item for item in request.params.items()]) … … 106 108 107 109 return WSGIController.__call__(self, environ, start_response) 108 110 111 112 def _OpenIDHandler(self): 113 '''OpenID handling - check for user set and if so that an existing 114 session doesn't already exist''' 115 116 if 'REMOTE_USER' in request.environ and \ 117 SecuritySession()['u'] != request.environ['REMOTE_USER']: 118 119 username = request.environ['REMOTE_USER'] 120 121 # No session exists - set one. 122 # TODO: OpenID integration with Session Manager WS? 123 # TODO: OpenID user attribute allocation 124 setSecuritySession(h=None, 125 u=username, 126 org=username, 127 roles=['OpenIDUser'], 128 sid=None) 129 SecuritySession.save() 130 109 131 # Include the '_' function in the public names 110 132 __all__ = [__name for __name in locals().keys() if not __name.startswith('_') \ -
TI12-security/trunk/python/ndg.security.client/ndg/security/client/ssoclient/ssoclient/templates/ndg/security/ndgPage.kid
r3892 r3918 9 9 function is needed to avoid escaping the < character --> 10 10 ${XML(h.javascript_include_tag(builtins=True))} 11 <script type="text/javascript" src="$g.ndg.security.c lient.ssoclient.cfg.server/js/toggleDiv.js"/>11 <script type="text/javascript" src="$g.ndg.security.common.sso.cfg.server/js/toggleDiv.js"/> 12 12 13 <link media="all, screen" href="$g.ndg.security.c lient.ssoclient.cfg.server/layout/ndg2.css" type="text/css" rel="stylesheet"/>14 <link rel="icon" type="image/ico" href="$g.ndg.security.c lient.ssoclient.cfg.server/layout/favicon.jpg" />13 <link media="all, screen" href="$g.ndg.security.common.sso.cfg.server/layout/ndg2.css" type="text/css" rel="stylesheet"/> 14 <link rel="icon" type="image/ico" href="$g.ndg.security.common.sso.cfg.server/layout/favicon.jpg" /> 15 15 16 16 </head> … … 18 18 <div py:def="header()"> 19 19 <div id="header"/> 20 <div id="logo"><img src="$g.ndg.security.c lient.ssoclient.cfg.LeftLogo" alt="$g.ndg.security.client.ssoclient.cfg.LeftAlt" /></div>20 <div id="logo"><img src="$g.ndg.security.common.sso.cfg.LeftLogo" alt="$g.ndg.security.common.sso.cfg.LeftAlt" /></div> 21 21 </div> 22 22 … … 49 49 <td align="left" width="60%"> 50 50 <table><tbody> 51 <tr><td><span py:replace="linkimage(g.ndg.security.c lient.ssoclient.cfg.ndgLink,g.ndg.security.client.ssoclient.cfg.ndgImage,'NDG')"/></td>51 <tr><td><span py:replace="linkimage(g.ndg.security.common.sso.cfg.ndgLink,g.ndg.security.common.sso.cfg.ndgImage,'NDG')"/></td> 52 52 <td> This portal is a product of the <a href="http://ndg.nerc.ac.uk"> NERC DataGrid</a> 53 ${g.ndg.security.c lient.ssoclient.cfg.disclaimer} </td>53 ${g.ndg.security.common.sso.cfg.disclaimer} </td> 54 54 </tr> 55 55 </tbody></table> … … 67 67 </div> 68 68 </td> 69 <td align="right"><span py:replace="linkimage(g.ndg.security.c lient.ssoclient.cfg.stfcLink,g.ndg.security.client.ssoclient.cfg.stfcImage,'Hosted by the STFC CEDA')"/></td>69 <td align="right"><span py:replace="linkimage(g.ndg.security.common.sso.cfg.stfcLink,g.ndg.security.common.sso.cfg.stfcImage,'Hosted by the STFC CEDA')"/></td> 70 70 </tr> 71 71 </tbody></table></center> … … 83 83 <span> 84 84 <a href="javascript:;" title="Toggle help" onclick="toggleDiv(1,'$value','shown','hidden','div'); return false;"> 85 <img src="$g.ndg.security.c lient.ssoclient.cfg.helpIcon" alt="Toggle help" class="helpicon"/></a>85 <img src="$g.ndg.security.common.sso.cfg.helpIcon" alt="Toggle help" class="helpicon"/></a> 86 86 </span> 87 87 </span> … … 94 94 # Base 64 encode to enable passing around in 'r' argument of query 95 95 # string for use with login/logout 96 c.returnTo= c.requestURL97 c.b64encReturnTo= urlsafe_b64encode(c.requestURL)96 g.ndg.security.common.sso.returnToURL = c.requestURL 97 g.ndg.security.common.sso.b64encReturnToURL = urlsafe_b64encode(c.requestURL) 98 98 ?> 99 <form action="$g.ndg.security.c lient.ssoclient.cfg.logoutURI">100 <input type="hidden" name="r" value="${ c.b64encReturnTo}"/>99 <form action="$g.ndg.security.common.sso.cfg.logoutURI"> 100 <input type="hidden" name="r" value="${g.ndg.security.common.sso.b64encReturnToURL}"/> 101 101 <input type="submit" value="Logout"/> 102 102 </form> … … 109 109 # Base 64 encode to enable passing around in 'r' argument of query 110 110 # string for use with login/logout 111 c.returnTo= c.requestURL112 c.b64encReturnTo= urlsafe_b64encode(c.requestURL)111 g.ndg.security.common.sso.returnToURL = c.requestURL 112 g.ndg.security.common.sso.b64encReturnToURL = urlsafe_b64encode(c.requestURL) 113 113 ?> 114 <form action="$g.ndg.security.c lient.ssoclient.cfg.wayfuri">115 <input type="hidden" name="r" value="${ c.b64encReturnTo}"/>114 <form action="$g.ndg.security.common.sso.cfg.wayfuri"> 115 <input type="hidden" name="r" value="${g.ndg.security.common.sso.b64encReturnToURL}"/> 116 116 <input type="submit" value="Login"/> 117 117 </form> -
TI12-security/trunk/python/ndg.security.common/ndg/security/common/AttAuthority/__init__.py
r3914 r3918 115 115 self.__uri = None 116 116 self._transdict = {} 117 self._transport = HTTPProxyConnection117 self._transport = ProxyHTTPConnection 118 118 119 119 if uri: … … 152 152 @param uri: URI for service to connect to""" 153 153 if not isinstance(uri, basestring): 154 raise AttAuthorityClientError , \155 "Attribute Authority WSDL URI must be a valid string"154 raise AttAuthorityClientError( 155 "Attribute Authority URI must be a valid string") 156 156 157 157 self.__uri = uri … … 159 159 scheme = urlparse.urlparse(self.__uri)[0] 160 160 except TypeError: 161 raise AttributeAuthorityClientError , \162 "Error parsing transport type from URI "161 raise AttributeAuthorityClientError( 162 "Error parsing transport type from URI: %s" % self.__uri) 163 163 164 164 if scheme == "https": … … 183 183 setting""" 184 184 if self._transport != ProxyHTTPConnection: 185 raise AttAuthorityClientError(\186 "Setting HTTP Proxy Host but transport class is not " + \187 "ProxyHTTPConnection type")185 log.info("Ignoring httpProxyHost setting: transport class is " +\ 186 " not ProxyHTTPConnection type") 187 return 188 188 189 189 self._transdict['httpProxyHost'] = val … … 197 197 """Set to True to ignore any http_proxy environment variable setting""" 198 198 if self._transport != ProxyHTTPConnection: 199 raise AttAuthorityClientError(\200 "Setting ignore HTTP Proxy Host flag but transport class " + \201 "is not ProxyHTTPConnection type")199 log.info("Ignore ignoreHttpProxyEnv setting: transport " + \ 200 "class is not ProxyHTTPConnection type") 201 return 202 202 203 203 self._transdict['ignoreHttpProxyEnv'] = val -
TI12-security/trunk/python/ndg.security.common/ndg/security/common/SessionMgr/__init__.py
r3914 r3918 202 202 if not isinstance(uri, basestring): 203 203 raise SessionMgrClientError( 204 "Session Manager WSDLURI must be a valid string")204 "Session Manager URI must be a valid string") 205 205 206 206 self.__uri = uri … … 209 209 except TypeError: 210 210 raise AttributeAuthorityClientError( 211 "Error parsing transport type from URI")211 "Error parsing transport type from URI: %s" % self.__uri) 212 212 213 213 if scheme == "https": … … 234 234 setting""" 235 235 if self._transport != ProxyHTTPConnection: 236 raise SessionMgrClientError(\ 237 "Setting HTTP Proxy Host - transport class is %s type, " % \ 238 self._transport + \ 239 "expecting ProxyHTTPConnection type") 240 241 self._transdict['httpProxyHost']= val 236 log.info("Ignoring httpProxyHost setting: transport class is " +\ 237 " not ProxyHTTPConnection type") 238 return 239 240 self._transdict['httpProxyHost'] = val 242 241 243 242 httpProxyHost = property(fset=__setHTTPProxyHost, … … 249 248 """Set to True to ignore any http_proxy environment variable setting""" 250 249 if self._transport != ProxyHTTPConnection: 251 raise SessionMgrClientError(\252 "Setting ignore HTTP Proxy Host flag but transport class " + \253 "is not ProxyHTTPConnection type")250 log.info("Ignore ignoreHttpProxyEnv setting: transport " + \ 251 "class is not ProxyHTTPConnection type") 252 return 254 253 255 254 self._transdict['ignoreHttpProxyEnv']= val … … 438 437 439 438 if sessID and userDN: 440 raise SessionMgrClientError, \ 441 'Only "SessID" or "userDN" keywords may be set' 442 439 raise SessionMgrClientError( 440 'Only "SessID" or "userDN" keywords may be set') 441 442 if not sessID and not userDN: 443 raise SessionMgrClientError( 444 'A "SessID" or "userDN" keyword must be set') 445 443 446 # Make connection 444 447 return self.__srv.getSessionStatus(userDN, sessID) -
TI12-security/trunk/python/ndg.security.common/ndg/security/common/pylons/security_util.py
r3892 r3918 17 17 18 18 19 class SecuritySession( object):19 class SecuritySession(dict): 20 20 """Utility for Pylons security session keys enables correct 21 21 keys to be set … … 32 32 subKeys = ('h', 'sid', 'u', 'org', 'roles') 33 33 34 def __init__(self, **subKeys): 34 def __init__(self): 35 '''Initialize security dict key in session object''' 36 if SecuritySession.key not in session: 37 session[SecuritySession.key] = {}.fromkeys(SecuritySession.subKeys) 38 39 session[SecuritySession.key]['roles'] = [] 40 41 def set(self, **subKeys): 35 42 """Update the security key of session object with the 36 43 input sub keys … … 43 50 # were input 44 51 if subKeys == {}: 45 subKeys = LoginServiceQuery.decodeRequestParams()52 subKeys = SSOServiceQuery.decodeRequestParams() 46 53 47 54 # Ensure security key is present … … 52 59 for k in subKeys: 53 60 if k not in SecuritySession.subKeys: 54 raise KeyError , 'Invalid key Security session dict: "%s"' % k61 raise KeyError('Invalid key Security session dict: "%s"' % k) 55 62 56 63 # Update security values … … 59 66 log.debug("Set security session: %s" % session[SecuritySession.key]) 60 67 68 def __delitem__(self, key): 69 "Keys cannot be removed" 70 raise KeyError('Keys cannot be deleted from security session') 71 72 def __getitem__(self, key): 73 '''data dictionary overload''' 74 if key not in session[SecuritySession.key]: 75 raise KeyError("Invalid key '%s'" % key) 76 77 return session[SecuritySession.key][key] 78 79 def __setitem__(self, key, item): 80 '''data dictionary overload''' 81 if key not in SecuritySession.subKeys: 82 raise KeyError("Invalid security key %s" % key) 83 84 session[SecuritySession.key][key] = item 85 86 def get(self, kw): 87 '''data dictionary overload''' 88 return session[SecuritySession.key][kw] 89 90 def clear(self): 91 '''data dictionary overload''' 92 raise KeyError("Data cannot be cleared from security session") 93 94 def keys(self): 95 '''data dictionary overload''' 96 return session[SecuritySession.key].keys() 97 98 def items(self): 99 '''data dictionary overload''' 100 return session[SecuritySession.key].items() 101 102 def values(self): 103 return session[SecuritySession.key].values() 104 105 def has_key(self, key): 106 return session[SecuritySession.key].has_key(key) 107 108 # 'in' operator 109 def __contains__(self, key): 110 return key in session[SecuritySession.key] 111 112 113 @classmethod 114 def save(self): 115 session.save() 116 61 117 @classmethod 62 118 def delete(self): … … 66 122 session.save() 67 123 log.debug("Deleted security key to session object: %s" % session) 68 69 setSecuritySession = SecuritySession 70 124 125 126 def setSecuritySession(**kw): 127 '''Convenience wrapper to SecuritySession and it's set method''' 128 SecuritySession().set(**kw) 129 71 130 72 131 class LoginServiceQueryError(Exception): -
TI12-security/trunk/python/ndg.security.server/ndg/security/server/sso/development.ini
r3914 r3918 32 32 authkit.cookie.secret=secret encryption string 33 33 authkit.cookie.signoutpath = /openidsignout 34 authkit.openid.path.signedin=/ login34 authkit.openid.path.signedin=/ 35 35 authkit.openid.store.type=file 36 36 authkit.openid.store.config=%(here)s/data/openid … … 62 62 # Logging configuration 63 63 [loggers] 64 keys = root, sso, ndg 64 keys = root, sso, ndg, authkit 65 65 66 66 [handlers] -
TI12-security/trunk/python/ndg.security.server/ndg/security/server/sso/sso/config/middleware.py
r3914 r3918 41 41 42 42 # CUSTOM MIDDLEWARE HERE (filtered by error handling middlewares) 43 app = SSOMiddleware(app, app_conf['configfile'], app.globals) 44 45 # OpenID Middleware 46 if app.globals.ndg.security.server.ssoservice.cfg.enableOpenID: 47 import authkit.authenticate 48 from beaker.middleware import SessionMiddleware 49 50 app = authkit.authenticate.middleware(app, app_conf) 51 app = SessionMiddleware(app)#,key='authkit.open_id',secret='some secret') 52 log.info('OpenID is enabled') 43 app = SSOMiddleware(app, app.globals, app_conf) 53 44 54 45 if asbool(full_stack): -
TI12-security/trunk/python/ndg.security.server/ndg/security/server/sso/sso/config/ssoServiceMiddleware.py
r3914 r3918 4 4 P J Kershaw 18/03/08 5 5 ''' 6 import authkit.authenticate 7 from beaker.middleware import SessionMiddleware 8 6 9 from os.path import expandvars as xpdvars 7 10 import logging … … 14 17 class security: 15 18 class server: 16 class sso service:19 class sso: 17 20 cfg = None 18 class client: 21 class state: 22 '''State information specific to server side''' 23 trustedIdPs = {} 24 25 class common: 19 26 '''Client class is also needed for BaseController handler to handle 20 27 responses from Single Sign On IdP''' 21 class sso client:28 class sso: 22 29 class cfg: 23 30 '''Placeholder for server and sslServer attributes''' 24 25 class SSOMiddleware: 26 27 def __init__(self, app, cfg, appGlobals, **kw): 31 class state: 32 '''State information - return to URL should be set each 33 time a new page is loaded. In ows_server this is handled 34 by setting it in ndgPage.kid a template that is extended by 35 all Browse pages.''' 36 returnToURL = None 37 b64encReturnToURL = None 38 39 class SSOMiddleware(object): 40 41 def __init__(self, app, g, app_conf, **kw): 28 42 log.debug("SSOMiddleware.__init__ ...") 29 self.app = app 30 ndg.security.server.ssoservice.cfg = SSOServiceConfig(cfg, **kw) 43 ndg.security.server.sso.cfg = SSOServiceConfig(app_conf['configfile'], **kw) 31 44 32 45 # Copy into client for the benefit of 33 46 # ndg.security.client.ssoclient.ssoclient.lib.base.BaseController 34 47 # used to process responses back from SSO IdP 35 ndg.security.client.ssoclient.cfg.server = \ 36 ndg.security.server.ssoservice.cfg.server 37 ndg.security.client.ssoclient.cfg.sslServer = \ 38 ndg.security.server.ssoservice.cfg.sslServer 39 40 appGlobals.ndg = ndg 41 self.globals = appGlobals 42 48 ndg.security.common.sso.cfg.server = ndg.security.server.sso.cfg.server 49 ndg.security.common.sso.cfg.sslServer = \ 50 ndg.security.server.sso.cfg.sslServer 51 52 g.ndg = ndg 53 self.globals = g 54 55 # OpenID Middleware 56 app = authkit.authenticate.middleware(app, app_conf) 57 app = SessionMiddleware(app) 58 59 self.app = app 60 43 61 def __call__(self, environ, start_response): 44 45 62 return self.app(environ, start_response) 46 63 … … 156 173 157 174 # Flag to enable OpenID interface 158 try:175 if self.cfg.has_option(defSection, 'enableOpenID'): 159 176 self.enableOpenID = self.cfg.getboolean(defSection, 'enableOpenID') 160 e xcept ConfigParser.NoOptionError:177 else: 161 178 self.enableOpenID = False 162 179 -
TI12-security/trunk/python/ndg.security.server/ndg/security/server/sso/sso/controllers/login.py
r3914 r3918 1 import logging 1 # _redirect requires this to parse the server name 2 from urlparse import urlsplit 3 2 4 3 5 from ndg.security.server.sso.sso.lib.base import * … … 11 13 12 14 from base64 import urlsafe_b64decode, urlsafe_b64decode 15 import logging 13 16 14 17 log = logging.getLogger(__name__) 15 18 16 class LoginController(BaseController): 19 class LoginController(BaseController): 20 '''Handle NDG Login and redirect backing to requesting URL if set''' 21 22 def __before__(self): 23 '''Set-up alias to SSO settings global''' 24 self.cfg = g.ndg.security.server.sso.cfg 25 self.state = g.ndg.security.common.sso.state 17 26 18 27 def index(self): … … 21 30 present login''' 22 31 log.debug("LoginController.index ...") 23 24 # Convenience alias 25 cfg = g.ndg.security.server.ssoservice.cfg 26 27 # Check the return to URL 28 c.b64encReturnTo = str(request.params.get('r', '')) 32 33 # Check the return to URL from the 'r' argument in the request 34 self.state.b64encReturnToURL = str(request.params.get('r', '')) 29 35 30 36 if 'ndgSec' not in session: … … 35 41 try: 36 42 smClnt = SessionMgrClient(uri=session['ndgSec']['h'], 37 tracefile=cfg.tracefile,38 httpProxyHost=cfg.httpProxyHost,39 ignoreHttpProxyEnv=cfg.ignoreHttpProxyEnv,40 **cfg.wss)43 tracefile=self.cfg.tracefile, 44 httpProxyHost=self.cfg.httpProxyHost, 45 ignoreHttpProxyEnv=self.cfg.ignoreHttpProxyEnv, 46 **self.cfg.wss) 41 47 42 48 except Exception, e: … … 53 59 session['ndgSec']['h'] + 'for user "%s" with sid="%s" ...'%\ 54 60 (session['ndgSec']['u'], session['ndgSec']['sid'])) 61 55 62 try: 56 63 bSessOK = smClnt.getSessionStatus(sessID=session['ndgSec']['sid']) 57 64 except Exception, e: 58 65 c.xml = "Error checking your session details. Please re-login" 59 log.error("Session Manager getSessionStatus returned: %s" % e)66 log.error("Session Manager getSessionStatus: %s" % e) 60 67 SecuritySession.delete() 61 68 response.status_code = 400 … … 75 82 76 83 def getCredentials(self): 77 """Authenticate user and cache user credentials in 78 Session Managerfollowing user login"""84 """Authenticate user and cache user credentials in Session Manager 85 following user login""" 79 86 log.debug("LoginController.getCredentials ...") 80 81 # Convenience alias82 cfg = g.ndg.security.server.ssoservice.cfg83 84 # Check the return to URL85 c.b64encReturnTo = str(request.params.get('r', ''))86 87 87 88 if 'username' not in request.params: … … 90 91 91 92 try: 92 smClnt = SessionMgrClient(uri= cfg.smURI,93 tracefile=cfg.tracefile,94 httpProxyHost=cfg.httpProxyHost,95 ignoreHttpProxyEnv=cfg.ignoreHttpProxyEnv,96 **cfg.wss)93 smClnt = SessionMgrClient(uri=self.cfg.smURI, 94 tracefile=self.cfg.tracefile, 95 httpProxyHost=self.cfg.httpProxyHost, 96 ignoreHttpProxyEnv=self.cfg.ignoreHttpProxyEnv, 97 **self.cfg.wss) 97 98 98 99 username = request.params['username'] … … 108 109 # Connect to Session Manager 109 110 log.debug('Calling Session Manager "%s" connect for user "%s" ...' % \ 110 ( cfg.smURI, username))111 (self.cfg.smURI, username)) 111 112 try: 112 113 sessID = smClnt.connect(username, passphrase=passphrase)[-1] … … 116 117 "please contact your site administrator." 117 118 log.error("Session Manager connect returned: %s" % e) 118 response.status_code = 40 1119 response.status_code = 400 119 120 return render('ndg.security.kid', 'ndg.security.login') 120 121 … … 124 125 # Make request for attribute certificate 125 126 attCert = smClnt.getAttCert(sessID=sessID, 126 attAuthorityURI= cfg.aaURI)127 attAuthorityURI=self.cfg.aaURI) 127 128 except SessionExpired, e: 128 129 log.info("Session expired getting Attribute Certificate: %s" % e) 129 130 c.xml = "Session has expired, please re-login" 130 response.status_code = 40 1131 response.status_code = 400 131 132 return render('ndg.security.kid', 'ndg.security.login') 132 133 … … 135 136 c.xml = "No authorisation roles are available for your " + \ 136 137 "account. Please check with your site administrator." 137 response.status_code = 40 1138 response.status_code = 400 138 139 return render('ndg.security.kid', 'ndg.security.login') 139 140 … … 148 149 149 150 # Make security session details 150 setSecuritySession(h= cfg.smURI,151 setSecuritySession(h=self.cfg.smURI, 151 152 u=username, 152 153 org=attCert.issuerName, … … 167 168 log.debug("LoginController._redirect...") 168 169 169 # Convenience alias170 cfg = g.ndg.security.server.ssoservice.cfg171 172 170 # This is set in index and getCredentials 173 if c.b64encReturnTo:171 if self.state.b64encReturnToURL: 174 172 175 173 # Only add token if return URI is in a different domain … … 177 175 178 176 # Decode return to address 179 returnToURL = urlsafe_b64decode( c.b64encReturnTo)177 returnToURL = urlsafe_b64decode(self.state.b64encReturnToURL) 180 178 log.debug('Login redirect to [%s]' % returnToURL) 181 179 … … 200 198 201 199 # Look-up list of Cert DNs for trusted requestors 202 aaClnt = AttAuthorityClient(uri= cfg.aaURI,203 tracefile=cfg.tracefile,204 httpProxyHost=cfg.httpProxyHost,205 ignoreHttpProxyEnv=cfg.ignoreHttpProxyEnv,206 **cfg.wss)200 aaClnt = AttAuthorityClient(uri=self.cfg.aaURI, 201 tracefile=self.cfg.tracefile, 202 httpProxyHost=self.cfg.httpProxyHost, 203 ignoreHttpProxyEnv=self.cfg.ignoreHttpProxyEnv, 204 **self.cfg.wss) 207 205 208 206 HostInfo = aaClnt.getAllHostsInfo() … … 211 209 log.debug(\ 212 210 "Attribute Authority [%s] expecting DN for SSL peer one of: %s" % \ 213 ( cfg.aaURI, requestServerDN))211 (self.cfg.aaURI, requestServerDN)) 214 212 215 213 hostCheck = HostCheck(acceptedDNs=requestServerDN, 216 caCertFilePathList=cfg.sslCACertFilePathList)214 caCertFilePathList=self.cfg.sslCACertFilePathList) 217 215 218 216 testConnection = HTTPSConnection(returnToURLHostname, -
TI12-security/trunk/python/ndg.security.server/ndg/security/server/sso/sso/controllers/logout.py
r3892 r3918 21 21 log.info("LogoutController.index ...") 22 22 23 # Convenience alias 24 cfg = g.ndg.security.server.sso.cfg 25 23 26 24 27 if 'ndgSec' not in session: … … 29 32 try: 30 33 smClnt = SessionMgrClient(uri=session['ndgSec']['h'], 31 tracefile=g.ndg.security.server.ssoservice.cfg.tracefile,32 **g.ndg.security.server.ssoservice.cfg.wss)34 tracefile=cfg.tracefile, 35 **cfg.wss) 33 36 except Exception, e: 34 37 log.error("logout - creating Session Manager client: %s" % e) -
TI12-security/trunk/python/ndg.security.server/ndg/security/server/sso/sso/controllers/wayf.py
r3914 r3918 3 3 from ndg.security.server.sso.sso.lib.base import * 4 4 from ndg.security.common.AttAuthority import AttAuthorityClient 5 import base64 5 from base64 import urlsafe_b64decode 6 6 7 7 log = logging.getLogger(__name__) … … 11 11 """Where Are You From Controller - display a list of trusted sites for 12 12 login""" 13 14 def __before__(self, action):15 """For each action, get 'r' return to URL argument from current URL16 query string. c.b64encReturnTo is used in some of the .kid files"""17 c.b64encReturnTo = str(request.params.get('r', ''))18 log.debug("WayfController.__before__: c.b64encReturnTo = %s" % \19 c.b64encReturnTo)20 21 # Decode the return URL so that it can be displayed to the user by22 # wayf.kid23 # The URL has previously been encoded from the BaseController and set24 # in ndgPage.kid25 # Use str() - urlsafe_b64decode() doesn't like unicode26 c.returnTo = base64.urlsafe_b64decode(str(c.b64encReturnTo))27 28 # Ensure login can return to an address over https to29 # preserve confidentiality of credentials30 if g.ndg.security.server.ssoservice.cfg.server in c.returnTo:31 c.returnTo = c.returnTo.replace(\32 g.ndg.security.server.ssoservice.cfg.server,33 g.ndg.security.server.ssoservice.cfg.sslServer)34 c.b64encReturnTo = urlsafe_b64encode(c.returnTo)35 log.debug(\36 "WayfController.__before__: switched return to address to https = %s" % \37 c.returnTo)38 39 13 40 14 def index(self): 41 15 ''' NDG equivalent to Shibboleth WAYF ''' 42 16 43 # Convenience alias 44 cfg = g.ndg.security.server.ssoservice.cfg 17 # Check for return to arg in query. This is necessary only if the 18 # WAYF query originates from a different service to this one 19 if 'r' in request.params: 20 # Convenience alias 21 state = g.ndg.security.common.sso.state 45 22 46 log.debug("WayfController.index ...") 47 log.debug("Initialising connection to Attribute Authority [%s]" % \ 48 cfg.aaURI) 49 50 try: 51 aaClnt = AttAuthorityClient(uri=cfg.aaURI, 52 tracefile=cfg.tracefile, 53 httpProxyHost=cfg.httpProxyHost, 54 ignoreHttpProxyEnv=cfg.ignoreHttpProxyEnv, 55 **cfg.wss) 56 except Exception, e: 57 c.xml='Error establishing security context. Please report ' + \ 58 'the error to your site administrator' 59 log.error("Initialising AttAuthorityClient for " + \ 60 "getAllHostsInfo call: %s" % e) 61 return render('ndg.security.kid', 'ndg.security.error') 62 63 # Get list of login uris for trusted sites including THIS one 64 log.debug("Calling Attribute Authority getAllHostsInfo for wayf ...") 23 state.b64encReturnToURL = str(request.params['r']) 24 state.returnToURL = urlsafe_b64decode(str(state.b64encReturnToURL)) 25 log.debug("Set return to URL from 'r' query arg: r = %s"% \ 26 state.returnToURL) 65 27 66 hosts = aaClnt.getAllHostsInfo() 67 try: 68 hosts = aaClnt.getAllHostsInfo() 69 except Exception, e: 70 c.xml='Error getting a list of trusted sites for login. ' + \ 71 'Please report the error to your site administrator.' 72 log.error("AttAuthorityClient getAllHostsInfo call: %s" % e) 73 return render('ndg.security.kid', 'ndg.security.error') 74 75 c.providers = dict([(k, v['loginURI']) for k, v in hosts.items()]) 76 77 session.save() 78 79 # Use an alias 'ndg.security.kid' to integration with another pylons 80 # code stack. The alias tells render to pick up the template from a 81 # separate SSO templates directory to whatever is the default 82 return render('ndg.security.kid', 'ndg.security.wayf') 28 # Trigger AuthKit handler: 29 abort(401) -
TI12-security/trunk/python/ndg.security.server/ndg/security/server/sso/sso/lib/base.py
r3914 r3918 37 37 if 'getCredentials' in pathInfo: 38 38 log.debug("Reverting request URL from getCredentials to login...") 39 c.requestURL = g.ndg.security.server.sso service.cfg.server+'/login'39 c.requestURL = g.ndg.security.server.sso.cfg.server+'/login' 40 40 else: 41 c.requestURL = g.ndg.security.server.sso service.cfg.server+pathInfo41 c.requestURL = g.ndg.security.server.sso.cfg.server+pathInfo 42 42 query='&'.join(["%s=%s" % item for item in request.params.items()]) 43 43 if query: 44 44 c.requestURL += '?' + query 45 45 46 #log.debug("BaseController.__call__: c.requestURL = %s" % c.requestURL)47 46 self._openidHandler(environ) 48 47 … … 60 59 u=environ['REMOTE_USER'], 61 60 org=environ['REMOTE_USER'], 62 roles=[ ],61 roles=['OpenIDUser'], 63 62 sid=None) 64 63 session.save() -
TI12-security/trunk/python/ndg.security.server/ndg/security/server/sso/sso/lib/openid_util.py
r3914 r3918 1 1 import pylons 2 2 from pylons.templating import Buffet 3 from pylons import config 4 import sso.lib.helpers as h5 from sso.lib.app_globals import Globals3 from pylons import config, request, session 4 import ndg.security.server.sso.sso.lib.helpers as h 5 from ndg.security.server.sso.sso.lib.app_globals import Globals 6 6 7 7 import logging … … 33 33 pass 34 34 35 36 # State variable for WAYF kid file set-up 35 37 c = State() 36 38 c.openid = 'None' 37 c.title = " OpenID Login"39 c.title = "Where are You From?" 38 40 c.xml = '' 41 c.doc = 'logged in' 39 42 c.providers = {} 40 43 41 log.debug("config=%s" % config) 44 import base64 45 42 46 def make_template(): 43 '''Make kid template for OpenID login - this piggy backs the NDG WAYF''' 44 return buffet.render( 45 template_name="ndg.security.wayf", 46 namespace=dict(h=h, g=config['pylons.g'], c=c) 47 ).replace("%", "%%").replace("SERVER", "%s") 47 '''Make kid template for OpenID login - the NDG WAYF piggy backs this. 48 49 It's triggered by a HTTP 401 authorisation error and called explicitly 50 via the WAYF controller''' 51 52 g = config['pylons.g'] 53 54 # Check for return from OpenID login 55 if 'REMOTE_USER' in request.environ: 56 if not g.ndg.security.common.sso.state.returnToURL: 57 log.error("No returnToURL set for redirect following OpenID " + \ 58 "login") 59 else: 60 log.info("Redirecting to [%s] following OpenID login ..." % \ 61 g.ndg.security.common.sso.state.returnToURL) 62 h.redirect_to(g.ndg.security.common.sso.state.returnToURL) 48 63 64 65 state = g.ndg.security.common.sso.state 66 cfg = g.ndg.security.common.sso.cfg 67 68 # Set encoded return to address - ensure login can return to an address 69 # over https to preserve confidentiality of credentials 70 if state.returnToURL and cfg.server in state.returnToURL: 71 state.returnToURL = state.returnToURL.replace(cfg.server, 72 cfg.sslServer) 73 log.debug("make_template: switched return to address to https = %s" % \ 74 state.returnToURL) 75 76 state.b64encReturnToURL = base64.urlsafe_b64encode(str(state.returnToURL)) 77 78 # Retrieve IdP details 79 _getTrustedIdPs(g) 80 81 return buffet.render('ndg.security.kid', 82 template_name="ndg.security.wayf", 83 namespace=dict(h=h, g=g, c=c)) 84 85 from ndg.security.common.AttAuthority import AttAuthorityClient 86 87 def _getTrustedIdPs(g): 88 '''Retrieve list of trusted login sites for user to select - calls 89 Attribute Authority WS''' 90 91 # Get references to globals 92 state = g.ndg.security.common.sso.state 93 cfg = g.ndg.security.server.sso.cfg 94 95 # Check for cached copy and return if set to avoid recalling 96 # Attribute Authority - This has the consequence that if the list 97 # of trusted hosts in the Map Configuration changes, the Attribute 98 # Authority and THIS service must be restarted. 99 if len(g.ndg.security.server.sso.state.trustedIdPs) > 0: 100 return buffet.render('ndg.security.kid', 101 template_name='ndg.security.wayf', 102 namespace=dict(h=h, g=g, c=c)) 103 104 log.debug("Initialising connection to Attribute Authority [%s]" % \ 105 cfg.aaURI) 106 107 try: 108 aaClnt = AttAuthorityClient(uri=cfg.aaURI, 109 tracefile=cfg.tracefile, 110 httpProxyHost=cfg.httpProxyHost, 111 ignoreHttpProxyEnv=cfg.ignoreHttpProxyEnv, 112 **cfg.wss) 113 except Exception, e: 114 c.xml='Error establishing security context. Please report ' + \ 115 'the error to your site administrator' 116 log.error("Initialising AttAuthorityClient for " + \ 117 "getAllHostsInfo call: %s" % e) 118 return buffet.render('ndg.security.kid', 119 template_name='ndg.security.error', 120 namespace=dict(h=h, g=config['pylons.g'], c=c)) 121 122 # Get list of login uris for trusted sites including THIS one 123 log.debug("Calling Attribute Authority getAllHostsInfo for wayf ...") 124 125 try: 126 hosts = aaClnt.getAllHostsInfo() 127 except Exception, e: 128 c.xml='Error getting a list of trusted sites for login. ' + \ 129 'Please report the error to your site administrator.' 130 log.error("AttAuthorityClient getAllHostsInfo call: %s" % e) 131 return render('ndg.security.kid', template_name='ndg.security.error') 132 133 g.ndg.security.server.sso.state.trustedIdPs = \ 134 dict([(k, v['loginURI']) for k, v in hosts.items()]) 135 136 137 from ndg.security.common.pylons.security_util import setSecuritySession 138 from urlparse import urlsplit 49 139 50 140 def url2user(environ, url): 51 141 '''Function picked up by authkit.openid.urltouser config setting. It 52 sets a session from the users OpenID URL following login''' 53 54 username = url.replace('http://', '').replace('https://', '').strip('/').split('/')[-1] 142 sets a username from the users OpenID URL following login''' 143 log.info("OpenID sign in with [%s]" % url) 144 145 # Remove protocol prefix and strip /'s 146 username = ''.join(urlsplit(url)[1:]).strip('/').replace('/', '-') 55 147 return username -
TI12-security/trunk/python/ndg.security.server/ndg/security/server/sso/sso/templates/ndg/security/error.kid
r3892 r3918 6 6 <div id="entirepage"> 7 7 <div py:replace="header()"/> 8 <?python9 id="contents"10 if "ndgSec" in session: id="contentsRight"11 ?>12 8 <div id="${id}"> 13 9 <div class="error" py:if="c.xml"> -
TI12-security/trunk/python/ndg.security.server/ndg/security/server/sso/sso/templates/ndg/security/login.kid
r3754 r3918 2 2 3 3 <div py:def="loginForm()" class="loginForm"> 4 <form action="$g.ndg.security.server.ssoservice.cfg.getCredentials" method="POST"> 5 <input type="hidden" name="r" value="${c.b64encReturnTo}"/> 4 <form action="$g.ndg.security.server.sso.cfg.getCredentials" method="POST"> 5 <!-- 6 <input type="hidden" name="r" value="${g.ndg.security.common.sso.b64encReturnToURL}"/> 7 --> 6 8 <table cellspacing="0" border="0" cellpadding="5"> 7 9 <tr> -
TI12-security/trunk/python/ndg.security.server/ndg/security/server/sso/sso/templates/ndg/security/ndgPage.kid
r3754 r3918 9 9 function is needed to avoid escaping the < character --> 10 10 ${XML(h.javascript_include_tag(builtins=True))} 11 <script type="text/javascript" src="$g.ndg.security.server.sso service.cfg.server/js/toggleDiv.js"/>11 <script type="text/javascript" src="$g.ndg.security.server.sso.cfg.server/js/toggleDiv.js"/> 12 12 13 <link media="all, screen" href="$g.ndg.security.server.sso service.cfg.server/layout/ndg2.css" type="text/css" rel="stylesheet"/>14 <link rel="icon" type="image/ico" href="$g.ndg.security.server.sso service.cfg.server/layout/favicon.jpg" />13 <link media="all, screen" href="$g.ndg.security.server.sso.cfg.server/layout/ndg2.css" type="text/css" rel="stylesheet"/> 14 <link rel="icon" type="image/ico" href="$g.ndg.security.server.sso.cfg.server/layout/favicon.jpg" /> 15 15 16 16 </head> … … 18 18 <div py:def="header()"> 19 19 <div id="header"/> 20 <div id="logo"><img src="$g.ndg.security.server.sso service.cfg.LeftLogo" alt="$g.ndg.security.server.ssoservice.cfg.LeftAlt" /></div>20 <div id="logo"><img src="$g.ndg.security.server.sso.cfg.LeftLogo" alt="$g.ndg.security.server.sso.cfg.LeftAlt" /></div> 21 21 </div> 22 22 … … 44 44 45 45 <!-- Page Footer follows --> 46 <div py:def="footer(showLoginStatus= True)" id="Footer">46 <div py:def="footer(showLoginStatus=False)" id="Footer"> 47 47 <center><table><tbody> 48 48 <tr> 49 49 <td align="left" width="60%"> 50 50 <table><tbody> 51 <tr><td><span py:replace="linkimage(g.ndg.security.server.sso service.cfg.ndgLink,g.ndg.security.server.ssoservice.cfg.ndgImage,'NDG')"/></td>51 <tr><td><span py:replace="linkimage(g.ndg.security.server.sso.cfg.ndgLink,g.ndg.security.server.sso.cfg.ndgImage,'NDG')"/></td> 52 52 <td> This portal is a product of the <a href="http://ndg.nerc.ac.uk"> NERC DataGrid</a> 53 ${g.ndg.security.server.sso service.cfg.disclaimer} </td>53 ${g.ndg.security.server.sso.cfg.disclaimer} </td> 54 54 </tr> 55 55 </tbody></table> 56 56 </td> 57 57 <td width="40%" align="center"> 58 <div id="loginStatus" py:if="showLoginStatus==True">59 <!--! now we choose one of the next two (logged in or not) -->60 <div py:if="'ndgSec' in session"><table><tbody><tr><td>61 User [${session['ndgSec']['u']}] logged in at62 ${session['ndgSec']['org']} with roles63 [${len(session['ndgSec']['roles'])==1 and session['ndgSec']['roles'][0] or ', '.join(session['ndgSec']['roles'])}]</td><td>64 <span py:replace="logOut()"/></td></tr></tbody></table></div>65 <div py:if="'ndgSec' not in session">Further services maybe available if you can66 <span py:replace="logIn()"/></div>67 </div>68 58 </td> 69 <td align="right"><span py:replace="linkimage(g.ndg.security.server.sso service.cfg.stfcLink,g.ndg.security.server.ssoservice.cfg.stfcImage,'Hosted by the STFC CEDA')"/></td>59 <td align="right"><span py:replace="linkimage(g.ndg.security.server.sso.cfg.stfcLink,g.ndg.security.server.sso.cfg.stfcImage,'Hosted by the STFC CEDA')"/></td> 70 60 </tr> 71 61 </tbody></table></center> … … 83 73 <span> 84 74 <a href="javascript:;" title="Toggle help" onclick="toggleDiv(1,'$value','shown','hidden','div'); return false;"> 85 <img src="$g.ndg.security.server.sso service.cfg.helpIcon" alt="Toggle help" class="helpicon"/></a>75 <img src="$g.ndg.security.server.sso.cfg.helpIcon" alt="Toggle help" class="helpicon"/></a> 86 76 87 77 </span> … … 90 80 <!-- Login and out buttons --> 91 81 <span py:def="logOut()" class="logOut"> 92 <form action="$g.ndg.security.server.sso service.cfg.logout">93 <input type="hidden" name="r" value="${ c.b64encReturnTo}"/>82 <form action="$g.ndg.security.server.sso.cfg.logoutURI"> 83 <input type="hidden" name="r" value="${g.ndg.security.common.sso.b64encReturnToURL}"/> 94 84 <input type="submit" value="Logout"/> 95 85 </form> … … 102 92 # Base 64 encode to enable passing around in 'r' argument of query 103 93 # string for use with login/logout 104 c.returnTo= c.requestURL105 c.b64encReturnTo= urlsafe_b64encode(c.requestURL)94 g.ndg.security.common.sso.returnToURL = c.requestURL 95 g.ndg.security.common.sso.b64encReturnToURL = urlsafe_b64encode(c.requestURL) 106 96 ?> 107 <form action="$g.ndg.security.server.sso service.cfg.wayfuri">108 <input type="hidden" name="r" value="${ c.b64encReturnTo}"/>97 <form action="$g.ndg.security.server.sso.cfg.wayfuri"> 98 <input type="hidden" name="r" value="${g.ndg.security.common.sso.b64encReturnToURL}"/> 109 99 <input type="submit" value="Login"/> 110 100 </form> -
TI12-security/trunk/python/ndg.security.server/ndg/security/server/sso/sso/templates/ndg/security/wayf.kid
r3914 r3918 5 5 <?python 6 6 # Sort alphabetically 7 providerNames = c.providers.keys()7 providerNames = g.ndg.security.server.sso.state.trustedIdPs.keys() 8 8 providerNames.sort() 9 9 ?> 10 10 <ul py:for="h in providerNames"> 11 <li> <a href="${ c.providers[h]}?r=${c.b64encReturnTo}">${h}</a></li>11 <li> <a href="${g.ndg.security.server.sso.state.trustedIdPs[h]}?r=${g.ndg.security.common.sso.state.b64encReturnToURL}">${h}</a></li> 12 12 </ul> 13 13 </p> 14 <!--15 <p>Before clicking on these links, please check that the links redirect to a site16 you trust with your security credentials.</p>17 <p> How can I tell? For any of the above, following login you will be18 redirected back to the URL: <a href="${c.returnTo}">${c.returnTo}</a></p>19 -->20 14 </div> 21 15 22 16 <div py:def="openIDSignin()" class="openIDSignin" style="text-indent:5px"> 23 17 <p>Alternatively, sign in with OpenID:</p> 24 <form action="$g.ndg.security.server.sso service.cfg.server/verify" method="post">18 <form action="$g.ndg.security.server.sso.cfg.server/verify" method="post"> 25 19 <table cellspacing="0" border="0" cellpadding="5"> 26 20 <tr> … … 37 31 <style> 38 32 input.openid-identifier { 39 background: url($g.ndg.security.server.sso service.cfg.server/layout/openid-inputicon.gif) no-repeat;33 background: url($g.ndg.security.server.sso.cfg.server/layout/openid-inputicon.gif) no-repeat; 40 34 background-color: #fff; 41 35 background-position: 0 50%;
Note: See TracChangeset
for help on using the changeset viewer.