You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by bh...@apache.org on 2012/12/06 00:01:15 UTC
[1/10] git commit: api_refactor: refactor user apis
Updated Branches:
refs/heads/api_refactoring ee0a4a41d -> ceddaf122
api_refactor: refactor user apis
Signed-off-by: Rohit Yadav <bh...@apache.org>
Project: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/commit/ceddaf12
Tree: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/tree/ceddaf12
Diff: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/diff/ceddaf12
Branch: refs/heads/api_refactoring
Commit: ceddaf122cdd857cd8269184dc0a478962095d35
Parents: ba8e61b
Author: Rohit Yadav <bh...@apache.org>
Authored: Wed Dec 5 14:55:58 2012 -0800
Committer: Rohit Yadav <bh...@apache.org>
Committed: Wed Dec 5 14:55:58 2012 -0800
----------------------------------------------------------------------
api/src/com/cloud/api/commands/CreateUserCmd.java | 143 ---------------
api/src/com/cloud/api/commands/DeleteUserCmd.java | 84 ---------
api/src/com/cloud/api/commands/DisableUserCmd.java | 104 -----------
api/src/com/cloud/api/commands/EnableUserCmd.java | 86 ---------
api/src/com/cloud/api/commands/GetUserCmd.java | 76 --------
api/src/com/cloud/api/commands/ListUsersCmd.java | 100 ----------
api/src/com/cloud/api/commands/UpdateUserCmd.java | 142 --------------
api/src/com/cloud/user/AccountService.java | 6 +-
.../api/admin/user/command/CreateUserCmd.java | 143 +++++++++++++++
.../api/admin/user/command/DeleteUserCmd.java | 84 +++++++++
.../api/admin/user/command/DisableUserCmd.java | 104 +++++++++++
.../api/admin/user/command/EnableUserCmd.java | 86 +++++++++
.../api/admin/user/command/GetUserCmd.java | 76 ++++++++
.../api/admin/user/command/ListUsersCmd.java | 100 ++++++++++
.../api/admin/user/command/UpdateUserCmd.java | 142 ++++++++++++++
client/tomcatconf/commands.properties.in | 14 +-
server/src/com/cloud/user/AccountManagerImpl.java | 6 +-
.../com/cloud/user/MockAccountManagerImpl.java | 6 +-
18 files changed, 751 insertions(+), 751 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/ceddaf12/api/src/com/cloud/api/commands/CreateUserCmd.java
----------------------------------------------------------------------
diff --git a/api/src/com/cloud/api/commands/CreateUserCmd.java b/api/src/com/cloud/api/commands/CreateUserCmd.java
deleted file mode 100644
index 95b11dc..0000000
--- a/api/src/com/cloud/api/commands/CreateUserCmd.java
+++ /dev/null
@@ -1,143 +0,0 @@
-// Licensed to the Apache Software Foundation (ASF) under one
-// or more contributor license agreements. See the NOTICE file
-// distributed with this work for additional information
-// regarding copyright ownership. The ASF licenses this file
-// to you under the Apache License, Version 2.0 (the
-// "License"); you may not use this file except in compliance
-// with the License. You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing,
-// software distributed under the License is distributed on an
-// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-// KIND, either express or implied. See the License for the
-// specific language governing permissions and limitations
-// under the License.
-package com.cloud.api.commands;
-
-import org.apache.log4j.Logger;
-
-import org.apache.cloudstack.api.ApiConstants;
-import org.apache.cloudstack.api.BaseCmd;
-import org.apache.cloudstack.api.IdentityMapper;
-import org.apache.cloudstack.api.Implementation;
-import org.apache.cloudstack.api.Parameter;
-import org.apache.cloudstack.api.ServerApiException;
-import com.cloud.api.response.UserResponse;
-import com.cloud.user.Account;
-import com.cloud.user.User;
-import com.cloud.user.UserContext;
-
-@Implementation(description="Creates a user for an account that already exists", responseObject=UserResponse.class)
-public class CreateUserCmd extends BaseCmd {
- public static final Logger s_logger = Logger.getLogger(CreateUserCmd.class.getName());
-
- private static final String s_name = "createuserresponse";
-
- /////////////////////////////////////////////////////
- //////////////// API parameters /////////////////////
- /////////////////////////////////////////////////////
-
- @Parameter(name=ApiConstants.ACCOUNT, type=CommandType.STRING, required=true, description="Creates the user under the specified account. If no account is specified, the username will be used as the account name.")
- private String accountName;
-
- @IdentityMapper(entityTableName="domain")
- @Parameter(name=ApiConstants.DOMAIN_ID, type=CommandType.LONG, description="Creates the user under the specified domain. Has to be accompanied with the account parameter")
- private Long domainId;
-
- @Parameter(name=ApiConstants.EMAIL, type=CommandType.STRING, required=true, description="email")
- private String email;
-
- @Parameter(name=ApiConstants.FIRSTNAME, type=CommandType.STRING, required=true, description="firstname")
- private String firstname;
-
- @Parameter(name=ApiConstants.LASTNAME, type=CommandType.STRING, required=true, description="lastname")
- private String lastname;
-
- @Parameter(name=ApiConstants.PASSWORD, type=CommandType.STRING, required=true, description="Hashed password (Default is MD5). If you wish to use any other hashing algorithm, you would need to write a custom authentication adapter See Docs section.")
- private String password;
-
- @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.")
- private String timezone;
-
- @Parameter(name=ApiConstants.USERNAME, type=CommandType.STRING, required=true, description="Unique username.")
- private String username;
-
- /////////////////////////////////////////////////////
- /////////////////// Accessors ///////////////////////
- /////////////////////////////////////////////////////
-
- public String getAccountName() {
- return accountName;
- }
-
- public Long getDomainId() {
- return domainId;
- }
-
- public String getEmail() {
- return email;
- }
-
- public String getFirstName() {
- return firstname;
- }
-
- public String getLastName() {
- return lastname;
- }
-
- public String getPassword() {
- return password;
- }
-
- public String getTimezone() {
- return timezone;
- }
-
- public String getUserName() {
- return username;
- }
-
- /////////////////////////////////////////////////////
- /////////////// API Implementation///////////////////
- /////////////////////////////////////////////////////
-
- @Override
- public String getCommandName() {
- return s_name;
- }
-
- @Override
- public long getEntityOwnerId() {
- Account account = UserContext.current().getCaller();
- if ((account == null) || isAdmin(account.getType())) {
- if ((domainId != null) && (accountName != null)) {
- Account userAccount = _responseGenerator.findAccountByNameDomain(accountName, domainId);
- if (userAccount != null) {
- return userAccount.getId();
- }
- }
- }
-
- if (account != null) {
- return account.getId();
- }
-
- return Account.ACCOUNT_ID_SYSTEM; // no account info given, parent this command to SYSTEM so ERROR events are tracked
- }
-
- @Override
- public void execute(){
- UserContext.current().setEventDetails("UserName: "+getUserName()+", FirstName :"+getFirstName()+", LastName: "+getLastName());
- User user = _accountService.createUser(getUserName(), getPassword(), getFirstName(), getLastName(), getEmail(), getTimezone(), getAccountName(), getDomainId());
- if (user != null) {
- UserResponse response = _responseGenerator.createUserResponse(user);
- response.setResponseName(getCommandName());
- this.setResponseObject(response);
- } else {
- throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to create a user");
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/ceddaf12/api/src/com/cloud/api/commands/DeleteUserCmd.java
----------------------------------------------------------------------
diff --git a/api/src/com/cloud/api/commands/DeleteUserCmd.java b/api/src/com/cloud/api/commands/DeleteUserCmd.java
deleted file mode 100644
index 0f913e8..0000000
--- a/api/src/com/cloud/api/commands/DeleteUserCmd.java
+++ /dev/null
@@ -1,84 +0,0 @@
-// Licensed to the Apache Software Foundation (ASF) under one
-// or more contributor license agreements. See the NOTICE file
-// distributed with this work for additional information
-// regarding copyright ownership. The ASF licenses this file
-// to you under the Apache License, Version 2.0 (the
-// "License"); you may not use this file except in compliance
-// with the License. You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing,
-// software distributed under the License is distributed on an
-// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-// KIND, either express or implied. See the License for the
-// specific language governing permissions and limitations
-// under the License.
-package com.cloud.api.commands;
-
-import org.apache.log4j.Logger;
-
-import org.apache.cloudstack.api.ApiConstants;
-import org.apache.cloudstack.api.BaseCmd;
-import org.apache.cloudstack.api.IdentityMapper;
-import org.apache.cloudstack.api.Implementation;
-import org.apache.cloudstack.api.Parameter;
-import org.apache.cloudstack.api.ServerApiException;
-import com.cloud.api.response.SuccessResponse;
-import com.cloud.api.response.UserResponse;
-import com.cloud.user.Account;
-import com.cloud.user.User;
-import com.cloud.user.UserContext;
-
-@Implementation(description="Creates a user for an account", responseObject=UserResponse.class)
-public class DeleteUserCmd extends BaseCmd {
- public static final Logger s_logger = Logger.getLogger(DeleteUserCmd.class.getName());
-
- private static final String s_name = "deleteuserresponse";
-
- /////////////////////////////////////////////////////
- //////////////// API parameters /////////////////////
- /////////////////////////////////////////////////////
- @IdentityMapper(entityTableName="user")
- @Parameter(name=ApiConstants.ID, type=CommandType.LONG, required=true, description="Deletes a user")
- private Long id;
-
- /////////////////////////////////////////////////////
- /////////////////// Accessors ///////////////////////
- /////////////////////////////////////////////////////
-
- public Long getId() {
- return id;
- }
-
- /////////////////////////////////////////////////////
- /////////////// API Implementation///////////////////
- /////////////////////////////////////////////////////
-
- @Override
- public String getCommandName() {
- return s_name;
- }
-
- @Override
- public long getEntityOwnerId() {
- User user = _entityMgr.findById(User.class, getId());
- if (user != null) {
- return user.getAccountId();
- }
-
- return Account.ACCOUNT_ID_SYSTEM; // no account info given, parent this command to SYSTEM so ERROR events are tracked
- }
-
- @Override
- public void execute(){
- UserContext.current().setEventDetails("UserId: "+getId());
- boolean result = _accountService.deleteUser(this);
- if (result) {
- SuccessResponse response = new SuccessResponse(getCommandName());
- this.setResponseObject(response);
- } else {
- throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to delete user");
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/ceddaf12/api/src/com/cloud/api/commands/DisableUserCmd.java
----------------------------------------------------------------------
diff --git a/api/src/com/cloud/api/commands/DisableUserCmd.java b/api/src/com/cloud/api/commands/DisableUserCmd.java
deleted file mode 100644
index c4997c2..0000000
--- a/api/src/com/cloud/api/commands/DisableUserCmd.java
+++ /dev/null
@@ -1,104 +0,0 @@
-// Licensed to the Apache Software Foundation (ASF) under one
-// or more contributor license agreements. See the NOTICE file
-// distributed with this work for additional information
-// regarding copyright ownership. The ASF licenses this file
-// to you under the Apache License, Version 2.0 (the
-// "License"); you may not use this file except in compliance
-// with the License. You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing,
-// software distributed under the License is distributed on an
-// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-// KIND, either express or implied. See the License for the
-// specific language governing permissions and limitations
-// under the License.
-package com.cloud.api.commands;
-
-import org.apache.log4j.Logger;
-
-import org.apache.cloudstack.api.ApiConstants;
-import org.apache.cloudstack.api.BaseAsyncCmd;
-import org.apache.cloudstack.api.BaseCmd;
-import org.apache.cloudstack.api.IdentityMapper;
-import org.apache.cloudstack.api.Implementation;
-import org.apache.cloudstack.api.Parameter;
-import org.apache.cloudstack.api.ServerApiException;
-import com.cloud.api.response.UserResponse;
-import com.cloud.async.AsyncJob;
-import com.cloud.event.EventTypes;
-import com.cloud.user.Account;
-import com.cloud.user.User;
-import com.cloud.user.UserAccount;
-import com.cloud.user.UserContext;
-
-@Implementation(description="Disables a user account", responseObject=UserResponse.class)
-public class DisableUserCmd extends BaseAsyncCmd {
- public static final Logger s_logger = Logger.getLogger(DisableUserCmd.class.getName());
- private static final String s_name = "disableuserresponse";
-
- /////////////////////////////////////////////////////
- //////////////// API parameters /////////////////////
- /////////////////////////////////////////////////////
-
- @IdentityMapper(entityTableName="user")
- @Parameter(name=ApiConstants.ID, type=CommandType.LONG, required=true, description="Disables user by user ID.")
- private Long id;
-
- /////////////////////////////////////////////////////
- /////////////////// Accessors ///////////////////////
- /////////////////////////////////////////////////////
-
- public Long getId() {
- return id;
- }
-
- /////////////////////////////////////////////////////
- /////////////// API Implementation///////////////////
- /////////////////////////////////////////////////////
-
- @Override
- public String getCommandName() {
- return s_name;
- }
-
- @Override
- public String getEventType() {
- return EventTypes.EVENT_USER_DISABLE;
- }
-
- @Override
- public long getEntityOwnerId() {
- User user = _entityMgr.findById(User.class, getId());
- if (user != null) {
- return user.getAccountId();
- }
-
- return Account.ACCOUNT_ID_SYSTEM; // no account info given, parent this command to SYSTEM so ERROR events are tracked
- }
-
- @Override
- public String getEventDescription() {
- return "disabling user: " + getId();
- }
-
-
- @Override
- public void execute(){
- UserContext.current().setEventDetails("UserId: "+getId());
- UserAccount user = _accountService.disableUser(getId());
- if (user != null){
- UserResponse response = _responseGenerator.createUserResponse(user);
- response.setResponseName(getCommandName());
- this.setResponseObject(response);
- } else {
- throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to disable user");
- }
- }
-
- @Override
- public AsyncJob.Type getInstanceType() {
- return AsyncJob.Type.User;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/ceddaf12/api/src/com/cloud/api/commands/EnableUserCmd.java
----------------------------------------------------------------------
diff --git a/api/src/com/cloud/api/commands/EnableUserCmd.java b/api/src/com/cloud/api/commands/EnableUserCmd.java
deleted file mode 100644
index 6c445f7..0000000
--- a/api/src/com/cloud/api/commands/EnableUserCmd.java
+++ /dev/null
@@ -1,86 +0,0 @@
-// Licensed to the Apache Software Foundation (ASF) under one
-// or more contributor license agreements. See the NOTICE file
-// distributed with this work for additional information
-// regarding copyright ownership. The ASF licenses this file
-// to you under the Apache License, Version 2.0 (the
-// "License"); you may not use this file except in compliance
-// with the License. You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing,
-// software distributed under the License is distributed on an
-// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-// KIND, either express or implied. See the License for the
-// specific language governing permissions and limitations
-// under the License.
-package com.cloud.api.commands;
-
-import org.apache.log4j.Logger;
-
-import org.apache.cloudstack.api.ApiConstants;
-import org.apache.cloudstack.api.BaseCmd;
-import org.apache.cloudstack.api.IdentityMapper;
-import org.apache.cloudstack.api.Implementation;
-import org.apache.cloudstack.api.Parameter;
-import org.apache.cloudstack.api.ServerApiException;
-import com.cloud.api.response.UserResponse;
-import com.cloud.user.Account;
-import com.cloud.user.User;
-import com.cloud.user.UserAccount;
-import com.cloud.user.UserContext;
-
-@Implementation(description="Enables a user account", responseObject=UserResponse.class)
-public class EnableUserCmd extends BaseCmd {
- public static final Logger s_logger = Logger.getLogger(EnableUserCmd.class.getName());
- private static final String s_name = "enableuserresponse";
-
- /////////////////////////////////////////////////////
- //////////////// API parameters /////////////////////
- /////////////////////////////////////////////////////
-
- @IdentityMapper(entityTableName="user")
- @Parameter(name=ApiConstants.ID, type=CommandType.LONG, required=true, description="Enables user by user ID.")
- private Long id;
-
-
- /////////////////////////////////////////////////////
- /////////////////// Accessors ///////////////////////
- /////////////////////////////////////////////////////
-
- public Long getId() {
- return id;
- }
-
- /////////////////////////////////////////////////////
- /////////////// API Implementation///////////////////
- /////////////////////////////////////////////////////
-
- @Override
- public String getCommandName() {
- return s_name;
- }
-
- @Override
- public long getEntityOwnerId() {
- User user = _entityMgr.findById(User.class, getId());
- if (user != null) {
- return user.getAccountId();
- }
-
- return Account.ACCOUNT_ID_SYSTEM; // no account info given, parent this command to SYSTEM so ERROR events are tracked
- }
-
- @Override
- public void execute(){
- UserContext.current().setEventDetails("UserId: "+getId());
- UserAccount user = _accountService.enableUser(getId());
- if (user != null){
- UserResponse response = _responseGenerator.createUserResponse(user);
- response.setResponseName(getCommandName());
- this.setResponseObject(response);
- } else {
- throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to enable user");
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/ceddaf12/api/src/com/cloud/api/commands/GetUserCmd.java
----------------------------------------------------------------------
diff --git a/api/src/com/cloud/api/commands/GetUserCmd.java b/api/src/com/cloud/api/commands/GetUserCmd.java
deleted file mode 100644
index 4628f1c..0000000
--- a/api/src/com/cloud/api/commands/GetUserCmd.java
+++ /dev/null
@@ -1,76 +0,0 @@
-// Licensed to the Apache Software Foundation (ASF) under one
-// or more contributor license agreements. See the NOTICE file
-// distributed with this work for additional information
-// regarding copyright ownership. The ASF licenses this file
-// to you under the Apache License, Version 2.0 (the
-// "License"); you may not use this file except in compliance
-// with the License. You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing,
-// software distributed under the License is distributed on an
-// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-// KIND, either express or implied. See the License for the
-// specific language governing permissions and limitations
-// under the License.
-package com.cloud.api.commands;
-
-import org.apache.log4j.Logger;
-
-import org.apache.cloudstack.api.ApiConstants;
-import org.apache.cloudstack.api.BaseCmd;
-import org.apache.cloudstack.api.Implementation;
-import org.apache.cloudstack.api.Parameter;
-import com.cloud.api.response.UserResponse;
-import com.cloud.exception.InvalidParameterValueException;
-import com.cloud.user.UserAccount;
-
-@Implementation(description="Find user account by API key", responseObject=UserResponse.class)
-public class GetUserCmd extends BaseCmd {
- public static final Logger s_logger = Logger.getLogger(GetUserCmd.class.getName());
-
- private static final String s_name = "getuserresponse";
-
- /////////////////////////////////////////////////////
- //////////////// API parameters /////////////////////
- /////////////////////////////////////////////////////
-
- @Parameter(name=ApiConstants.API_KEY, type=CommandType.STRING, required=true, description="API key of the user")
- private String apiKey;
-
- /////////////////////////////////////////////////////
- /////////////////// Accessors ///////////////////////
- /////////////////////////////////////////////////////
-
- public String getApiKey() {
- return apiKey;
- }
-
- /////////////////////////////////////////////////////
- /////////////// API Implementation///////////////////
- /////////////////////////////////////////////////////
-
- @Override
- public String getCommandName() {
- return s_name;
- }
-
- @Override
- public long getEntityOwnerId() {
- return 0;
- }
-
- @Override
- public void execute(){
- UserAccount result = _accountService.getUserByApiKey(getApiKey());
- if(result != null){
- UserResponse response = _responseGenerator.createUserResponse(result);
- response.setResponseName(getCommandName());
- response.setResponseName(getCommandName());
- this.setResponseObject(response);
- } else {
- throw new InvalidParameterValueException("User with specified API key does not exist");
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/ceddaf12/api/src/com/cloud/api/commands/ListUsersCmd.java
----------------------------------------------------------------------
diff --git a/api/src/com/cloud/api/commands/ListUsersCmd.java b/api/src/com/cloud/api/commands/ListUsersCmd.java
deleted file mode 100644
index 2305494..0000000
--- a/api/src/com/cloud/api/commands/ListUsersCmd.java
+++ /dev/null
@@ -1,100 +0,0 @@
-// Licensed to the Apache Software Foundation (ASF) under one
-// or more contributor license agreements. See the NOTICE file
-// distributed with this work for additional information
-// regarding copyright ownership. The ASF licenses this file
-// to you under the Apache License, Version 2.0 (the
-// "License"); you may not use this file except in compliance
-// with the License. You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing,
-// software distributed under the License is distributed on an
-// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-// KIND, either express or implied. See the License for the
-// specific language governing permissions and limitations
-// under the License.
-package com.cloud.api.commands;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.apache.log4j.Logger;
-
-import org.apache.cloudstack.api.ApiConstants;
-import org.apache.cloudstack.api.BaseListAccountResourcesCmd;
-import org.apache.cloudstack.api.IdentityMapper;
-import org.apache.cloudstack.api.Implementation;
-import org.apache.cloudstack.api.Parameter;
-import com.cloud.api.response.ListResponse;
-import com.cloud.api.response.UserResponse;
-import com.cloud.user.UserAccount;
-import com.cloud.utils.Pair;
-
-@Implementation(description="Lists user accounts", responseObject=UserResponse.class)
-public class ListUsersCmd extends BaseListAccountResourcesCmd {
- public static final Logger s_logger = Logger.getLogger(ListUsersCmd.class.getName());
-
- private static final String s_name = "listusersresponse";
-
- /////////////////////////////////////////////////////
- //////////////// API parameters /////////////////////
- /////////////////////////////////////////////////////
-
- @Parameter(name=ApiConstants.ACCOUNT_TYPE, type=CommandType.LONG, description="List users by account type. Valid types include admin, domain-admin, read-only-admin, or user.")
- private Long accountType;
-
- @IdentityMapper(entityTableName="user")
- @Parameter(name=ApiConstants.ID, type=CommandType.LONG, description="List user by ID.")
- private Long id;
-
- @Parameter(name=ApiConstants.STATE, type=CommandType.STRING, description="List users by state of the user account.")
- private String state;
-
- @Parameter(name=ApiConstants.USERNAME, type=CommandType.STRING, description="List user by the username")
- private String username;
-
- /////////////////////////////////////////////////////
- /////////////////// Accessors ///////////////////////
- /////////////////////////////////////////////////////
-
-
- public Long getAccountType() {
- return accountType;
- }
-
- public Long getId() {
- return id;
- }
-
- public String getState() {
- return state;
- }
-
- public String getUsername() {
- return username;
- }
-
- /////////////////////////////////////////////////////
- /////////////// API Implementation///////////////////
- /////////////////////////////////////////////////////
-
- @Override
- public String getCommandName() {
- return s_name;
- }
-
- @Override
- public void execute(){
- Pair<List<? extends UserAccount>, Integer> result = _accountService.searchForUsers(this);
- ListResponse<UserResponse> response = new ListResponse<UserResponse>();
- List<UserResponse> userResponses = new ArrayList<UserResponse>();
- for (UserAccount user : result.first()) {
- UserResponse userResponse = _responseGenerator.createUserResponse(user);
- userResponses.add(userResponse);
- }
- response.setResponses(userResponses, result.second());
- response.setResponseName(getCommandName());
- this.setResponseObject(response);
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/ceddaf12/api/src/com/cloud/api/commands/UpdateUserCmd.java
----------------------------------------------------------------------
diff --git a/api/src/com/cloud/api/commands/UpdateUserCmd.java b/api/src/com/cloud/api/commands/UpdateUserCmd.java
deleted file mode 100644
index fbe062e..0000000
--- a/api/src/com/cloud/api/commands/UpdateUserCmd.java
+++ /dev/null
@@ -1,142 +0,0 @@
-// Licensed to the Apache Software Foundation (ASF) under one
-// or more contributor license agreements. See the NOTICE file
-// distributed with this work for additional information
-// regarding copyright ownership. The ASF licenses this file
-// to you under the Apache License, Version 2.0 (the
-// "License"); you may not use this file except in compliance
-// with the License. You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing,
-// software distributed under the License is distributed on an
-// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-// KIND, either express or implied. See the License for the
-// specific language governing permissions and limitations
-// under the License.
-package com.cloud.api.commands;
-
-import org.apache.log4j.Logger;
-
-import org.apache.cloudstack.api.ApiConstants;
-import org.apache.cloudstack.api.BaseCmd;
-import org.apache.cloudstack.api.IdentityMapper;
-import org.apache.cloudstack.api.Implementation;
-import org.apache.cloudstack.api.Parameter;
-import org.apache.cloudstack.api.ServerApiException;
-import com.cloud.api.response.UserResponse;
-import com.cloud.user.Account;
-import com.cloud.user.User;
-import com.cloud.user.UserAccount;
-import com.cloud.user.UserContext;
-
-@Implementation(description="Updates a user account", responseObject=UserResponse.class)
-public class UpdateUserCmd extends BaseCmd {
- public static final Logger s_logger = Logger.getLogger(UpdateUserCmd.class.getName());
-
- private static final String s_name = "updateuserresponse";
-
- /////////////////////////////////////////////////////
- //////////////// API parameters /////////////////////
- /////////////////////////////////////////////////////
-
- @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")
- private String email;
-
- @Parameter(name=ApiConstants.FIRSTNAME, type=CommandType.STRING, description="first name")
- private String firstname;
-
- @IdentityMapper(entityTableName="user")
- @Parameter(name=ApiConstants.ID, type=CommandType.LONG, required=true, description="User id")
- private Long id;
-
- @Parameter(name=ApiConstants.LASTNAME, type=CommandType.STRING, description="last name")
- private String lastname;
-
- @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 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.")
- private String timezone;
-
- @Parameter(name=ApiConstants.USERNAME, type=CommandType.STRING, description="Unique username")
- private String username;
-
- /////////////////////////////////////////////////////
- /////////////////// Accessors ///////////////////////
- /////////////////////////////////////////////////////
-
- public String getApiKey() {
- return apiKey;
- }
-
- public String getEmail() {
- return email;
- }
-
- public String getFirstname() {
- return firstname;
- }
-
- public Long getId() {
- return id;
- }
-
- public String getLastname() {
- return lastname;
- }
-
- public String getPassword() {
- return password;
- }
-
- public String getSecretKey() {
- return secretKey;
- }
-
- public String getTimezone() {
- return timezone;
- }
-
- public String getUsername() {
- return username;
- }
-
- /////////////////////////////////////////////////////
- /////////////// API Implementation///////////////////
- /////////////////////////////////////////////////////
-
- @Override
- public String getCommandName() {
- return s_name;
- }
-
- @Override
- public long getEntityOwnerId() {
- User user = _entityMgr.findById(User.class, getId());
- if (user != null) {
- return user.getAccountId();
- }
-
- return Account.ACCOUNT_ID_SYSTEM; // no account info given, parent this command to SYSTEM so ERROR events are tracked
- }
-
- @Override
- public void execute(){
- UserContext.current().setEventDetails("UserId: "+getId());
- UserAccount user = _accountService.updateUser(this);
- if (user != null){
- UserResponse response = _responseGenerator.createUserResponse(user);
- response.setResponseName(getCommandName());
- this.setResponseObject(response);
- } else {
- throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to update user");
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/ceddaf12/api/src/com/cloud/user/AccountService.java
----------------------------------------------------------------------
diff --git a/api/src/com/cloud/user/AccountService.java b/api/src/com/cloud/user/AccountService.java
index 001d498..8be8e9e 100755
--- a/api/src/com/cloud/user/AccountService.java
+++ b/api/src/com/cloud/user/AccountService.java
@@ -21,12 +21,12 @@ import java.util.Map;
import com.cloud.acl.ControlledEntity;
import com.cloud.acl.SecurityChecker.AccessType;
-import com.cloud.api.commands.DeleteUserCmd;
+import org.apache.cloudstack.api.admin.user.command.DeleteUserCmd;
+import org.apache.cloudstack.api.admin.user.command.UpdateUserCmd;
import org.apache.cloudstack.api.user.account.command.ListAccountsCmd;
-import com.cloud.api.commands.ListUsersCmd;
+import org.apache.cloudstack.api.admin.user.command.ListUsersCmd;
import com.cloud.api.commands.RegisterCmd;
import com.cloud.api.commands.UpdateAccountCmd;
-import com.cloud.api.commands.UpdateUserCmd;
import com.cloud.domain.Domain;
import com.cloud.exception.ConcurrentOperationException;
import com.cloud.exception.PermissionDeniedException;
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/ceddaf12/api/src/org/apache/cloudstack/api/admin/user/command/CreateUserCmd.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/api/admin/user/command/CreateUserCmd.java b/api/src/org/apache/cloudstack/api/admin/user/command/CreateUserCmd.java
new file mode 100644
index 0000000..a4b3bca
--- /dev/null
+++ b/api/src/org/apache/cloudstack/api/admin/user/command/CreateUserCmd.java
@@ -0,0 +1,143 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+package org.apache.cloudstack.api.admin.user.command;
+
+import org.apache.log4j.Logger;
+
+import org.apache.cloudstack.api.ApiConstants;
+import org.apache.cloudstack.api.BaseCmd;
+import org.apache.cloudstack.api.IdentityMapper;
+import org.apache.cloudstack.api.Implementation;
+import org.apache.cloudstack.api.Parameter;
+import org.apache.cloudstack.api.ServerApiException;
+import com.cloud.api.response.UserResponse;
+import com.cloud.user.Account;
+import com.cloud.user.User;
+import com.cloud.user.UserContext;
+
+@Implementation(description="Creates a user for an account that already exists", responseObject=UserResponse.class)
+public class CreateUserCmd extends BaseCmd {
+ public static final Logger s_logger = Logger.getLogger(CreateUserCmd.class.getName());
+
+ private static final String s_name = "createuserresponse";
+
+ /////////////////////////////////////////////////////
+ //////////////// API parameters /////////////////////
+ /////////////////////////////////////////////////////
+
+ @Parameter(name=ApiConstants.ACCOUNT, type=CommandType.STRING, required=true, description="Creates the user under the specified account. If no account is specified, the username will be used as the account name.")
+ private String accountName;
+
+ @IdentityMapper(entityTableName="domain")
+ @Parameter(name=ApiConstants.DOMAIN_ID, type=CommandType.LONG, description="Creates the user under the specified domain. Has to be accompanied with the account parameter")
+ private Long domainId;
+
+ @Parameter(name=ApiConstants.EMAIL, type=CommandType.STRING, required=true, description="email")
+ private String email;
+
+ @Parameter(name=ApiConstants.FIRSTNAME, type=CommandType.STRING, required=true, description="firstname")
+ private String firstname;
+
+ @Parameter(name=ApiConstants.LASTNAME, type=CommandType.STRING, required=true, description="lastname")
+ private String lastname;
+
+ @Parameter(name=ApiConstants.PASSWORD, type=CommandType.STRING, required=true, description="Hashed password (Default is MD5). If you wish to use any other hashing algorithm, you would need to write a custom authentication adapter See Docs section.")
+ private String password;
+
+ @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.")
+ private String timezone;
+
+ @Parameter(name=ApiConstants.USERNAME, type=CommandType.STRING, required=true, description="Unique username.")
+ private String username;
+
+ /////////////////////////////////////////////////////
+ /////////////////// Accessors ///////////////////////
+ /////////////////////////////////////////////////////
+
+ public String getAccountName() {
+ return accountName;
+ }
+
+ public Long getDomainId() {
+ return domainId;
+ }
+
+ public String getEmail() {
+ return email;
+ }
+
+ public String getFirstName() {
+ return firstname;
+ }
+
+ public String getLastName() {
+ return lastname;
+ }
+
+ public String getPassword() {
+ return password;
+ }
+
+ public String getTimezone() {
+ return timezone;
+ }
+
+ public String getUserName() {
+ return username;
+ }
+
+ /////////////////////////////////////////////////////
+ /////////////// API Implementation///////////////////
+ /////////////////////////////////////////////////////
+
+ @Override
+ public String getCommandName() {
+ return s_name;
+ }
+
+ @Override
+ public long getEntityOwnerId() {
+ Account account = UserContext.current().getCaller();
+ if ((account == null) || isAdmin(account.getType())) {
+ if ((domainId != null) && (accountName != null)) {
+ Account userAccount = _responseGenerator.findAccountByNameDomain(accountName, domainId);
+ if (userAccount != null) {
+ return userAccount.getId();
+ }
+ }
+ }
+
+ if (account != null) {
+ return account.getId();
+ }
+
+ return Account.ACCOUNT_ID_SYSTEM; // no account info given, parent this command to SYSTEM so ERROR events are tracked
+ }
+
+ @Override
+ public void execute(){
+ UserContext.current().setEventDetails("UserName: "+getUserName()+", FirstName :"+getFirstName()+", LastName: "+getLastName());
+ User user = _accountService.createUser(getUserName(), getPassword(), getFirstName(), getLastName(), getEmail(), getTimezone(), getAccountName(), getDomainId());
+ if (user != null) {
+ UserResponse response = _responseGenerator.createUserResponse(user);
+ response.setResponseName(getCommandName());
+ this.setResponseObject(response);
+ } else {
+ throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to create a user");
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/ceddaf12/api/src/org/apache/cloudstack/api/admin/user/command/DeleteUserCmd.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/api/admin/user/command/DeleteUserCmd.java b/api/src/org/apache/cloudstack/api/admin/user/command/DeleteUserCmd.java
new file mode 100644
index 0000000..5bdbfe7
--- /dev/null
+++ b/api/src/org/apache/cloudstack/api/admin/user/command/DeleteUserCmd.java
@@ -0,0 +1,84 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+package org.apache.cloudstack.api.admin.user.command;
+
+import org.apache.log4j.Logger;
+
+import org.apache.cloudstack.api.ApiConstants;
+import org.apache.cloudstack.api.BaseCmd;
+import org.apache.cloudstack.api.IdentityMapper;
+import org.apache.cloudstack.api.Implementation;
+import org.apache.cloudstack.api.Parameter;
+import org.apache.cloudstack.api.ServerApiException;
+import com.cloud.api.response.SuccessResponse;
+import com.cloud.api.response.UserResponse;
+import com.cloud.user.Account;
+import com.cloud.user.User;
+import com.cloud.user.UserContext;
+
+@Implementation(description="Creates a user for an account", responseObject=UserResponse.class)
+public class DeleteUserCmd extends BaseCmd {
+ public static final Logger s_logger = Logger.getLogger(DeleteUserCmd.class.getName());
+
+ private static final String s_name = "deleteuserresponse";
+
+ /////////////////////////////////////////////////////
+ //////////////// API parameters /////////////////////
+ /////////////////////////////////////////////////////
+ @IdentityMapper(entityTableName="user")
+ @Parameter(name=ApiConstants.ID, type=CommandType.LONG, required=true, description="Deletes a user")
+ private Long id;
+
+ /////////////////////////////////////////////////////
+ /////////////////// Accessors ///////////////////////
+ /////////////////////////////////////////////////////
+
+ public Long getId() {
+ return id;
+ }
+
+ /////////////////////////////////////////////////////
+ /////////////// API Implementation///////////////////
+ /////////////////////////////////////////////////////
+
+ @Override
+ public String getCommandName() {
+ return s_name;
+ }
+
+ @Override
+ public long getEntityOwnerId() {
+ User user = _entityMgr.findById(User.class, getId());
+ if (user != null) {
+ return user.getAccountId();
+ }
+
+ return Account.ACCOUNT_ID_SYSTEM; // no account info given, parent this command to SYSTEM so ERROR events are tracked
+ }
+
+ @Override
+ public void execute(){
+ UserContext.current().setEventDetails("UserId: "+getId());
+ boolean result = _accountService.deleteUser(this);
+ if (result) {
+ SuccessResponse response = new SuccessResponse(getCommandName());
+ this.setResponseObject(response);
+ } else {
+ throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to delete user");
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/ceddaf12/api/src/org/apache/cloudstack/api/admin/user/command/DisableUserCmd.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/api/admin/user/command/DisableUserCmd.java b/api/src/org/apache/cloudstack/api/admin/user/command/DisableUserCmd.java
new file mode 100644
index 0000000..3758991
--- /dev/null
+++ b/api/src/org/apache/cloudstack/api/admin/user/command/DisableUserCmd.java
@@ -0,0 +1,104 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+package org.apache.cloudstack.api.admin.user.command;
+
+import org.apache.log4j.Logger;
+
+import org.apache.cloudstack.api.ApiConstants;
+import org.apache.cloudstack.api.BaseAsyncCmd;
+import org.apache.cloudstack.api.BaseCmd;
+import org.apache.cloudstack.api.IdentityMapper;
+import org.apache.cloudstack.api.Implementation;
+import org.apache.cloudstack.api.Parameter;
+import org.apache.cloudstack.api.ServerApiException;
+import com.cloud.api.response.UserResponse;
+import com.cloud.async.AsyncJob;
+import com.cloud.event.EventTypes;
+import com.cloud.user.Account;
+import com.cloud.user.User;
+import com.cloud.user.UserAccount;
+import com.cloud.user.UserContext;
+
+@Implementation(description="Disables a user account", responseObject=UserResponse.class)
+public class DisableUserCmd extends BaseAsyncCmd {
+ public static final Logger s_logger = Logger.getLogger(DisableUserCmd.class.getName());
+ private static final String s_name = "disableuserresponse";
+
+ /////////////////////////////////////////////////////
+ //////////////// API parameters /////////////////////
+ /////////////////////////////////////////////////////
+
+ @IdentityMapper(entityTableName="user")
+ @Parameter(name=ApiConstants.ID, type=CommandType.LONG, required=true, description="Disables user by user ID.")
+ private Long id;
+
+ /////////////////////////////////////////////////////
+ /////////////////// Accessors ///////////////////////
+ /////////////////////////////////////////////////////
+
+ public Long getId() {
+ return id;
+ }
+
+ /////////////////////////////////////////////////////
+ /////////////// API Implementation///////////////////
+ /////////////////////////////////////////////////////
+
+ @Override
+ public String getCommandName() {
+ return s_name;
+ }
+
+ @Override
+ public String getEventType() {
+ return EventTypes.EVENT_USER_DISABLE;
+ }
+
+ @Override
+ public long getEntityOwnerId() {
+ User user = _entityMgr.findById(User.class, getId());
+ if (user != null) {
+ return user.getAccountId();
+ }
+
+ return Account.ACCOUNT_ID_SYSTEM; // no account info given, parent this command to SYSTEM so ERROR events are tracked
+ }
+
+ @Override
+ public String getEventDescription() {
+ return "disabling user: " + getId();
+ }
+
+
+ @Override
+ public void execute(){
+ UserContext.current().setEventDetails("UserId: "+getId());
+ UserAccount user = _accountService.disableUser(getId());
+ if (user != null){
+ UserResponse response = _responseGenerator.createUserResponse(user);
+ response.setResponseName(getCommandName());
+ this.setResponseObject(response);
+ } else {
+ throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to disable user");
+ }
+ }
+
+ @Override
+ public AsyncJob.Type getInstanceType() {
+ return AsyncJob.Type.User;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/ceddaf12/api/src/org/apache/cloudstack/api/admin/user/command/EnableUserCmd.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/api/admin/user/command/EnableUserCmd.java b/api/src/org/apache/cloudstack/api/admin/user/command/EnableUserCmd.java
new file mode 100644
index 0000000..92545fb
--- /dev/null
+++ b/api/src/org/apache/cloudstack/api/admin/user/command/EnableUserCmd.java
@@ -0,0 +1,86 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+package org.apache.cloudstack.api.admin.user.command;
+
+import org.apache.log4j.Logger;
+
+import org.apache.cloudstack.api.ApiConstants;
+import org.apache.cloudstack.api.BaseCmd;
+import org.apache.cloudstack.api.IdentityMapper;
+import org.apache.cloudstack.api.Implementation;
+import org.apache.cloudstack.api.Parameter;
+import org.apache.cloudstack.api.ServerApiException;
+import com.cloud.api.response.UserResponse;
+import com.cloud.user.Account;
+import com.cloud.user.User;
+import com.cloud.user.UserAccount;
+import com.cloud.user.UserContext;
+
+@Implementation(description="Enables a user account", responseObject=UserResponse.class)
+public class EnableUserCmd extends BaseCmd {
+ public static final Logger s_logger = Logger.getLogger(EnableUserCmd.class.getName());
+ private static final String s_name = "enableuserresponse";
+
+ /////////////////////////////////////////////////////
+ //////////////// API parameters /////////////////////
+ /////////////////////////////////////////////////////
+
+ @IdentityMapper(entityTableName="user")
+ @Parameter(name=ApiConstants.ID, type=CommandType.LONG, required=true, description="Enables user by user ID.")
+ private Long id;
+
+
+ /////////////////////////////////////////////////////
+ /////////////////// Accessors ///////////////////////
+ /////////////////////////////////////////////////////
+
+ public Long getId() {
+ return id;
+ }
+
+ /////////////////////////////////////////////////////
+ /////////////// API Implementation///////////////////
+ /////////////////////////////////////////////////////
+
+ @Override
+ public String getCommandName() {
+ return s_name;
+ }
+
+ @Override
+ public long getEntityOwnerId() {
+ User user = _entityMgr.findById(User.class, getId());
+ if (user != null) {
+ return user.getAccountId();
+ }
+
+ return Account.ACCOUNT_ID_SYSTEM; // no account info given, parent this command to SYSTEM so ERROR events are tracked
+ }
+
+ @Override
+ public void execute(){
+ UserContext.current().setEventDetails("UserId: "+getId());
+ UserAccount user = _accountService.enableUser(getId());
+ if (user != null){
+ UserResponse response = _responseGenerator.createUserResponse(user);
+ response.setResponseName(getCommandName());
+ this.setResponseObject(response);
+ } else {
+ throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to enable user");
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/ceddaf12/api/src/org/apache/cloudstack/api/admin/user/command/GetUserCmd.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/api/admin/user/command/GetUserCmd.java b/api/src/org/apache/cloudstack/api/admin/user/command/GetUserCmd.java
new file mode 100644
index 0000000..5cfc27a
--- /dev/null
+++ b/api/src/org/apache/cloudstack/api/admin/user/command/GetUserCmd.java
@@ -0,0 +1,76 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+package org.apache.cloudstack.api.admin.user.command;
+
+import org.apache.log4j.Logger;
+
+import org.apache.cloudstack.api.ApiConstants;
+import org.apache.cloudstack.api.BaseCmd;
+import org.apache.cloudstack.api.Implementation;
+import org.apache.cloudstack.api.Parameter;
+import com.cloud.api.response.UserResponse;
+import com.cloud.exception.InvalidParameterValueException;
+import com.cloud.user.UserAccount;
+
+@Implementation(description="Find user account by API key", responseObject=UserResponse.class)
+public class GetUserCmd extends BaseCmd {
+ public static final Logger s_logger = Logger.getLogger(GetUserCmd.class.getName());
+
+ private static final String s_name = "getuserresponse";
+
+ /////////////////////////////////////////////////////
+ //////////////// API parameters /////////////////////
+ /////////////////////////////////////////////////////
+
+ @Parameter(name=ApiConstants.API_KEY, type=CommandType.STRING, required=true, description="API key of the user")
+ private String apiKey;
+
+ /////////////////////////////////////////////////////
+ /////////////////// Accessors ///////////////////////
+ /////////////////////////////////////////////////////
+
+ public String getApiKey() {
+ return apiKey;
+ }
+
+ /////////////////////////////////////////////////////
+ /////////////// API Implementation///////////////////
+ /////////////////////////////////////////////////////
+
+ @Override
+ public String getCommandName() {
+ return s_name;
+ }
+
+ @Override
+ public long getEntityOwnerId() {
+ return 0;
+ }
+
+ @Override
+ public void execute(){
+ UserAccount result = _accountService.getUserByApiKey(getApiKey());
+ if(result != null){
+ UserResponse response = _responseGenerator.createUserResponse(result);
+ response.setResponseName(getCommandName());
+ response.setResponseName(getCommandName());
+ this.setResponseObject(response);
+ } else {
+ throw new InvalidParameterValueException("User with specified API key does not exist");
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/ceddaf12/api/src/org/apache/cloudstack/api/admin/user/command/ListUsersCmd.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/api/admin/user/command/ListUsersCmd.java b/api/src/org/apache/cloudstack/api/admin/user/command/ListUsersCmd.java
new file mode 100644
index 0000000..6314e5e
--- /dev/null
+++ b/api/src/org/apache/cloudstack/api/admin/user/command/ListUsersCmd.java
@@ -0,0 +1,100 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+package org.apache.cloudstack.api.admin.user.command;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.log4j.Logger;
+
+import org.apache.cloudstack.api.ApiConstants;
+import org.apache.cloudstack.api.BaseListAccountResourcesCmd;
+import org.apache.cloudstack.api.IdentityMapper;
+import org.apache.cloudstack.api.Implementation;
+import org.apache.cloudstack.api.Parameter;
+import com.cloud.api.response.ListResponse;
+import com.cloud.api.response.UserResponse;
+import com.cloud.user.UserAccount;
+import com.cloud.utils.Pair;
+
+@Implementation(description="Lists user accounts", responseObject=UserResponse.class)
+public class ListUsersCmd extends BaseListAccountResourcesCmd {
+ public static final Logger s_logger = Logger.getLogger(ListUsersCmd.class.getName());
+
+ private static final String s_name = "listusersresponse";
+
+ /////////////////////////////////////////////////////
+ //////////////// API parameters /////////////////////
+ /////////////////////////////////////////////////////
+
+ @Parameter(name=ApiConstants.ACCOUNT_TYPE, type=CommandType.LONG, description="List users by account type. Valid types include admin, domain-admin, read-only-admin, or user.")
+ private Long accountType;
+
+ @IdentityMapper(entityTableName="user")
+ @Parameter(name=ApiConstants.ID, type=CommandType.LONG, description="List user by ID.")
+ private Long id;
+
+ @Parameter(name=ApiConstants.STATE, type=CommandType.STRING, description="List users by state of the user account.")
+ private String state;
+
+ @Parameter(name=ApiConstants.USERNAME, type=CommandType.STRING, description="List user by the username")
+ private String username;
+
+ /////////////////////////////////////////////////////
+ /////////////////// Accessors ///////////////////////
+ /////////////////////////////////////////////////////
+
+
+ public Long getAccountType() {
+ return accountType;
+ }
+
+ public Long getId() {
+ return id;
+ }
+
+ public String getState() {
+ return state;
+ }
+
+ public String getUsername() {
+ return username;
+ }
+
+ /////////////////////////////////////////////////////
+ /////////////// API Implementation///////////////////
+ /////////////////////////////////////////////////////
+
+ @Override
+ public String getCommandName() {
+ return s_name;
+ }
+
+ @Override
+ public void execute(){
+ Pair<List<? extends UserAccount>, Integer> result = _accountService.searchForUsers(this);
+ ListResponse<UserResponse> response = new ListResponse<UserResponse>();
+ List<UserResponse> userResponses = new ArrayList<UserResponse>();
+ for (UserAccount user : result.first()) {
+ UserResponse userResponse = _responseGenerator.createUserResponse(user);
+ userResponses.add(userResponse);
+ }
+ response.setResponses(userResponses, result.second());
+ response.setResponseName(getCommandName());
+ this.setResponseObject(response);
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/ceddaf12/api/src/org/apache/cloudstack/api/admin/user/command/UpdateUserCmd.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/api/admin/user/command/UpdateUserCmd.java b/api/src/org/apache/cloudstack/api/admin/user/command/UpdateUserCmd.java
new file mode 100644
index 0000000..c77db33
--- /dev/null
+++ b/api/src/org/apache/cloudstack/api/admin/user/command/UpdateUserCmd.java
@@ -0,0 +1,142 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+package org.apache.cloudstack.api.admin.user.command;
+
+import org.apache.log4j.Logger;
+
+import org.apache.cloudstack.api.ApiConstants;
+import org.apache.cloudstack.api.BaseCmd;
+import org.apache.cloudstack.api.IdentityMapper;
+import org.apache.cloudstack.api.Implementation;
+import org.apache.cloudstack.api.Parameter;
+import org.apache.cloudstack.api.ServerApiException;
+import com.cloud.api.response.UserResponse;
+import com.cloud.user.Account;
+import com.cloud.user.User;
+import com.cloud.user.UserAccount;
+import com.cloud.user.UserContext;
+
+@Implementation(description="Updates a user account", responseObject=UserResponse.class)
+public class UpdateUserCmd extends BaseCmd {
+ public static final Logger s_logger = Logger.getLogger(UpdateUserCmd.class.getName());
+
+ private static final String s_name = "updateuserresponse";
+
+ /////////////////////////////////////////////////////
+ //////////////// API parameters /////////////////////
+ /////////////////////////////////////////////////////
+
+ @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")
+ private String email;
+
+ @Parameter(name=ApiConstants.FIRSTNAME, type=CommandType.STRING, description="first name")
+ private String firstname;
+
+ @IdentityMapper(entityTableName="user")
+ @Parameter(name=ApiConstants.ID, type=CommandType.LONG, required=true, description="User id")
+ private Long id;
+
+ @Parameter(name=ApiConstants.LASTNAME, type=CommandType.STRING, description="last name")
+ private String lastname;
+
+ @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 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.")
+ private String timezone;
+
+ @Parameter(name=ApiConstants.USERNAME, type=CommandType.STRING, description="Unique username")
+ private String username;
+
+ /////////////////////////////////////////////////////
+ /////////////////// Accessors ///////////////////////
+ /////////////////////////////////////////////////////
+
+ public String getApiKey() {
+ return apiKey;
+ }
+
+ public String getEmail() {
+ return email;
+ }
+
+ public String getFirstname() {
+ return firstname;
+ }
+
+ public Long getId() {
+ return id;
+ }
+
+ public String getLastname() {
+ return lastname;
+ }
+
+ public String getPassword() {
+ return password;
+ }
+
+ public String getSecretKey() {
+ return secretKey;
+ }
+
+ public String getTimezone() {
+ return timezone;
+ }
+
+ public String getUsername() {
+ return username;
+ }
+
+ /////////////////////////////////////////////////////
+ /////////////// API Implementation///////////////////
+ /////////////////////////////////////////////////////
+
+ @Override
+ public String getCommandName() {
+ return s_name;
+ }
+
+ @Override
+ public long getEntityOwnerId() {
+ User user = _entityMgr.findById(User.class, getId());
+ if (user != null) {
+ return user.getAccountId();
+ }
+
+ return Account.ACCOUNT_ID_SYSTEM; // no account info given, parent this command to SYSTEM so ERROR events are tracked
+ }
+
+ @Override
+ public void execute(){
+ UserContext.current().setEventDetails("UserId: "+getId());
+ UserAccount user = _accountService.updateUser(this);
+ if (user != null){
+ UserResponse response = _responseGenerator.createUserResponse(user);
+ response.setResponseName(getCommandName());
+ this.setResponseObject(response);
+ } else {
+ throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to update user");
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/ceddaf12/client/tomcatconf/commands.properties.in
----------------------------------------------------------------------
diff --git a/client/tomcatconf/commands.properties.in b/client/tomcatconf/commands.properties.in
index 3df1ca6..9868710 100755
--- a/client/tomcatconf/commands.properties.in
+++ b/client/tomcatconf/commands.properties.in
@@ -29,14 +29,14 @@ listAccounts=org.apache.cloudstack.api.user.account.command.ListAccountsCmd;15
markDefaultZoneForAccount=com.cloud.api.commands.MarkDefaultZoneForAccountCmd;1
#### User commands
-createUser=com.cloud.api.commands.CreateUserCmd;3
-deleteUser=com.cloud.api.commands.DeleteUserCmd;3
-updateUser=com.cloud.api.commands.UpdateUserCmd;3
-listUsers=com.cloud.api.commands.ListUsersCmd;7
+createUser=org.apache.cloudstack.api.admin.user.command.CreateUserCmd;3
+deleteUser=org.apache.cloudstack.api.admin.user.command.DeleteUserCmd;3
+updateUser=org.apache.cloudstack.api.admin.user.command.UpdateUserCmd;3
+listUsers=org.apache.cloudstack.api.admin.user.command.ListUsersCmd;7
####lockUser=com.cloud.api.commands.LockUserCmd;7
-disableUser=com.cloud.api.commands.DisableUserCmd;7
-enableUser=com.cloud.api.commands.EnableUserCmd;7
-getUser=com.cloud.api.commands.GetUserCmd;1
+disableUser=org.apache.cloudstack.api.admin.user.command.DisableUserCmd;7
+enableUser=org.apache.cloudstack.api.admin.user.command.EnableUserCmd;7
+getUser=org.apache.cloudstack.api.admin.user.command.GetUserCmd;1
#### Domain commands
createDomain=com.cloud.api.commands.CreateDomainCmd;1
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/ceddaf12/server/src/com/cloud/user/AccountManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/user/AccountManagerImpl.java b/server/src/com/cloud/user/AccountManagerImpl.java
index 5a1f840..ab04a9c 100755
--- a/server/src/com/cloud/user/AccountManagerImpl.java
+++ b/server/src/com/cloud/user/AccountManagerImpl.java
@@ -36,6 +36,7 @@ import javax.crypto.spec.SecretKeySpec;
import javax.ejb.Local;
import javax.naming.ConfigurationException;
+import org.apache.cloudstack.api.admin.user.command.ListUsersCmd;
import org.apache.commons.codec.binary.Base64;
import org.apache.log4j.Logger;
@@ -43,12 +44,11 @@ import com.cloud.acl.ControlledEntity;
import com.cloud.acl.SecurityChecker;
import com.cloud.acl.SecurityChecker.AccessType;
import com.cloud.api.ApiDBUtils;
-import com.cloud.api.commands.DeleteUserCmd;
+import org.apache.cloudstack.api.admin.user.command.DeleteUserCmd;
import org.apache.cloudstack.api.user.account.command.ListAccountsCmd;
-import com.cloud.api.commands.ListUsersCmd;
import com.cloud.api.commands.RegisterCmd;
import com.cloud.api.commands.UpdateAccountCmd;
-import com.cloud.api.commands.UpdateUserCmd;
+import org.apache.cloudstack.api.admin.user.command.UpdateUserCmd;
import com.cloud.configuration.Config;
import com.cloud.configuration.ConfigurationManager;
import com.cloud.configuration.ResourceLimit;
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/ceddaf12/server/test/com/cloud/user/MockAccountManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/test/com/cloud/user/MockAccountManagerImpl.java b/server/test/com/cloud/user/MockAccountManagerImpl.java
index d464fc8..b8d9043 100644
--- a/server/test/com/cloud/user/MockAccountManagerImpl.java
+++ b/server/test/com/cloud/user/MockAccountManagerImpl.java
@@ -24,12 +24,12 @@ import javax.naming.ConfigurationException;
import com.cloud.acl.ControlledEntity;
import com.cloud.acl.SecurityChecker.AccessType;
-import com.cloud.api.commands.DeleteUserCmd;
+import org.apache.cloudstack.api.admin.user.command.DeleteUserCmd;
+import org.apache.cloudstack.api.admin.user.command.ListUsersCmd;
import org.apache.cloudstack.api.user.account.command.ListAccountsCmd;
-import com.cloud.api.commands.ListUsersCmd;
import com.cloud.api.commands.RegisterCmd;
import com.cloud.api.commands.UpdateAccountCmd;
-import com.cloud.api.commands.UpdateUserCmd;
+import org.apache.cloudstack.api.admin.user.command.UpdateUserCmd;
import com.cloud.domain.Domain;
import com.cloud.exception.ConcurrentOperationException;
import com.cloud.exception.PermissionDeniedException;