From cad16ed27f37348ba717418dd601db0795ebfc1a Mon Sep 17 00:00:00 2001 From: alena Date: Thu, 16 Jun 2011 11:30:41 -0700 Subject: [PATCH] bug 10325: renamed apiKey/secretKey to userApiKey/userSecretKey in updateUser api call This reverts commit 927508215de383bdcc5b2e289e5103e011d72843. --- api/src/com/cloud/api/ApiConstants.java | 4 ++-- .../com/cloud/api/commands/UpdateUserCmd.java | 4 ++-- .../com/cloud/api/response/UserResponse.java | 5 +++-- .../com/cloud/user/AccountManagerImpl.java | 21 ++----------------- 4 files changed, 9 insertions(+), 25 deletions(-) diff --git a/api/src/com/cloud/api/ApiConstants.java b/api/src/com/cloud/api/ApiConstants.java index 977baeba4f1..7353384100b 100755 --- a/api/src/com/cloud/api/ApiConstants.java +++ b/api/src/com/cloud/api/ApiConstants.java @@ -24,7 +24,7 @@ public class ApiConstants { public static final String ACCOUNT_ID = "accountid"; public static final String ALGORITHM = "algorithm"; public static final String ALLOCATED_ONLY = "allocatedonly"; - public static final String API_KEY = "apikey"; + public static final String API_KEY = "userapikey"; public static final String APPLIED = "applied"; public static final String AVAILABLE = "available"; public static final String BITS = "bits"; @@ -144,7 +144,7 @@ public class ApiConstants { public static final String RESOURCE_TYPE = "resourcetype"; public static final String SCHEDULE = "schedule"; public static final String SCOPE = "scope"; - public static final String SECRET_KEY = "secretkey"; + public static final String SECRET_KEY = "usersecretkey"; public static final String SECURITY_GROUP_IDS = "securitygroupids"; public static final String SECURITY_GROUP_NAMES = "securitygroupnames"; public static final String SECURITY_GROUP_NAME = "securitygroupname"; diff --git a/api/src/com/cloud/api/commands/UpdateUserCmd.java b/api/src/com/cloud/api/commands/UpdateUserCmd.java index cb38111d648..8709a45aca1 100644 --- a/api/src/com/cloud/api/commands/UpdateUserCmd.java +++ b/api/src/com/cloud/api/commands/UpdateUserCmd.java @@ -41,7 +41,7 @@ public class UpdateUserCmd extends BaseCmd { //////////////// API parameters ///////////////////// ///////////////////////////////////////////////////// - @Parameter(name=ApiConstants.API_KEY, type=CommandType.STRING, description="The API key for the user. Must be specified with secretKey") + @Parameter(name=ApiConstants.API_KEY, type=CommandType.STRING, description="The API key for the user. Must be specified with userSecretKey") private String apiKey; @Parameter(name=ApiConstants.EMAIL, type=CommandType.STRING, description="email") @@ -59,7 +59,7 @@ public class UpdateUserCmd extends BaseCmd { @Parameter(name=ApiConstants.PASSWORD, type=CommandType.STRING, description="Hashed password (default is MD5). If you wish to use any other hasing algorithm, you would need to write a custom authentication adapter") private String password; - @Parameter(name=ApiConstants.SECRET_KEY, type=CommandType.STRING, description="The secret key for the user. Must be specified with apiKey") + @Parameter(name=ApiConstants.SECRET_KEY, type=CommandType.STRING, description="The secret key for the user. Must be specified with userApiKey") private String secretKey; @Parameter(name=ApiConstants.TIMEZONE, type=CommandType.STRING, description="Specifies a timezone for this command. For more information on the timezone parameter, see Time Zone Format.") diff --git a/api/src/com/cloud/api/response/UserResponse.java b/api/src/com/cloud/api/response/UserResponse.java index 4df9802d3d5..d4d44d2b5c6 100644 --- a/api/src/com/cloud/api/response/UserResponse.java +++ b/api/src/com/cloud/api/response/UserResponse.java @@ -19,6 +19,7 @@ package com.cloud.api.response; import java.util.Date; +import com.cloud.api.ApiConstants; import com.cloud.serializer.Param; import com.google.gson.annotations.SerializedName; @@ -59,10 +60,10 @@ public class UserResponse extends BaseResponse { @SerializedName("timezone") @Param(description="the timezone user was created in") private String timezone; - @SerializedName("apikey") @Param(description="the api key of the user") + @SerializedName(ApiConstants.API_KEY) @Param(description="the api key of the user") private String apiKey; - @SerializedName("secretkey") @Param(description="the secret key of the user") + @SerializedName(ApiConstants.SECRET_KEY) @Param(description="the secret key of the user") private String secretKey; public Long getId() { diff --git a/server/src/com/cloud/user/AccountManagerImpl.java b/server/src/com/cloud/user/AccountManagerImpl.java index da29087cc50..f584aa1aef1 100755 --- a/server/src/com/cloud/user/AccountManagerImpl.java +++ b/server/src/com/cloud/user/AccountManagerImpl.java @@ -1400,8 +1400,6 @@ public class AccountManagerImpl implements AccountManager, AccountService, Manag String secretKey = cmd.getSecretKey(); String timeZone = cmd.getTimezone(); String userName = cmd.getUsername(); - - long callerUserId = UserContext.current().getCallerUserId(); // Input validation UserVO user = _userDao.getUser(id); @@ -1409,24 +1407,9 @@ public class AccountManagerImpl implements AccountManager, AccountService, Manag if (user == null) { throw new InvalidParameterValueException("unable to find user by id"); } - - if (apiKey != null) { - Long apiKeyOwnerId = null; - Pair apiKeyOwner = _accountDao.findUserAccountByApiKey(apiKey); - if (apiKeyOwner != null) { - apiKeyOwnerId = apiKeyOwner.first().getId(); - } - - if ((apiKeyOwnerId == null || callerUserId != apiKeyOwnerId) && secretKey == null) { - throw new InvalidParameterValueException("Please provide an api key/secret key pair"); - } else if (apiKeyOwnerId != null && callerUserId == apiKeyOwnerId && id != callerUserId) { - // No need to update api key if provided api key belongs to the caller and caller updates api key for someone else - apiKey = null; - } - } - if (apiKey == null && secretKey != null) { - throw new InvalidParameterValueException("Please provide an api key/secret key pair"); + if ((apiKey == null && secretKey != null) || (apiKey != null && secretKey == null)) { + throw new InvalidParameterValueException("Please provide an userApiKey/userSecretKey pair"); } // If the account is an admin type, return an error. We do not allow this