Example usage for org.springframework.dao PermissionDeniedDataAccessException PermissionDeniedDataAccessException

List of usage examples for org.springframework.dao PermissionDeniedDataAccessException PermissionDeniedDataAccessException

Introduction

In this page you can find the example usage for org.springframework.dao PermissionDeniedDataAccessException PermissionDeniedDataAccessException.

Prototype

public PermissionDeniedDataAccessException(String msg, Throwable cause) 

Source Link

Document

Constructor for PermissionDeniedDataAccessException.

Usage

From source file:com.frank.search.solr.core.SolrExceptionTranslator.java

@Override
public DataAccessException translateExceptionIfPossible(RuntimeException ex) {
    if (ex.getCause() instanceof SolrServerException) {
        SolrServerException solrServerException = (SolrServerException) ex.getCause();
        if (solrServerException.getCause() instanceof SolrException) {
            SolrException solrException = (SolrException) solrServerException.getCause();
            // solr 4.x moved ParseExecption from org.apache.lucene.queryParser to org.apache.lucene.queryparser.classic
            // therefore compare ShortClassName instead of using instanceof expression
            if (solrException.getCause() != null && ClassUtils.getShortName(solrException.getCause().getClass())
                    .equalsIgnoreCase("ParseException")) {
                return new InvalidDataAccessApiUsageException((solrException.getCause()).getMessage(),
                        solrException.getCause());
            } else {
                ErrorCode errorCode = ErrorCode.getErrorCode(solrException.code());
                switch (errorCode) {
                case NOT_FOUND:
                case SERVICE_UNAVAILABLE:
                case SERVER_ERROR:
                    return new DataAccessResourceFailureException(solrException.getMessage(), solrException);
                case FORBIDDEN:
                case UNAUTHORIZED:
                    return new PermissionDeniedDataAccessException(solrException.getMessage(), solrException);
                case BAD_REQUEST:
                    return new InvalidDataAccessApiUsageException(solrException.getMessage(), solrException);
                case UNKNOWN:
                    return new UncategorizedSolrException(solrException.getMessage(), solrException);
                default:
                    break;
                }/*from  w  ww.j av  a  2  s  . co m*/
            }
        } else if (solrServerException.getCause() instanceof ConnectException) {
            return new DataAccessResourceFailureException(solrServerException.getCause().getMessage(),
                    solrServerException.getCause());
        }
    }
    return null;
}

From source file:com.ge.predix.acs.monitoring.AcsDBHealthIndicatorTest.java

@DataProvider
public Object[][] dp() {

    TitanMigrationManager happyMigrationManager = new TitanMigrationManager();
    TitanMigrationManager sadMigrationManager = new TitanMigrationManager();
    Whitebox.setInternalState(happyMigrationManager, "isMigrationComplete", true);
    Whitebox.setInternalState(sadMigrationManager, "isMigrationComplete", false);

    return new Object[][] { new Object[]

            { mockDBWithUp(), Status.UP, happyMigrationManager },

            { mockDBWithException(new TransientDataAccessResourceException("")),
                    new Status(AcsMonitoringConstants.ACS_DB_OUT_OF_SERVICE), happyMigrationManager },

            { mockDBWithException(new QueryTimeoutException("")),
                    new Status(AcsMonitoringConstants.ACS_DB_OUT_OF_SERVICE), happyMigrationManager },

            { mockDBWithException(new DataSourceLookupFailureException("")),
                    new Status(AcsMonitoringConstants.ACS_DB_OUT_OF_SERVICE), happyMigrationManager },

            { mockDBWithException(new PermissionDeniedDataAccessException("", null)),
                    new Status(AcsMonitoringConstants.ACS_DB_OUT_OF_SERVICE), happyMigrationManager },

            { mockDBWithUp(), new Status(AcsMonitoringConstants.ACS_DB_MIGRATION_INCOMPLETE),
                    sadMigrationManager },

    };//from w w  w  .j a v  a 2 s . c om
}

From source file:org.jasig.portlet.weather.service.AbstractWeatherService.java

