Search in sources :

Example 1 with JsonResponse

use of org.apache.zeppelin.server.JsonResponse in project zeppelin by apache.

the class SecurityRestApi method ticket.

/**
   * Get ticket
   * Returns username & ticket
   * for anonymous access, username is always anonymous.
   * After getting this ticket, access through websockets become safe
   *
   * @return 200 response
   */
@GET
@Path("ticket")
@ZeppelinApi
public Response ticket() {
    ZeppelinConfiguration conf = ZeppelinConfiguration.create();
    String principal = SecurityUtils.getPrincipal();
    HashSet<String> roles = SecurityUtils.getRoles();
    JsonResponse response;
    // ticket set to anonymous for anonymous user. Simplify testing.
    String ticket;
    if ("anonymous".equals(principal))
        ticket = "anonymous";
    else
        ticket = TicketContainer.instance.getTicket(principal);
    Map<String, String> data = new HashMap<>();
    data.put("principal", principal);
    data.put("roles", roles.toString());
    data.put("ticket", ticket);
    response = new JsonResponse(Response.Status.OK, "", data);
    LOG.warn(response.toString());
    return response.build();
}
Also used : ZeppelinConfiguration(org.apache.zeppelin.conf.ZeppelinConfiguration) JsonResponse(org.apache.zeppelin.server.JsonResponse) Path(javax.ws.rs.Path) ZeppelinApi(org.apache.zeppelin.annotation.ZeppelinApi) GET(javax.ws.rs.GET)

Example 2 with JsonResponse

use of org.apache.zeppelin.server.JsonResponse in project zeppelin by apache.

the class NotebookRestApi method moveParagraph.

/**
   * Move paragraph REST API
   *
   * @param newIndex - new index to move
   * @return JSON with status.OK
   * @throws IOException
   */
@POST
@Path("{noteId}/paragraph/{paragraphId}/move/{newIndex}")
@ZeppelinApi
public Response moveParagraph(@PathParam("noteId") String noteId, @PathParam("paragraphId") String paragraphId, @PathParam("newIndex") String newIndex) throws IOException {
    LOG.info("move paragraph {} {} {}", noteId, paragraphId, newIndex);
    Note note = notebook.getNote(noteId);
    checkIfNoteIsNotNull(note);
    checkIfUserCanWrite(noteId, "Insufficient privileges you cannot move paragraph");
    Paragraph p = note.getParagraph(paragraphId);
    checkIfParagraphIsNotNull(p);
    try {
        note.moveParagraph(paragraphId, Integer.parseInt(newIndex), true);
        AuthenticationInfo subject = new AuthenticationInfo(SecurityUtils.getPrincipal());
        note.persist(subject);
        notebookServer.broadcastNote(note);
        return new JsonResponse(Status.OK, "").build();
    } catch (IndexOutOfBoundsException e) {
        LOG.error("Exception in NotebookRestApi while moveParagraph ", e);
        return new JsonResponse(Status.BAD_REQUEST, "paragraph's new index is out of bound").build();
    }
}
Also used : Note(org.apache.zeppelin.notebook.Note) AuthenticationInfo(org.apache.zeppelin.user.AuthenticationInfo) JsonResponse(org.apache.zeppelin.server.JsonResponse) Paragraph(org.apache.zeppelin.notebook.Paragraph) Path(javax.ws.rs.Path) ZeppelinApi(org.apache.zeppelin.annotation.ZeppelinApi) POST(javax.ws.rs.POST)

Example 3 with JsonResponse

use of org.apache.zeppelin.server.JsonResponse in project zeppelin by apache.

the class InterpreterRestApi method removeSetting.

/**
   * Remove interpreter setting
   */
