Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
dm-docs
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
hammonds
dm-docs
Commits
50c26fdc
Commit
50c26fdc
authored
9 years ago
by
sveseli
Browse files
Options
Downloads
Patches
Plain Diff
login changes due to single sign on implementation
parent
0ec5eceb
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/python/dm/common/service/loginController.py
+34
-3
34 additions, 3 deletions
src/python/dm/common/service/loginController.py
with
34 additions
and
3 deletions
src/python/dm/common/service/loginController.py
+
34
−
3
View file @
50c26fdc
#!/usr/bin/env python
import
cherrypy
import
datetime
import
urllib
from
cherrypy.lib
import
httpauth
...
...
@@ -14,6 +15,7 @@ from dm.common.exceptions.invalidSession import InvalidSession
from
dm.common.utility.loggingManager
import
LoggingManager
from
dm.common.service.dmController
import
DmController
from
dm.common.service.auth.authorizationPrincipalManager
import
AuthorizationPrincipalManager
from
dm.common.service.auth.singleSignOnManager
import
SingleSignOnManager
class
LoginController
(
DmController
):
"""
Controller to provide login and logout actions.
"""
...
...
@@ -21,6 +23,7 @@ class LoginController(DmController):
SESSION_USERNAME_KEY
=
'
_cp_username
'
SESSION_USER_KEY
=
'
user
'
SESSION_ROLE_KEY
=
'
role
'
ORIGINAL_SESSION_ID_KEY
=
'
originalid
'
INVALID_SESSION_KEY
=
'
invalidSession
'
_cp_config
=
{
...
...
@@ -97,6 +100,14 @@ class LoginController(DmController):
if
principal
:
cherrypy
.
session
[
LoginController
.
SESSION_ROLE_KEY
]
=
principal
.
getRole
()
logger
.
debug
(
'
Successful login from user: %s (role: %s)
'
%
(
username
,
principal
.
getRole
()))
# Try adding to SingleSignOnManager
sessionId
=
cherrypy
.
serving
.
session
.
id
sessionCache
=
cherrypy
.
session
.
cache
sessionInfo
=
{
LoginController
.
SESSION_ROLE_KEY
:
principal
.
getRole
()}
sessionInfo
[
LoginController
.
SESSION_USER_KEY
]
=
principal
.
getUserInfo
()
sessionInfo
[
LoginController
.
SESSION_USERNAME_KEY
]
=
username
ssoManager
=
SingleSignOnManager
.
getInstance
()
ssoManager
.
addSession
(
sessionId
,
sessionInfo
)
else
:
logger
.
debug
(
'
Login denied for user: %s
'
%
username
)
username
=
cherrypy
.
session
.
get
(
LoginController
.
SESSION_USERNAME_KEY
,
None
)
...
...
@@ -128,17 +139,37 @@ class LoginController(DmController):
sessionId
=
cherrypy
.
serving
.
session
.
id
sessionCache
=
cherrypy
.
session
.
cache
# If session cache does not have current session id, reuse original
# session id
if
not
sessionCache
.
has_key
(
sessionId
)
and
cherrypy
.
serving
.
session
.
__dict__
.
has_key
(
LoginController
.
ORIGINAL_SESSION_ID_KEY
):
logger
.
debug
(
'
Reusing original session id: %s
'
%
sessionId
)
sessionId
=
cherrypy
.
serving
.
session
.
__dict__
.
get
(
LoginController
.
ORIGINAL_SESSION_ID_KEY
)
#logger.debug('Session: %s' % ((cherrypy.session.__dict__)))
#
logger.debug('Session cache length: %s' % (len(sessionCache)))
logger
.
debug
(
'
Session cache length: %s
'
%
(
len
(
sessionCache
)))
#logger.debug('Session cache: %s' % (sessionCache))
# Check session.
if
not
sessionCache
.
has_key
(
sessionId
):
# Try SingleSignOnManager first
ssoManager
=
SingleSignOnManager
.
getInstance
()
# SSO Manager returns session info
sessionInfo
=
ssoManager
.
checkSession
(
sessionId
)
if
not
sessionInfo
:
# Cache has tuple (sessionInfo, updateTime)
sessionTuple
=
sessionCache
.
get
(
sessionId
)
if
sessionTuple
:
sessionInfo
=
sessionTuple
[
0
]
else
:
logger
.
debug
(
'
Retrieved session %s from SSO Manager
'
%
sessionId
)
sessionCache
[
sessionId
]
=
(
sessionInfo
,
datetime
.
datetime
.
now
())
if
not
sessionInfo
:
errorMsg
=
'
Invalid or expired session id: %s.
'
%
sessionId
logger
.
debug
(
errorMsg
)
raise
DmHttpError
(
dmHttpStatus
.
DM_HTTP_UNAUTHORIZED
,
'
User Not Authorized
'
,
InvalidSession
(
errorMsg
))
username
=
cherrypy
.
session
.
get
(
LoginController
.
SESSION_USERNAME_KEY
)
username
=
sessionInfo
.
get
(
LoginController
.
SESSION_USERNAME_KEY
)
cherrypy
.
session
[
LoginController
.
SESSION_ROLE_KEY
]
=
sessionInfo
[
LoginController
.
SESSION_ROLE_KEY
]
logger
.
debug
(
'
Session id %s is valid (username: %s)
'
%
(
sessionId
,
username
))
if
username
:
cherrypy
.
request
.
login
=
username
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment