Example usage for java.lang SecurityException getMessage

List of usage examples for java.lang SecurityException getMessage

Introduction

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

Prototype

public String getMessage() 

Source Link

Document

Returns the detail message string of this throwable.

Usage

From source file:org.kuali.coeus.common.budget.framework.query.QueryList.java

/**
 * sorts the QueryList by the fieldName in ascending or descending order.
 * Note: the field Object should be of Comparable type.
 * @return boolean indicating whether the sort is completed successfully or not.
 * @param ignoreCase use only when comparing strings. as default implementation uses case sensitive comparison.
 * @param fieldName field which is used to sort the bean.
 * @param ascending if true sorting is done in ascending order,
 * else sorting is done in descending order.
 *///  w ww  .j ava 2 s .  c o m
@SuppressWarnings("rawtypes")
public boolean sort(String fieldName, boolean ascending, boolean ignoreCase) {
    Object current, next;
    int compareValue = 0;
    Field field = null;
    Method method = null;
    if (this.size() == 0) {
        return false;
    }
    Class dataClass = get(0).getClass();
    String methodName = null;
    try {
        field = dataClass.getDeclaredField(fieldName);
        if (!field.isAccessible()) {
            throw new NoSuchFieldException();
        }
    } catch (NoSuchFieldException noSuchFieldException) {
        //field not available. Use method invokation.
        try {
            methodName = "get" + (fieldName.charAt(0) + "").toUpperCase() + fieldName.substring(1);
            method = dataClass.getMethod(methodName, null);
        } catch (NoSuchMethodException noSuchMethodException) {
            LOG.error(noSuchMethodException.getMessage(), noSuchMethodException);
            return false;
        }
    }

    for (int index = 0; index < size() - 1; index++) {
        for (int nextIndex = index + 1; nextIndex < size(); nextIndex++) {
            current = get(index);
            next = get(nextIndex);
            //Check if current and next implements Comparable else can't compare.
            //so return without comparing.May be we can have an exception for this purpose.
            try {
                if (field != null && field.isAccessible()) {
                    Comparable thisObj = (Comparable) field.get(current);
                    Comparable otherObj = (Comparable) field.get(next);
                    if (thisObj == null) {
                        compareValue = -1;
                    } else if (otherObj == null) {
                        compareValue = 1;
                    } else {
                        if (thisObj instanceof String && ignoreCase) {
                            compareValue = ((String) thisObj).compareToIgnoreCase((String) otherObj);
                        } else {
                            compareValue = thisObj.compareTo(otherObj);
                        }
                    }
                } else {
                    Comparable thisObj = null;
                    Comparable otherObj = null;
                    if (methodName != null) {
                        Method thisObjMethod = current.getClass().getMethod(methodName, null);
                        Method otherObjMethod = next.getClass().getMethod(methodName, null);
                        thisObj = (Comparable) thisObjMethod.invoke(current, null);
                        otherObj = (Comparable) otherObjMethod.invoke(next, null);
                    } else {
                        thisObj = (Comparable) method.invoke(current, null);
                        otherObj = (Comparable) method.invoke(next, null);
                    }
                    if (thisObj == null) {
                        compareValue = -1;
                    } else if (otherObj == null) {
                        compareValue = 1;
                    } else {
                        if (thisObj instanceof String && ignoreCase) {
                            compareValue = ((String) thisObj).compareToIgnoreCase((String) otherObj);
                        } else {
                            compareValue = thisObj.compareTo(otherObj);
                        }
                    }
                }
            } catch (IllegalAccessException illegalAccessException) {
                LOG.warn(illegalAccessException.getMessage());
                return false;
            } catch (InvocationTargetException invocationTargetException) {
                LOG.warn(invocationTargetException.getMessage(), invocationTargetException);
                return false;
            } catch (SecurityException e) {
                LOG.warn(e.getMessage(), e);
                return false;
            } catch (NoSuchMethodException e) {
                LOG.warn(e.getMessage(), e);
                return false;
            }

            if (ascending && compareValue > 0) {
                E temp = get(index);
                set(index, get(nextIndex));
                set(nextIndex, temp);
            } else if (!ascending && compareValue < 0) {
                E temp = get(index);
                set(index, get(nextIndex));
                set(nextIndex, temp);
            }

        }
    }
    return true;
}