public void saveLocations(List<SavedLocation> savedLocations, PortletPreferences prefs) {
    final List<String> locationCodes = new ArrayList<String>(savedLocations.size());
    final List<String> locations = new ArrayList<String>(savedLocations.size());
    final List<String> metrics = new ArrayList<String>(savedLocations.size());

    for (final SavedLocation savedLocation : savedLocations) {
        locationCodes.add(savedLocation.code);
        locations.add(savedLocation.name);
        metrics.add(savedLocation.temperatureUnit.toString());
    }/*from   w ww  .  j a  va 2  s.  co m*/

    try {
        prefs.setValues(LOCATION_CODES, locationCodes.toArray(new String[locationCodes.size()]));
        prefs.setValues(LOCATIONS, locations.toArray(new String[locations.size()]));
        prefs.setValues(UNITS, metrics.toArray(new String[metrics.size()]));
        prefs.reset(METRICS); //Clear value, handling legacy preferences structure
        prefs.store();
    } catch (ReadOnlyException roe) {
        throw new PermissionDeniedDataAccessException(
                "Failed to save preferences due to one being marked read-only. The portlet preferences locationCode, locations, and metrics must not be read only.",
                roe);
    } catch (ValidatorException ve) {
        throw new DataIntegrityViolationException("Validation of saved locations preferences failed", ve);
    } catch (IOException ioe) {
        throw new RuntimeException("Failed to store saved locations preferences due to IO error", ioe);
    }
}

From source file:org.openspaces.events.adapter.AbstractReflectionDynamicEventTemplateProviderAdapter.java

/**
 * Delegates the event listener invocation to the appropriate method of the configured {@link
 * #setDelegate(Object)}./*from  w  ww  .  ja va 2 s.c om*/
 */
@Override
public Object getDynamicTemplate() {

    Object result = null;

    // single method, use the already obtained Method to invoke the listener
    try {
        result = fastMethod.invoke(delegate);
    } catch (IllegalAccessException ex) {
        throw new PermissionDeniedDataAccessException(
                "Failed to invoke event method [" + listenerMethod.getName() + "]", ex);
    } catch (InvocationTargetException ex) {
        throw new ListenerExecutionFailedException(
                "Listener event method [" + listenerMethod.getName() + "] of class ["
                        + listenerMethod.getDeclaringClass().getName() + "] threw exception",
                ex.getTargetException());
    } catch (Throwable ex) {
        throw new ListenerExecutionFailedException("Listener event method [" + listenerMethod.getName()
                + "] of class [" + listenerMethod.getDeclaringClass().getName() + "] threw exception", ex);
    }

    return result;
}

From source file:org.openspaces.events.adapter.AbstractReflectionEventListenerAdapter.java

/**
 * Delegates the event listener invocation to the appropriate method of the configured {@link
 * #setDelegate(Object)}. If a single event listener delegate method is found, uses the cached
 * reflection Method. If more than one event listener delegate method is configured uses
 * reflection to dynamically find the relevant event listener method.
 *//*w ww .  j  av  a  2  s.  co m*/
