Search in sources :

Example 6 with UsernamePassword

use of org.apache.zeppelin.user.UsernamePassword in project zeppelin by apache.

the class JDBCInterpreter method setUserProperty.

private void setUserProperty(String dbPrefix, InterpreterContext context) throws SQLException, IOException, InterpreterException {
    String user = getUser(context);
    JDBCUserConfigurations jdbcUserConfigurations = getJDBCConfiguration(user);
    if (basePropertiesMap.get(dbPrefix).containsKey(USER_KEY) && !basePropertiesMap.get(dbPrefix).getProperty(USER_KEY).isEmpty()) {
        String password = getPassword(basePropertiesMap.get(dbPrefix));
        if (!isEmpty(password)) {
            basePropertiesMap.get(dbPrefix).setProperty(PASSWORD_KEY, password);
        }
    }
    jdbcUserConfigurations.setPropertyMap(dbPrefix, basePropertiesMap.get(dbPrefix));
    if (existAccountInBaseProperty(dbPrefix)) {
        return;
    }
    UsernamePassword usernamePassword = getUsernamePassword(context, getEntityName(context.getReplName(), dbPrefix));
    if (usernamePassword != null) {
        jdbcUserConfigurations.cleanUserProperty(dbPrefix);
        jdbcUserConfigurations.setUserProperty(dbPrefix, usernamePassword);
    } else {
        closeDBPool(user, dbPrefix);
    }
}
Also used : UsernamePassword(org.apache.zeppelin.user.UsernamePassword)

Example 7 with UsernamePassword

use of org.apache.zeppelin.user.UsernamePassword 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
 */
@PUT
public Response putCredentials(String message) {
    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 (StringUtils.isEmpty(entity) || StringUtils.isEmpty(username) || StringUtils.isEmpty(password)) {
        return new JsonResponse<>(Status.BAD_REQUEST).build();
    }
    String user = authenticationService.getPrincipal();
    LOGGER.info("Update credentials for user {} entity {}", user, entity);
    UserCredentials uc;
    try {
        uc = credentials.getUserCredentials(user);
        uc.putUsernamePassword(entity, new UsernamePassword(username, password));
        credentials.putUserCredentials(user, uc);
        return new JsonResponse<>(Status.OK).build();
    } catch (IOException e) {
        LOGGER.error(e.getMessage(), e);
        return new JsonResponse<>(Status.INTERNAL_SERVER_ERROR).build();
    }
}
Also used : TypeToken(com.google.gson.reflect.TypeToken) UserCredentials(org.apache.zeppelin.user.UserCredentials) IOException(java.io.IOException) JsonResponse(org.apache.zeppelin.server.JsonResponse) UsernamePassword(org.apache.zeppelin.user.UsernamePassword) PUT(javax.ws.rs.PUT)

Aggregations

UsernamePassword (org.apache.zeppelin.user.UsernamePassword)7 UserCredentials (org.apache.zeppelin.user.UserCredentials)5 TypeToken (com.google.gson.reflect.TypeToken)2 InterpreterResult (org.apache.zeppelin.interpreter.InterpreterResult)2 JsonResponse (org.apache.zeppelin.server.JsonResponse)2 AuthenticationInfo (org.apache.zeppelin.user.AuthenticationInfo)2 Test (org.junit.Test)2 IOException (java.io.IOException)1 Matcher (java.util.regex.Matcher)1 PUT (javax.ws.rs.PUT)1 AngularObjectRegistry (org.apache.zeppelin.display.AngularObjectRegistry)1 AbstractInterpreterTest (org.apache.zeppelin.interpreter.AbstractInterpreterTest)1 Interpreter (org.apache.zeppelin.interpreter.Interpreter)1 InterpreterContext (org.apache.zeppelin.interpreter.InterpreterContext)1 ManagedInterpreterGroup (org.apache.zeppelin.interpreter.ManagedInterpreterGroup)1 ResourcePool (org.apache.zeppelin.resource.ResourcePool)1 Credentials (org.apache.zeppelin.user.Credentials)1 Ignore (org.junit.Ignore)1