Example usage for java.lang IllegalAccessException IllegalAccessException

List of usage examples for java.lang IllegalAccessException IllegalAccessException

Introduction

In this page you can find the example usage for java.lang IllegalAccessException IllegalAccessException.

Prototype

public IllegalAccessException(String s) 

Source Link

Document

Constructs an IllegalAccessException with a detail message.

Usage

From source file:com.stratelia.webactiv.servlets.RestOnlineFileServer.java

protected OnlineFile getWantedAttachment(RestRequest restRequest) throws Exception {
    String componentId = restRequest.getElementValue("componentId");
    OnlineFile file = null;/*from  www.  j a v a  2  s . c om*/
    String attachmentId = restRequest.getElementValue("attachmentId");
    String language = restRequest.getElementValue("lang");
    if (StringUtil.isDefined(attachmentId)) {
        AttachmentDetail attachment = AttachmentController.searchAttachmentByPK(new AttachmentPK(attachmentId));
        if (attachment != null) {
            if (isUserAuthorized(restRequest, componentId, attachment)) {
                file = new OnlineFile(attachment.getType(language), attachment.getPhysicalName(language),
                        FileRepositoryManager.getRelativePath(
                                FileRepositoryManager.getAttachmentContext(attachment.getContext())));
                file.setComponentId(componentId);
            } else {
                throw new IllegalAccessException("You can't access this file " + attachment.getLogicalName());
            }
        }
    }
    return file;
}

From source file:org.apache.hadoop.chukwa.datastore.UserStore.java

public static JSONArray list() throws IllegalAccessException {
    StringBuilder profilePath = new StringBuilder();
    profilePath.append(hiccPath);//from   w ww.j a v a  2 s.  c  o m
    profilePath.append(File.separator);
    profilePath.append("*.profile");
    Path viewFile = new Path(profilePath.toString());
    FileSystem fs;
    JSONArray list = new JSONArray();
    try {
        fs = FileSystem.get(config);
        FileStatus[] fstatus = fs.listStatus(viewFile);
        if (fstatus != null) {
            for (int i = 0; i < fstatus.length; i++) {
                long size = fstatus[i].getLen();
                FSDataInputStream profileStream = fs.open(fstatus[i].getPath());
                byte[] buffer = new byte[(int) size];
                profileStream.readFully(buffer);
                profileStream.close();
                try {
                    UserBean user = new UserBean(new JSONObject(new String(buffer)));
                    list.put(user.getId());
                } catch (Exception e) {
                    log.error(ExceptionUtil.getStackTrace(e));
                }
            }
        }
    } catch (IOException ex) {
        log.error(ExceptionUtil.getStackTrace(ex));
        throw new IllegalAccessException("Unable to access user profile database.");
    }
    return list;
}

From source file:org.sparkcommerce.openadmin.server.service.persistence.module.provider.RuleFieldPersistenceProvider.java

