Example usage for javax.xml.registry RegistryException RegistryException

List of usage examples for javax.xml.registry RegistryException RegistryException

Introduction

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

Prototype

public RegistryException(Throwable cause) 

Source Link

Document

Constructs a JAXRException object initialized with the given Throwable object.

Usage

From source file:org.freebxml.omar.server.repository.AbstractRepositoryManager.java

/**
 * Get the size of a repository item in bytes.
 * @param id Unique id for ExtrinsicObject whose repository item size is desired
 * @return 0 if the file does not exist.
 *///from   w w w  .j a  va2s . c om
public long getItemSize(String id) throws RegistryException {
    long itemSize = 0;
    try {
        RepositoryItem ri = getRepositoryItem(id);
        itemSize = (long) ri.getSize();
    } catch (RepositoryItemNotFoundException e) {
        //return 0;
    } catch (Exception e) {
        log.error(e, e);
        String msg = ServerResourceBundle.getInstance().getString("message.FailedToGetSizeForRepositoryItem",
                new Object[] { id, null });
        throw new RegistryException(ServerResourceBundle.getInstance().getString("message.seeLogsForDetails",
                new Object[] { msg }));
    }

    return itemSize;
}

From source file:org.freebxml.omar.server.repository.AbstractRepositoryManager.java

/**
 * Gets the versionName of the latest version of RepositoryItem
 * that matches the specified lid.//ww w. j av a  2 s  .  c o m
 */
public String getLatestVersionName(ServerRequestContext context, String lid) throws RegistryException {
    String latestVersion = null;

    try {
        ResponseOption responseOption = bu.queryFac.createResponseOption();
        responseOption.setReturnComposedObjects(true);
        responseOption.setReturnType(ReturnType.LEAF_CLASS);

        List objectRefs = new ArrayList();
        String sqlQuery = "SELECT eo.* FROM ExtrinsicObject eo WHERE eo.lid= ? AND eo.contentVersionName IS NOT NULL";
        ArrayList queryParams = new ArrayList();
        queryParams.add(lid);
        String tableName = Utility.getInstance().mapTableName("ExtrinsicObject");

        List eos = PersistenceManagerFactory.getInstance().getPersistenceManager().executeSQLQuery(context,
                sqlQuery, queryParams, responseOption, tableName, objectRefs);

        if (eos.size() == 0) {
            return null;
        }

        ExtrinsicObjectType latestEO = null;
        for (Iterator it = eos.iterator(); it.hasNext();) {
            if (latestEO == null) {
                latestEO = (ExtrinsicObjectType) it.next();
                latestVersion = latestEO.getContentVersionInfo().getVersionName();
                continue;
            }

            ExtrinsicObjectType next = (ExtrinsicObjectType) it.next();
            String nextVersion = next.getContentVersionInfo().getVersionName();

            if (compareVersions(nextVersion, latestVersion) > 0) {
                latestEO = next;
                latestVersion = latestEO.getContentVersionInfo().getVersionName();
            }
        }

    } catch (javax.xml.bind.JAXBException e) {
        throw new RegistryException(e);
    }

    return latestVersion;
}

From source file:org.freebxml.omar.server.repository.filesystem.FileSystemRepositoryManager.java

/**
* Returns the RepositoryItem with the given unique ID.
*
* @param id Unique id for repository item
* @return RepositoryItem instance/*  w  w w . j  ava  2  s  .c o  m*/
* @exception RegistryException
*/
public RepositoryItem getRepositoryItem(String id) throws RegistryException {
    RepositoryItem repositoryItem = null;
    String origId = id;

    // Strip off the "urn:uuid:"
    id = Utility.getInstance().stripId(id);

    try {
        String path = getRepositoryItemPath(id);
        File riFile = new File(path);

        if (!riFile.exists()) {
            String errmsg = ServerResourceBundle.getInstance().getString("message.RepositoryItemDoesNotExist",
                    new Object[] { id });
            log.error(errmsg);
            throw new RegistryException(errmsg);
        }

        DataHandler contentDataHandler = new DataHandler(new FileDataSource(riFile));

        Element sigElement = null;
        path += ".sig";

        File sigFile = new File(path);

        if (!sigFile.exists()) {
            String errmsg = "Payload signature for repository item id=\"" + id + "\" does not exist!";
            //log.error(errmsg);

            throw new RegistryException(errmsg);
        } else {

            javax.xml.parsers.DocumentBuilderFactory dbf = javax.xml.parsers.DocumentBuilderFactory
                    .newInstance();
            dbf.setNamespaceAware(true);
            javax.xml.parsers.DocumentBuilder db = dbf.newDocumentBuilder();
            org.w3c.dom.Document sigDoc = db.parse(new FileInputStream(sigFile));

            repositoryItem = new RepositoryItemImpl(id, sigDoc.getDocumentElement(), contentDataHandler);
        }

    } catch (RegistryException e) {
        throw e;
    } catch (Exception e) {
        throw new RegistryException(e);
    }

    return repositoryItem;
}

From source file:org.freebxml.omar.server.repository.filesystem.FileSystemRepositoryManager.java

public void delete(org.freebxml.omar.server.repository.RepositoryItemKey key) throws RegistryException {
    throw new RegistryException(ServerResourceBundle.getInstance().getString("message.unimplemented"));
}

From source file:org.freebxml.omar.server.repository.filesystem.FileSystemRepositoryManager.java

public RepositoryItem getRepositoryItem(org.freebxml.omar.server.repository.RepositoryItemKey key)
        throws RegistryException {
    throw new RegistryException(ServerResourceBundle.getInstance().getString("message.unimplemented"));
}

