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.forgerock.patch.Main.java

private static Patch instantiatePatch() throws PatchException {
    Object obj = null;//  ww  w . ja v a2  s.com
    try {
        String patchClass = config.getString(CONFIG_PATCH_IMPL_CLASS);
        if (patchClass == null) {
            throw new PatchException("Invalid configuration, " + CONFIG_PATCH_IMPL_CLASS + " not specified.");
        }
        Class c = Class.forName(patchClass);
        obj = c.newInstance();
    } catch (SecurityException ex) {
        logger.log(Level.SEVERE, null, ex);
        throw new PatchException(ex.getMessage(), ex);
    } catch (InstantiationException ex) {
        logger.log(Level.SEVERE, null, ex);
        throw new PatchException(ex.getMessage(), ex);
    } catch (IllegalAccessException ex) {
        logger.log(Level.SEVERE, null, ex);
        throw new PatchException(ex.getMessage(), ex);
    } catch (ClassNotFoundException ex) {
        Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
    }
    return (Patch) obj;
}

From source file:stream.Sample.java

public static void dataStoreManager() {

    Timestamp stamp = new Timestamp(System.currentTimeMillis());
    Date date1 = new Date(stamp.getTime());

    SimpleDateFormat format1 = new SimpleDateFormat("E MMM dd hh:mm:ss z yyyy");
    SimpleDateFormat format2 = new SimpleDateFormat("yyyyMMdd");
    Date date = null;//w w w.  j  av a  2s  .c  o  m
    try {
        date = format1.parse("" + date1);
    } catch (ParseException e) {
    }
    String dateDirName = format2.format(date);

    String dateDirPath = OutputDirPath + "/";
    File dateDir = new File(dateDirPath + dateDirName);

    // If the directory does not exist, create it
    if (!dateDir.exists()) {

        try {
            dateDir.mkdirs();
            FileCounter = 0;

        } catch (SecurityException se) {

            System.err.println("Could not create output " + "directory: " + OutputDirPath);
            System.err.println(se.getMessage());
            System.exit(-1);
        }
    }

    if (firstRun || FileCounter >= 100) {

        if (dateDir.exists()) {

            currentDirPath = dateDirPath + dateDirName + "/" + System.currentTimeMillis() / 1000;
            File currentDir = new File(currentDirPath);
            // If the directory does not exist, create it
            if (!currentDir.exists()) {

                try {
                    currentDir.mkdirs();

                } catch (SecurityException se) {

                    System.err.println("Could not create output " + "directory: " + currentDirPath);
                    System.err.println(se.getMessage());
                    System.exit(-1);
                }
            }

        }

        firstRun = false;
        FileCounter = 0;
    }

    if (writer != null) {
        writer.close();
    }

    counter = 0;
    FileCounter++;
    try {
        writer = new PrintWriter(currentDirPath + "/" + FileCounter + ".txt", "UTF-8");

    } catch (FileNotFoundException | UnsupportedEncodingException e) {
    }
}

From source file:org.forgerock.openidm.patch.Main.java

private static Patch instantiatePatch() throws PatchException {
    Object obj = null;/*  ww w . j  ava 2  s  .com*/
    try {
        String patchClass = CONFIG.getString(CONFIG_PATCH_IMPL_CLASS);
        if (patchClass == null) {
            throw new PatchException("Invalid configuration, " + CONFIG_PATCH_IMPL_CLASS + " not specified.");
        }
        Class c = Class.forName(patchClass);
        obj = c.newInstance();
    } catch (SecurityException ex) {
        logger.log(Level.SEVERE, null, ex);
        throw new PatchException(ex.getMessage(), ex);
    } catch (InstantiationException ex) {
        logger.log(Level.SEVERE, null, ex);
        throw new PatchException(ex.getMessage(), ex);
    } catch (IllegalAccessException ex) {
        logger.log(Level.SEVERE, null, ex);
        throw new PatchException(ex.getMessage(), ex);
    } catch (ClassNotFoundException ex) {
        Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
    }
    return (Patch) obj;
}

From source file:com.evolveum.midpoint.util.ReflectionUtil.java

/**
 * Try to get java property from the object by reflection
 *//*from w  w w  . j  a v  a  2 s .  c om*/