@Override
public FieldProviderResponse populateValue(PopulateValueRequest populateValueRequest, Serializable instance)
        throws PersistenceException {
    if (!canHandlePersistence(populateValueRequest, instance)) {
        return FieldProviderResponse.NOT_HANDLED;
    }//from w ww  . j a va2 s  .  co m
    boolean dirty = false;
    try {
        setNonDisplayableValues(populateValueRequest);
        switch (populateValueRequest.getMetadata().getFieldType()) {
        case RULE_WITH_QUANTITY: {
            //currently, this only works with Collection fields
            Class<?> valueType = getListFieldType(instance, populateValueRequest.getFieldManager(),
                    populateValueRequest.getProperty(), populateValueRequest.getPersistenceManager());
            if (valueType == null) {
                throw new IllegalAccessException("Unable to determine the valueType for the rule field ("
                        + populateValueRequest.getProperty().getName() + ")");
            }
            DataDTOToMVELTranslator translator = new DataDTOToMVELTranslator();
            Collection<QuantityBasedRule> rules;
            try {
                rules = (Collection<QuantityBasedRule>) populateValueRequest.getFieldManager()
                        .getFieldValue(instance, populateValueRequest.getProperty().getName());
            } catch (FieldNotAvailableException e) {
                throw new IllegalArgumentException(e);
            }
            //AntiSamy HTML encodes the rule JSON - pass the unHTMLEncoded version
            dirty = populateQuantityBaseRuleCollection(
                    populateValueRequest.getPersistenceManager().getDynamicEntityDao()
                            .getStandardEntityManager(),
                    translator,
                    RuleIdentifier.ENTITY_KEY_MAP.get(populateValueRequest.getMetadata().getRuleIdentifier()),
                    populateValueRequest.getMetadata().getRuleIdentifier(),
                    populateValueRequest.getProperty().getUnHtmlEncodedValue(), rules, valueType);
            break;
        }
        case RULE_SIMPLE: {
            DataDTOToMVELTranslator translator = new DataDTOToMVELTranslator();
            //AntiSamy HTML encodes the rule JSON - pass the unHTMLEncoded version
            DataWrapper dw = ruleFieldExtractionUtility
                    .convertJsonToDataWrapper(populateValueRequest.getProperty().getUnHtmlEncodedValue());
            if (dw == null || StringUtils.isEmpty(dw.getError())) {
                String mvel = ruleFieldExtractionUtility.convertSimpleMatchRuleJsonToMvel(translator,
                        RuleIdentifier.ENTITY_KEY_MAP
                                .get(populateValueRequest.getMetadata().getRuleIdentifier()),
                        populateValueRequest.getMetadata().getRuleIdentifier(), dw);
                Class<?> valueType = null;
                //is this a regular field?
                if (!populateValueRequest.getProperty().getName().contains(FieldManager.MAPFIELDSEPARATOR)) {
                    valueType = populateValueRequest.getReturnType();
                } else {
                    String valueClassName = populateValueRequest.getMetadata().getMapFieldValueClass();
                    if (valueClassName != null) {
                        valueType = Class.forName(valueClassName);
                    }
                    if (valueType == null) {
                        valueType = populateValueRequest.getReturnType();
                    }
                }
                if (valueType == null) {
                    throw new IllegalAccessException("Unable to determine the valueType for the rule field ("
                            + populateValueRequest.getProperty().getName() + ")");
                }
                //This is a simple String field (or String map field)
                if (String.class.isAssignableFrom(valueType)) {
                    //first check if the property is null and the mvel is null
                    if (instance != null && mvel == null) {
                        Object value = populateValueRequest.getFieldManager().getFieldValue(instance,
                                populateValueRequest.getProperty().getName());
                        dirty = value != null;
                    } else {
                        dirty = checkDirtyState(populateValueRequest, instance, mvel);
                    }
                    populateValueRequest.getFieldManager().setFieldValue(instance,
                            populateValueRequest.getProperty().getName(), mvel);
                }
                if (SimpleRule.class.isAssignableFrom(valueType)) {
                    //see if there's an existing rule
                    SimpleRule rule;
                    try {
                        rule = (SimpleRule) populateValueRequest.getFieldManager().getFieldValue(instance,
                                populateValueRequest.getProperty().getName());
                    } catch (FieldNotAvailableException e) {
                        throw new IllegalArgumentException(e);
                    }
                    if (mvel == null) {
                        //cause the rule to be deleted
                        dirty = populateValueRequest.getFieldManager().getFieldValue(instance,
                                populateValueRequest.getProperty().getName()) != null;
                        populateValueRequest.getFieldManager().setFieldValue(instance,
                                populateValueRequest.getProperty().getName(), null);
                    } else if (rule != null) {
                        dirty = !rule.getMatchRule().equals(mvel);
                        rule.setMatchRule(mvel);
                    } else {
                        //create a new instance, persist and set
                        dirty = true;
                        rule = (SimpleRule) valueType.newInstance();
                        rule.setMatchRule(mvel);
                        populateValueRequest.getPersistenceManager().getDynamicEntityDao().persist(rule);
                        populateValueRequest.getFieldManager().setFieldValue(instance,
                                populateValueRequest.getProperty().getName(), rule);
                    }
                }
            }
            break;
        }
        }
    } catch (Exception e) {
        throw new PersistenceException(e);
    }
    populateValueRequest.getProperty().setIsDirty(dirty);

    return FieldProviderResponse.HANDLED_BREAK;
}

