List of usage examples for javax.xml.registry.infomodel User getLifeCycleManager
LifeCycleManager getLifeCycleManager() throws JAXRException;
From source file:it.cnr.icar.eric.client.xml.registry.util.CertificateUtil.java
/** * Generate a self signed certificate and store it in the keystore. * /*from ww w . j av a 2 s .c o m*/ * @param userRegInfo * @throws JAXRException */ public static void generateRegistryIssuedCertificate(UserRegistrationInfo userRegInfo) throws JAXRException { User user = userRegInfo.getUser(); LifeCycleManager lcm = user.getLifeCycleManager(); String dname = getDNameFromUser(userRegInfo); File keystoreFile = KeystoreUtil.getKeystoreFile(); KeystoreUtil.createKeystoreDirectory(keystoreFile); String keystoreType = ProviderProperties.getInstance().getProperty("jaxr-ebxml.security.storetype", "JKS"); String storePassStr = new String(userRegInfo.getStorePassword()); String keyPassStr = new String(userRegInfo.getKeyPassword()); String alias = userRegInfo.getAlias(); String keyAlg = "RSA"; // XWSS does not support DSA which is default is // KeyTool. Hmm. Weird. String[] args = { "-genkey", "-keyAlg", keyAlg, "-alias", alias, "-keypass", keyPassStr, "-keystore", keystoreFile.getAbsolutePath(), "-storepass", storePassStr, "-storetype", keystoreType, "-dname", dname }; try { KeyTool keytool = new KeyTool(); keytool.run(args, System.out); // Now load the KeyStore and get the cert FileInputStream fis = new FileInputStream(keystoreFile); KeyStore keyStore = KeyStore.getInstance(keystoreType); keyStore.load(fis, storePassStr.toCharArray()); fis.close(); X509Certificate cert = (X509Certificate) keyStore.getCertificate(alias); Certificate[] certChain = getCertificateSignedByRegistry(lcm, cert); Key key = keyStore.getKey(alias, userRegInfo.getKeyPassword()); // Now overwrite original cert with signed cert keyStore.deleteEntry(alias); // keyStore.setCertificateEntry(alias, cert); keyStore.setKeyEntry(alias, key, userRegInfo.getKeyPassword(), certChain); FileOutputStream fos = new java.io.FileOutputStream(keystoreFile); keyStore.store(fos, storePassStr.toCharArray()); fos.flush(); fos.close(); } catch (Exception e) { throw new JAXRException(JAXRResourceBundle.getInstance().getString("message.CertGenFailed"), e); } log.debug(JAXRResourceBundle.getInstance().getString("message.StoredUserInKeyStore", new Object[] { alias, keystoreFile.getAbsolutePath() })); try { // Export registry issued cert to certFile so it can be available // for import into a web browser for SSL access to registry exportRegistryIssuedCert(userRegInfo); } catch (Exception e) { String msg = JAXRResourceBundle.getInstance().getString( "message.UnableToExportCertificateSeeNextExceptionNoteThatThisFeatureRequiresUseOfJDK5"); log.warn(msg, e); // Do not throw exception as user reg can be done despite not // exporting the p12 file for the web browser. } }
From source file:it.cnr.icar.eric.client.xml.registry.util.CertificateUtil.java
/** * DOCUMENT ME!/*from w ww .j a v a 2s.co m*/ * * @param user * DOCUMENT ME! * * @return DOCUMENT ME! * * @throws JAXRException * DOCUMENT ME! */ private static String getDNameFromUser(UserRegistrationInfo userRegInfo) throws JAXRException { User user = userRegInfo.getUser(); String dname = "CN="; LifeCycleManager lcm = user.getLifeCycleManager(); Collection<?> addresses = user.getPostalAddresses(); PostalAddress address; PersonName personName = user.getPersonName(); // CN=Farrukh Najmi, OU=freebxml.org, O=ebxmlrr, L=Islamabad, ST=Punjab, // C=PK if (personName == null) { personName = lcm.createPersonName("firstName", "middleName", "lastName"); } if ((addresses != null) && (addresses.size() > 0)) { address = (PostalAddress) (addresses.iterator().next()); } else { address = lcm.createPostalAddress("number", "street", "city", "state", "country", "postalCode", "Office"); } String city = address.getCity(); if ((city == null) || (city.length() == 0)) { city = "Unknown"; } String state = address.getStateOrProvince(); if ((state == null) || (state.length() == 0)) { state = "Unknown"; } String country = address.getCountry(); if ((country == null) || (country.length() == 0)) { country = "US"; } if (country.length() > 0) { country = country.substring(0, 2); } String organization = userRegInfo.getOrganization(); if (organization == null || organization.trim().length() == 0) { organization = "Unknown"; } String unit = userRegInfo.getOrganizationUnit(); if (unit == null || unit.trim().length() == 0) { unit = "Unknown"; } // Escape "," in formattedName per section 2.4 of RFC 2253. \u002c is // hex code for "," String formattedName = ((PersonNameImpl) personName).getFormattedName(); formattedName = formattedName.replaceAll(",", "\\\\,"); dname += (formattedName + ", OU=" + unit + ", O=" + organization + ", L=" + city + ", ST=" + state + ", C=" + country); return dname; }
From source file:it.cnr.icar.eric.client.ui.thin.RegistryObjectCollectionBean.java
/** * Prepares this bean to be used by RegistrationWizard for creating a new user account. */// w w w.java2 s. c o m public String doRegister() { String status = "error"; try { SearchPanelBean.getInstance().doClear(); User user = RegistryBrowser.getBLCM().createUser(); // Create the SRVBs // Create the ROB using the RO and SRVBs // Register the ROB PersonName pn = (PersonName) user.getLifeCycleManager().createObject("PersonName"); user.setPersonName(pn); EmailAddress ea = (EmailAddress) user.getLifeCycleManager().createObject("EmailAddress"); ((UserImpl) user).addEmailAddress(ea); PostalAddress pa = (PostalAddress) user.getLifeCycleManager().createObject("PostalAddress"); ((UserImpl) user).addPostalAddress(pa); TelephoneNumber tn = (TelephoneNumber) user.getLifeCycleManager().createObject("TelephoneNumber"); ((UserImpl) user).addTelephoneNumber(tn); List<RegistryObject> ros = new ArrayList<RegistryObject>(1); ros.add(user); handleRegistryObjects(ros); currentRegistryObject = registryObjectBeans.iterator().next(); currentRegistryObject.initRelatedObjects(); status = "showRegisterPage"; } catch (Throwable t) { append(WebUIResourceBundle.getInstance().getString("errorInRegistration")); } return status; }