public static <T> T getJavaProperty(Object object, String propertyName, Class<T> propetyClass) {
    String getterName = getterName(propertyName);
    Method method;
    try {
        method = object.getClass().getMethod(getterName);
    } catch (SecurityException e) {
        throw new IllegalArgumentException(
                "Security error getting getter for property " + propertyName + ": " + e.getMessage(), e);
    } catch (NoSuchMethodException e) {
        throw new IllegalArgumentException(
                "No getter for property " + propertyName + " in " + object + " (" + object.getClass() + ")");
    }
    if (method == null) {
        throw new IllegalArgumentException(
                "No getter for property " + propertyName + " in " + object + " (" + object.getClass() + ")");
    }
    if (!propetyClass.isAssignableFrom(method.getReturnType())) {
        throw new IllegalArgumentException(
                "The getter for property " + propertyName + " returns " + method.getReturnType() + ", expected "
                        + propetyClass + " in " + object + " (" + object.getClass() + ")");
    }
    try {
        return (T) method.invoke(object);
    } catch (IllegalArgumentException e) {
        throw new IllegalArgumentException(
                "Error invoking getter for property " + propertyName + " in " + object + " ("
                        + object.getClass() + "): " + e.getClass().getSimpleName() + ": " + e.getMessage(),
                e);
    } catch (IllegalAccessException e) {
        throw new IllegalArgumentException(
                "Error invoking getter for property " + propertyName + " in " + object + " ("
                        + object.getClass() + "): " + e.getClass().getSimpleName() + ": " + e.getMessage(),
                e);
    } catch (InvocationTargetException e) {
        throw new IllegalArgumentException(
                "Error invoking getter for property " + propertyName + " in " + object + " ("
                        + object.getClass() + "): " + e.getClass().getSimpleName() + ": " + e.getMessage(),
                e);
    }
}

From source file:Main.java

public static void checkAndFixAccess(Member paramMember) {
    AccessibleObject localAccessibleObject = (AccessibleObject) paramMember;
    try {/* ww  w.j a  v  a2 s  .c  o  m*/
        localAccessibleObject.setAccessible(true);
        return;
    } catch (SecurityException localSecurityException) {
        while (localAccessibleObject.isAccessible())
            ;
        Class localClass = paramMember.getDeclaringClass();
        throw new IllegalArgumentException("Can not access " + paramMember + " (from class "
                + localClass.getName() + "; failed to set access: " + localSecurityException.getMessage());
    }
}

From source file:com.cws.esolutions.security.listeners.SecurityServiceInitializer.java

/**
 * Initializes the security service in a standalone mode - used for applications outside of a container or when
 * run as a standalone jar./* ww  w.  j av  a 2 s. c om*/
 *
 * @param configFile - The security configuration file to utilize
 * @param logConfig - The logging configuration file to utilize
 * @param startConnections - Configure, load and start repository connections
 * @throws SecurityServiceException @{link com.cws.esolutions.security.exception.SecurityServiceException}
 * if an exception occurs during initialization
 */
