Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/awg integration #209

Merged
merged 90 commits into from
May 23, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
90 commits
Select commit Hold shift + click to select a range
6c90b57
feat(documentation): add steps and clarifications on readme file
Jan 23, 2018
e3f57df
feat(openAPI-doc): add swagger ops to file
Jan 25, 2018
0c592fa
feat(migration): add old code from user-api
Jan 26, 2018
d5eb404
feat(migration): modifying create_user to allow groups or projects or…
Jan 31, 2018
1439d27
feat(migration): add more functions
Feb 1, 2018
1f49f1b
feat(migration): add create and delete group
Feb 1, 2018
ac1a3d9
feat(chore): fix mock dependency when not needed
Feb 1, 2018
c41bd74
feat(fix-userdatamodel): fix fence-create to user group instead of re…
Feb 2, 2018
b407555
feat(migration): add operations for demo, need refactor and separatio…
Feb 2, 2018
939543a
feat(migration): add op to add projects to groups and remove projects…
Feb 2, 2018
14eb092
feat(migration): add get groups from user
Feb 2, 2018
8f77886
feat(oicr-demo): add get users from group
Feb 2, 2018
bb68ffb
feat(refactor): remove add groups and projects, move operations from …
Feb 6, 2018
4659a9a
feat(refactoring): fix missing project __init__.py file
Feb 6, 2018
2d71c45
feat(refactor): fix current_session uniquely create on blueprint and …
Feb 9, 2018
77d2132
feat(refactor): fix missing param
Feb 9, 2018
2d4b59e
feat(refactor): add role to user creation and refactor code
Feb 12, 2018
00909df
feat(refactor): fix method from put to post for creation
Feb 12, 2018
1e86664
feat(refactor): add update_user and refactor code
Feb 13, 2018
2f9a1c3
feat(refactor): fix stuff
Feb 14, 2018
329675f
feat(refactor): fix import
Feb 14, 2018
1b3d6b2
feat(refactor): add projects to get_group, add update_group
Feb 14, 2018
da6aebc
feat(refactor): add different files to split admin, remove ~ file
Feb 14, 2018
2341b16
feat(refactor) fix missing imports
Feb 14, 2018
e3d21a3
feat(refactor): add get_all_projects, move users code
Feb 15, 2018
96f1209
feat(refactor): fix delete user from group, fix delete user
Feb 16, 2018
0b637b6
feat(refactor): add return get_groups in create, update users on remo…
Feb 21, 2018
0669a47
feat(refactor): add clean up of project and users inside remove_group
Feb 21, 2018
75e3413
geat(refactor): add description and projects to get_groups, fix typo …
Feb 21, 2018
8366cee
feat(refactor): fix get_user_groups, get_group_users to return full info
Feb 22, 2018
692fe5b
feat(refactor): fix get_group_users, fix add_project_to_group
Feb 22, 2018
35c4f59
feat(refactor): fix remove_projects_from_group
Feb 22, 2018
5c7fa7b
feat(refactor): fix exception typo
Feb 22, 2018
2131509
merge(master): merge master to TT-305
Feb 23, 2018
e367ad0
feat(merge): fix commit not happening at the end of a request
Feb 23, 2018
23bdd48
feat(refactor): fix get_current_user endpoint
Feb 23, 2018
c1becc5
incorrect function name fix
Feb 23, 2018
f5034e1
Merge remote-tracking branch 'origin/feat/TT-305-merge-master' into f…
Feb 23, 2018
42b2368
feat(refactor): fix delete project from group
Feb 27, 2018
c350981
feat(refactor): fix error logging error
Feb 27, 2018
33e17b7
feat(refactor): fix research groups in get user access
Feb 28, 2018
842fedf
feat(refactor): add admin to audience and scope
Mar 1, 2018
3b93ced
feat(test): add basic test files
Mar 2, 2018
592d46e
feat(refator): add name edition capabilities to user and group
Mar 6, 2018
88b515f
feat(test): fix parameters in fixtures
Mar 6, 2018
374a5fd
feat(test): add basic get tests
Mar 8, 2018
34d265d
feat(test): fix missing file
Mar 8, 2018
230ee37
feat(test): add user tests
Mar 8, 2018
45c8081
feat(test): add user to group test
Mar 9, 2018
6da7c4e
feat(test): fix test
Mar 9, 2018
5df92b5
feat(test): fix test list number
Mar 9, 2018
93f4401
feat(test): add test remove from wrong group
Mar 9, 2018
555127b
feat(refactor): fix current session typo and differentiate from the o…
Mar 9, 2018
9665ca7
feat(test): fix remove user from group test
Mar 9, 2018
c13836d
feat(test): add get user groups test
Mar 9, 2018
66e0f87
feat(test): add get group and create groups tests
Mar 9, 2018
25cc961
feat(test): add group test cases and fix group data
Mar 10, 2018
1d45530
feat(refactor): fix response text format
Mar 10, 2018
cefd836
feat(test): add group tests
Mar 10, 2018
3232948
feat(test): update group tests
Mar 10, 2018
d36342c
feat(test): add user access and user groups when deleting
Mar 12, 2018
4ccd587
feat(refactor): fix function location in resources
Mar 15, 2018
19515a7
feat(refactor): add tests and fix errors due to previous refactor
Mar 20, 2018
4c3947a
feat(refactor): move functions out of userdatamodel
Mar 26, 2018
e92b4c5
feat(refactor): remove code from userdatamodel and split it into 4 files
Mar 27, 2018
ffb8d3d
feat(refactor): remove code from userdatamodel into other classes
Mar 30, 2018
878ef0d
feat(sec): add referer check to CSRF checkings
Mar 30, 2018
8529612
feat(sec): fix referer
Mar 30, 2018
c25078e
feat(sec): fix referer
Mar 30, 2018
7cf9122
feat(sec): fix referer
Mar 30, 2018
028d053
feat(logout): add logging and modify return url. TO BE REFACTORED
Apr 2, 2018
b4d911b
feat(logout): fix logging. TO BE REFACTORED
Apr 2, 2018
fa9dae1
feat(logout): fix logout redirect url
Apr 2, 2018
08d8fff
feat(refactor): fix commit problem with after_request decorator
Apr 3, 2018
5c102bf
feat(refactor): remove commit from blueprint
Apr 3, 2018
cd2c372
feat(refactor): add logs fix uppercase
Apr 5, 2018
47fa6a3
feat(refactor): fix upper parenthesis
Apr 5, 2018
a3d4ce8
feat(refactor): remove uppercase, fix username lookup on create
Apr 5, 2018
ae108a8
feat(token): add token endpoint
Apr 10, 2018
192212c
feat(token) add settings
Apr 10, 2018
26c021a
feat(token): remove admin required from token endpoint
Apr 11, 2018
965373e
feat(token): fix user retrieval and login issue
Apr 11, 2018
6a73560
feat(refactor): fix update user allows similar names
Apr 25, 2018
75e6356
merge from master
May 8, 2018
a5a542b
feat(pr-comments): add pr comment changes
May 14, 2018
b54410d
Merge branch 'master' into feat/awg-integration
May 22, 2018
3fc974b
feat(pr-comments): fix tests
May 22, 2018
500a336
feat(pr-comments): remove unreachable code
May 23, 2018
52249e7
refactor(debug): add debug logging decorator
May 23, 2018
df5c10b
feat(pr-comments): add missing comments from pr
May 23, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions bin/fence-create
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ def main():
# get database information
sys.path.append(args.path)


