/** * Convert a EJBException into FacesMessage which is presented to the user. * * @param ex * the EJBException to be analyzed */ public static void execute(EJBException ex) { if (ex != null && ex.getCause() instanceof Exception && ex.getCausedByException() instanceof AccessException) { handleOrganizationAuthoritiesException(); } else if (ex != null && isInvalidUserSession(ex)) { HttpServletRequest request = JSFUtils.getRequest(); request.getSession().removeAttribute(Constants.SESS_ATTR_USER); request.getSession().invalidate(); handleInvalidSession(); } else if (ex != null && isConnectionException(ex)) { handleMissingConnect(BaseBean.ERROR_DATABASE_NOT_AVAILABLE); } else { throw new FacesException(ex); } }
private void handleServletException(HttpServletRequest httpRequest, HttpServletResponse httpResponse, ServletException e) throws IOException, ServletException { EJBException ejbEx = ExceptionHandler.getEJBException(e); if (ejbEx != null && ejbEx.getCause() instanceof Exception && ejbEx.getCausedByException() instanceof AccessException) { String forwardErrorPage; if (BesServletRequestReader.isMarketplaceRequest(httpRequest)) { forwardErrorPage = Marketplace.MARKETPLACE_ROOT + Constants.INSUFFICIENT_AUTHORITIES_URI; } else { forwardErrorPage = Constants.INSUFFICIENT_AUTHORITIES_URI; } JSFUtils.sendRedirect(httpResponse, httpRequest.getContextPath() + forwardErrorPage); } else { // make sure we do not catch exceptions cause by // ViewExpiredException here, they'll be handled directly in the // doFilter() throw e; } }
/** * Shutdown the activation system. Destroys all groups spawned by * the activation daemon and exits the activation daemon. */ public void shutdown() throws AccessException { RegistryImpl.checkAccess("ActivationSystem.shutdown"); Object lock = startupLock; if (lock != null) { synchronized (lock) { // nothing } } synchronized (Activation.this) { if (!shuttingDown) { shuttingDown = true; (new Shutdown()).start(); } } }
/** * Shutdown the activation system. Destroys all groups spawned by * the activation daemon and exits the activation daemon. */ public void shutdown() throws AccessException { // RegistryImpl.checkAccess() is done in the SameHostOnlyServerRef // during unmarshallCustomData and is not applicable to local access. Object lock = startupLock; if (lock != null) { synchronized (lock) { // nothing } } synchronized (Activation.this) { if (!shuttingDown) { shuttingDown = true; (new Shutdown()).start(); } } }
/** * Check the exception chain for the expected AccessException and message. * @param ex the exception from the remote invocation. */ private static void assertIsAccessException(Exception ex, String msg1) { Throwable t = ex; System.out.println(); while (!(t instanceof AccessException) && t.getCause() != null) { t = t.getCause(); } if (t instanceof AccessException) { String msg = t.getMessage(); int asIndex = msg.indexOf(msg1); int disallowIndex = msg.indexOf("disallowed"); int nonLocalHostIndex = msg.indexOf("non-local host"); if (asIndex < 0 || disallowIndex < 0 || nonLocalHostIndex < 0 ) { throw new RuntimeException("exception message is malformed", t); } System.out.printf("Found expected AccessException: %s%n", t); } else { throw new RuntimeException("AccessException did not occur", ex); } }
/** * Check the exception chain for the expected AccessException and message. * @param ex the exception from the remote invocation. */ private static void assertIsAccessException(Throwable ex) { Throwable t = ex; while (!(t instanceof AccessException) && t.getCause() != null) { t = t.getCause(); } if (t instanceof AccessException) { String msg = t.getMessage(); int asIndex = msg.indexOf("Registry"); int rrIndex = msg.indexOf("Registry.Registry"); // Obsolete error text int disallowIndex = msg.indexOf("disallowed"); int nonLocalHostIndex = msg.indexOf("non-local host"); if (asIndex < 0 || rrIndex != -1 || disallowIndex < 0 || nonLocalHostIndex < 0 ) { throw new RuntimeException("exception message is malformed", t); } System.out.printf("Found expected AccessException: %s%n%n", t); } else { throw new RuntimeException("AccessException did not occur when expected", ex); } }
/** * Check the exception chain for the expected AccessException and message. * @param ex the exception from the remote invocation. */ private static void assertIsAccessException(Throwable ex) { Throwable t = ex; while (!(t instanceof AccessException) && t.getCause() != null) { t = t.getCause(); } if (t instanceof AccessException) { String msg = t.getMessage(); int asIndex = msg.indexOf("Registry"); int disallowIndex = msg.indexOf("disallowed"); int nonLocalHostIndex = msg.indexOf("non-local host"); if (asIndex < 0 || disallowIndex < 0 || nonLocalHostIndex < 0 ) { throw new RuntimeException("exception message is malformed", t); } System.out.printf("Found expected AccessException: %s%n%n", t); } else { throw new RuntimeException("AccessException did not occur when expected", ex); } }
/** @inheritDoc */ public void unbind(String name) throws RemoteException, NotBoundException, AccessException { if (name.equals(Main.STOP)) { if (bindings instanceof Persistent) ((Persistent) bindings).writeContent(); // Terminate in 10 seconds. System.out.println("Shutdown command received. Will terminate in 10 s"); Persistent.timer.schedule(new Persistent.ExitTask(), 10000); } else { if (Main.verbose) System.out.println("Unbind "+name); if (!bindings.containsKey(name)) throw new NotBoundException(name); else bindings.remove(name); } }
@Override public void takeCharge(String fileName, List<ReplicaLoc> slaveReplicas) throws AccessException, RemoteException, NotBoundException { System.out.println("[@Replica] taking charge of file: "+fileName); System.out.println(slaveReplicas); List<ReplicaReplicaInterface> slaveReplicasStubs = new ArrayList<ReplicaReplicaInterface>(slaveReplicas.size()); for (ReplicaLoc loc : slaveReplicas) { // if the current locations is this replica .. ignore if (loc.getId() == this.id) continue; // if this is a new replica generate stub for this replica if (!replicaServersLoc.containsKey(loc.getId())){ replicaServersLoc.put(loc.getId(), loc); ReplicaReplicaInterface stub = (ReplicaReplicaInterface) registry.lookup("ReplicaClient"+loc.getId()); replicaServersStubs.put(loc.getId(), stub); } ReplicaReplicaInterface replicaStub = replicaServersStubs.get(loc.getId()); slaveReplicasStubs.add(replicaStub); } filesReplicaMap.put(fileName, slaveReplicasStubs); }
public void testProviderMethodWithSubclassOfExceptionIsOk() { providesInjector = Guice.createInjector(new AbstractModule() { protected void configure() { install(ThrowingProviderBinder.forModule(this)); } @SuppressWarnings("unused") @CheckedProvides(RemoteProvider.class) String foo() throws AccessException { throw new AccessException("boo!"); } }); RemoteProvider<String> remoteProvider = providesInjector.getInstance(Key.get(remoteProviderOfString)); try { remoteProvider.get(); fail(); } catch (RemoteException expected) { assertTrue(expected instanceof AccessException); assertEquals("boo!", expected.getMessage()); } }
/** * @see Registry.bind(String, Remote) */ public void bind(String name, Remote obj) throws RemoteException, AlreadyBoundException, AccessException { if (name == null) { // rmi.5D=name could not be null. throw new NullPointerException(Messages.getString("rmi.5D")); //$NON-NLS-1$ } if (obj == null) { // rmi.5C=obj could not be null. throw new NullPointerException(Messages.getString("rmi.5C")); //$NON-NLS-1$ } if (table.containsKey(name)) { // rmi.5E=There is already binding to the name {0}. throw new AlreadyBoundException(Messages.getString("rmi.5E", name)); //$NON-NLS-1$ } checkAccess("RegistryImpl.bind"); //$NON-NLS-1$ table.put(name, obj); }
/** * @see Registry.lookup(String) */ public Remote lookup(String name) throws RemoteException, NotBoundException, AccessException { if (name == null) { // rmi.5D=name could not be null. throw new NullPointerException(Messages.getString("rmi.5D")); //$NON-NLS-1$ } Remote ref = (Remote) table.get(name); if (ref == null) { // rmi.5F=Name {0} is not associated with any remote reference. throw new NotBoundException(Messages.getString("rmi.5F", name)); //$NON-NLS-1$ } return ref; }
public void testCxtorWithSubclassOfExceptionIsOk() throws Exception { cxtorInjector = Guice.createInjector(new AbstractModule() { @Override protected void configure() { ThrowingProviderBinder.create(binder()) .bind(RemoteProvider.class, Foo.class) .providing(SubclassExceptionFoo.class); } }); RemoteProvider<Foo> remoteProvider = cxtorInjector.getInstance(Key.get(remoteProviderOfFoo)); try { remoteProvider.get(); fail(); } catch (RemoteException expected) { assertTrue(expected instanceof AccessException); assertEquals("boo!", expected.getMessage()); } }
/** * Export the remote object under a given name for access as a service. This is the method you call on the server * side to make an object available. The registry connection must have been initialised already with a call to * {@link #initServer()} for the bound object to be immediately available. Otherwise, the requested binding will be * queued until the registry connection is available. * * @param serviceName * name of the service * @param object * object to export * @throws AccessException * if the registry is available and local, and security restrictions prevent binding * @throws RemoteException * if RMI is disabled entirely, or if object binding fails for a non-security related reason */ public synchronized void exportAndRegisterObject(String serviceName, Remote object) throws AccessException, RemoteException { disabledCheck(); remotes.put(serviceName, object); if (serverRegistry == null) { LOGGER.info("Registry not initialised. Queuing " + serviceName); if (waitingRemotes == null) { waitingRemotes = new LinkedList<String>(); } waitingRemotes.add(serviceName); } else { bindExportedObject(serviceName, object); } }
public void testProviderMethodWithSubclassOfExceptionIsOk() throws Exception { providesInjector = Guice.createInjector( new AbstractModule() { @Override protected void configure() { install(ThrowingProviderBinder.forModule(this)); } @SuppressWarnings("unused") @CheckedProvides(RemoteProvider.class) Foo foo() throws AccessException { throw new AccessException("boo!"); } }); RemoteProvider<Foo> remoteProvider = providesInjector.getInstance(Key.get(remoteProviderOfFoo)); try { remoteProvider.get(); fail(); } catch (RemoteException expected) { assertTrue(expected instanceof AccessException); assertEquals("boo!", expected.getMessage()); } }
public void testCxtorWithSubclassOfExceptionIsOk() throws Exception { cxtorInjector = Guice.createInjector( new AbstractModule() { @Override protected void configure() { ThrowingProviderBinder.create(binder()) .bind(RemoteProvider.class, Foo.class) .providing(SubclassExceptionFoo.class); } }); RemoteProvider<Foo> remoteProvider = cxtorInjector.getInstance(Key.get(remoteProviderOfFoo)); try { remoteProvider.get(); fail(); } catch (RemoteException expected) { assertTrue(expected instanceof AccessException); assertEquals("boo!", expected.getMessage()); } }
public void testProviderMethodWithSubclassOfExceptionIsOk() throws Exception { providesInjector = Guice.createInjector(new AbstractModule() { @Override protected void configure() { install(ThrowingProviderBinder.forModule(this)); } @SuppressWarnings("unused") @CheckedProvides(RemoteProvider.class) Foo foo() throws AccessException { throw new AccessException("boo!"); } }); RemoteProvider<Foo> remoteProvider = providesInjector.getInstance(Key.get(remoteProviderOfFoo)); try { remoteProvider.get(); fail(); } catch (RemoteException expected) { assertTrue(expected instanceof AccessException); assertEquals("boo!", expected.getMessage()); } }
public void bind(String name, Remote obj) throws RemoteException, AlreadyBoundException, AccessException { if (name.equals(NAME)) { throw new AccessException( "binding ActivationSystem is disallowed"); } else { super.bind(name, obj); } }
public void unbind(String name) throws RemoteException, NotBoundException, AccessException { if (name.equals(NAME)) { throw new AccessException( "unbinding ActivationSystem is disallowed"); } else { super.unbind(name); } }
public void rebind(String name, Remote obj) throws RemoteException, AccessException { if (name.equals(NAME)) { throw new AccessException( "binding ActivationSystem is disallowed"); } else { super.rebind(name, obj); } }
public void init(Registry registry, int numVMs) throws AccessException, RemoteException, NotBoundException, InterruptedException { for(int i = 0; i < numVMs; i++) { RemoteDUnitVMIF remote = processManager.getStub(i); addVM(i, remote); } addLocator(LOCATOR_VM_NUM, processManager.getStub(LOCATOR_VM_NUM)); addHost(this); }
public void init(Registry registry, int numVMs) throws AccessException, RemoteException, NotBoundException, InterruptedException { for (int i = 0; i < numVMs; i++) { RemoteDUnitVMIF remote = processManager.getStub(i); addVM(i, remote); } addLocator(LOCATOR_VM_NUM, processManager.getStub(LOCATOR_VM_NUM)); addHost(this); }