From source file:org.slc.sli.dashboard.web.controller.ConfigController.java

/**
 * Generic layout handler/*from  w  ww  .  j ava 2  s.c o m*/
 *
 * @deprecated retiring method
 * @param id
 * @param request
 * @return
 * @throws IllegalAccessException
 */
@Deprecated
@RequestMapping(value = CONFIG_URL, method = RequestMethod.GET)
public ModelAndView getConfig(HttpServletRequest request) throws IllegalAccessException {
    ModelMap model = new ModelMap();

    String token = SecurityUtil.getToken();
    GenericEntity staffEntity = userEdOrgManager.getStaffInfo(token);

    Boolean isAdmin = SecurityUtil.isAdmin();
    if (isAdmin != null && isAdmin.booleanValue()) {
        GenericEntity edOrg = (GenericEntity) staffEntity.get(Constants.ATTR_ED_ORG);
        boolean configUser = false;

        if (edOrg != null) {
            List<String> organizationCategories = (List<String>) edOrg.get(Constants.ATTR_ORG_CATEGORIES);
            if (organizationCategories != null && !organizationCategories.isEmpty()) {
                for (String educationAgency : organizationCategories) {
                    if (educationAgency != null && educationAgency.equals(Constants.LOCAL_EDUCATION_AGENCY)) {
                        configUser = true;
                        break;
                    } else if (educationAgency != null
                            && educationAgency.equals(Constants.STATE_EDUCATION_AGENCY)) {
                        configUser = true;
                        break;
                    }
                }
            }
        }
        if (configUser) {
            ConfigMap configMap = configManager.getCustomConfig(token, userEdOrgManager.getUserEdOrg(token));

            if (configMap != null) {
                model.addAttribute("configJSON", new GsonBuilder().create().toJson(configMap));
            } else {
                model.addAttribute("configJSON", "");
            }
        } else {
            model.addAttribute("configJSON", "nonLocalEducationAgency");

        }

        addCommonData(model, request);
        model.addAttribute(Constants.PAGE_TO_INCLUDE, DASHBOARD_CONFIG_FTL);
        return new ModelAndView(Constants.OVERALL_CONTAINER_PAGE, model);
    }
    throw new IllegalAccessException("Access Denied");
}

From source file:com.wso2telco.claims.RemoteClaimsRetriever.java

public Map<String, Object> getTotalClaims(String operatorName, CustomerInfo customerInfo)
        throws IllegalAccessException, InstantiationException, ClassNotFoundException {

    Map<String, Object> totalClaims;

    try {//from  w  w w.  j a  v a  2  s.co m
        totalClaims = getRemoteTotalClaims(operatorName, customerInfo);
    } catch (ClassNotFoundException e) {
        log.error("Class Not Found Exception occurred when calling operator'd endpoint - " + operatorName + ":"
                + e);
        throw new ClassNotFoundException(e.getMessage(), e);
    } catch (InstantiationException e) {
        log.error("Instantiation Exception occurred when calling operator'd endpoint - " + operatorName + ":"
                + e);
        throw new InstantiationException(e.getMessage());
    } catch (IllegalAccessException e) {
        log.error("Illegal Access Exception occurred when calling operator'd endpoint - " + operatorName + ":"
                + e);
        throw new IllegalAccessException(e.getMessage());
    }
    return totalClaims;
}

From source file:org.cloudgraph.hbase.mutation.Update.java

