Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public NotebookRestApi(Notebook notebook, NotebookServer notebookServer, SearchS
@ZeppelinApi
public Response getNotePermissions(@PathParam("noteId") String noteId) throws IOException {

checkIfUserIsAnon(blockNotAuthenticatedUserError());
checkIfUserIsAnon(getBlockNotAuthenticatedUserErrorMsg());
checkIfUserCanRead(noteId,
"Insufficient privileges you cannot get the list of permissions for this note");
HashMap<String, Set<String>> permissionsMap = new HashMap<>();
Expand All @@ -113,8 +113,7 @@ private String ownerPermissionError(Set<String> current, Set<String> allowed) th
"User belongs to: " + current.toString();
}

private String blockNotAuthenticatedUserError() throws IOException {
LOG.info("Anonymous user cannot set any permissions for this note.");
private String getBlockNotAuthenticatedUserErrorMsg() throws IOException {
return "Only authenticated user can set the permission.";
}

Expand All @@ -129,7 +128,8 @@ private String blockNotAuthenticatedUserError() throws IOException {
*/
private void checkIfUserIsAnon(String errorMsg) {
boolean isAuthenticated = SecurityUtils.isAuthenticated();
if (!isAuthenticated) {
if (isAuthenticated && SecurityUtils.getPrincipal().equals("anonymous")) {
LOG.info("Anonymous user cannot set any permissions for this note.");
throw new ForbiddenException(errorMsg);
}
}
Expand Down Expand Up @@ -196,7 +196,7 @@ public Response putNotePermissions(@PathParam("noteId") String noteId, String re
userAndRoles.add(principal);
userAndRoles.addAll(roles);

checkIfUserIsAnon(blockNotAuthenticatedUserError());
checkIfUserIsAnon(getBlockNotAuthenticatedUserErrorMsg());
checkIfUserIsOwner(noteId,
ownerPermissionError(userAndRoles, notebookAuthorization.getOwners(noteId)));

Expand Down
65 changes: 32 additions & 33 deletions zeppelin-web/src/app/notebook/notebook.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,31 +91,25 @@
};

$scope.blockAnonUsers = function() {
var principal = $rootScope.ticket.principal;
if (principal) {
$scope.isAnonymous = principal === 'anonymous' ? true : false;
if ($scope.isAnonymous) {
var zeppelinVersion = $rootScope.zeppelinVersion;
var url = 'https://zeppelin.apache.org/docs/' + zeppelinVersion + '/security/notebook_authorization.html';
var content = 'Only authenticated user can set the permission.' +
'<a data-toggle="tooltip" data-placement="top" title="Learn more" target="_blank" href=' + url + '>' +
'<i class="icon-question" />' +
'</a>';
BootstrapDialog.show({
closable: false,
closeByBackdrop: false,
closeByKeyboard: false,
title: 'No permission',
message: content,
buttons: [{
label: 'Close',
action: function(dialog) {
dialog.close();
}
}]
});
}
}
var zeppelinVersion = $rootScope.zeppelinVersion;
var url = 'https://zeppelin.apache.org/docs/' + zeppelinVersion + '/security/notebook_authorization.html';
var content = 'Only authenticated user can set the permission.' +
'<a data-toggle="tooltip" data-placement="top" title="Learn more" target="_blank" href=' + url + '>' +
'<i class="icon-question" />' +
'</a>';
BootstrapDialog.show({
closable: false,
closeByBackdrop: false,
closeByKeyboard: false,
title: 'No permission',
message: content,
buttons: [{
label: 'Close',
action: function(dialog) {
dialog.close();
}
}]
});
};

/** Init the new controller */
Expand Down Expand Up @@ -772,15 +766,20 @@
};

$scope.togglePermissions = function() {
$scope.blockAnonUsers();
if ($scope.showPermissions) {
$scope.closePermissions();
angular.element('#selectOwners').select2({});
angular.element('#selectReaders').select2({});
angular.element('#selectWriters').select2({});
var principal = $rootScope.ticket.principal;
$scope.isAnonymous = principal === 'anonymous' ? true : false;
if (!!principal && $scope.isAnonymous) {
$scope.blockAnonUsers();
} else {
$scope.openPermissions();
$scope.closeSetting();
if ($scope.showPermissions) {
$scope.closePermissions();
angular.element('#selectOwners').select2({});
angular.element('#selectReaders').select2({});
angular.element('#selectWriters').select2({});
} else {
$scope.openPermissions();
$scope.closeSetting();
}
}
};

Expand Down