if os.environ.get('FENCE_DB'):
DB = os.environ['FENCE_DB']
else:
Expand Down
30 changes: 21 additions & 9 deletions fence/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from authutils.oauth2.client import OAuthClient
import flask
from flask.ext.cors import CORS
from flask_sqlalchemy_session import flask_scoped_session
from flask_sqlalchemy_session import flask_scoped_session, current_session
import urlparse
from userdatamodel.driver import SQLAlchemyDriver

Expand Down Expand Up @@ -109,9 +109,14 @@ def root():
@app.route('/logout')
def logout_endpoint():
root = app.config.get('APPLICATION_ROOT', '')
next_url = build_redirect_url(app.config.get('ROOT_URL', ''), flask.request.args.get('next', root))
request_next = flask.request.args.get('next', root)
if request_next.startswith('https') or request_next.startswith('http'):
next_url = request_next
else:
next_url = build_redirect_url(app.config.get('ROOT_URL', ''), request_next)
return logout(next_url=next_url)


@app.route('/jwt/keys')
def public_keys():
"""
Expand Down Expand Up @@ -140,10 +145,10 @@ def app_sessions(app):
app.db = SQLAlchemyDriver(app.config['DB'])
migrate(app.db)
session = flask_scoped_session(app.db.Session, app) # noqa
# app.storage_manager = StorageManager(
# app.config['STORAGE_CREDENTIALS'],
# logger=app.logger
# )
app.storage_manager = StorageManager(
app.config['STORAGE_CREDENTIALS'],
logger=app.logger
)
enabled_idp_ids = (
app.config['ENABLED_IDENTITY_PROVIDERS']['providers'].keys()
)
Expand Down Expand Up @@ -177,6 +182,7 @@ def app_init(app, settings='fence.settings', root_dir=None):
server.init_app(app)



@app.errorhandler(Exception)
def user_error(error):
"""
Expand All @@ -195,9 +201,11 @@ def check_csrf():
return
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems peculiar to only check the csrf token if you don't have an authorization header... line 192.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can discuss if you have any specific concerns about it or a suggestion on how to improve it :)

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added it to the issue I had originally opened.