@Override
public void collect(DataGraph dataGraph, PlasmaDataObject dataObject, DistributedWriter graphWriter,
        TableWriter tableWriter, RowWriter rowWriter) throws IllegalAccessException, IOException {
    PlasmaType type = (PlasmaType) dataObject.getType();
    CoreNode dataNode = (CoreNode) dataObject;
    // FIXME: get rid of cast - define instance properties in 'base type'
    Timestamp snapshotDate = (Timestamp) dataNode.getValue(CoreConstants.PROPERTY_NAME_SNAPSHOT_TIMESTAMP);
    if (snapshotDate == null)
        throw new RequiredPropertyException(
                "instance property '" + CoreConstants.PROPERTY_NAME_SNAPSHOT_TIMESTAMP
                        + "' is required to update data object, " + dataObject);
    if (log.isDebugEnabled())
        log.debug(dataObject + " timestamp: " + String.valueOf(snapshotDate));

    Long sequence = (Long) dataNode.getValue(CloudGraphConstants.SEQUENCE);
    if (sequence == null)
        throw new RequiredPropertyException("instance property '" + CloudGraphConstants.SEQUENCE
                + "' is required to update data object, " + dataObject);

    if (log.isDebugEnabled())
        log.debug(dataObject + " (seq: " + sequence + ")");

    List<Setting> settingList = dataGraph.getChangeSummary().getOldValues(dataObject);
    HashSet<PlasmaProperty> properties = this.collectProperties(settingList);
    Iterator<PlasmaProperty> iter = properties.iterator();
    while (iter.hasNext()) {
        PlasmaProperty property = iter.next();

        if (property.getConcurrent() != null)
            return; // processed above

        if (property.isReadOnly())
            throw new IllegalAccessException("attempt to modify read-only property, " + property);

        Object dataValue = dataObject.get(property);
        if (dataValue != null)
            if (log.isDebugEnabled())
                log.debug("updating " + property.toString());
            else if (log.isDebugEnabled())
                log.debug("removing " + property.toString());

        if (!property.getType().isDataType()) {
            SettingCollector<PlasmaDataObject> settingCollector = new SettingCollector<>();
            HashSet<PlasmaDataObject> oldSettings = settingCollector.collect(property, settingList);
            HashSet<PlasmaDataObject> oldValues = new HashSet<>(oldSettings.size());
            for (PlasmaDataObject oldSettingObject : oldSettings) {
                if (!oldSettingObject.getDataGraph().getChangeSummary().isCreated(oldSettingObject))
                    oldValues.add(oldSettingObject);
            }/* ww w.j ava2s.co m*/

            EdgeWriter edgeWriter = rowWriter.getEdgeWriter(dataObject, property, sequence);
            if (!property.isMany()) {
                this.collectSingular(edgeWriter, dataObject, oldValues, property, dataValue);
            } else {
                this.collectMulti(edgeWriter, dataObject, oldValues, property, dataValue);
            }
            edgeWriter.write();
        } else {
            Increment increment = property.getIncrement();
            if (dataValue != null) {
                if (increment == null) {
                    byte[] valueBytes = HBaseDataConverter.INSTANCE.toBytes(property, dataValue);
                    rowWriter.writeRowData(dataObject, sequence, property, valueBytes);
                } else { // increment
                    if (type.isConcurrent())
                        throw new GraphServiceException(
                                "increment property, " + property + ", found on concurrent type, " + type
                                        + " - increment properties cannot coexist within a concurrent type");
                    DataType dataType = DataType.valueOf(property.getType().getName());
                    if (increment != null) { // user can increment/decrement by whatever
                                             // value
                        if (dataType.ordinal() != DataType.Long.ordinal())
                            throw new GraphServiceException("property, " + property + ", must be datatype "
                                    + DataType.Long + " to support increment operations");
                        long longDataValue = DataConverter.INSTANCE.toLong(property.getType(), dataValue);
                        rowWriter.incrementRowData(dataObject, sequence, property, longDataValue);
                    }
                }

            } else {
                rowWriter.deleteRowData(dataObject, sequence, property);
            }
        }
    }
}

