Search in sources :

Example 6 with UserCredentials

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();
}
Also used : TypeToken(com.google.gson.reflect.TypeToken) UserCredentials(org.apache.zeppelin.user.UserCredentials) JsonResponse(org.apache.zeppelin.server.JsonResponse) UsernamePassword(org.apache.zeppelin.user.UsernamePassword)

Example 7 with UserCredentials

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;
}
Also used : TypeToken(com.google.gson.reflect.TypeToken) GetMethod(org.apache.commons.httpclient.methods.GetMethod) UserCredentials(org.apache.zeppelin.user.UserCredentials) Map(java.util.Map)

Aggregations

UserCredentials (org.apache.zeppelin.user.UserCredentials)7 JsonResponse (org.apache.zeppelin.server.JsonResponse)3 TypeToken (com.google.gson.reflect.TypeToken)2 AngularObjectRegistry (org.apache.zeppelin.display.AngularObjectRegistry)2 ResourcePool (org.apache.zeppelin.resource.ResourcePool)2 Credentials (org.apache.zeppelin.user.Credentials)2 UsernamePassword (org.apache.zeppelin.user.UsernamePassword)2 Map (java.util.Map)1 GetMethod (org.apache.commons.httpclient.methods.GetMethod)1 AuthenticationInfo (org.apache.zeppelin.user.AuthenticationInfo)1