java/code/src/com/redhat/rhn/frontend/xmlrpc/system/SystemHandler.java | 10 ++++++++++
1 file changed, 10 insertions(+)
New commits:
commit 66b40db71571aca6acb98d604c580267f4e91fb0
Author: Brad Buckingham <bbuckingham(a)redhat.com>
Date: Thu Apr 30 11:44:36 2009 -0400
498275 - api - system.obtainReactivationKey updated to replace existing key
In the UI, if a user generates a reactivation key, the new key replaces the
old one; however, with the current API it simply creates a new key. As
a result, there will be multiple reactivation keys for the system; however,
only one is seen from the UI.
This update will remove any existing reactivation keys for the system before
creating the new one.
diff --git a/java/code/src/com/redhat/rhn/frontend/xmlrpc/system/SystemHandler.java
b/java/code/src/com/redhat/rhn/frontend/xmlrpc/system/SystemHandler.java
index 508bff4..067167f 100644
--- a/java/code/src/com/redhat/rhn/frontend/xmlrpc/system/SystemHandler.java
+++ b/java/code/src/com/redhat/rhn/frontend/xmlrpc/system/SystemHandler.java
@@ -79,6 +79,7 @@ import com.redhat.rhn.domain.server.ServerGroupFactory;
import com.redhat.rhn.domain.server.VirtualInstance;
import com.redhat.rhn.domain.server.VirtualInstanceFactory;
import com.redhat.rhn.domain.token.ActivationKey;
+import com.redhat.rhn.domain.token.ActivationKeyFactory;
import com.redhat.rhn.domain.user.User;
import com.redhat.rhn.frontend.dto.ActivationKeyDto;
import com.redhat.rhn.frontend.dto.ErrataOverview;
@@ -161,6 +162,15 @@ public class SystemHandler extends BaseHandler {
if (!SystemManager.serverHasFeature(server.getId(), "ftr_agent_smith"))
{
throw new PermissionCheckFailureException();
}
+
+ // if there are any existing reactivation keys, remove them before
+ // creating a new one... there should only be 1; however, earlier
+ // versions of the API did not remove the existing reactivation keys;
+ // therefore, it is possible that multiple will be returned...
+ List<ActivationKey> existingKeys =
ActivationKeyFactory.lookupByServer(server);
+ for (ActivationKey key : existingKeys) {
+ ActivationKeyFactory.removeKey(key);
+ }
String note = "Reactivation key for " + server.getName() +
".";
ActivationKey key = ActivationKeyManager.getInstance().