From source file:org.netxilia.server.rest.AdminResource.java

@POST
@Path("/create")
@Produces(MediaType.TEXT_HTML)// w  w w. j a v  a  2 s  . c o  m
public void create(@FormParam("login") String login, @FormParam("password") String password,
        @FormParam("email") Email email,
        @FormParam("ds.id") DataSourceConfigurationId dataSourceConfigurationId,
        @FormParam("ds.driver") String driver, @FormParam("ds.url") String url,
        @FormParam("ds.username") String dsUsername, @FormParam("ds.password") String dsPassword, //
        @FormParam("createDemo") boolean createDemo)
        throws IllegalAccessException, NetxiliaResourceException, NetxiliaBusinessException {
    if (userService.isAdminAccountCreated()) {
        throw new IllegalAccessException("");
    }

    // TODO use validation
    if (StringUtils.isEmpty(login)) {
        throw new IllegalArgumentException("Login cannot be empty!");
    }
    if (StringUtils.isEmpty(password)) {
        throw new IllegalArgumentException("Password cannot be empty!");
    }

    DataSourceConfiguration ds = null;
    if (dataSourceConfigurationId.getId() < 0) {
        // new datasource
        ds = new DataSourceConfiguration(null, "SYSTEM", "The SYSTEM Datasource", driver, url, dsUsername,
                dsPassword);
    } else {
        DataSourceConfiguration prevDs = dataSourceConfigurationService.load(dataSourceConfigurationId);
        ds = new DataSourceConfiguration(prevDs.getId(), prevDs.getName(), prevDs.getDescription(), driver, url,
                dsUsername, dsPassword);
    }
    ds = dataSourceConfigurationService.save(ds);
    dataSourceConfigurationService.setConfigurationForWorkbook(userService.getWorkbookId(), ds.getId());

    User user = new User();
    user.setLogin(login);
    user.setPassword(password);
    user.setEmail(email);
    user.setRoles(new Role[] { Role.ROLE_ADMIN });

    userService.addUser(user);

    Map<String, IStartupService> startupServices = applicationContext.getBeansOfType(IStartupService.class);
    for (IStartupService service : startupServices.values()) {
        try {
            service.startup(ds, user, createDemo);
        } catch (Exception ex) {
            log.error("Could not execute startup service:" + ex, ex);
        }
    }
    authenticateWithSpring(user);
    throw new RedirectionException(HomeResource.class);
}

From source file:io.cloudslang.lang.logging.LoggingServiceImplTest.java

@Test
public void testLogEventWithThreeParams() {
    final List<Runnable> runnableList = new ArrayList<>();
    doAnswer(new Answer() {
        @Override/*from  w  w w  . ja v  a2  s  .  c  o  m*/
        public Object answer(InvocationOnMock invocationOnMock) throws Throwable {
            Object[] arguments = invocationOnMock.getArguments();
            runnableList.add((Runnable) arguments[0]);
            return null;
        }
    }).when(singleThreadExecutor).submit(Mockito.any(Runnable.class));

    final RuntimeException ex1 = new RuntimeException("some exception 1");
    final IllegalArgumentException ex2 = new IllegalArgumentException(
            "some value does not respect its contract");
    final IllegalStateException ex3 = new IllegalStateException("state is illegal");
    final IllegalAccessException ex4 = new IllegalAccessException("Access denied");
    final String message1 = "message1";
    final String message2 = "message2";
    final String message3 = "message3";
    final String message4 = "message4";

    // Tested calls
    loggingService.logEvent(Level.DEBUG, message1, ex1);
    loggingService.logEvent(Level.TRACE, message2, ex2);
    loggingService.logEvent(Level.ERROR, message3, ex3);
    loggingService.logEvent(Level.FATAL, message4, ex4);

    assertEquals(4, runnableList.size());
    assertTrue(runnableList.get(0) instanceof LoggingServiceImpl.LoggingDetailsRunnable);
    assertTrue(runnableList.get(1) instanceof LoggingServiceImpl.LoggingDetailsRunnable);
    assertTrue(runnableList.get(2) instanceof LoggingServiceImpl.LoggingDetailsRunnable);
    assertTrue(runnableList.get(3) instanceof LoggingServiceImpl.LoggingDetailsRunnable);

    assertEquals(new LoggingServiceImpl.LoggingDetailsRunnable(Level.DEBUG, message1, ex1),
            runnableList.get(0));
    assertEquals(new LoggingServiceImpl.LoggingDetailsRunnable(Level.TRACE, message2, ex2),
            runnableList.get(1));
    assertEquals(new LoggingServiceImpl.LoggingDetailsRunnable(Level.ERROR, message3, ex3),
            runnableList.get(2));
    assertEquals(new LoggingServiceImpl.LoggingDetailsRunnable(Level.FATAL, message4, ex4),
            runnableList.get(3));
}

