List of usage examples for javax.xml.registry RegistryException RegistryException
public RegistryException(Throwable cause)
JAXRException
object initialized with the given Throwable
object. From source file:org.freebxml.omar.server.security.authentication.AuthenticationServiceImpl.java
private void loadPredefinedUsers() throws RegistryException { ServerRequestContext context = null; try {/*from ww w. j a va 2s. c o m*/ context = new ServerRequestContext("AuthenticationServiceImpl.loadPredefinedUsers", null); registryOperator = (User) pm.getRegistryObject(context, ALIAS_REGISTRY_OPERATOR, "User"); registryGuest = (User) pm.getRegistryObject(context, ALIAS_REGISTRY_GUEST, "User"); /* HIEOS/BHT: DISABLED farrukh = (User)pm.getRegistryObject(context, ALIAS_FARRUKH, "User"); nikola = (User)pm.getRegistryObject(context, ALIAS_NIKOLA, "User"); */ if (registryOperator == null) { throw new RegistryException(ServerResourceBundle.getInstance().getString("message.registryOperator", new Object[] { ALIAS_REGISTRY_OPERATOR })); } if (registryGuest == null) { throw new RegistryException(ServerResourceBundle.getInstance().getString("message.registryGuest", new Object[] { ALIAS_REGISTRY_GUEST })); } } catch (RegistryException e) { log.error(ServerResourceBundle.getInstance() .getString("message.InternalErrorCouldNotLoadPredefinedUsers"), e); throw e; } finally { // All of above uses of this context were queries, roll back. context.rollback(); } }
From source file:org.freebxml.omar.server.security.authentication.AuthenticationServiceImpl.java
/** * Gets the User that is associated with the specified certificate. * * @throws UserNotFoundException when no matching User is found */// www.j ava2 s . co m public UserType getUserFromCertificate(X509Certificate cert) throws RegistryException { UserType user = null; if (cert == null) { boolean noRegRequired = Boolean.valueOf( CommonProperties.getInstance().getProperty("omar.common.noUserRegistrationRequired", "false")) .booleanValue(); if (noRegRequired) { return registryOperator; } else { return registryGuest; } } //The registry expects the KeyInfo to either have the PublicKey or the DN from the public key //In case of DN the registry can lookup the public key based on the DN java.security.PublicKey publicKey = null; String alias = null; try { // lots of trace if (log.isTraceEnabled()) { log.trace("getUserFromCertificate cert:\n" + cert); StringBuffer storedCerts = new StringBuffer("Stored certificates:"); Enumeration aliases = getKeyStore().aliases(); while (aliases.hasMoreElements()) { X509Certificate storedCert = (X509Certificate) getKeyStore() .getCertificate((String) aliases.nextElement()); storedCerts.append("\n").append(storedCert).append("\n--------"); } log.trace(storedCerts.toString()); } else if (log.isDebugEnabled()) { log.debug("getUserFromCertificate cert:\n" + cert); } alias = getKeyStore().getCertificateAlias(cert); if (alias == null) { if (log.isDebugEnabled()) { log.debug("Unknown certificate: " + cert.getSubjectDN().getName()); } throw new UserNotFoundException(cert.getSubjectDN().getName()); } if (log.isDebugEnabled()) { log.debug("Alias found for certificate:: " + alias); } } catch (KeyStoreException e) { throw new RegistryException(e); } user = getUserFromAlias(alias); return user; }
From source file:org.freebxml.omar.server.security.authentication.AuthenticationServiceImpl.java
/** * This method is used to remove a certificate from the server keystore. * This is called, for example, when a rim:User has been deleted and the * User's credentials need to be cleared from the server keystore * * @param alias//from w w w. j a v a2 s . c o m * A java.lang.String that contains the alias of the public key credential */ public void deleteUserCertificate(String alias) throws RegistryException { KeyStore keyStore = getKeyStore(); java.io.FileOutputStream fos = null; try { String keystoreFile = getKeyStoreFileName(); synchronized (keyStoreWriteLock) { fos = new java.io.FileOutputStream(keystoreFile); keyStore.deleteEntry(alias); String keystorePass = getKeyStorePassword(); keyStore.store(fos, keystorePass.toCharArray()); fos.flush(); this.keyStore = null; } } catch (Throwable t) { throw new RegistryException(t); } finally { if (fos != null) { try { fos.close(); } catch (IOException io) { } } } }
From source file:org.freebxml.omar.server.security.authentication.UserRegistrar.java
/** * It will try to register the user if the certificate in a signed SubmitObjectsRequest * is not yet in the keystore. The SubmitObjectsRequest must contain a single * User object and its id must be a valid UUID and equal to the alias parameter, * which should be extracted from the KeyInfo of XML signature element. * @return the User object of the newly registered user * @throws UserRegistrationException if SubmitObjectsRequest has more than * one User object, or its alias is not equal to the id of the unique User object, * or the id is not a valid UUID./*from w w w.ja v a 2s.c o m*/ */ public User registerUser(X509Certificate cert, org.oasis.ebxml.registry.bindings.lcm.SubmitObjectsRequest req) throws RegistryException { User user = null; try { AuthenticationServiceImpl ac = AuthenticationServiceImpl.getInstance(); //Get all User objects org.oasis.ebxml.registry.bindings.rim.RegistryObjectListType objs = req.getRegistryObjectList(); java.util.List al = org.freebxml.omar.common.BindingUtility.getInstance().getRegistryObjectList(objs); java.util.List users = new java.util.ArrayList(); java.util.Iterator objIter = al.iterator(); while (objIter.hasNext()) { org.oasis.ebxml.registry.bindings.rim.RegistryObjectType obj = (org.oasis.ebxml.registry.bindings.rim.RegistryObjectType) objIter .next(); if (obj instanceof User) { User _user = (User) obj; // check to see if a user ACL file exists, and // if it does, check to see if the user is in // the list boolean isInACLFile = isUserInACLFile(_user); if (isInACLFile) { log.info(ServerResourceBundle.getInstance().getString("message.isAuthorized", new Object[] { _user.getPersonName().getFirstName(), _user.getPersonName().getLastName() })); } else { String message = ServerResourceBundle.getInstance().getString("message.isNotAuthorized", new Object[] { _user.getPersonName().getFirstName(), _user.getPersonName().getLastName() }); log.warn(message); throw new UserRegistrationException(message); } String userId = _user.getId(); users.add(_user); } } if (users.size() == 0) { //This Exception seems to be misleading. Should we throw UserRegistrationException with message saying no user was found, instead? //Then again I doubt that this can this ever happen. throw new UnregisteredUserException(cert); } if (!((users.size() == 1) && ((users.get(0)) instanceof User))) { throw new UserRegistrationException( ServerResourceBundle.getInstance().getString("message.userRegistrationFailedOneUser")); } user = (User) users.get(0); String userId = user.getId(); //System.err.println("UserId: " + userId); if (!(org.freebxml.omar.common.Utility.getInstance().isValidRegistryId(userId))) { throw new UserRegistrationException( ServerResourceBundle.getInstance().getString("message.userRegistrationFailedUUID")); } if (log.isInfoEnabled()) { log.info(ServerResourceBundle.getInstance().getString("message.registeringNewUser", new Object[] { userId })); } ac.registerUserCertificate(userId, cert); if (log.isInfoEnabled()) { log.info(ServerResourceBundle.getInstance().getString("message.userRegistered", new Object[] { userId })); } } catch (JAXRException e) { throw new RegistryException(e); } return user; }