Search in sources :

Example 1 with ForbiddenException

use of org.apache.zeppelin.rest.exception.ForbiddenException 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

IOException (java.io.IOException)1 URISyntaxException (java.net.URISyntaxException)1 UnknownHostException (java.net.UnknownHostException)1 FileSystemException (org.apache.commons.vfs2.FileSystemException)1 Note (org.apache.zeppelin.notebook.Note)1 Notebook (org.apache.zeppelin.notebook.Notebook)1 Paragraph (org.apache.zeppelin.notebook.Paragraph)1 ForbiddenException (org.apache.zeppelin.rest.exception.ForbiddenException)1 AuthenticationInfo (org.apache.zeppelin.user.AuthenticationInfo)1 SchedulerException (org.quartz.SchedulerException)1