@DELETE
@Path("setting/{settingId}")
@ZeppelinApi
public Response removeSetting(@PathParam("settingId") String settingId) throws IOException {
    logger.info("Remove interpreterSetting {}", settingId);
    interpreterSettingManager.remove(settingId);
    return new JsonResponse(Status.OK).build();
}
Also used : JsonResponse(org.apache.zeppelin.server.JsonResponse) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE) ZeppelinApi(org.apache.zeppelin.annotation.ZeppelinApi)

Example 4 with JsonResponse

use of org.apache.zeppelin.server.JsonResponse in project zeppelin by apache.

the class NotebookRestApi method deleteParagraph.

/**
   * Delete paragraph REST API
   *
   * @param noteId ID of Note
   * @return JSON with status.OK
   * @throws IOException
   */
@DELETE
@Path("{noteId}/paragraph/{paragraphId}")
@ZeppelinApi
public Response deleteParagraph(@PathParam("noteId") String noteId, @PathParam("paragraphId") String paragraphId) throws IOException {
    LOG.info("delete paragraph {} {}", noteId, paragraphId);
    Note note = notebook.getNote(noteId);
    checkIfNoteIsNotNull(note);
    checkIfUserCanRead(noteId, "Insufficient privileges you cannot remove paragraph from this note");
    Paragraph p = note.getParagraph(paragraphId);
    checkIfParagraphIsNotNull(p);
    AuthenticationInfo subject = new AuthenticationInfo(SecurityUtils.getPrincipal());
    note.removeParagraph(SecurityUtils.getPrincipal(), paragraphId);
    note.persist(subject);
    notebookServer.broadcastNote(note);
    return new JsonResponse(Status.OK, "").build();
}
Also used : Note(org.apache.zeppelin.notebook.Note) AuthenticationInfo(org.apache.zeppelin.user.AuthenticationInfo) JsonResponse(org.apache.zeppelin.server.JsonResponse) Paragraph(org.apache.zeppelin.notebook.Paragraph) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE) ZeppelinApi(org.apache.zeppelin.annotation.ZeppelinApi)

Example 5 with JsonResponse

use of org.apache.zeppelin.server.JsonResponse in project zeppelin by apache.

the class CredentialRestApi method getCredentials.

/**
   * Get User Credentials list REST API
   * @param
   * @return JSON with status.OK
   * @throws IOException, IllegalArgumentException
   */
@GET
public Response getCredentials(String message) throws IOException, IllegalArgumentException {
    String user = SecurityUtils.getPrincipal();
    logger.info("getCredentials credentials for user {} ", user);
    UserCredentials uc = credentials.getUserCredentials(user);
    return new JsonResponse(Status.OK, uc).build();
}
Also used : UserCredentials(org.apache.zeppelin.user.UserCredentials) JsonResponse(org.apache.zeppelin.server.JsonResponse)

Aggregations

JsonResponse (org.apache.zeppelin.server.JsonResponse)37 ZeppelinApi (org.apache.zeppelin.annotation.ZeppelinApi)22 Path (javax.ws.rs.Path)20 IOException (java.io.IOException)12 POST (javax.ws.rs.POST)12 UserCredentials (org.apache.zeppelin.user.UserCredentials)8 PUT (javax.ws.rs.PUT)6 Note (org.apache.zeppelin.notebook.Note)6 GET (javax.ws.rs.GET)5 Paragraph (org.apache.zeppelin.notebook.Paragraph)5 AuthenticationInfo (org.apache.zeppelin.user.AuthenticationInfo)5 HashMap (java.util.HashMap)4 Subject (org.apache.shiro.subject.Subject)4 ZeppelinConfiguration (org.apache.zeppelin.conf.ZeppelinConfiguration)4 InterpreterException (org.apache.zeppelin.interpreter.InterpreterException)4 Map (java.util.Map)3 DELETE (javax.ws.rs.DELETE)3 InterpreterSetting (org.apache.zeppelin.interpreter.InterpreterSetting)3 MetaStoreException (org.smartdata.metastore.MetaStoreException)3 UserInfo (org.smartdata.model.UserInfo)3