@Override
protected Object onEventWithResult(Object data, GigaSpace gigaSpace, TransactionStatus txStatus,
        Object source) {
    Method listenerMethod = listenerMethods[0];

    /*
    Object newValue = null, oldValue = null;
    boolean doubleParameter = false;
    if (notifyPreviousValueOnUpdate && source instanceof EntryArrivedRemoteEvent) {
    EntryArrivedRemoteEvent event = (EntryArrivedRemoteEvent) source;
    try {
        newValue = event.getNewObject();
        oldValue = event.getOldObject();
        doubleParameter = true;
    } catch (Exception e) {
        newValue = null;
        oldValue = null;
    }
    }
            
    // set up the arguments passed to the method
    Object[] listenerArguments = null;
    if (numberOfParameters == 1) {
    listenerArguments = new Object[] { data };
    } else if (numberOfParameters == 2) {
    if (doubleParameter) {
        listenerArguments = new Object[] { oldValue, newValue };
    } else {
        listenerArguments = new Object[]{ data, gigaSpace};
    }
    } else if (numberOfParameters == 3) {
    if (doubleParameter) {
        listenerArguments = new Object[] { oldValue, newValue, gigaSpace };
    } else {
        listenerArguments = new Object[]{ data, gigaSpace, txStatus};
    }
    } else if (numberOfParameters == 4) {
    if (doubleParameter) {
        listenerArguments = new Object[] { oldValue, newValue, gigaSpace, txStatus };
    } else {
        listenerArguments = new Object[]{ data, gigaSpace, txStatus, source};
    }
    } else if (numberOfParameters == 5 && doubleParameter) {
    listenerArguments = new Object[] { oldValue, newValue, gigaSpace, txStatus, source};
    }
    */
    // set up the arguments passed to the method
    Object[] listenerArguments = null;
    if (numberOfParameters == 1) {
        listenerArguments = new Object[] { data };
    } else if (numberOfParameters == 2) {
        listenerArguments = new Object[] { data, gigaSpace };
    } else if (numberOfParameters == 3) {
        listenerArguments = new Object[] { data, gigaSpace, txStatus };
    } else if (numberOfParameters == 4) {
        listenerArguments = new Object[] { data, gigaSpace, txStatus, source };
    }

    Object result = null;
    if (listenerMethods.length == 1) {
        // single method, use the already obtained Method to invoke the listener
        try {
            result = fastMethod.invoke(delegate, listenerArguments);
        } catch (IllegalAccessException ex) {
            throw new PermissionDeniedDataAccessException(
                    "Failed to invoke event method [" + listenerMethod.getName() + "]", ex);
        } catch (InvocationTargetException ex) {
            throw new ListenerExecutionFailedException(
                    "Listener event method [" + listenerMethod.getName() + "] of class ["
                            + listenerMethod.getDeclaringClass().getName() + "] threw exception",
                    ex.getTargetException());
        } catch (Throwable ex) {
            throw new ListenerExecutionFailedException("Listener event method [" + listenerMethod.getName()
                    + "] of class [" + listenerMethod.getDeclaringClass().getName() + "] threw exception", ex);
        }
    } else {
        // more than one method, we need to use reflection to find the matched method
        MethodInvoker methodInvoker = new MethodInvoker();
        methodInvoker.setTargetObject(getDelegate());
        methodInvoker.setTargetMethod(listenerMethod.getName());
        methodInvoker.setArguments(listenerArguments);
        try {
            methodInvoker.prepare();
            result = methodInvoker.invoke();
        } catch (InvocationTargetException ex) {
            throw new ListenerExecutionFailedException(
                    "Listener method '" + listenerMethod.getName() + "' threw exception",
                    ex.getTargetException());
        } catch (Throwable ex) {
            throw new ListenerExecutionFailedException(
                    "Failed to invoke target method '" + listenerMethod.getName() + "' with arguments "
                            + ObjectUtils.nullSafeToString(listenerArguments),
                    ex);
        }

    }
    return result;
}

From source file:org.springframework.jdbc.support.SQLExceptionSubclassTranslator.java

public DataAccessException translate(String task, String sql, SQLException ex) {
    Assert.notNull(ex, "Cannot translate a null SQLException.");
    if (task == null) {
        task = "";
    }//from  ww w . jav a  2s . c  om
    if (sql == null) {
        sql = "";
    }
    if (ex instanceof SQLTransientException) {
        if (ex instanceof SQLTransactionRollbackException) {
            return new ConcurrencyFailureException(buildMessage(task, sql, ex), ex);
        }
        if (ex instanceof SQLTransientConnectionException) {
            return new TransientDataAccessResourceException(buildMessage(task, sql, ex), ex);
        }
        if (ex instanceof SQLTimeoutException) {
            return new TransientDataAccessResourceException(buildMessage(task, sql, ex), ex);
        }
    } else if (ex instanceof SQLNonTransientException) {
        if (ex instanceof SQLDataException) {
            return new DataIntegrityViolationException(buildMessage(task, sql, ex), ex);
        } else if (ex instanceof SQLFeatureNotSupportedException) {
            return new BadSqlGrammarException(task, sql, ex);
        } else if (ex instanceof SQLIntegrityConstraintViolationException) {
            return new DataIntegrityViolationException(buildMessage(task, sql, ex), ex);
        } else if (ex instanceof SQLInvalidAuthorizationSpecException) {
            return new PermissionDeniedDataAccessException(buildMessage(task, sql, ex), ex);
        } else if (ex instanceof SQLNonTransientConnectionException) {
            return new DataAccessResourceFailureException(buildMessage(task, sql, ex), ex);
        } else if (ex instanceof SQLSyntaxErrorException) {
            return new BadSqlGrammarException(task, sql, ex);
        }
    } else if (ex instanceof SQLRecoverableException) {
        return new RecoverableDataAccessException(buildMessage(task, sql, ex), ex);
    }
    // We couldn't identify it more precisely - let's allow other translation strategies to kick in.
    return null;
}