summaryrefslogtreecommitdiffstats
path: root/pki/base/ca/src/com/netscape/ca/CAPolicy.java
blob: 8b2a48a3d9b57cf128317e069be1858e1c7d05de (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
125
126
127
128
129
130
131
132
133
134
135
136
// --- 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.ca;


import com.netscape.certsrv.policy.*;
import com.netscape.certsrv.request.*;
import com.netscape.certsrv.base.*;
import com.netscape.certsrv.profile.*;
import com.netscape.certsrv.apps.*;
import com.netscape.certsrv.ca.*;

import com.netscape.cmscore.policy.*;
import com.netscape.cmscore.util.Debug;


/**
 * XXX Just inherit 'GenericPolicyProcessor' (from RA) for now. 
 * This really bad. need to make a special case just for connector. 
 * would like a much better way of doing this to handle both EE and 
 * connectors.
 * XXX2 moved to just implement IPolicy since GenericPolicyProcessor is 
 * unuseable for CA.
 * 
 * @version $Revision$, $Date$
 */
public class CAPolicy implements IPolicy {
    IConfigStore mConfig = null;
    ICertificateAuthority mCA = null;

    public static String PROP_PROCESSOR = 
        "processor";
    // These are the different types of policy that are
    // allowed for the "processor" property
    public static String PR_TYPE_CLASSIC = "classic";

    // XXX this way for now since generic just works for EE.
    public GenericPolicyProcessor mPolicies = null;

    public CAPolicy() {
    }

    public IPolicyProcessor getPolicyProcessor() {
        return mPolicies;
    }

    public void init(ISubsystem owner, IConfigStore config)
        throws EBaseException {
        mCA = (ICertificateAuthority) owner;
        mConfig = config;

        String processorType =    // XXX - need to upgrade 4.2
            config.getString(PROP_PROCESSOR, PR_TYPE_CLASSIC);

        Debug.trace("selected policy processor = " + processorType);
        if (processorType.equals(PR_TYPE_CLASSIC)) {
            mPolicies = new GenericPolicyProcessor();
        } else {
            throw new EBaseException("Unknown policy processor type (" +
                    processorType + ")");
        }

        mPolicies.init(mCA, mConfig);
    }

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

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

    /** 
     */
    public PolicyResult apply(IRequest r) {
        if (r == null) {
            Debug.trace("in CAPolicy.apply(request=null)");
            return PolicyResult.REJECTED;
        }

        Debug.trace("in CAPolicy.apply(requestType=" +
            r.getRequestType() + ",requestId=" + 
            r.getRequestId().toString() + ",requestStatus=" +  
            r.getRequestStatus().toString() + ")");

        if (isProfileRequest(r)) { 
            Debug.trace("CAPolicy: Profile-base Request " + 
                r.getRequestId().toString()); 

            CMS.debug("CAPolicy: requestId=" + 
                r.getRequestId().toString());

            String profileId = r.getExtDataInString("profileId");

            if (profileId == null || profileId.equals("")) { 
                return PolicyResult.REJECTED;
            }

            IProfileSubsystem ps = (IProfileSubsystem) 
                CMS.getSubsystem("profile"); 

            try {
                IProfile profile = ps.getProfile(profileId); 

                r.setExtData("dbStatus", "NOT_UPDATED");
                profile.populate(r); 
                profile.validate(r); 
                return PolicyResult.ACCEPTED;
            } catch (EBaseException e) {
                CMS.debug("CAPolicy: " + e.toString());
                return PolicyResult.REJECTED;
            }
        }
        Debug.trace("mPolicies = " + mPolicies.getClass());
        return mPolicies.apply(r);
    }

}