From source file:com.ca.servicenow.AttachFile.java

private void createOutputLocationFile(String outputLocation, String content) throws ActionException {
    File outputDirs = new File(outputLocation);
    if (!outputDirs.exists()) {
        try {//from   ww w .ja v  a2  s  . c  o m
            outputDirs.mkdirs();
        } catch (SecurityException se) {
            log.error("Caught security exception while creating output location: " + outputLocation);
            throw new ActionException("Security exception while creating output location: " + se.getMessage(),
                    se);
        }
    }

    String fileName = outputLocation + File.separator + WEBSERVICE_OUTPUT;
    try {
        FileWriter fw = new FileWriter(fileName);
        fw.write(content);
        fw.flush();
        fw.close();
    } catch (IOException e) {
        log.error("Caught IO exception during writing to file");
        throw new ActionException("IO exception during writing to file: " + e.getMessage(), e);
    }
}

From source file:org.sakaiproject.iclicker.logic.IClickerLogicImplTest.java

/**
 * How to create a valid encoded key://from  w w  w.  ja  v a2s . co m
 * Take the input key (must be 10 chars long or longer) and append ':' and the current unix timestamp in seconds
 * Take that string and SHA-1 encode it into a hexadecimal encoded string
 * Take the hex string and append '|' and the same timestamp as before
 * This is the encoded key which should be sent with the request
 * 
 * NOTE: it is safe to pass the encode key in the clear (as a url param or otherwise) 
 * as it is one way encrypted and very very difficult to brute force decrypt
 * 
 * Sample key:
 * abcdef1234566890
 * Sample timestamp:
 * 1332470760
 * Encoded key:
 * cc80462bfc0da7e614237d7cab4b7971b0e71e9f|1332470760
 */
public void testVerifyKey() {
    String key = "abcdef1234566890";
    logicImpl.setSharedKey(key);

    // test expired timestamp
    String encodedKey = "cc80462bfc0da7e614237d7cab4b7971b0e71e9f|1332470760";
    try {
        logicImpl.verifyKey(encodedKey);
        fail("should have died");
    } catch (SecurityException e) {
        assertNotNull(e.getMessage());
    }

    // test invalid format
    try {
        logicImpl.verifyKey("xxxxxxxxxxxxx");
        fail("should have died");
    } catch (IllegalArgumentException e) {
        assertNotNull(e.getMessage());
    }
    try {
        logicImpl.verifyKey("xxxxxxxxxxxxx|");
        fail("should have died");
    } catch (IllegalArgumentException e) {
        assertNotNull(e.getMessage());
    }
    try {
        logicImpl.verifyKey("xxxxxxxx|12344ffff");
        fail("should have died");
    } catch (IllegalArgumentException e) {
        assertNotNull(e.getMessage());
    }

    // test valid encoded key
    long timestamp = System.currentTimeMillis() / 1000l;
    byte[] sha1Bytes = DigestUtils.sha(key + ":" + timestamp);
    encodedKey = Hex.encodeHexString(sha1Bytes) + "|" + timestamp;
    boolean result = logicImpl.verifyKey(encodedKey);
    assertTrue(result);
    //System.out.println("key: "+key+" , encoded: "+encodedKey);

    // for testing other keys
    /*
    key = "66f3b80a-96b5-41c0-a2fb-1d0b17aec523";
    logicImpl.setSharedKey(key);
    //timestamp = System.currentTimeMillis() / 1000l;
    timestamp = 1333495162;
    sha1Bytes = DigestUtils.sha(key + ":" + timestamp);
    encodedKey = Hex.encodeHexString(sha1Bytes) + "|" + timestamp;
    result = logicImpl.verifyKey(encodedKey);
    System.out.println("key: "+key+", timestamp: "+timestamp+", encoded: "+encodedKey+", result="+result);
    assertTrue(result);
    */
}