# cookie based authentication
if flask.request.method != 'GET':
csrf_cookie = flask.request.headers.get('x-csrf-token')
csrf_header = flask.request.cookies.get('csrftoken')
if not csrf_cookie or not csrf_header or csrf_cookie != csrf_header:
csrf_header = flask.request.headers.get('x-csrf-token')
csrf_cookie = flask.request.cookies.get('csrftoken')
referer = flask.request.headers.get('referer')
flask.current_app.logger.debug('HTTP REFERER ' + referer)
if not all([csrf_cookie, csrf_header, csrf_cookie == csrf_header, referer]):
raise UserError("CSRF verification failed. Request aborted")


Expand All @@ -209,4 +217,8 @@ def set_csrf(response):
if not flask.request.cookies.get('csrftoken'):
secure = app.config.get('SESSION_COOKIE_SECURE', True)
response.set_cookie('csrftoken', random_str(40), secure=secure)

if flask.request.method in ['POST', 'PUT', 'DELETE']:
current_session.commit()
return response

20 changes: 18 additions & 2 deletions fence/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,15 @@ def logout(next_url=None):
# Call get_current_user (but ignore the result) just to check that either
# the user is logged in or that authorization is mocked.
user = get_current_user()
flask.current_app.logger.debug("IN AUTH LOGOUT, next_url = {0}".format(next_url))
if not user:
raise Unauthorized("You are not logged in")
itrust_next_url = None
if flask.session.get('provider') == IdentityProvider.itrust:
next_url = flask.current_app.config['ITRUST_GLOBAL_LOGOUT'] + next_url
itrust_next_url = flask.current_app.config['ITRUST_GLOBAL_LOGOUT'] + next_url
flask.session.clear()
redirect_response = flask.make_response(
flask.redirect(next_url)
flask.redirect(itrust_next_url or next_url)
)
clear_cookies(redirect_response)
return redirect_response
Expand All @@ -84,6 +86,7 @@ def check_scope_and_call(*args, **kwargs):
return wrapper



def login_required(scope=None):
"""
Create decorator to require a user session in shibboleth.
Expand Down Expand Up @@ -184,3 +187,16 @@ def get_user_from_claims(claims):
.filter(User.id == claims['sub'])
.first()
)

def admin_required(f):
"""
Require user to be an admin user.
"""
@wraps(f)
def wrapper(*args, **kwargs):
if not flask.g.user:
raise Unauthorized("Require login")
if flask.g.user.is_admin is not True:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if not flask.g.user.is_admin:
    ...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if wouldn't blow up it g.user has not been intialized somewhere else

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if it isn't initialized then it should blow up anyways I think, the only case this is different is that if is_admin == "True" (or some truthy value) then is_admin is not True == True but not is_admin == False. It should be a boolean though, so I suggested the more idiomatic way to paint the bike shed...

raise Unauthorized("Require admin user")
return f(*args, **kwargs)
return wrapper
Loading