public static void initializeService(final String configFile, final String logConfig,
        final boolean startConnections) throws SecurityServiceException {
    URL xmlURL = null;
    JAXBContext context = null;
    Unmarshaller marshaller = null;
    SecurityConfigurationData configData = null;

    final ClassLoader classLoader = SecurityServiceInitializer.class.getClassLoader();
    final String serviceConfig = (StringUtils.isBlank(configFile)) ? System.getProperty("configFileFile")
            : configFile;
    final String loggingConfig = (StringUtils.isBlank(logConfig)) ? System.getProperty("secLogConfig")
            : logConfig;

    try {
        try {
            DOMConfigurator.configure(Loader.getResource(loggingConfig));
        } catch (NullPointerException npx) {
            try {
                DOMConfigurator.configure(FileUtils.getFile(loggingConfig).toURI().toURL());
            } catch (NullPointerException npx1) {
                System.err.println("Unable to load logging configuration. No logging enabled!");
                System.err.println("");
                npx1.printStackTrace();
            }
        }

        xmlURL = classLoader.getResource(serviceConfig);

        if (xmlURL == null) {
            // try loading from the filesystem
            xmlURL = FileUtils.getFile(serviceConfig).toURI().toURL();
        }

        context = JAXBContext.newInstance(SecurityConfigurationData.class);
        marshaller = context.createUnmarshaller();
        configData = (SecurityConfigurationData) marshaller.unmarshal(xmlURL);

        SecurityServiceInitializer.svcBean.setConfigData(configData);

        if (startConnections) {
            DAOInitializer.configureAndCreateAuthConnection(
                    new FileInputStream(FileUtils.getFile(configData.getSecurityConfig().getAuthConfig())),
                    false, SecurityServiceInitializer.svcBean);

            Map<String, DataSource> dsMap = SecurityServiceInitializer.svcBean.getDataSources();

            if (DEBUG) {
                DEBUGGER.debug("dsMap: {}", dsMap);
            }

            if (configData.getResourceConfig() != null) {
                if (dsMap == null) {
                    dsMap = new HashMap<String, DataSource>();
                }

                for (DataSourceManager mgr : configData.getResourceConfig().getDsManager()) {
                    if (!(dsMap.containsKey(mgr.getDsName()))) {
                        StringBuilder sBuilder = new StringBuilder()
                                .append("connectTimeout=" + mgr.getConnectTimeout() + ";")
                                .append("socketTimeout=" + mgr.getConnectTimeout() + ";")
                                .append("autoReconnect=" + mgr.getAutoReconnect() + ";")
                                .append("zeroDateTimeBehavior=convertToNull");

                        if (DEBUG) {
                            DEBUGGER.debug("StringBuilder: {}", sBuilder);
                        }

                        BasicDataSource dataSource = new BasicDataSource();
                        dataSource.setDriverClassName(mgr.getDriver());
                        dataSource.setUrl(mgr.getDataSource());
                        dataSource.setUsername(mgr.getDsUser());
                        dataSource.setConnectionProperties(sBuilder.toString());
                        dataSource.setPassword(PasswordUtils.decryptText(mgr.getDsPass(), mgr.getDsSalt(),
                                configData.getSecurityConfig().getSecretAlgorithm(),
                                configData.getSecurityConfig().getIterations(),
                                configData.getSecurityConfig().getKeyBits(),
                                configData.getSecurityConfig().getEncryptionAlgorithm(),
                                configData.getSecurityConfig().getEncryptionInstance(),
                                configData.getSystemConfig().getEncoding()));

                        if (DEBUG) {
                            DEBUGGER.debug("BasicDataSource: {}", dataSource);
                        }

                        dsMap.put(mgr.getDsName(), dataSource);
                    }
                }

                if (DEBUG) {
                    DEBUGGER.debug("dsMap: {}", dsMap);
                }

                SecurityServiceInitializer.svcBean.setDataSources(dsMap);
            }
        }
    } catch (JAXBException jx) {
        jx.printStackTrace();
        throw new SecurityServiceException(jx.getMessage(), jx);
    } catch (FileNotFoundException fnfx) {
        fnfx.printStackTrace();
        throw new SecurityServiceException(fnfx.getMessage(), fnfx);
    } catch (MalformedURLException mux) {
        mux.printStackTrace();
        throw new SecurityServiceException(mux.getMessage(), mux);
    } catch (SecurityException sx) {
        sx.printStackTrace();
        throw new SecurityServiceException(sx.getMessage(), sx);
    }
}

From source file:org.squidy.common.util.ReflectionUtil.java

/**
 * @param type/*from  www .j  a v a 2  s  .c  o  m*/
 * @param name
 * @return
 */
public static Field getFieldInObjectHierarchy(Class<? extends Object> type, String name) {
    if (type == Object.class) {
        return null;
    }

    try {
        return type.getDeclaredField(name);
    } catch (SecurityException e) {
        if (LOG.isErrorEnabled()) {
            LOG.error(e.getMessage(), e);
        }
    } catch (NoSuchFieldException e) {
        // TODO: [RR] Check whether trace will be logged only if developer requires.
        if (LOG.isTraceEnabled()) {
            LOG.trace(e.getMessage(), e);
        }
    }

    return getFieldInObjectHierarchy(type.getSuperclass(), name);
}

From source file:org.squidy.common.util.ReflectionUtil.java

/**
 * @param invokable//from   ww  w  .java 2 s  . c o m
 * @param methodName
 * @param parameters
 * @param parameterTypes
 * @return
 */
public static Object callMethod(Object invokable, String methodName, Object[] parameters,
        Class[] parameterTypes) {
    try {
        Method method = invokable.getClass().getMethod(methodName, parameterTypes);
        method.setAccessible(true);
        return method.invoke(invokable, parameters);
    } catch (SecurityException e) {
        if (LOG.isErrorEnabled()) {
            LOG.error(e.getMessage(), e);
        }
    } catch (IllegalArgumentException e) {
        if (LOG.isErrorEnabled()) {
            LOG.error(e.getMessage(), e);
        }
    } catch (NoSuchMethodException e) {
        if (LOG.isErrorEnabled()) {
            LOG.error(e.getMessage(), e);
        }
    } catch (IllegalAccessException e) {
        if (LOG.isErrorEnabled()) {
            LOG.error(e.getMessage(), e);
        }
    } catch (InvocationTargetException e) {
        if (LOG.isErrorEnabled()) {
            LOG.error(e.getMessage(), e);
        }
    }
    return null;
}