From source file:net.lightbody.bmp.proxy.jetty.jetty.servlet.Default.java

public void handleDelete(HttpServletRequest request, HttpServletResponse response, String pathInContext,
        Resource resource) throws ServletException, IOException {
    if (!resource.exists() || !passConditionalHeaders(request, response, resource))
        return;/*from  w w w  .jav a 2  s .  c  o  m*/
    try {
        // delete the file
        if (resource.delete()) {
            response.setStatus(HttpResponse.__204_No_Content);
            response.flushBuffer();
        } else
            response.sendError(HttpResponse.__403_Forbidden);
    } catch (SecurityException sex) {
        log.warn(LogSupport.EXCEPTION, sex);
        response.sendError(HttpResponse.__403_Forbidden, sex.getMessage());
    }
}

From source file:JavaFiles.AbstractWsToolClient.java

/** Generate a string containing the values of the fields with "get" methods. 
 * /* w  w w  .  j a va  2  s .  c  o  m*/
 * @param obj Object the get values from
 * @return String containing values and method names.
 */
// @SuppressWarnings("unchecked")
protected String objectFieldsToString(Object obj) {
    printDebugMessage("ObjectFieldsToString", "Begin", 31);
    StringBuilder strBuilder = new StringBuilder();
    try {
        Class objType = obj.getClass();
        printDebugMessage("ObjectFieldsToString", "objType: " + objType, 32);
        java.lang.reflect.Method[] methods = objType.getMethods();
        for (int i = 0; i < methods.length; i++) {
            String methodName = methods[i].getName();
            if (methodName.startsWith("get") && methods[i].getParameterTypes().length == 0
                    && !methodName.equals("getClass") && !methodName.equals("getTypeDesc")) {
                printDebugMessage("ObjectFieldsToString", "invoke(): " + methodName, 32);
                Object tmpObj = methods[i].invoke(obj, new Object[0]);
                // Handle any string lists (e.g. database)
                if (tmpObj instanceof String[]) {
                    String[] tmpList = (String[]) tmpObj;
                    strBuilder.append(methodName + ":\n");
                    for (int j = 0; j < tmpList.length; j++) {
                        strBuilder.append("\t" + tmpList[j] + "\n");
                    }
                }
                // Otherwise just use implicit toString();
                else {
                    strBuilder.append(methodName + ": " + tmpObj + "\n");
                }
            }
        }
    } catch (SecurityException e) {
        System.err.println(e.getMessage());
    } catch (IllegalArgumentException e) {
        System.err.println(e.getMessage());
    } catch (IllegalAccessException e) {
        System.err.println(e.getMessage());
    } catch (InvocationTargetException e) {
        System.err.println(e.getMessage());
    }
    printDebugMessage("ObjectFieldsToString", "End", 31);
    return strBuilder.toString();
}

From source file:com.dungnv.vfw5.base.dao.BaseFWDAOImpl.java

@Transactional
public String saveListNoId(List<T> obj) {
    try {/*w w w.j  a  va  2s.  com*/
        for (T item : obj) {
            getSession().save(item);
        }
        return ParamUtils.SUCCESS;
    } catch (SecurityException ex) {
        return ex.getMessage();
    }
}

From source file:jp.co.acroquest.endosnipe.perfdoctor.rule.RuleManager.java

/**
 * ???xml???/*from www . ja  va2 s.co  m*/
 */
