Search in sources :

Example 1 with SecurityVaultException

use of org.jboss.security.vault.SecurityVaultException in project wildfly by wildfly.

the class MockRuntimeVaultReader method createVault.

public void createVault(final String fqn, final Map<String, Object> options) throws VaultReaderException {
    Map<String, Object> vaultOptions = new HashMap<String, Object>(options);
    SecurityVault vault = null;
    try {
        vault = AccessController.doPrivileged(new PrivilegedExceptionAction<SecurityVault>() {

            @Override
            public SecurityVault run() throws Exception {
                if (fqn == null || fqn.isEmpty()) {
                    return SecurityVaultFactory.get();
                } else {
                    return SecurityVaultFactory.get(fqn);
                }
            }
        });
    } catch (PrivilegedActionException e) {
        Throwable t = e.getCause();
        if (t instanceof SecurityVaultException) {
            throw SecurityLogger.ROOT_LOGGER.vaultReaderException(t);
        }
        if (t instanceof RuntimeException) {
            throw SecurityLogger.ROOT_LOGGER.runtimeException(t);
        }
        throw SecurityLogger.ROOT_LOGGER.runtimeException(t);
    }
    try {
        vault.init(vaultOptions);
    } catch (SecurityVaultException e) {
        e.printStackTrace();
        throw SecurityLogger.ROOT_LOGGER.vaultReaderException(e);
    }
    this.vault = vault;
}
Also used : HashMap(java.util.HashMap) PrivilegedActionException(java.security.PrivilegedActionException) SecurityVaultException(org.jboss.security.vault.SecurityVaultException) PrivilegedExceptionAction(java.security.PrivilegedExceptionAction) SecurityVault(org.jboss.security.vault.SecurityVault)

Example 2 with SecurityVaultException

use of org.jboss.security.vault.SecurityVaultException in project wildfly by wildfly.

the class CheckVaultedPassServlet method doGet.

@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    resp.setContentType("text/plain");
    final PrintWriter writer = resp.getWriter();
    String vaultString = req.getParameter(VAULTED_PASS);
    char[] password = "nopass".toCharArray();
    if (vaultString != null) {
        try {
            password = SecurityVaultUtil.getValue(vaultString);
        } catch (SecurityVaultException e) {
            e.printStackTrace();
        }
    }
    writer.write(password);
    writer.close();
}
Also used : SecurityVaultException(org.jboss.security.vault.SecurityVaultException) PrintWriter(java.io.PrintWriter)

Aggregations

SecurityVaultException (org.jboss.security.vault.SecurityVaultException)2 PrintWriter (java.io.PrintWriter)1 PrivilegedActionException (java.security.PrivilegedActionException)1 PrivilegedExceptionAction (java.security.PrivilegedExceptionAction)1 HashMap (java.util.HashMap)1 SecurityVault (org.jboss.security.vault.SecurityVault)1