Search in sources :

Example 86 with AuthenticationInfo

use of org.apache.zeppelin.user.AuthenticationInfo in project zeppelin by apache.

the class NotebookServer method renameNote.

private void renameNote(NotebookSocket conn, HashSet<String> userAndRoles, Notebook notebook, Message fromMessage, String op) throws SchedulerException, IOException {
    String noteId = (String) fromMessage.get("id");
    String name = (String) fromMessage.get("name");
    if (noteId == null) {
        return;
    }
    if (!hasParagraphOwnerPermission(conn, notebook, noteId, userAndRoles, fromMessage.principal, "rename")) {
        return;
    }
    Note note = notebook.getNote(noteId);
    if (note != null) {
        note.setName(name);
        AuthenticationInfo subject = new AuthenticationInfo(fromMessage.principal);
        note.persist(subject);
        broadcastNote(note);
        broadcastNoteList(subject, userAndRoles);
    }
}
Also used : Note(org.apache.zeppelin.notebook.Note) AuthenticationInfo(org.apache.zeppelin.user.AuthenticationInfo)

Example 87 with AuthenticationInfo

use of org.apache.zeppelin.user.AuthenticationInfo in project zeppelin by apache.

the class NotebookServer method cloneNote.

private void cloneNote(NotebookSocket conn, HashSet<String> userAndRoles, Notebook notebook, Message fromMessage) throws IOException, CloneNotSupportedException {
    String noteId = getOpenNoteId(conn);
    String name = (String) fromMessage.get("name");
    Note newNote = notebook.cloneNote(noteId, name, new AuthenticationInfo(fromMessage.principal));
    AuthenticationInfo subject = new AuthenticationInfo(fromMessage.principal);
    addConnectionToNote(newNote.getId(), (NotebookSocket) conn);
    conn.send(serializeMessage(new Message(OP.NEW_NOTE).put("note", newNote)));
    broadcastNoteList(subject, userAndRoles);
}
Also used : InterpreterResultMessage(org.apache.zeppelin.interpreter.InterpreterResultMessage) Message(org.apache.zeppelin.notebook.socket.Message) WatcherMessage(org.apache.zeppelin.notebook.socket.WatcherMessage) Note(org.apache.zeppelin.notebook.Note) AuthenticationInfo(org.apache.zeppelin.user.AuthenticationInfo)

Example 88 with AuthenticationInfo

use of org.apache.zeppelin.user.AuthenticationInfo in project zeppelin by apache.

the class NotebookServer method createNote.

private void createNote(NotebookSocket conn, HashSet<String> userAndRoles, Notebook notebook, Message message) throws IOException {
    AuthenticationInfo subject = new AuthenticationInfo(message.principal);
    try {
        Note note = null;
        String defaultInterpreterId = (String) message.get("defaultInterpreterId");
        if (!StringUtils.isEmpty(defaultInterpreterId)) {
            List<String> interpreterSettingIds = new LinkedList<>();
            interpreterSettingIds.add(defaultInterpreterId);
            for (String interpreterSettingId : notebook.getInterpreterSettingManager().getDefaultInterpreterSettingList()) {
                if (!interpreterSettingId.equals(defaultInterpreterId)) {
                    interpreterSettingIds.add(interpreterSettingId);
                }
            }
            note = notebook.createNote(interpreterSettingIds, subject);
        } else {
            note = notebook.createNote(subject);
        }
        // it's an empty note. so add one paragraph
        note.addParagraph(subject);
        if (message != null) {
            String noteName = (String) message.get("name");
            if (StringUtils.isEmpty(noteName)) {
                noteName = "Note " + note.getId();
            }
            note.setName(noteName);
        }
        note.persist(subject);
        addConnectionToNote(note.getId(), (NotebookSocket) conn);
        conn.send(serializeMessage(new Message(OP.NEW_NOTE).put("note", note)));
    } catch (FileSystemException e) {
        LOG.error("Exception from createNote", e);
        conn.send(serializeMessage(new Message(OP.ERROR_INFO).put("info", "Oops! There is something wrong with the notebook file system. " + "Please check the logs for more details.")));
        return;
    }
    broadcastNoteList(subject, userAndRoles);
}
Also used : FileSystemException(org.apache.commons.vfs2.FileSystemException) InterpreterResultMessage(org.apache.zeppelin.interpreter.InterpreterResultMessage) Message(org.apache.zeppelin.notebook.socket.Message) WatcherMessage(org.apache.zeppelin.notebook.socket.WatcherMessage) Note(org.apache.zeppelin.notebook.Note) AuthenticationInfo(org.apache.zeppelin.user.AuthenticationInfo) LinkedList(java.util.LinkedList)