@SuppressWarnings("deprecation")
public synchronized void commit() {
    // ?ID??
    RulePreferenceUtil.saveActiveRuleSetId(this.activeRuleSetId_);

    // ??
    List<String> ruleSetIdList = new ArrayList<String>();
    Collection<RuleSetConfig> ruleSetConfigs = this.ruleSetConfigMap_.values();

    for (RuleSetConfig config : ruleSetConfigs) {
        String id = config.getId();
        if (isDefaultRuleSet(id)) {
            continue;
        }

        RulePreferenceUtil.saveRuleSet(config);

        // 
        ruleSetIdList.add(id);
    }

    // ID??
    String[] ruleSetIds = ruleSetIdList.toArray(new String[ruleSetIdList.size()]);
    RulePreferenceUtil.saveRuleSetIds(ruleSetIds);

    // ??
    // ????????
    for (String ruleId : this.dirtyRuleSetIds_) {
        if (isDefaultRuleSet(ruleId)) {
            continue;
        }

        RuleSetConfig config = this.ruleSetConfigMap_.get(ruleId);
        if (config == null) {
            continue;
        }
        RuleSetDef def = this.ruleSetMap_.get(ruleId);
        this.accessor_.updateRuleSet(def, config.getFileName());
    }

    // ??
    // ?????????
    // ????
    for (RuleSetConfig config : ruleSetConfigs) {
        String id = config.getId();
        if (isDefaultRuleSet(id)) {
            continue;
        }

        File file = new File(config.getFileName());
        if (file.exists() && file.isFile()) {
            continue;
        }

        File parentFile = file.getParentFile();

        if (parentFile != null && parentFile.exists() == false) {
            try {
                parentFile.mkdirs();
            } catch (SecurityException ex) {
                LOGGER.error(ex.getMessage(), ex);
            }
        }

        // ?????
        try {
            RuleSetDef defaultRuleSetClone = new RuleSetDef(getRuleSetDef(DEFAULT_RULESET_ID));
            defaultRuleSetClone.setName(config.getName());
            this.accessor_.updateRuleSet(defaultRuleSetClone, config.getFileName());
        } catch (RuleCreateException ex) {
            LOGGER.error(ex.getMessage(), ex);
        }
    }

    // ?
    for (RuleSetConfig config : this.removeList_) {
        File file = new File(config.getFileName());
        if (file.exists()) {
            try {
                file.delete();
            } catch (SecurityException ex) {
                LOGGER.error(ex.getMessage(), ex);
            }
        }
    }
    this.removeList_ = Collections.synchronizedList(new ArrayList<RuleSetConfig>());
}

From source file:ti.modules.titanium.network.NetworkModule.java

@Kroll.getProperty
@Kroll.method//from  w  ww.j av  a 2  s . co m
public int getNetworkType() {
    int type = NETWORK_UNKNOWN;

    // start event needs network type. So get it if we don't have it.
    if (connectivityManager == null) {
        connectivityManager = getConnectivityManager();
    }

    try {
        NetworkInfo ni = connectivityManager.getActiveNetworkInfo();
        if (ni != null && ni.isAvailable() && ni.isConnected()) {
            type = networkTypeToTitanium(true, ni.getType());
        } else {
            type = NetworkModule.NETWORK_NONE;
        }
    } catch (SecurityException e) {
        Log.w(TAG, "Permission has been removed. Cannot determine network type: " + e.getMessage());
    }
    return type;
}

From source file:org.kuali.kra.budget.calculator.QueryList.java

/**
 * sorts the QueryList by the fieldName in ascending or descending order.
 * Note: the field Object should be of Comparable type.
 * @return boolean indicating whether the sort is completed successfully or not.
 * @param ignoreCase use only when comparing strings. as default implementation uses case sensitive comparison.
 * @param fieldName field which is used to sort the bean.
 * @param ascending if true sorting is done in ascending order,
 * else sorting is done in descending order.
 *///ww  w. j a v  a 2s.c  om
