summaryrefslogtreecommitdiffstats
path: root/pki/base/common/src/com/netscape/cmscore/connector/RequestTransfer.java
blob: b00950209b2117a4234172b42bf1e6d163d3069f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
// --- BEGIN COPYRIGHT BLOCK ---
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; version 2 of the License.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License along
// with this program; if not, write to the Free Software Foundation, Inc.,
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
//
// (C) 2007 Red Hat, Inc.
// All rights reserved.
// --- END COPYRIGHT BLOCK ---
package com.netscape.cmscore.connector;


import java.util.Enumeration;
import java.util.Vector;

import com.netscape.certsrv.apps.CMS;
import com.netscape.certsrv.request.IRequest;
import com.netscape.cmscore.authentication.ChallengePhraseAuthentication;


public class RequestTransfer {

    private static final String DOT = ".";

    private static String[] transferAttributes = { 
            IRequest.HTTP_PARAMS,
            IRequest.AGENT_PARAMS, 
            IRequest.CERT_INFO, 
            IRequest.ISSUED_CERTS, 
            IRequest.OLD_CERTS, 
            IRequest.OLD_SERIALS, 
            IRequest.REVOKED_CERTS, 
            IRequest.CACERTCHAIN, 
            IRequest.CRL, 
            IRequest.ERRORS, 
            IRequest.RESULT,
            IRequest.ERROR,
            IRequest.SVCERRORS, 
            IRequest.REMOTE_STATUS, 
            IRequest.REMOTE_REQID, 
            IRequest.REVOKED_CERT_RECORDS,
            IRequest.CERT_STATUS,
            ChallengePhraseAuthentication.CHALLENGE_PHRASE,
            ChallengePhraseAuthentication.SUBJECTNAME,
            ChallengePhraseAuthentication.SERIALNUMBER,
            ChallengePhraseAuthentication.SERIALNOARRAY,
            IRequest.ISSUERDN,
            IRequest.CERT_FILTER, 
            "keyRecord",
            "uid", // UidPwdDirAuthentication.CRED_UID,
            "udn", // UdnPwdDirAuthentication.CRED_UDN,
        }; 

    public static boolean isProfileRequest(IRequest request) {
        String profileId = request.getExtDataInString("profileId");

        if (profileId == null || profileId.equals(""))
            return false;
        else
            return true;
    }

    public static String[] getTransferAttributes(IRequest r) {
        if (isProfileRequest(r)) {
            // copy everything in the request
            CMS.debug("RequestTransfer: profile request " + 
                r.getRequestId().toString());
            Enumeration e = r.getExtDataKeys();
            Vector v = new Vector();

            while (e.hasMoreElements()) {
                String k = (String) e.nextElement();

                if (k.equals("requestType"))
                    continue;
                if (k.equals("requestId"))
                    continue;
                if (k.equals("requestVersion"))
                    continue;
                if (k.equals("AUTH_TOKEN"))
                    continue;
                CMS.debug("RequestTransfer: attribute=" + k);
                if (k.equals("requestStatus")) {
                    CMS.debug("RequestTransfer : requestStatus=" +
                            r.getExtDataInString("requestStatus"));
                }
                v.addElement(k);
            }
            CMS.debug("RequestTransfer: attribute size=" + v.size());
            if (v.size() == 0)
                return null;
            String attrs[] = new String[v.size()];

            v.copyInto(attrs);
            return attrs;
        } else {
            return transferAttributes;
        }
    }

    public static void transfer(IRequest src, IRequest dest) {
        CMS.debug("Transfer srcId=" +
            src.getRequestId().toString() + 
            " destId=" + dest.getRequestId().toString());
        String attrs[] = getTransferAttributes(src);

        for (int i = 0; i < attrs.length; i++) {
            String key = attrs[i];
            if (src.isSimpleExtDataValue(key)) {
                dest.setExtData(key, src.getExtDataInString(key));
            } else {
                dest.setExtData(key, src.getExtDataInHashtable(key));
            }
        }
    }
}