You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by ki...@apache.org on 2012/07/18 23:21:20 UTC
git commit: Added getUser API to get user details using API key.
Services like S3 can user this API to authenticate. API is admin only.
Updated Branches:
refs/heads/master 2b2e491f2 -> f2bbf62d9
Added getUser API to get user details using API key. Services like S3 can user this API to authenticate. API is admin only.
Project: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/commit/f2bbf62d
Tree: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/tree/f2bbf62d
Diff: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/diff/f2bbf62d
Branch: refs/heads/master
Commit: f2bbf62d9d5d87149b5db729b902e6ba6364718a
Parents: 2b2e491
Author: kishan <ki...@cloud.com>
Authored: Wed Jul 18 14:20:04 2012 -0700
Committer: kishan <ki...@cloud.com>
Committed: Wed Jul 18 14:20:04 2012 -0700
----------------------------------------------------------------------
api/src/com/cloud/api/commands/GetUserCmd.java | 76 +++++++++++++++
api/src/com/cloud/user/AccountService.java | 2 +
client/tomcatconf/commands.properties.in | 1 +
server/src/com/cloud/user/AccountManagerImpl.java | 5 +
server/src/com/cloud/user/dao/UserAccountDao.java | 1 +
.../src/com/cloud/user/dao/UserAccountDaoImpl.java | 17 +++
6 files changed, 102 insertions(+), 0 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/f2bbf62d/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
new file mode 100644
index 0000000..465e440
--- /dev/null
+++ b/api/src/com/cloud/api/commands/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 com.cloud.api.commands;
+
+import org.apache.log4j.Logger;
+
+import com.cloud.api.ApiConstants;
+import com.cloud.api.BaseCmd;
+import com.cloud.api.Implementation;
+import com.cloud.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/f2bbf62d/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 02e9b27..53383d3 100755
--- a/api/src/com/cloud/user/AccountService.java
+++ b/api/src/com/cloud/user/AccountService.java
@@ -196,6 +196,8 @@ public interface AccountService {
List<? extends UserAccount> searchForUsers(ListUsersCmd cmd)
throws PermissionDeniedException;
+ UserAccount getUserByApiKey(String apiKey);
+
void checkAccess(Account account, Domain domain) throws PermissionDeniedException;
void checkAccess(Account account, AccessType accessType, boolean sameOwner, ControlledEntity... entities) throws PermissionDeniedException;
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/f2bbf62d/client/tomcatconf/commands.properties.in
----------------------------------------------------------------------
diff --git a/client/tomcatconf/commands.properties.in b/client/tomcatconf/commands.properties.in
index 08c175b..28beade 100755
--- a/client/tomcatconf/commands.properties.in
+++ b/client/tomcatconf/commands.properties.in
@@ -19,6 +19,7 @@ listUsers=com.cloud.api.commands.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
#### Domain commands
createDomain=com.cloud.api.commands.CreateDomainCmd;1
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/f2bbf62d/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 e66b886..0a11dc4 100755
--- a/server/src/com/cloud/user/AccountManagerImpl.java
+++ b/server/src/com/cloud/user/AccountManagerImpl.java
@@ -2225,4 +2225,9 @@ public class AccountManagerImpl implements AccountManager, AccountService, Manag
}
}
+
+ @Override
+ public UserAccount getUserByApiKey(String apiKey) {
+ return _userAccountDao.getUserByApiKey(apiKey);
+ }
}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/f2bbf62d/server/src/com/cloud/user/dao/UserAccountDao.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/user/dao/UserAccountDao.java b/server/src/com/cloud/user/dao/UserAccountDao.java
index f090719..eb4e0cd 100644
--- a/server/src/com/cloud/user/dao/UserAccountDao.java
+++ b/server/src/com/cloud/user/dao/UserAccountDao.java
@@ -23,4 +23,5 @@ import com.cloud.utils.db.GenericDao;
public interface UserAccountDao extends GenericDao<UserAccountVO, Long> {
UserAccount getUserAccount(String username, Long domainId);
boolean validateUsernameInDomain(String username, Long domainId);
+ UserAccount getUserByApiKey(String apiKey);
}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/f2bbf62d/server/src/com/cloud/user/dao/UserAccountDaoImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/user/dao/UserAccountDaoImpl.java b/server/src/com/cloud/user/dao/UserAccountDaoImpl.java
index 5cc7434..663e58f 100644
--- a/server/src/com/cloud/user/dao/UserAccountDaoImpl.java
+++ b/server/src/com/cloud/user/dao/UserAccountDaoImpl.java
@@ -21,10 +21,20 @@ import javax.ejb.Local;
import com.cloud.user.UserAccount;
import com.cloud.user.UserAccountVO;
import com.cloud.utils.db.GenericDaoBase;
+import com.cloud.utils.db.SearchBuilder;
import com.cloud.utils.db.SearchCriteria;
@Local(value={UserAccountDao.class})
public class UserAccountDaoImpl extends GenericDaoBase<UserAccountVO, Long> implements UserAccountDao {
+
+ protected final SearchBuilder<UserAccountVO> userAccountSearch;
+
+ protected UserAccountDaoImpl() {
+ userAccountSearch = createSearchBuilder();
+ userAccountSearch.and("apiKey", userAccountSearch.entity().getApiKey(), SearchCriteria.Op.EQ);
+ userAccountSearch.done();
+ }
+
@Override
public UserAccount getUserAccount(String username, Long domainId) {
if ((username == null) || (domainId == null)) {
@@ -45,4 +55,11 @@ public class UserAccountDaoImpl extends GenericDaoBase<UserAccountVO, Long> impl
}
return false;
}
+
+ @Override
+ public UserAccount getUserByApiKey(String apiKey) {
+ SearchCriteria<UserAccountVO> sc = userAccountSearch.create();
+ sc.setParameters("apiKey",apiKey);
+ return findOneBy(sc);
+ }
}