@SuppressWarnings("rawtypes")
public boolean sort(String fieldName, boolean ascending, boolean ignoreCase) {
    Object current, next;
    int compareValue = 0;
    Field field = null;
    Method method = null;
    if (this.size() == 0) {
        return false;
    }
    Class dataClass = get(0).getClass();
    String methodName = null;
    try {
        field = dataClass.getDeclaredField(fieldName);
        if (!field.isAccessible()) {
            throw new NoSuchFieldException();
        }
    } catch (NoSuchFieldException noSuchFieldException) {
        //field not available. Use method invokation.
        try {
            methodName = "get" + (fieldName.charAt(0) + "").toUpperCase() + fieldName.substring(1);
            method = dataClass.getMethod(methodName, null);
        } catch (NoSuchMethodException noSuchMethodException) {
            noSuchMethodException.printStackTrace();
            return false;
        }
    }

    for (int index = 0; index < size() - 1; index++) {
        for (int nextIndex = index + 1; nextIndex < size(); nextIndex++) {
            current = get(index);
            next = get(nextIndex);
            //Check if current and next implements Comparable else can't compare.
            //so return without comparing.May be we can have an exception for this purpose.
            try {
                if (field != null && field.isAccessible()) {
                    Comparable thisObj = (Comparable) field.get(current);
                    Comparable otherObj = (Comparable) field.get(next);
                    if (thisObj == null) {
                        compareValue = -1;
                    } else if (otherObj == null) {
                        compareValue = 1;
                    } else {
                        if (thisObj instanceof String && ignoreCase) {
                            compareValue = ((String) thisObj).compareToIgnoreCase((String) otherObj);
                        } else {
                            compareValue = thisObj.compareTo(otherObj);
                        }
                    }
                } else {
                    Comparable thisObj = null;
                    Comparable otherObj = null;
                    if (methodName != null) {
                        Method thisObjMethod = current.getClass().getMethod(methodName, null);
                        Method otherObjMethod = next.getClass().getMethod(methodName, null);
                        thisObj = (Comparable) thisObjMethod.invoke(current, null);
                        otherObj = (Comparable) otherObjMethod.invoke(next, null);
                    } else {
                        thisObj = (Comparable) method.invoke(current, null);
                        otherObj = (Comparable) method.invoke(next, null);
                    }
                    if (thisObj == null) {
                        compareValue = -1;
                    } else if (otherObj == null) {
                        compareValue = 1;
                    } else {
                        if (thisObj instanceof String && ignoreCase) {
                            compareValue = ((String) thisObj).compareToIgnoreCase((String) otherObj);
                        } else {
                            compareValue = thisObj.compareTo(otherObj);
                        }
                    }
                }
            } catch (IllegalAccessException illegalAccessException) {
                LOG.warn(illegalAccessException.getMessage());
                return false;
            } catch (InvocationTargetException invocationTargetException) {
                LOG.warn(invocationTargetException.getMessage(), invocationTargetException);
                return false;
            } catch (SecurityException e) {
                LOG.warn(e.getMessage(), e);
                return false;
            } catch (NoSuchMethodException e) {
                LOG.warn(e.getMessage(), e);
                return false;
            }

            if (ascending && compareValue > 0) {
                E temp = get(index);
                set(index, get(nextIndex));
                set(nextIndex, temp);
            } else if (!ascending && compareValue < 0) {
                E temp = get(index);
                set(index, get(nextIndex));
                set(nextIndex, temp);
            }

        }
    }
    return true;
}

From source file:com.dungnv.vfw5.base.dao.BaseFWDAOImpl.java

@Transactional
public String saveList(List<T> obj, String methodName) {

    try {//from w  ww. j  a  va 2  s .co m

        for (T item : obj) {
            getSession().saveOrUpdate(item);
        }

        //            Class c = obj.get(0).getClass();
        //            Method method = c.getMethod("get" + StringUtils.upperFirstChar(methodName));
        //
        //            for (T item : obj) {
        //                String value;
        //                try {
        //                    value = String.valueOf(method.invoke(item));
        //
        //                } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
        //                    return ParamUtils.ERROR;
        //                }
        //
        //                if (value == "null") {
        //                    getSession().saveOrUpdate(item);
        //                } else {
        //                    getSession().update(item);
        //                }
        //            }
    } catch (SecurityException ex) {
        return ex.getMessage();
    }
    return ParamUtils.SUCCESS;

}