Example usage for javax.xml.registry BusinessLifeCycleManager getRegistryService

List of usage examples for javax.xml.registry BusinessLifeCycleManager getRegistryService

Introduction

In this page you can find the example usage for javax.xml.registry BusinessLifeCycleManager getRegistryService.

Prototype

RegistryService getRegistryService() throws JAXRException;

Source Link

Document

Returns the parent RegistryService that created this object.

Usage

From source file:it.cnr.icar.eric.client.ui.swing.registration.UserManager.java

/** First check if certificate already exists in client keystore. If it does,
  * use it. If not then create a self signed certificate for the user and use it to
  * authenticate with the ebxmlrr server.
  * If the authentication is sucessful, save the user model to the server.
  *// w  w  w.j  ava2  s  . co m
  * @throw Exception
  *     An exception could indicate either a communications problem or an
  *     authentication error.
  */
public static void authenticateAndSaveUser(UserModel userModel) throws Exception {
    @SuppressWarnings("unused")
    boolean generatedCert = false;
    UserRegistrationInfo userRegInfo = userModel.getUserRegistrationInfo();
    try {
        JAXRClient client = RegistryBrowser.getInstance().getClient();
        BusinessLifeCycleManager lcm = client.getBusinessLifeCycleManager();
        RegistryServiceImpl rs = (RegistryServiceImpl) lcm.getRegistryService();
        ConnectionImpl connection = rs.getConnection();

        if (!userRegInfo.isCAIssuedCert()) {
            if (!CertificateUtil.certificateExists(userRegInfo.getAlias(), userRegInfo.getStorePassword())) {
                CertificateUtil.generateRegistryIssuedCertificate(userRegInfo);
            }
        } else {
            try {
                CertificateUtil.importCAIssuedCert(userRegInfo);
            } catch (Exception e) {
                throw new JAXRException(
                        JavaUIResourceBundle.getInstance().getString("error.importCertificateFailed"), e);
            }
        }

        // Force re-authentication in case credentials are already set
        connection.authenticate();

        RegistryBrowser.setWaitCursor();

        // Now save the User
        ArrayList<User> objects = new ArrayList<User>();
        objects.add(userModel.getUser());
        client.saveObjects(objects, false, false);

        // saveObjects uses XML-Security which overwrites the log4j
        // configuration and we never get to see this:
        log.info(JavaUIResourceBundle.getInstance().getString("message.SavedUserOnServer",
                new Object[] { ((PersonNameImpl) (userModel.getUser().getPersonName())).getFormattedName() }));
    } catch (Exception e) {
        // Remove the self-signed certificate from the keystore, if one
        // was created during the self-registration process
        try {
            if (userRegInfo != null) {
                String alias = userRegInfo.getAlias();

                if ((alias != null) && (!userRegInfo.isCAIssuedCert())) {
                    CertificateUtil.removeCertificate(alias, userRegInfo.getStorePassword());
                }
            }
        } catch (Exception removeCertException) {
            log.warn(
                    JavaUIResourceBundle.getInstance()
                            .getString("message.FailedToRemoveTheCertificateFromTheKeystoreGenerated"),
                    removeCertException);
        }

        throw e;
    } finally {
        RegistryBrowser.setDefaultCursor();
    }
}