Example 89 with AuthenticationInfo

use of org.apache.zeppelin.user.AuthenticationInfo in project zeppelin by apache.

the class NotebookServer method removeFolder.

private void removeFolder(NotebookSocket conn, HashSet<String> userAndRoles, Notebook notebook, Message fromMessage) throws SchedulerException, IOException {
    String folderId = (String) fromMessage.get("id");
    if (folderId == null) {
        return;
    }
    List<Note> notes = notebook.getNotesUnderFolder(folderId);
    for (Note note : notes) {
        String noteId = note.getId();
        if (!hasParagraphOwnerPermission(conn, notebook, noteId, userAndRoles, fromMessage.principal, "remove folder of '" + note.getName() + "'")) {
            return;
        }
    }
    AuthenticationInfo subject = new AuthenticationInfo(fromMessage.principal);
    for (Note note : notes) {
        notebook.removeNote(note.getId(), subject);
        removeNote(note.getId());
    }
    broadcastNoteList(subject, userAndRoles);
}
Also used : Note(org.apache.zeppelin.notebook.Note) AuthenticationInfo(org.apache.zeppelin.user.AuthenticationInfo)

Example 90 with AuthenticationInfo

use of org.apache.zeppelin.user.AuthenticationInfo in project zeppelin by apache.

the class NotebookServer method onRemoteRunParagraph.

@Override
public void onRemoteRunParagraph(String noteId, String paragraphId) throws Exception {
    Notebook notebookIns = notebook();
    try {
        if (notebookIns == null) {
            throw new Exception("onRemoteRunParagraph notebook instance is null");
        }
        Note noteIns = notebookIns.getNote(noteId);
        if (noteIns == null) {
            throw new Exception(String.format("Can't found note id %s", noteId));
        }
        Paragraph paragraph = noteIns.getParagraph(paragraphId);
        if (paragraph == null) {
            throw new Exception(String.format("Can't found paragraph %s %s", noteId, paragraphId));
        }
        Set<String> userAndRoles = Sets.newHashSet();
        userAndRoles.add(SecurityUtils.getPrincipal());
        userAndRoles.addAll(SecurityUtils.getRoles());
        if (!notebookIns.getNotebookAuthorization().hasWriteAuthorization(userAndRoles, noteId)) {
            throw new ForbiddenException(String.format("can't execute note %s", noteId));
        }
        AuthenticationInfo subject = new AuthenticationInfo(SecurityUtils.getPrincipal());
        paragraph.setAuthenticationInfo(subject);
        noteIns.run(paragraphId);
    } catch (Exception e) {
        throw e;
    }
}
Also used : ForbiddenException(org.apache.zeppelin.rest.exception.ForbiddenException) Notebook(org.apache.zeppelin.notebook.Notebook) Note(org.apache.zeppelin.notebook.Note) URISyntaxException(java.net.URISyntaxException) FileSystemException(org.apache.commons.vfs2.FileSystemException) ForbiddenException(org.apache.zeppelin.rest.exception.ForbiddenException) SchedulerException(org.quartz.SchedulerException) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException) AuthenticationInfo(org.apache.zeppelin.user.AuthenticationInfo) Paragraph(org.apache.zeppelin.notebook.Paragraph)

Aggregations

AuthenticationInfo (org.apache.zeppelin.user.AuthenticationInfo)128 Test (org.junit.Test)44 HashMap (java.util.HashMap)40 AngularObjectRegistry (org.apache.zeppelin.display.AngularObjectRegistry)29 Properties (java.util.Properties)28 Note (org.apache.zeppelin.notebook.Note)27 LocalResourcePool (org.apache.zeppelin.resource.LocalResourcePool)23 LinkedList (java.util.LinkedList)22 GUI (org.apache.zeppelin.display.GUI)22 Map (java.util.Map)21 ZeppelinApi (org.apache.zeppelin.annotation.ZeppelinApi)20 AngularObject (org.apache.zeppelin.display.AngularObject)19 InterpreterResultMessage (org.apache.zeppelin.interpreter.InterpreterResultMessage)19 IOException (java.io.IOException)18 InterpreterContext (org.apache.zeppelin.interpreter.InterpreterContext)18 InterpreterResult (org.apache.zeppelin.interpreter.InterpreterResult)18 Paragraph (org.apache.zeppelin.notebook.Paragraph)18 InterpreterOutput (org.apache.zeppelin.interpreter.InterpreterOutput)16 Path (javax.ws.rs.Path)15 HashSet (java.util.HashSet)13