From source file:com.rockagen.commons.util.ClassUtil.java

/**
 * Create new instance of specified class and type
 * // w w w  . j  a  v  a2s . c  om
 * @param clazz class
 * @param accessible accessible
 * @param parameterTypes parameter types
 * @param paramValue param value
 * @param <T> t
 * @return instance
 */
public static <T> T getInstance(Class<T> clazz, boolean accessible, Class<?>[] parameterTypes,
        Object[] paramValue) {
    if (clazz == null)
        return null;

    T t = null;

    try {
        if (parameterTypes != null && paramValue != null) {
            Constructor<T> constructor = clazz.getDeclaredConstructor(parameterTypes);
            Object[] obj = new Object[parameterTypes.length];

            System.arraycopy(paramValue, 0, obj, 0, parameterTypes.length);
            constructor.setAccessible(accessible);
            t = constructor.newInstance(obj);
        }

    } catch (SecurityException e) {
        log.error("{}", e.getMessage(), e);
    } catch (NoSuchMethodException e) {
        log.error("{}", e.getMessage(), e);
    } catch (IllegalArgumentException e) {
        log.error("{}", e.getMessage(), e);
    } catch (InstantiationException e) {
        log.error("{}", e.getMessage(), e);
    } catch (IllegalAccessException e) {
        log.error("{}", e.getMessage(), e);
    } catch (InvocationTargetException e) {
        log.error("{}", e.getMessage(), e);
    }

    return t;
}

From source file:com.github.magicsky.sya.checkers.TestSourceReader.java

/**
 * Returns an array of StringBuilder objects for each comment section found preceding the named
 * test in the source code./*from  w w  w. j av a2  s .  c o  m*/
 *
 * @param srcRoot     the directory inside the bundle containing the packages
 * @param clazz       the name of the class containing the test
 * @param testName    the name of the test
 * @param numSections the number of comment sections preceding the named test to return.
 *                    Pass zero to get all available sections.
 * @return an array of StringBuilder objects for each comment section found preceding the named
 * test in the source code.
 * @throws IOException
 */
public static StringBuilder[] getContentsForTest(String srcRoot, Class clazz, final String testName,
        int numSections) throws IOException {
    // Walk up the class inheritance chain until we find the test method.
    try {
        while (clazz.getMethod(testName).getDeclaringClass() != clazz) {
            clazz = clazz.getSuperclass();
        }
    } catch (SecurityException e) {
        Assert.fail(e.getMessage());
    } catch (NoSuchMethodException e) {
        Assert.fail(e.getMessage());
    }

    while (true) {
        // Find and open the .java file for the class clazz.
        String fqn = clazz.getName().replace('.', '/');
        fqn = fqn.indexOf("$") == -1 ? fqn : fqn.substring(0, fqn.indexOf("$"));
        String classFile = fqn + ".java";
        InputStream in;
        Class superclass = clazz.getSuperclass();
        try {
            in = FileUtils.openInputStream(new File(srcRoot + '/' + classFile));
        } catch (IOException e) {
            if (superclass == null || !superclass.getPackage().equals(clazz.getPackage())) {
                throw e;
            }
            clazz = superclass;
            continue;
        }

        BufferedReader br = new BufferedReader(new InputStreamReader(in));
        try {
            // Read the java file collecting comments until we encounter the test method.
            List<StringBuilder> contents = new ArrayList<StringBuilder>();
            StringBuilder content = new StringBuilder();
            for (String line = br.readLine(); line != null; line = br.readLine()) {
                line = line.replaceFirst("^\\s*", ""); // Replace leading whitespace, preserve trailing
                if (line.startsWith("//")) {
                    content.append(line.substring(2) + "\n");
                } else {
                    if (!line.startsWith("@") && content.length() > 0) {
                        contents.add(content);
                        if (numSections > 0 && contents.size() == numSections + 1)
                            contents.remove(0);
                        content = new StringBuilder();
                    }
                    if (line.length() > 0 && !contents.isEmpty()) {
                        int idx = line.indexOf(testName);
                        if (idx != -1
                                && !Character.isJavaIdentifierPart(line.charAt(idx + testName.length()))) {
                            return contents.toArray(new StringBuilder[contents.size()]);
                        }
                        if (!line.startsWith("@")) {
                            contents.clear();
                        }
                    }
                }
            }
        } finally {
            br.close();
        }

        if (superclass == null || !superclass.getPackage().equals(clazz.getPackage())) {
            throw new IOException("Test data not found for " + clazz.getName() + "." + testName);
        }
        clazz = superclass;
    }
}