mirror of
https://github.com/apache/zeppelin
synced 2026-05-24 09:38:26 +00:00
add isAnonymous
This commit is contained in:
parent
1a54cc0571
commit
b104249db8
2 changed files with 33 additions and 11 deletions
|
|
@ -18,13 +18,20 @@
|
|||
|
||||
package org.apache.zeppelin.user;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/***
|
||||
*
|
||||
*/
|
||||
public class AuthenticationInfo {
|
||||
private static final Logger LOG = LoggerFactory.getLogger(AuthenticationInfo.class);
|
||||
String user;
|
||||
String ticket;
|
||||
UserCredentials userCredentials;
|
||||
public static final AuthenticationInfo ANONYMOUS = new AuthenticationInfo("anonymous",
|
||||
"anonymous");
|
||||
|
||||
public AuthenticationInfo() {}
|
||||
|
||||
|
|
@ -66,4 +73,17 @@ public class AuthenticationInfo {
|
|||
this.userCredentials = userCredentials;
|
||||
}
|
||||
|
||||
public static boolean isAnonymous(AuthenticationInfo subject) {
|
||||
if (subject == null) {
|
||||
LOG.warn("Subject is null, assuming anonymous. "
|
||||
+ "Not recommended to use subject as null except in tests");
|
||||
return true;
|
||||
}
|
||||
return subject.isAnonymous();
|
||||
}
|
||||
|
||||
public boolean isAnonymous() {
|
||||
return ANONYMOUS.equals(this) || "anonymous".equalsIgnoreCase(this.getUser())
|
||||
|| StringUtils.isEmpty(this.getUser());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -249,18 +249,20 @@ public class NotebookRepoSync implements NotebookRepo {
|
|||
}
|
||||
|
||||
private void makePrivate(String noteId, AuthenticationInfo subject) {
|
||||
if (subject != null && !"anonymous".equals(subject.getUser())) {
|
||||
NotebookAuthorization notebookAuthorization = NotebookAuthorization.getInstance();
|
||||
Set<String> users = notebookAuthorization.getOwners(noteId);
|
||||
users.add(subject.getUser());
|
||||
notebookAuthorization.setOwners(noteId, users);
|
||||
users = notebookAuthorization.getReaders(noteId);
|
||||
users.add(subject.getUser());
|
||||
notebookAuthorization.setReaders(noteId, users);
|
||||
users = notebookAuthorization.getWriters(noteId);
|
||||
users.add(subject.getUser());
|
||||
notebookAuthorization.setWriters(noteId, users);
|
||||
if (AuthenticationInfo.isAnonymous(subject)) {
|
||||
LOG.info("User is anonymous, permissions are not set for pulled notes");
|
||||
return;
|
||||
}
|
||||
NotebookAuthorization notebookAuthorization = NotebookAuthorization.getInstance();
|
||||
Set<String> users = notebookAuthorization.getOwners(noteId);
|
||||
users.add(subject.getUser());
|
||||
notebookAuthorization.setOwners(noteId, users);
|
||||
users = notebookAuthorization.getReaders(noteId);
|
||||
users.add(subject.getUser());
|
||||
notebookAuthorization.setReaders(noteId, users);
|
||||
users = notebookAuthorization.getWriters(noteId);
|
||||
users.add(subject.getUser());
|
||||
notebookAuthorization.setWriters(noteId, users);
|
||||
}
|
||||
|
||||
private void deleteNotes(AuthenticationInfo subject, List<String> ids, NotebookRepo repo)
|
||||
|
|
|
|||
Loading…
Reference in a new issue