summaryrefslogtreecommitdiffstats
path: root/base/tps/src/org/dogtagpki/server/tps/main/ExternalRegAttrs.java
blob: b9088883978c89ff75b59a3c40cfa2491793ccea (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
137
138
139
140
141
142
143
144
145
package org.dogtagpki.server.tps.main;

import java.math.BigInteger;
import java.util.ArrayList;

import org.dogtagpki.server.tps.engine.TPSEngine;
import org.dogtagpki.tps.main.TPSException;
import org.dogtagpki.tps.msg.EndOpMsg.TPSStatus;

import com.netscape.certsrv.apps.CMS;
import com.netscape.certsrv.base.EBaseException;
import com.netscape.certsrv.base.IConfigStore;

public class ExternalRegAttrs {
    public String ldapAttrNameTokenType;
    public String ldapAttrNameTokenCUID;
    public String ldapAttrNameCertsToRecover;

    String tokenCUID;
    String tokenType;
    String tokenUserId;
    String tokenMSN;

    ArrayList<ExternalRegCertToRecover> certsToRecover;

    boolean isDelegation;

    public ExternalRegAttrs(String authId) {
        String method = "ExternalRegAttrs";
        IConfigStore configStore = CMS.getConfigStore();
        String configName = null;

        try {
            configName = "auths.instance." + authId + ".externalReg.tokenTypeAttributeName";
            CMS.debug(method + ": getting config: " + configName);
            ldapAttrNameTokenType = configStore.getString(configName,
                    "tokenType");

            configName = "auths.instance." + authId + ".externalReg.cuidAttributeName";
            CMS.debug(method + ": getting config: " + configName);
            ldapAttrNameTokenCUID = configStore.getString(configName,
                    "tokenCUID");

            configName = "auths.instance." + authId + ".externalReg.certs.recoverAttributeName";
            CMS.debug(method + ": getting config: " + configName);
            ldapAttrNameCertsToRecover = configStore.getString(configName,
                    "certsToRecover");

            String RH_Delegation_Cfg = TPSEngine.CFG_EXTERNAL_REG + "." +
                    TPSEngine.CFG_ER_DELEGATION + ".enable";
            isDelegation = configStore.getBoolean(RH_Delegation_Cfg, false);
        } catch (EBaseException e) {
            CMS.debug("ExternalRegAttrs: unable to obtain certain config values.  Default to be used");
        }

        certsToRecover = new ArrayList<ExternalRegCertToRecover>();
    }

    public void setTokenType(String type) {
        tokenType = type;
    }

    public String getTokenType() {
        return tokenType;
    }

    public void setTokenCUID(String cuid) {
        tokenCUID = cuid;
    }

    public String getTokenCUID() {
        return tokenCUID;
    }

    public void setTokenUserId(String uid) {
        tokenUserId = uid;
    }

    public String getTokenUserId() {
        return tokenUserId;
    }

    public void setTokenMSN(String msn) {
        tokenMSN = msn;
    }

    public String getTokenMSN() {
        return tokenMSN;
    }

    public int getCertsToRecoverCount()
    {
        return certsToRecover.size();
    }

    public void addCertToRecover(ExternalRegCertToRecover cert)
    {
        certsToRecover.add(cert);
    }

    public ArrayList<ExternalRegCertToRecover> getCertsToRecover() {
        return certsToRecover;
    }

    public void setIsDelegation(boolean isDelegation) {
        this.isDelegation = isDelegation;
    }

    public boolean getIsDelegation() {
        return isDelegation;
    }

    /*
     *
     * @param serialString serial number in hex
     */
    public ExternalRegCertToRecover.CertStatus getCertStatus(String serialString) throws TPSException {
        String method = "ExternalRegAttrs.getCertStatus:";
        String logMsg = "";
        CMS.debug(method + "begins. getCertsToRecoverCount=" + getCertsToRecoverCount());
        if (serialString == null) {
            logMsg = "parameter serialString cannnot be null";
            CMS.debug(method + logMsg);
            throw new TPSException(method + logMsg, TPSStatus.STATUS_ERROR_CONTACT_ADMIN);
        } else
            CMS.debug(method + "searching for serialString =" + serialString);
        if (serialString.startsWith("0x")) {
            serialString = serialString.substring(2);
        }
        BigInteger serial = new BigInteger(serialString, 16);
        CMS.debug(method + "searching for serial=" + serial);
        for (ExternalRegCertToRecover cert: certsToRecover) {
            CMS.debug(method + "cert.getSerial()=" + cert.getSerial());
            if (serial.compareTo(cert.getSerial()) == 0) {
                CMS.debug(method + " cert found... returning status: " + cert.getCertStatus().toString());
                return cert.getCertStatus();
            }
        }
        logMsg = "cert not found in ExternalReg, status not reset";
        CMS.debug(method + logMsg);
        // no match means cert was not one of the ExternalReg recovered certs; so don't reset
        // use UNINITIALIZED to mean not found, as all certs in externalReg must have been set by now
        return ExternalRegCertToRecover.CertStatus.UNINITIALIZED;
    }
}