From source file:org.freebxml.omar.server.security.authentication.AuthenticationServiceImpl.java

private void loadPublicKeyToCertMap() throws RegistryException {
    try {//from   w w  w  . j av a 2s . c o m
        KeyStore store = getKeyStore();

        for (Enumeration e = store.aliases(); e.hasMoreElements();) {
            String alias = (String) e.nextElement();
            X509Certificate cert = (X509Certificate) store.getCertificate(alias);
            PublicKey publicKey = cert.getPublicKey();
            publicKeyToCertMap.put(publicKey, cert);
        }
    } catch (KeyStoreException e) {
        throw new RegistryException(e);
    }

}

From source file:org.freebxml.omar.server.security.authentication.AuthenticationServiceImpl.java

/**
 * Get the keystore whose path is specified  by {@link #getKeyStoreFileName()}.
 * Note that all the methods that access the keystore MUST access the keystore
 * via this method. Do not access the keystore directly by accessing the keystore
 * field. Otherwise the checking the write lock to keystore will be bypassed.
 *//*  www . ja  v  a2  s  .c  o  m*/
public KeyStore getKeyStore() throws RegistryException {
    synchronized (keyStoreWriteLock) {
        if (keyStore == null) {
            java.io.FileInputStream fis = null;

            try {
                String keystoreType = RegistryProperties.getInstance().getProperty("omar.security.keystoreType",
                        "JKS");
                keyStore = KeyStore.getInstance(keystoreType);

                String keystoreFile = getKeyStoreFileName();
                fis = new java.io.FileInputStream(keystoreFile);

                String keystorePass = getKeyStorePassword();
                keyStore.load(fis, keystorePass.toCharArray());
            } catch (java.security.cert.CertificateException e) {
                throw new RegistryException(e);
            } catch (KeyStoreException e) {
                throw new RegistryException(e);
            } catch (NoSuchAlgorithmException e) {
                throw new RegistryException(e);
            } catch (java.io.FileNotFoundException e) {
                throw new RegistryException(e);
            } catch (IOException e) {
                throw new RegistryException(e);
            } finally {
                if (fis != null) {
                    try {
                        fis.close();
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                }
            }
        }

        return keyStore;
    }
}

From source file:org.freebxml.omar.server.security.authentication.AuthenticationServiceImpl.java

/**
 * Gets the alias within the KeyStore for a User
 *///  ww  w.  j a  v  a  2  s.com
public X509Certificate getCertificateFromUser(User user) throws RegistryException {
    X509Certificate cert = null;

    try {
        String alias = getAliasFromUser(user);

        cert = (X509Certificate) (getKeyStore().getCertificate(alias));
    } catch (KeyStoreException e) {
        throw new RegistryException(e);
    }

    return cert;
}

From source file:org.freebxml.omar.server.security.authentication.AuthenticationServiceImpl.java

/**
 * Gets the User that is associated with the given alias.
 *
 * @throws UserNotFoundException when no matching User is found
 *//*from   ww  w.j av  a  2s.  com*/
public UserType getUserFromAlias(String alias) throws RegistryException {
    UserType user = null;

    ServerRequestContext context = null;
    try {
        context = new ServerRequestContext("AuthenticationServiceImpl.getUserFromAlias", null);
        context.setUser(this.registryOperator);
        String userId = alias;
        user = (UserType) ServerCache.getInstance().getRegistryObject(context, userId, "User");
        if (user == null) {
            throw new UserNotFoundException(userId);
        }

        //See if User need to be auto-classified as RegistryAdministrator
        boolean isAdmin = isRegistryAdministratorInPropFile(user);

        if (isAdmin) {
            //Make sure that the user is classified with the RegistryAdministrator role
            makeRegistryAdministrator(context, user);
        }

        context.commit();
        context = null;
    } catch (RegistryException e) {
        throw e;
    } catch (Exception e) {
        throw new RegistryException(e);
    } finally {
        if (null != context) {
            // Oh no, it's still here...
            context.rollback();
        }
    }

    return user;
}

From source file:org.freebxml.omar.server.security.authentication.AuthenticationServiceImpl.java

/**
 * Make sure user gets auto-classified as RegistryAdministrator if not so already.
 *//*from  ww w.j a  v a2 s. c  o m*/
private void makeRegistryAdministrator(ServerRequestContext context, UserType user) throws RegistryException {

    try {
        if (user != null) {
            boolean isAdmin = hasRegistryAdministratorRole(user);

            if (!isAdmin) {
                /* ??? Need new message for this logging. 
                // Log real changes to security realm -- new admins.
                          if (log.isInfoEnabled()) {
                log.info(ServerResourceBundle.getInstance().
                   getString("message.getRegistryAdministratorsAddingAdmin",
                        new Object[]{user.getId()}));
                          }
                */
                org.oasis.ebxml.registry.bindings.rim.Classification classification = BindingUtility
                        .getInstance().rimFac.createClassification();
                classification.setId(org.freebxml.omar.common.Utility.getInstance().createId());
                classification
                        .setClassificationNode(BindingUtility.CANONICAL_SUBJECT_ROLE_ID_RegistryAdministrator);
                classification.setClassifiedObject(user.getId());
                user.getClassification().add(classification);

                //Now persists updated User 
                java.util.List al = new java.util.ArrayList();
                al.add(user);
                pm.update(context, al);
            }
        }

        // ??? This method did not create this context, should it commit?
        context.commit();
        // A local signal to the finally block below.
        context = null;
    } catch (RegistryException e) {
        throw e;
    } catch (Exception e) {
        throw new RegistryException(e);
    } finally {
        if (null != context) {
            // Oh no, it's still here...
            context.rollback();
        }
    }
}