From source file:bdi4jade.core.Intention.java

/**
 * Creates a new intention. It is associated with an agent and the goal that
 * it is committed to achieve. It also receives a {@link Capability} as
 * parameter indicating the owner of the goal (dispatched the goal).
 * //  ww w.jav  a  2  s .  c  o  m
 * @param goal
 *            the goal to be achieved.
 * @param bdiAgent
 *            the bdiAgent associated with this intention.
 * @param dispatcher
 *            the Capability that dispatched the goal.
 * 
 * @throws IllegalAccessException
 *             if the goal was dispatched by a capability that has no access
 *             to the goal to be achieved.
 */
public Intention(Goal goal, AbstractBDIAgent bdiAgent, Capability dispatcher) throws IllegalAccessException {
    this.goal = goal;
    this.myAgent = bdiAgent;
    this.unachievable = false;
    this.noLongerDesired = false;
    this.waiting = true;
    this.executedPlans = new HashSet<>();
    this.currentPlan = null;
    this.goalListeners = new LinkedList<>();
    this.dispatcher = dispatcher;

    Class<? extends Capability> owner = null;
    boolean internal = false;

    if (goal.getClass().isAnnotationPresent(GoalOwner.class)) {
        GoalOwner ownerAnnotation = goal.getClass().getAnnotation(GoalOwner.class);
        owner = ownerAnnotation.capability();
        internal = ownerAnnotation.internal();
    } else {
        Class<?> enclosingClass = goal.getClass().getEnclosingClass();
        if (enclosingClass != null && Capability.class.isAssignableFrom(goal.getClass().getEnclosingClass())) {
            owner = (Class<Capability>) enclosingClass;
        }
    }

    if (owner == null) {
        this.owners = new HashSet<>();
    } else {
        if (dispatcher == null) {
            this.owners = myAgent.getGoalOwner(owner, internal);
        } else {
            this.owners = dispatcher.getGoalOwner(owner, internal);
            if (owners.isEmpty()) {
                throw new IllegalAccessException("Capability " + dispatcher + " has no access to goal "
                        + goal.getClass().getName() + " of capability " + owner.getName());
            }
        }
    }
}

From source file:com.qwazr.Qwazr.java

/**
 * Start the server//w ww  .  j  av a2 s.  c  o  m
 *
 * @throws IOException
 * @throws InstantiationException
 * @throws ServletException
 * @throws IllegalAccessException
 * @throws ParseException
 */
public static synchronized void start(QwazrConfiguration configuration)
        throws IOException, InstantiationException, ServletException, IllegalAccessException, ParseException {
    if (qwazr != null)
        throw new IllegalAccessException("QWAZR is already started");
    qwazr = new Qwazr(configuration);
    qwazr.startAll();
}