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);
}
}
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();
}
}
Aggregations