Search in sources :

Example 1 with NotebookAuthorization

use of org.apache.zeppelin.notebook.NotebookAuthorization in project SSM by Intel-bigdata.

the class NotebookRepoSync method makePrivate.

private void makePrivate(String noteId, AuthenticationInfo subject) {
    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);
}
Also used : NotebookAuthorization(org.apache.zeppelin.notebook.NotebookAuthorization)

Example 2 with NotebookAuthorization

use of org.apache.zeppelin.notebook.NotebookAuthorization in project SSM by Intel-bigdata.

the class ZeppelinClient method relayToAllZeppelinHub.

private void relayToAllZeppelinHub(ZeppelinhubMessage hubMsg, String noteId) {
    if (StringUtils.isBlank(noteId)) {
        return;
    }
    NotebookAuthorization noteAuth = NotebookAuthorization.getInstance();
    Map<String, String> userTokens = UserTokenContainer.getInstance().getAllUserTokens();
    Client client = Client.getInstance();
    Set<String> userAndRoles;
    String token;
    for (String user : userTokens.keySet()) {
        userAndRoles = noteAuth.getRoles(user);
        userAndRoles.add(user);
        if (noteAuth.isReader(noteId, userAndRoles)) {
            token = userTokens.get(user);
            hubMsg.meta.put("token", token);
            client.relayToZeppelinHub(hubMsg.serialize(), token);
        }
    }
}
Also used : NotebookAuthorization(org.apache.zeppelin.notebook.NotebookAuthorization) WebSocketClient(org.eclipse.jetty.websocket.client.WebSocketClient)

Example 3 with NotebookAuthorization

use of org.apache.zeppelin.notebook.NotebookAuthorization in project zeppelin by apache.

the class NotebookRepoSync method makePrivate.

private void makePrivate(String noteId, AuthenticationInfo subject) {
    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);
}
Also used : NotebookAuthorization(org.apache.zeppelin.notebook.NotebookAuthorization)

Example 4 with NotebookAuthorization

use of org.apache.zeppelin.notebook.NotebookAuthorization in project zeppelin by apache.

the class NotebookServer method broadcastNoteListExcept.

private void broadcastNoteListExcept(List<Map<String, String>> notesInfo, AuthenticationInfo subject) {
    Set<String> userAndRoles;
    NotebookAuthorization authInfo = NotebookAuthorization.getInstance();
    for (String user : userConnectedSockets.keySet()) {
        if (subject.getUser().equals(user)) {
            continue;
        }
        //reloaded already above; parameter - false
        userAndRoles = authInfo.getRoles(user);
        userAndRoles.add(user);
        notesInfo = generateNotesInfo(false, new AuthenticationInfo(user), userAndRoles);
        multicastToUser(user, new Message(OP.NOTES_INFO).put("notes", notesInfo));
    }
}
Also used : NotebookAuthorization(org.apache.zeppelin.notebook.NotebookAuthorization) InterpreterResultMessage(org.apache.zeppelin.interpreter.InterpreterResultMessage) Message(org.apache.zeppelin.notebook.socket.Message) WatcherMessage(org.apache.zeppelin.notebook.socket.WatcherMessage) AuthenticationInfo(org.apache.zeppelin.user.AuthenticationInfo)

Example 5 with NotebookAuthorization

use of org.apache.zeppelin.notebook.NotebookAuthorization in project SSM by Intel-bigdata.

the class NotebookRepoSync method sync.

/**
 * Copies new/updated notes from source to destination storage
 *
 * @throws IOException
 */
void sync(int sourceRepoIndex, int destRepoIndex, AuthenticationInfo subject) throws IOException {
    LOG.info("Sync started");
    NotebookAuthorization auth = NotebookAuthorization.getInstance();
    NotebookRepo srcRepo = getRepo(sourceRepoIndex);
    NotebookRepo dstRepo = getRepo(destRepoIndex);
    List<NoteInfo> allSrcNotes = srcRepo.list(subject);
    List<NoteInfo> srcNotes = auth.filterByUser(allSrcNotes, subject);
    List<NoteInfo> dstNotes = dstRepo.list(subject);
    Map<String, List<String>> noteIds = notesCheckDiff(srcNotes, srcRepo, dstNotes, dstRepo, subject);
    List<String> pushNoteIds = noteIds.get(pushKey);
    List<String> pullNoteIds = noteIds.get(pullKey);
    List<String> delDstNoteIds = noteIds.get(delDstKey);
    if (!pushNoteIds.isEmpty()) {
        LOG.info("Notes with the following IDs will be pushed");
        for (String id : pushNoteIds) {
            LOG.info("ID : " + id);
        }
        pushNotes(subject, pushNoteIds, srcRepo, dstRepo, false);
    } else {
        LOG.info("Nothing to push");
    }
    if (!pullNoteIds.isEmpty()) {
        LOG.info("Notes with the following IDs will be pulled");
        for (String id : pullNoteIds) {
            LOG.info("ID : " + id);
        }
        pushNotes(subject, pullNoteIds, dstRepo, srcRepo, true);
    } else {
        LOG.info("Nothing to pull");
    }
    if (!delDstNoteIds.isEmpty()) {
        LOG.info("Notes with the following IDs will be deleted from dest");
        for (String id : delDstNoteIds) {
            LOG.info("ID : " + id);
        }
        deleteNotes(subject, delDstNoteIds, dstRepo);
    } else {
        LOG.info("Nothing to delete from dest");
    }
    LOG.info("Sync ended");
}
Also used : NotebookAuthorization(org.apache.zeppelin.notebook.NotebookAuthorization) NoteInfo(org.apache.zeppelin.notebook.NoteInfo) ArrayList(java.util.ArrayList) List(java.util.List)

Aggregations

NotebookAuthorization (org.apache.zeppelin.notebook.NotebookAuthorization)5 ArrayList (java.util.ArrayList)1 List (java.util.List)1 InterpreterResultMessage (org.apache.zeppelin.interpreter.InterpreterResultMessage)1 NoteInfo (org.apache.zeppelin.notebook.NoteInfo)1 Message (org.apache.zeppelin.notebook.socket.Message)1 WatcherMessage (org.apache.zeppelin.notebook.socket.WatcherMessage)1 AuthenticationInfo (org.apache.zeppelin.user.AuthenticationInfo)1 WebSocketClient (org.eclipse.jetty.websocket.client.WebSocketClient)1