diff options
Diffstat (limited to 'base/common/src/com/netscape/certsrv/key/KeyRecoveryRequest.java')
-rw-r--r-- | base/common/src/com/netscape/certsrv/key/KeyRecoveryRequest.java | 108 |
1 files changed, 61 insertions, 47 deletions
diff --git a/base/common/src/com/netscape/certsrv/key/KeyRecoveryRequest.java b/base/common/src/com/netscape/certsrv/key/KeyRecoveryRequest.java index aa69d8336..f2d259bf8 100644 --- a/base/common/src/com/netscape/certsrv/key/KeyRecoveryRequest.java +++ b/base/common/src/com/netscape/certsrv/key/KeyRecoveryRequest.java @@ -24,14 +24,10 @@ package com.netscape.certsrv.key; import javax.ws.rs.core.MultivaluedMap; import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlAccessorType; -import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlRootElement; -import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter; import com.netscape.certsrv.dbs.keydb.KeyId; -import com.netscape.certsrv.dbs.keydb.KeyIdAdapter; import com.netscape.certsrv.request.RequestId; -import com.netscape.certsrv.request.RequestIdAdapter; /** * @author alee @@ -39,36 +35,15 @@ import com.netscape.certsrv.request.RequestIdAdapter; */ @XmlRootElement(name="KeyRecoveryRequest") @XmlAccessorType(XmlAccessType.FIELD) -public class KeyRecoveryRequest { +public class KeyRecoveryRequest extends Request { private static final String KEY_ID = "keyId"; private static final String REQUEST_ID = "requestId"; private static final String TRANS_WRAPPED_SESSION_KEY = "transWrappedSessionKey"; private static final String SESSION_WRAPPED_PASSPHRASE = "sessionWrappedPassphrase"; private static final String NONCE_DATA = "nonceData"; - - @XmlElement - @XmlJavaTypeAdapter(KeyIdAdapter.class) - protected KeyId keyId; - - @XmlElement - @XmlJavaTypeAdapter(RequestIdAdapter.class) - protected RequestId requestId; - - @XmlElement - protected String transWrappedSessionKey; - - @XmlElement - protected String sessionWrappedPassphrase; - - @XmlElement - protected String nonceData; - - @XmlElement - protected String certificate; - - @XmlElement - protected String passphrase; + private static final String CERTIFICATE = "certificate"; + private static final String PASSPHRASE = "passphrase"; public KeyRecoveryRequest() { // required for JAXB (defaults) @@ -76,70 +51,73 @@ public class KeyRecoveryRequest { public KeyRecoveryRequest(MultivaluedMap<String, String> form) { if (form.containsKey(KEY_ID)) { - keyId = new KeyId(form.getFirst(KEY_ID)); + this.properties.put(KEY_ID, form.getFirst(KEY_ID)); } if (form.containsKey(REQUEST_ID)) { - requestId = new RequestId(form.getFirst(REQUEST_ID)); + this.properties.put(REQUEST_ID, form.getFirst(REQUEST_ID)); } - transWrappedSessionKey = form.getFirst(TRANS_WRAPPED_SESSION_KEY); - sessionWrappedPassphrase = form.getFirst(SESSION_WRAPPED_PASSPHRASE); - nonceData = form.getFirst(NONCE_DATA); + this.properties.put(TRANS_WRAPPED_SESSION_KEY, form.getFirst(TRANS_WRAPPED_SESSION_KEY)); + this.properties.put(SESSION_WRAPPED_PASSPHRASE, form.getFirst(SESSION_WRAPPED_PASSPHRASE)); + this.properties.put(NONCE_DATA, form.getFirst(NONCE_DATA)); + this.properties.put(CERTIFICATE, form.getFirst(CERTIFICATE)); + this.properties.put(PASSPHRASE, form.getFirst(PASSPHRASE)); + } /** * @return the keyId */ public KeyId getKeyId() { - return keyId; + return new KeyId(this.properties.get(KEY_ID)); } /** * @param keyId the keyId to set */ public void setKeyId(KeyId keyId) { - this.keyId = keyId; + this.properties.put(KEY_ID, keyId.toString()); } /** * @return the requestId */ public RequestId getRequestId() { - return requestId; + return new RequestId(this.properties.get(REQUEST_ID)); } /** * @param requestId the requestId to set */ public void setRequestId(RequestId requestId) { - this.requestId = requestId; + this.properties.put(REQUEST_ID, requestId.toString()); } /** * @return the transWrappedSessionKey */ public String getTransWrappedSessionKey() { - return transWrappedSessionKey; + return this.properties.get(TRANS_WRAPPED_SESSION_KEY); } /** * @param transWrappedSessionKey the transWrappedSessionKey to set */ public void setTransWrappedSessionKey(String transWrappedSessionKey) { - this.transWrappedSessionKey = transWrappedSessionKey; + this.properties.put(TRANS_WRAPPED_SESSION_KEY, transWrappedSessionKey); } /** * @return the sessionWrappedPassphrase */ public String getSessionWrappedPassphrase() { - return sessionWrappedPassphrase; + return this.properties.get(SESSION_WRAPPED_PASSPHRASE); } /** * @param sessionWrappedPassphrase the sessionWrappedPassphrase to set */ public void setSessionWrappedPassphrase(String sessionWrappedPassphrase) { - this.sessionWrappedPassphrase = sessionWrappedPassphrase; + this.properties.put(SESSION_WRAPPED_PASSPHRASE, sessionWrappedPassphrase); } /** @@ -147,7 +125,7 @@ public class KeyRecoveryRequest { */ public String getNonceData() { - return nonceData; + return this.properties.get(NONCE_DATA); } /** @@ -155,34 +133,70 @@ public class KeyRecoveryRequest { */ public void setNonceData(String nonceData) { - this.nonceData = nonceData; + this.properties.put(NONCE_DATA, nonceData); } /** * @return the certificate */ public String getCertificate() { - return certificate; + return this.properties.get(CERTIFICATE); } /** * @param certificate the certificate to set */ public void setCertificate(String certificate) { - this.certificate = certificate; + this.properties.put(CERTIFICATE, certificate); } /** * @return the passphrase */ public String getPassphrase() { - return passphrase; + return this.properties.get(PASSPHRASE); } /** * @param passphrase the passphrase to set */ public void setPassphrase(String passphrase) { - this.passphrase = passphrase; + this.properties.put(PASSPHRASE, passphrase); + } + + + public static KeyRecoveryRequest valueOf(String string) throws Exception { + try { + return Request.unmarshal(string, KeyRecoveryRequest.class); + } catch (Exception e) { + return null; + } + } + + public String toString() { + try { + return Request.marshal(this, KeyRecoveryRequest.class); + } catch (Exception e) { + return super.toString(); + } + } + + public static void main(String args[]) throws Exception { + + KeyRecoveryRequest before = new KeyRecoveryRequest(); + before.setKeyId(new KeyId("0x123456")); + before.setNonceData("nonce-XXX12345"); + before.setPassphrase("password"); + before.setRequestId(new RequestId("0x123F")); + before.setCertificate("123ABCAAAA"); + before.setSessionWrappedPassphrase("XXXXXXXX1234"); + before.setTransWrappedSessionKey("124355AAA"); + before.setRequestType(KeyRequestResource.RECOVERY_REQUEST); + + String string = before.toString(); + System.out.println(string); + + KeyRecoveryRequest after = KeyRecoveryRequest.valueOf(string); + System.out.println(before.equals(after)); } } |