Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
6 changes: 5 additions & 1 deletion desktop/core/src/desktop/middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -499,7 +499,11 @@ def process_view(self, request, view_func, view_args, view_kwargs):
)
}) # Remove embeddable so redirect from & to login works. Login page is not embeddable
else:
return HttpResponseRedirect("%s?%s=%s" % (settings.LOGIN_URL, REDIRECT_FIELD_NAME, quote(request.get_full_path())))
# Return a page that redirects using JavaScript to capture the exact browser URL
return render('redirect_to_login.mako', request, {
'login_url': settings.LOGIN_URL,
'redirect_field_name': REDIRECT_FIELD_NAME,
})

def process_response(self, request, response):
if hasattr(request, 'ts') and hasattr(request, 'view_func'):
Expand Down
31 changes: 31 additions & 0 deletions desktop/core/src/desktop/templates/redirect_to_login.mako
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
## Licensed to Cloudera, Inc. under one
## or more contributor license agreements. See the NOTICE file
## distributed with this work for additional information
## regarding copyright ownership. Cloudera, Inc. licenses this file
## to you under the Apache License, Version 2.0 (the
## "License"); you may not use this file except in compliance
## with the License. You may obtain a copy of the License at
##
## http://www.apache.org/licenses/LICENSE-2.0
##
## Unless required by applicable law or agreed to in writing, software
## distributed under the License is distributed on an "AS IS" BASIS,
## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
## See the License for the specific language governing permissions and
## limitations under the License.

<!DOCTYPE html>
<html>
<head>
<title>Redirecting to login...</title>
</head>
<body>
<script>
var browserUrl = window.location.pathname + window.location.search + window.location.hash;
window.location.href = '${login_url}?${redirect_field_name}=' + encodeURIComponent(browserUrl);
Comment on lines +24 to +25
Copy link
Collaborator

Choose a reason for hiding this comment

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

@ranade1 What do you think, is it possible somehow to achieve this in middleware.py‎ so that we still can rely on standard browser redirects instead of JS redirect?

</script>
<noscript>
<p>Please <a href="${login_url}">click here to login</a>.</p>
</noscript>
</body>
</html>
Loading