java/code/src/com/redhat/rhn/frontend/xmlrpc/BaseHandler.java |
16 ++++
java/code/src/com/redhat/rhn/frontend/xmlrpc/PermissionCheckFailureException.java |
11 +++
java/code/src/com/redhat/rhn/frontend/xmlrpc/kickstart/keys/CryptoKeysHandler.java |
29 ++++++++
java/code/src/com/redhat/rhn/manager/kickstart/crypto/EditCryptoKeyCommand.java |
3
java/code/src/com/redhat/rhn/manager/kickstart/crypto/NoSuchCryptoKeyException.java |
33 ++++++++++
5 files changed, 92 insertions(+)
New commits:
commit fc334dc95b0fcf33916eccd261bb27c97ecfb79d
Author: Tomas Lestach <tlestach(a)redhat.com>
Date: Thu Aug 25 16:39:46 2011 +0200
699489 - introduce kickstart.keys.update API
diff --git a/java/code/src/com/redhat/rhn/frontend/xmlrpc/BaseHandler.java
b/java/code/src/com/redhat/rhn/frontend/xmlrpc/BaseHandler.java
index b8b3c58..22664ef 100644
--- a/java/code/src/com/redhat/rhn/frontend/xmlrpc/BaseHandler.java
+++ b/java/code/src/com/redhat/rhn/frontend/xmlrpc/BaseHandler.java
@@ -275,6 +275,22 @@ public class BaseHandler implements XmlRpcInvocationHandler {
}
/**
+ * Public helper method to make sure a user has either
+ * an org admin or a config admin role
+ * If not, this will throw a generic Permission exception.
+ * @param user The user to check
+ * @throws PermissionCheckFailureException if user is neither org nor config admin.
+ */
+ public static void ensureOrgOrConfigAdmin(User user)
+ throws PermissionCheckFailureException {
+ if (!user.hasRole(RoleFactory.ORG_ADMIN) &&
+ !user.hasRole(RoleFactory.CONFIG_ADMIN)) {
+ throw new PermissionCheckFailureException(RoleFactory.ORG_ADMIN,
+ RoleFactory.CONFIG_ADMIN);
+ }
+ }
+
+ /**
* Private helper method to make sure a user the given role..
* If not, this will throw a generic Permission exception.
* @param user The user to check
diff --git
a/java/code/src/com/redhat/rhn/frontend/xmlrpc/PermissionCheckFailureException.java
b/java/code/src/com/redhat/rhn/frontend/xmlrpc/PermissionCheckFailureException.java
index 388e5fb..f11112f 100644
--- a/java/code/src/com/redhat/rhn/frontend/xmlrpc/PermissionCheckFailureException.java
+++ b/java/code/src/com/redhat/rhn/frontend/xmlrpc/PermissionCheckFailureException.java
@@ -76,6 +76,17 @@ public class PermissionCheckFailureException extends FaultException {
/**
* Constructor
+ * @param role1 Cause for the exception (bad role)
+ * @param role2 Cause for the exception (bad role)
+ */
+ public PermissionCheckFailureException(Role role1, Role role2) {
+ super(-23, "permissionCheckFailure", "You do not have permissions
to " +
+ "perform this action. You need to have at least a " +
role1.getName() +
+ " or " + role2.getName() + " role to perform this
action");
+ }
+
+ /**
+ * Constructor
* @param ent Cause for the exception (bad org entitlement type)
*/
public PermissionCheckFailureException(OrgEntitlementType ent) {
diff --git
a/java/code/src/com/redhat/rhn/frontend/xmlrpc/kickstart/keys/CryptoKeysHandler.java
b/java/code/src/com/redhat/rhn/frontend/xmlrpc/kickstart/keys/CryptoKeysHandler.java
index 75e50bc..32ce62c 100644
--- a/java/code/src/com/redhat/rhn/frontend/xmlrpc/kickstart/keys/CryptoKeysHandler.java
+++ b/java/code/src/com/redhat/rhn/frontend/xmlrpc/kickstart/keys/CryptoKeysHandler.java
@@ -142,6 +142,35 @@ public class CryptoKeysHandler extends BaseHandler {
}
/**
+ * Updates type and content of the key identified by the description
+ *
+ * @param sessionKey identifies the user that is logged in and performing the call
+ * @param description description of the key used for identification
+ * @param type type of key being created
+ * @param content contents of the key itself
+ * @return 1 if the delete was successful
+ * @throws KickstartKeyDeleteException if there is an error during the delete
+ *
+ * @xmlrpc.doc Updates type and content of the key identified by the description
+ * @xmlrpc.param #param("string", "session_key")
+ * @xmlrpc.param #param("string", "description")
+ * @xmlrpc.param #param_desc("string", "type", "valid values
are GPG or SSL")
+ * @xmlrpc.param #param("string", "content")
+ * @xmlrpc.returntype #return_int_success()
+ */
+ public int update(String sessionKey, String description, String type, String content)
{
+ User loggedInUser = getLoggedInUser(sessionKey);
+ BaseHandler.ensureOrgOrConfigAdmin(loggedInUser);
+
+ EditCryptoKeyCommand cmd = new EditCryptoKeyCommand(loggedInUser, description);
+ cmd.setType(type);
+ cmd.setContents(content);
+ cmd.store(); // in this case we do not expect any error
+ // because we do not touch description
+ return 1;
+ }
+
+ /**
* Returns all of the data associated with the given key.
*
* @param sessionKey identifies the user that is logged in and performing the call
diff --git
a/java/code/src/com/redhat/rhn/manager/kickstart/crypto/EditCryptoKeyCommand.java
b/java/code/src/com/redhat/rhn/manager/kickstart/crypto/EditCryptoKeyCommand.java
index 154ab4d..068be67 100644
--- a/java/code/src/com/redhat/rhn/manager/kickstart/crypto/EditCryptoKeyCommand.java
+++ b/java/code/src/com/redhat/rhn/manager/kickstart/crypto/EditCryptoKeyCommand.java
@@ -52,5 +52,8 @@ public class EditCryptoKeyCommand extends BaseCryptoKeyCommand {
}
this.key = KickstartFactory.lookupCryptoKey(description, currentUser.getOrg());
+ if (this.key == null) {
+ throw new NoSuchCryptoKeyException(description);
+ }
}
}
diff --git
a/java/code/src/com/redhat/rhn/manager/kickstart/crypto/NoSuchCryptoKeyException.java
b/java/code/src/com/redhat/rhn/manager/kickstart/crypto/NoSuchCryptoKeyException.java
new file mode 100644
index 0000000..0f5090f
--- /dev/null
+++ b/java/code/src/com/redhat/rhn/manager/kickstart/crypto/NoSuchCryptoKeyException.java
@@ -0,0 +1,33 @@
+/**
+ * Copyright (c) 2011 Red Hat, Inc.
+ *
+ * This software is licensed to you under the GNU General Public License,
+ * version 2 (GPLv2). There is NO WARRANTY for this software, express or
+ * implied, including the implied warranties of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE. You should have received a copy of GPLv2
+ * along with this software; if not, see
+ *
http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
+ *
+ * Red Hat trademarks are not licensed under GPLv2. No permission is
+ * granted to use or replicate Red Hat trademarks that are incorporated
+ * in this software or its documentation.
+ */
+package com.redhat.rhn.manager.kickstart.crypto;
+
+import com.redhat.rhn.FaultException;
+
+
+/**
+ * NoSuchCryptoKeyException
+ * @version $Rev$
+ */
+public class NoSuchCryptoKeyException extends FaultException {
+
+ /**
+ * Constructor
+ * @param description the key description
+ */
+ public NoSuchCryptoKeyException(String description) {
+ super(1210, "invalidCryptoKey", "Invalid crypto key description:
" + description);
+ }
+}