/**
* Creates a "hardtoken" with certficates.
*/
private void createHardToken(String username, String caName, String serialNumber) throws Exception {
GlobalConfiguration gc = raAdminSession.getCachedGlobalConfiguration(intAdmin);
boolean originalProfileSetting = gc.getEnableEndEntityProfileLimitations();
gc.setEnableEndEntityProfileLimitations(false);
raAdminSession.saveGlobalConfigurationRemote(intAdmin, gc);
if (certificateProfileSession.getCertificateProfileId(intAdmin, "WSTESTPROFILE") != 0) {
certificateProfileSession.removeCertificateProfile(intAdmin, "WSTESTPROFILE");
}
CertificateProfile profile = new EndUserCertificateProfile();
profile.setAllowValidityOverride(true);
certificateProfileSession.addCertificateProfile(intAdmin, "WSTESTPROFILE", profile);
UserDataVOWS tokenUser1 = new UserDataVOWS();
tokenUser1.setUsername(username);
tokenUser1.setPassword("foo123");
tokenUser1.setClearPwd(true);
tokenUser1.setSubjectDN("CN=" + username);
tokenUser1.setCaName(caName);
tokenUser1.setEmail(null);
tokenUser1.setSubjectAltName(null);
tokenUser1.setStatus(UserDataVOWS.STATUS_NEW);
tokenUser1.setTokenType(UserDataVOWS.TOKEN_TYPE_USERGENERATED);
tokenUser1.setEndEntityProfileName("EMPTY");
tokenUser1.setCertificateProfileName("ENDUSER");
KeyPair basickeys = KeyTools.genKeys("1024", AlgorithmConstants.KEYALGORITHM_RSA);
PKCS10CertificationRequest basicpkcs10 = new PKCS10CertificationRequest("SHA1WithRSA", CertTools.stringToBcX509Name("CN=NOTUSED"), basickeys
.getPublic(), new DERSet(), basickeys.getPrivate());
ArrayList<TokenCertificateRequestWS> requests = new ArrayList<TokenCertificateRequestWS>();
TokenCertificateRequestWS tokenCertReqWS = new TokenCertificateRequestWS();
tokenCertReqWS.setCAName(caName);
tokenCertReqWS.setCertificateProfileName("WSTESTPROFILE");
tokenCertReqWS.setValidityIdDays("1");
tokenCertReqWS.setPkcs10Data(basicpkcs10.getDEREncoded());
tokenCertReqWS.setType(HardTokenConstants.REQUESTTYPE_PKCS10_REQUEST);
requests.add(tokenCertReqWS);
tokenCertReqWS = new TokenCertificateRequestWS();
tokenCertReqWS.setCAName(caName);
tokenCertReqWS.setCertificateProfileName("ENDUSER");
tokenCertReqWS.setKeyalg("RSA");
tokenCertReqWS.setKeyspec("1024");
tokenCertReqWS.setType(HardTokenConstants.REQUESTTYPE_KEYSTORE_REQUEST);
requests.add(tokenCertReqWS);
HardTokenDataWS hardTokenDataWS = new HardTokenDataWS();
hardTokenDataWS.setLabel(HardTokenConstants.LABEL_PROJECTCARD);
hardTokenDataWS.setTokenType(HardTokenConstants.TOKENTYPE_SWEDISHEID);
hardTokenDataWS.setHardTokenSN(serialNumber);
PinDataWS basicPinDataWS = new PinDataWS();
basicPinDataWS.setType(HardTokenConstants.PINTYPE_BASIC);
basicPinDataWS.setInitialPIN("1234");
basicPinDataWS.setPUK("12345678");
PinDataWS signaturePinDataWS = new PinDataWS();
signaturePinDataWS.setType(HardTokenConstants.PINTYPE_SIGNATURE);
signaturePinDataWS.setInitialPIN("5678");
signaturePinDataWS.setPUK("23456789");
hardTokenDataWS.getPinDatas().add(basicPinDataWS);
hardTokenDataWS.getPinDatas().add(signaturePinDataWS);
List<TokenCertificateResponseWS> responses = ejbcaraws.genTokenCertificates(tokenUser1, requests, hardTokenDataWS, true, false);
assertTrue(responses.size() == 2);
certificateProfileSession.removeCertificateProfile(intAdmin, "WSTESTPROFILE");
gc.setEnableEndEntityProfileLimitations(originalProfileSetting);
raAdminSession.saveGlobalConfigurationRemote(intAdmin, gc);
} // createHardToken