This commit is contained in:
cloverhearts 2016-12-28 23:55:08 -08:00
parent 754309ed4c
commit ed317886f2
2 changed files with 38 additions and 37 deletions

View file

@ -95,7 +95,7 @@ public class NotebookRestApi {
@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<>();
@ -113,8 +113,7 @@ public class NotebookRestApi {
"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.";
}
@ -129,7 +128,8 @@ public class NotebookRestApi {
*/
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);
}
}
@ -196,7 +196,7 @@ public class NotebookRestApi {
userAndRoles.add(principal);
userAndRoles.addAll(roles);
checkIfUserIsAnon(blockNotAuthenticatedUserError());
checkIfUserIsAnon(getBlockNotAuthenticatedUserErrorMsg());
checkIfUserIsOwner(noteId,
ownerPermissionError(userAndRoles, notebookAuthorization.getOwners(noteId)));

View file

@ -91,30 +91,26 @@
};
$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();
}
}]
});
}
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();
}
}]
});
}
};
@ -772,15 +768,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.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();
}
}
};