use of org.apache.zeppelin.server.JsonResponse in project zeppelin by apache.
the class ConfigurationsRestApi method getByPrefix.
@GET
@Path("prefix/{prefix}")
@ZeppelinApi
public Response getByPrefix(@PathParam("prefix") final String prefix) {
ZeppelinConfiguration conf = notebook.getConf();
Map<String, String> configurations = conf.dumpConfigurations(conf, new ZeppelinConfiguration.ConfigurationKeyPredicate() {
@Override
public boolean apply(String key) {
return !key.contains("password") && !key.equals(ZeppelinConfiguration.ConfVars.ZEPPELIN_NOTEBOOK_AZURE_CONNECTION_STRING.getVarName()) && key.startsWith(prefix);
}
});
return new JsonResponse(Status.OK, "", configurations).build();
}
use of org.apache.zeppelin.server.JsonResponse in project zeppelin by apache.
the class InterpreterRestApi method addRepository.
/**
* Add new repository
*
* @param message Repository
*/
@POST
@Path("repository")
@ZeppelinApi
public Response addRepository(String message) {
try {
Repository request = gson.fromJson(message, Repository.class);
interpreterSettingManager.addRepository(request.getId(), request.getUrl(), request.isSnapshot(), request.getAuthentication(), request.getProxy());
logger.info("New repository {} added", request.getId());
} catch (Exception e) {
logger.error("Exception in InterpreterRestApi while adding repository ", e);
return new JsonResponse<>(Status.INTERNAL_SERVER_ERROR, e.getMessage(), ExceptionUtils.getStackTrace(e)).build();
}
return new JsonResponse(Status.OK).build();
}
use of org.apache.zeppelin.server.JsonResponse in project zeppelin by apache.
the class InterpreterRestApi method updateSetting.
@PUT
@Path("setting/{settingId}")
@ZeppelinApi
public Response updateSetting(String message, @PathParam("settingId") String settingId) {
logger.info("Update interpreterSetting {}", settingId);
try {
UpdateInterpreterSettingRequest request = gson.fromJson(message, UpdateInterpreterSettingRequest.class);
interpreterSettingManager.setPropertyAndRestart(settingId, request.getOption(), request.getProperties(), request.getDependencies());
} catch (InterpreterException e) {
logger.error("Exception in InterpreterRestApi while updateSetting ", e);
return new JsonResponse<>(Status.NOT_FOUND, e.getMessage(), ExceptionUtils.getStackTrace(e)).build();
} catch (IOException e) {
logger.error("Exception in InterpreterRestApi while updateSetting ", e);
return new JsonResponse<>(Status.INTERNAL_SERVER_ERROR, e.getMessage(), ExceptionUtils.getStackTrace(e)).build();
}
InterpreterSetting setting = interpreterSettingManager.get(settingId);
if (setting == null) {
return new JsonResponse<>(Status.NOT_FOUND, "", settingId).build();
}
return new JsonResponse<>(Status.OK, "", setting).build();
}
use of org.apache.zeppelin.server.JsonResponse in project zeppelin by apache.
the class InterpreterRestApi method newSettings.
/**
* Add new interpreter setting
*
* @param message NewInterpreterSettingRequest
*/
@POST
@Path("setting")
@ZeppelinApi
public Response newSettings(String message) {
try {
NewInterpreterSettingRequest request = gson.fromJson(message, NewInterpreterSettingRequest.class);
if (request == null) {
return new JsonResponse<>(Status.BAD_REQUEST).build();
}
Properties p = new Properties();
p.putAll(request.getProperties());
InterpreterSetting interpreterSetting = interpreterSettingManager.createNewSetting(request.getName(), request.getGroup(), request.getDependencies(), request.getOption(), p);
logger.info("new setting created with {}", interpreterSetting.getId());
return new JsonResponse<>(Status.OK, "", interpreterSetting).build();
} catch (InterpreterException | IOException e) {
logger.error("Exception in InterpreterRestApi while creating ", e);
return new JsonResponse<>(Status.NOT_FOUND, e.getMessage(), ExceptionUtils.getStackTrace(e)).build();
}
}
use of org.apache.zeppelin.server.JsonResponse in project zeppelin by apache.
the class LoginRestApi method postLogin.
/**
* Post Login
* Returns userName & password
* for anonymous access, username is always anonymous.
* After getting this ticket, access through websockets become safe
*
* @return 200 response
*/
@POST
@ZeppelinApi
public Response postLogin(@FormParam("userName") String userName, @FormParam("password") String password) {
JsonResponse response = null;
// ticket set to anonymous for anonymous user. Simplify testing.
Subject currentUser = org.apache.shiro.SecurityUtils.getSubject();
if (currentUser.isAuthenticated()) {
currentUser.logout();
}
if (!currentUser.isAuthenticated()) {
try {
UsernamePasswordToken token = new UsernamePasswordToken(userName, password);
// token.setRememberMe(true);
currentUser.login(token);
HashSet<String> roles = SecurityUtils.getRoles();
String principal = SecurityUtils.getPrincipal();
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);
//if no exception, that's it, we're done!
//set roles for user in NotebookAuthorization module
NotebookAuthorization.getInstance().setRoles(principal, roles);
} catch (UnknownAccountException uae) {
//username wasn't in the system, show them an error message?
LOG.error("Exception in login: ", uae);
} catch (IncorrectCredentialsException ice) {
//password didn't match, try again?
LOG.error("Exception in login: ", ice);
} catch (LockedAccountException lae) {
//account for that username is locked - can't login. Show them a message?
LOG.error("Exception in login: ", lae);
} catch (AuthenticationException ae) {
//unexpected condition - error?
LOG.error("Exception in login: ", ae);
}
}
if (response == null) {
response = new JsonResponse(Response.Status.FORBIDDEN, "", "");
}
LOG.warn(response.toString());
return response.build();
}
Aggregations