use of org.apache.zeppelin.user.UserCredentials in project zeppelin by apache.
the class CredentialRestApi method putCredentials.
/**
* Put User Credentials REST API
* @param message - JSON with entity, username, password.
* @return JSON with status.OK
* @throws IOException, IllegalArgumentException
*/
@PUT
public Response putCredentials(String message) throws IOException, IllegalArgumentException {
Map<String, String> messageMap = gson.fromJson(message, new TypeToken<Map<String, String>>() {
}.getType());
String entity = messageMap.get("entity");
String username = messageMap.get("username");
String password = messageMap.get("password");
if (Strings.isNullOrEmpty(entity) || Strings.isNullOrEmpty(username) || Strings.isNullOrEmpty(password)) {
return new JsonResponse(Status.BAD_REQUEST).build();
}
String user = SecurityUtils.getPrincipal();
logger.info("Update credentials for user {} entity {}", user, entity);
UserCredentials uc = credentials.getUserCredentials(user);
uc.putUsernamePassword(entity, new UsernamePassword(username, password));
credentials.putUserCredentials(user, uc);
return new JsonResponse(Status.OK).build();
}
use of org.apache.zeppelin.user.UserCredentials in project zeppelin by apache.
the class CredentialsRestApiTest method testGetUserCredentials.
public Map<String, UserCredentials> testGetUserCredentials() throws IOException {
GetMethod getMethod = httpGet("/credential");
getMethod.addRequestHeader("Origin", "http://localhost");
Map<String, Object> resp = gson.fromJson(getMethod.getResponseBodyAsString(), new TypeToken<Map<String, Object>>() {
}.getType());
Map<String, Object> body = (Map<String, Object>) resp.get("body");
Map<String, UserCredentials> credentialMap = (Map<String, UserCredentials>) body.get("userCredentials");
getMethod.releaseConnection();
return credentialMap;
}
Aggregations