Example usage for java.security NoSuchAlgorithmException getMessage

List of usage examples for java.security NoSuchAlgorithmException getMessage

Introduction

In this page you can find the example usage for java.security NoSuchAlgorithmException getMessage.

Prototype

public String getMessage() 

Source Link

Document

Returns the detail message string of this throwable.

Usage

From source file:eu.europa.ec.markt.dss.signature.xades.XAdESProfileBES.java

DigestAlgAndValueType getDigestAlgAndValue(byte[] data, DigestAlgorithm digestAlgorithm) {
    DigestAlgAndValueType digestAlgAndValue = xades13ObjectFactory.createDigestAlgAndValueType();

    DigestMethodType digestMethod = getDsObjectFactory().createDigestMethodType();
    digestAlgAndValue.setDigestMethod(digestMethod);
    digestMethod.setAlgorithm(digestAlgorithm.getXmlId());

    MessageDigest messageDigest;/*from  w  ww.j  a v  a  2 s.c o  m*/
    try {
        messageDigest = MessageDigest.getInstance(digestAlgorithm.getName());
    } catch (NoSuchAlgorithmException e) {
        throw new RuntimeException("message digest algo error: " + e.getMessage(), e);
    }
    byte[] digestValue = messageDigest.digest(data);
    digestAlgAndValue.setDigestValue(digestValue);

    return digestAlgAndValue;
}

From source file:net.sourceforge.msscodefactory.cfasterisk.v2_4.CFAsteriskSMWar.CFAsteriskSMWarCancelResetPasswordHtml.java

/**
 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
 *///  ww  w  .j a  v a 2  s.c om
protected void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    final String S_ProcName = "doPost";

    ICFAsteriskSchemaObj schemaObj;
    HttpSession sess = request.getSession(false);
    if (sess == null) {
        sess = request.getSession(true);
        schemaObj = new CFAsteriskSchemaPooledObj();
        sess.setAttribute("SchemaObj", schemaObj);
    } else {
        schemaObj = (ICFAsteriskSchemaObj) sess.getAttribute("SchemaObj");
        if (schemaObj == null) {
            throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0,
                    "schemaObj");
        }
    }

    ICFAsteriskSchema dbSchema = null;
    try {
        CFSecurityAuthorization auth = schemaObj.getAuthorization();
        if (auth != null) {
            response.sendRedirect("CFAsteriskSMWarSecurityMainHtml");
            return;
        }

        dbSchema = (ICFAsteriskSchema) CFAsteriskSchemaPool.getSchemaPool().getInstance();
        schemaObj.setBackingStore(dbSchema);
        schemaObj.beginTransaction();
        ICFSecuritySecUserObj systemUser = schemaObj.getSecUserTableObj().readSecUserByULoginIdx("system");
        String passwordHash = systemUser.getRequiredPasswordHash();
        if ((passwordHash == null) || (passwordHash.length() <= 0) || passwordHash.equals("bootstrap")) {
            response.sendRedirect("CFAsteriskSMWarSetSystemPasswordHtml");
            return;
        }

        ICFSecuritySysClusterObj sysCluster = schemaObj.getSysClusterTableObj().readSysClusterByIdIdx(1, false);
        if (sysCluster == null) {
            throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0,
                    "sysCluster");
        }

        ICFSecurityClusterObj resolvedCluster = sysCluster.getRequiredContainerCluster();
        if (resolvedCluster == null) {
            throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName,
                    "resolvedCluster");
        }
        String clusterDomainName = resolvedCluster.getRequiredFullDomainName();
        String clusterDescription = resolvedCluster.getRequiredDescription();

        String resetUUIDStr = (String) request.getParameter("ResetUUID");
        if ((resetUUIDStr == null) || (resetUUIDStr.length() <= 0)) {
            response.setContentType("text/html");
            PrintWriter out = response.getWriter();
            out.println("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01//EN\">");
            out.println("<HTML>");
            out.println("<BODY>");
            out.println("<form method=\"post\" formaction=\"CFAsteriskSMWarResetPasswordHtml\">");
            out.println("<H1 style=\"text-align:center\">" + clusterDescription + " Security Manager</H1>");
            out.println("<H2 style=\"text-align:center\">ERROR</H2>");
            out.println("<p>");
            out.println("<center>");
            out.println("<p>");
            out.println(
                    "The ResetUUID parameter was missing in your request.  Please use the link provided by your Password Reset email.");
            out.println("</BODY>");
            out.println("</HTML>");
            return;
        }

        UUID resetUUID = UUID.fromString(resetUUIDStr);
        if (resetUUID == null) {
            response.setContentType("text/html");
            PrintWriter out = response.getWriter();
            out.println("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01//EN\">");
            out.println("<HTML>");
            out.println("<BODY>");
            out.println("<form method=\"post\" formaction=\"CFAsteriskSMWarResetPasswordHtml\">");
            out.println("<H1 style=\"text-align:center\">" + clusterDescription + " Security Manager</H1>");
            out.println("<H2 style=\"text-align:center\">ERROR</H2>");
            out.println("<p>");
            out.println("<center>");
            out.println("<p>");
            out.println("Invalid ResetUUID \"" + resetUUIDStr
                    + "\".  Please use the link provided by your Password Reset email.");
            out.println("</BODY>");
            out.println("</HTML>");
            return;
        }

        ICFSecuritySecUserObj resetUser = null;
        Iterator<ICFSecuritySecUserObj> secUserForUUID = schemaObj.getSecUserTableObj()
                .readSecUserByPwdResetIdx(resetUUID).iterator();
        if (secUserForUUID.hasNext()) {
            resetUser = secUserForUUID.next();
            if (secUserForUUID.hasNext()) {
                throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), S_ProcName,
                        "Multiple SecUser instances found for ResetUUID \"" + resetUUIDStr + "\"");
            }
        } else {
            response.setContentType("text/html");
            PrintWriter out = response.getWriter();
            out.println("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01//EN\">");
            out.println("<HTML>");
            out.println("<BODY>");
            out.println("<form method=\"post\" formaction=\"CFAsteriskSMWarResetPasswordHtml\">");
            out.println("<H1 style=\"text-align:center\">" + clusterDescription + " Security Manager</H1>");
            out.println("<H2 style=\"text-align:center\">ERROR</H2>");
            out.println("<p>");
            out.println("<center>");
            out.println("<p>");
            out.println("Invalid ResetUUID \"" + resetUUIDStr
                    + "\".  Please use the link provided by your HTML Passsword Reset email.");
            out.println("</BODY>");
            out.println("</HTML>");
            return;
        }

        String password = (String) request.getParameter("Password");
        if ((password == null) || (password.length() <= 0)) {
            response.setContentType("text/html");
            PrintWriter out = response.getWriter();
            out.println("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01//EN\">");
            out.println("<HTML>");
            out.println("<BODY>");
            out.println("<form method=\"post\" formaction=\"CFAsteriskSMWarResetPasswordHtml\">");
            out.println("<H1 style=\"text-align:center\">" + clusterDescription + " Security Manager</H1>");
            out.println("<H2 style=\"text-align:center\">ERROR</H2>");
            out.println("<p style=\"text-align:center\">");
            out.println("New Password must be specified.");
            out.println("<p>");
            out.println("<center>");
            out.println("<table style=\"width:75%\">");
            out.println(
                    "<tr><th style=\"text-align:left\">Reset UUID:</th><td><input type=\"text\" name=\"ResetUUID\" readonly=\"true\" value=\""
                            + resetUUID.toString() + "\"/></td></tr>");
            out.println(
                    "<tr><th style=\"text-align:left\">Login Id:</th><td><input type=\"text\" name=\"LoginId\" readonly=\"true\" value=\""
                            + resetUser.getRequiredEMailAddress() + "\"/></td></tr>");
            out.println(
                    "<tr><th style=\"text-align:left\">New Password:</th><td><input type=\"password\" name=\"Password\"/></td></tr>");
            out.println(
                    "<tr><th style=\"text-align:left\">Confirm New Password:</th><td><input type=\"password\" name=\"ConfirmPassword\"/></td></tr>");
            out.println(
                    "<tr><td colspan=\"2\" style=\"text-align:center\"><button type=\"submit\" name=\"Ok\"\">Ok</button></td></tr>");
            out.println(
                    "<tr><td colSpan=\"2\" style=\"text-align:center\"><A HRef=\"CFAsteriskSMWarLoginHtml\">Take me to the "
                            + clusterDescription + " Security Manager Login</A></td></tr>");
            out.println("</table>");
            out.println("</center>");
            out.println("</form>");
            out.println("</BODY>");
            out.println("</HTML>");
            return;
        }

        String confirmPassword = (String) request.getParameter("ConfirmPassword");
        if ((confirmPassword == null) || (confirmPassword.length() <= 0)) {
            response.setContentType("text/html");
            PrintWriter out = response.getWriter();
            out.println("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01//EN\">");
            out.println("<HTML>");
            out.println("<BODY>");
            out.println("<form method=\"post\" formaction=\"CFAsteriskSMWarResetPasswordHtml\">");
            out.println("<H1 style=\"text-align:center\">" + clusterDescription + " Security Manager</H1>");
            out.println("<H2 style=\"text-align:center\">ERROR</H2>");
            out.println("<p style=\"text-align:center\">");
            out.println("Confirm New Password must be specified.");
            out.println("<p>");
            out.println("<center>");
            out.println("<table style=\"width:75%\">");
            out.println(
                    "<tr><th style=\"text-align:left\">Reset UUID:</th><td><input type=\"text\" name=\"ResetUUID\" readonly=\"true\" value=\""
                            + resetUUID.toString() + "\"/></td></tr>");
            out.println(
                    "<tr><th style=\"text-align:left\">Login Id:</th><td><input type=\"text\" name=\"LoginId\" readonly=\"true\" value=\""
                            + resetUser.getRequiredEMailAddress() + "\"/></td></tr>");
            out.println(
                    "<tr><th style=\"text-align:left\">New Password:</th><td><input type=\"password\" name=\"Password\"/></td></tr>");
            out.println(
                    "<tr><th style=\"text-align:left\">Confirm New Password:</th><td><input type=\"password\" name=\"ConfirmPassword\"/></td></tr>");
            out.println(
                    "<tr><td colspan=\"2\" style=\"text-align:center\"><button type=\"submit\" name=\"Ok\"\">Ok</button></td></tr>");
            out.println(
                    "<tr><td colSpan=\"2\" style=\"text-align:center\"><A HRef=\"CFAsteriskSMWarLoginHtml\">Take me to the "
                            + clusterDescription + " Security Manager Login</A></td></tr>");
            out.println("</table>");
            out.println("</center>");
            out.println("</form>");
            out.println("</BODY>");
            out.println("</HTML>");
            return;
        }

        if (!confirmPassword.equals(password)) {
            response.setContentType("text/html");
            PrintWriter out = response.getWriter();
            out.println("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01//EN\">");
            out.println("<HTML>");
            out.println("<BODY>");
            out.println("<form method=\"post\" formaction=\"CFAsteriskSMWarResetPasswordHtml\">");
            out.println("<H1 style=\"text-align:center\">" + clusterDescription + " Security Manager</H1>");
            out.println("<H2 style=\"text-align:center\">ERROR</H2>");
            out.println("<p style=\"text-align:center\">");
            out.println("New Password and Confirm New Password do not match.");
            out.println("<p>");
            out.println("<center>");
            out.println("<table style=\"width:75%\">");
            out.println(
                    "<tr><th style=\"text-align:left\">Reset UUID:</th><td><input type=\"text\" name=\"ResetUUID\" readonly=\"true\" value=\""
                            + resetUUID.toString() + "\"/></td></tr>");
            out.println(
                    "<tr><th style=\"text-align:left\">Login Id:</th><td><input type=\"text\" name=\"LoginId\" readonly=\"true\" value=\""
                            + resetUser.getRequiredEMailAddress() + "\"/></td></tr>");
            out.println(
                    "<tr><th style=\"text-align:left\">New Password:</th><td><input type=\"password\" name=\"Password\"/></td></tr>");
            out.println(
                    "<tr><th style=\"text-align:left\">Confirm New Password:</th><td><input type=\"password\" name=\"ConfirmPassword\"/></td></tr>");
            out.println(
                    "<tr><td colspan=\"2\" style=\"text-align:center\"><button type=\"submit\" name=\"Ok\"\">Ok</button></td></tr>");
            out.println(
                    "<tr><td colSpan=\"2\" style=\"text-align:center\"><A HRef=\"CFAsteriskSMWarLoginHtml\">Take me to the "
                            + clusterDescription + " Security Manager Login</A></td></tr>");
            out.println("</table>");
            out.println("</center>");
            out.println("</form>");
            out.println("</BODY>");
            out.println("</HTML>");
            return;
        }

        MessageDigest msgDigest = MessageDigest.getInstance("SHA-512");
        msgDigest.update(password.getBytes("UTF-8"));
        byte[] hash = msgDigest.digest();
        byte[] encodedHash = Base64.encodeBase64(hash);
        String hashedAndEncodedPassword = new String(encodedHash);

        ICFSecurityClusterObj systemCluster = schemaObj.getClusterTableObj()
                .readClusterByUDomainNameIdx("system");
        ICFSecurityTenantObj systemTenant = schemaObj.getTenantTableObj()
                .readTenantByUNameIdx(systemCluster.getRequiredId(), "system");
        ICFSecuritySecSessionObj systemSession = schemaObj.getSecSessionTableObj().newInstance();
        ICFSecuritySecSessionEditObj editSystemSession = (ICFSecuritySecSessionEditObj) systemSession
                .beginEdit();
        editSystemSession.setRequiredContainerSecUser(systemUser);
        editSystemSession.setRequiredStart(Calendar.getInstance());
        systemSession = editSystemSession.create();
        editSystemSession.endEdit();

        auth = new CFSecurityAuthorization();
        auth.setSecCluster(systemCluster);
        auth.setSecTenant(systemTenant);
        auth.setSecSession(systemSession);
        schemaObj.setAuthorization(auth);

        ICFSecuritySecUserEditObj editResetUser = resetUser.beginEdit();
        editResetUser.setRequiredPasswordHash(hashedAndEncodedPassword);
        editResetUser.setOptionalPasswordResetUuid(null);
        editResetUser.update();
        editResetUser.endEdit();

        editSystemSession = (ICFSecuritySecSessionEditObj) systemSession.beginEdit();
        editSystemSession.setOptionalFinish(Calendar.getInstance());
        editSystemSession.update();
        editSystemSession.endEdit();

        schemaObj.commit();

        schemaObj.setAuthorization(null);

        response.setContentType("text/html");
        PrintWriter out = response.getWriter();
        out.println("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01//EN\">");
        out.println("<HTML>");
        out.println("<BODY>");
        out.println("<form method=\"post\" formaction=\"CFAsteriskSMWarConfirmEMailAddressHtml\">");
        out.println("<H1 style=\"text-align:center\">" + clusterDescription + " Security Manager</H1>");
        out.println("<H2 style=\"text-align:center\">Password Set.</H2>");
        out.println("<p>");
        out.println("<center>");
        out.println("<table style=\"width:75%\">");
        out.println(
                "<tr><td colSpan=\"2\" style=\"text-align:center\">You may now <A HRef=\"CFAsteriskSMWarLoginHtml\">log in</A> to the "
                        + clusterDescription + " Security Manager</td></tr>");
        out.println("</table>");
        out.println("</center>");
        out.println("</form>");
        out.println("</BODY>");
        out.println("</HTML>");
    } catch (NoSuchAlgorithmException e) {
        throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), S_ProcName,
                "Caught NoSuchAlgorithmException -- " + e.getMessage(), e);
    } catch (RuntimeException e) {
        throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), S_ProcName,
                "Caught RuntimeException -- " + e.getMessage(), e);
    } finally {
        if (dbSchema != null) {
            try {
                if (schemaObj.isTransactionOpen()) {
                    schemaObj.rollback();
                }
            } catch (RuntimeException e) {
            }
            schemaObj.setBackingStore(null);
            CFAsteriskSchemaPool.getSchemaPool().releaseInstance(dbSchema);
        }
    }
}

From source file:net.sourceforge.msscodefactory.cfasterisk.v2_2.CFAstSMWar.CFAstSMWarResetPasswordHtml.java

/**
 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
 *//*from  www.  j a  v  a  2 s  . c o  m*/
protected void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    final String S_ProcName = "doPost";

    ICFAstSchemaObj schemaObj;
    HttpSession sess = request.getSession(false);
    if (sess == null) {
        sess = request.getSession(true);
        schemaObj = new CFAstSchemaObj();
        sess.setAttribute("SchemaObj", schemaObj);
    } else {
        schemaObj = (ICFAstSchemaObj) sess.getAttribute("SchemaObj");
        if (schemaObj == null) {
            throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0,
                    "schemaObj");
        }
    }

    ICFAstSchema dbSchema = null;
    try {
        CFAstAuthorization auth = schemaObj.getAuthorization();
        if (auth != null) {
            response.sendRedirect("CFAstSMWarSecurityMainHtml");
            return;
        }

        dbSchema = CFAstSchemaPool.getSchemaPool().getInstance();
        schemaObj.setBackingStore(dbSchema);
        schemaObj.beginTransaction();
        ICFAstSecUserObj systemUser = schemaObj.getSecUserTableObj().readSecUserByULoginIdx("system");
        String passwordHash = systemUser.getRequiredPasswordHash();
        if ((passwordHash == null) || (passwordHash.length() <= 0) || passwordHash.equals("bootstrap")) {
            response.sendRedirect("CFAstSMWarSetSystemPasswordHtml");
            return;
        }

        ICFAstClusterObj resolvedCluster;
        ICFAstSysClusterObj sysCluster = schemaObj.getSysClusterTableObj().readSysClusterByIdIdx(1, false);
        if (sysCluster == null) {
            throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0,
                    "sysCluster");
        }
        resolvedCluster = sysCluster.getRequiredContainerCluster();
        if (resolvedCluster == null) {
            throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName,
                    "resolvedCluster");
        }
        String clusterDescription = resolvedCluster.getRequiredDescription();

        String resetUUIDStr = (String) request.getParameter("ResetUUID");
        if ((resetUUIDStr == null) || (resetUUIDStr.length() <= 0)) {
            response.setContentType("text/html");
            PrintWriter out = response.getWriter();
            out.println("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01//EN\">");
            out.println("<HTML>");
            out.println("<BODY>");
            out.println("<form method=\"post\" formaction=\"CFAstSMWarResetPasswordHtml\">");
            out.println("<H1 style=\"text-align:center\">" + clusterDescription + " Security Manager</H1>");
            out.println("<H2 style=\"text-align:center\">ERROR</H2>");
            out.println("<p>");
            out.println("<center>");
            out.println("<p>");
            out.println(
                    "The ResetUUID parameter was missing in your request.  Please use the link provided by your Password Reset email.");
            out.println("</BODY>");
            out.println("</HTML>");
            return;
        }

        UUID resetUUID = UUID.fromString(resetUUIDStr);
        if (resetUUID == null) {
            response.setContentType("text/html");
            PrintWriter out = response.getWriter();
            out.println("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01//EN\">");
            out.println("<HTML>");
            out.println("<BODY>");
            out.println("<form method=\"post\" formaction=\"CFAstSMWarResetPasswordHtml\">");
            out.println("<H1 style=\"text-align:center\">" + clusterDescription + " Security Manager</H1>");
            out.println("<H2 style=\"text-align:center\">ERROR</H2>");
            out.println("<p>");
            out.println("<center>");
            out.println("<p>");
            out.println("Invalid ResetUUID \"" + resetUUIDStr
                    + "\".  Please use the link provided by your Password Reset email.");
            out.println("</BODY>");
            out.println("</HTML>");
            return;
        }

        ICFAstSecUserObj resetUser = null;
        Iterator<ICFAstSecUserObj> secUserForUUID = schemaObj.getSecUserTableObj()
                .readSecUserByPwdResetIdx(resetUUID).iterator();
        if (secUserForUUID.hasNext()) {
            resetUser = secUserForUUID.next();
            if (secUserForUUID.hasNext()) {
                throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), S_ProcName,
                        "Multiple SecUser instances found for ResetUUID \"" + resetUUIDStr + "\"");
            }
        } else {
            response.setContentType("text/html");
            PrintWriter out = response.getWriter();
            out.println("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01//EN\">");
            out.println("<HTML>");
            out.println("<BODY>");
            out.println("<form method=\"post\" formaction=\"CFAstSMWarResetPasswordHtml\">");
            out.println("<H1 style=\"text-align:center\">" + clusterDescription + " Security Manager</H1>");
            out.println("<H2 style=\"text-align:center\">ERROR</H2>");
            out.println("<p>");
            out.println("<center>");
            out.println("<p>");
            out.println("Invalid ResetUUID \"" + resetUUIDStr
                    + "\".  Please use the link provided by your HTML Passsword Reset email.");
            out.println("</BODY>");
            out.println("</HTML>");
            return;
        }

        String password = (String) request.getParameter("Password");
        if ((password == null) || (password.length() <= 0)) {
            response.setContentType("text/html");
            PrintWriter out = response.getWriter();
            out.println("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01//EN\">");
            out.println("<HTML>");
            out.println("<BODY>");
            out.println("<form method=\"post\" formaction=\"CFAstSMWarResetPasswordHtml\">");
            out.println("<H1 style=\"text-align:center\">" + clusterDescription + " Security Manager</H1>");
            out.println("<H2 style=\"text-align:center\">ERROR</H2>");
            out.println("<p style=\"text-align:center\">");
            out.println("New Password must be specified.");
            out.println("<p>");
            out.println("<center>");
            out.println("<table style=\"width:75%\">");
            out.println(
                    "<tr><th style=\"text-align:left\">Reset UUID:</th><td><input type=\"text\" name=\"ResetUUID\" readonly=\"true\" value=\""
                            + resetUUID.toString() + "\"/></td></tr>");
            out.println(
                    "<tr><th style=\"text-align:left\">Login Id:</th><td><input type=\"text\" name=\"LoginId\" readonly=\"true\" value=\""
                            + resetUser.getRequiredEMailAddress() + "\"/></td></tr>");
            out.println(
                    "<tr><th style=\"text-align:left\">New Password:</th><td><input type=\"password\" name=\"Password\"/></td></tr>");
            out.println(
                    "<tr><th style=\"text-align:left\">Confirm New Password:</th><td><input type=\"password\" name=\"ConfirmPassword\"/></td></tr>");
            out.println(
                    "<tr><td colspan=\"2\" style=\"text-align:center\"><button type=\"submit\" name=\"Ok\"\">Ok</button></td></tr>");
            out.println(
                    "<tr><td colSpan=\"2\" style=\"text-align:center\"><A HRef=\"CFAstSMWarLoginHtml\">Take me to the "
                            + clusterDescription + " Security Manager Login</A></td></tr>");
            out.println("</table>");
            out.println("</center>");
            out.println("</form>");
            out.println("</BODY>");
            out.println("</HTML>");
            return;
        }

        String confirmPassword = (String) request.getParameter("ConfirmPassword");
        if ((confirmPassword == null) || (confirmPassword.length() <= 0)) {
            response.setContentType("text/html");
            PrintWriter out = response.getWriter();
            out.println("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01//EN\">");
            out.println("<HTML>");
            out.println("<BODY>");
            out.println("<form method=\"post\" formaction=\"CFAstSMWarResetPasswordHtml\">");
            out.println("<H1 style=\"text-align:center\">" + clusterDescription + " Security Manager</H1>");
            out.println("<H2 style=\"text-align:center\">ERROR</H2>");
            out.println("<p style=\"text-align:center\">");
            out.println("Confirm New Password must be specified.");
            out.println("<p>");
            out.println("<center>");
            out.println("<table style=\"width:75%\">");
            out.println(
                    "<tr><th style=\"text-align:left\">Reset UUID:</th><td><input type=\"text\" name=\"ResetUUID\" readonly=\"true\" value=\""
                            + resetUUID.toString() + "\"/></td></tr>");
            out.println(
                    "<tr><th style=\"text-align:left\">Login Id:</th><td><input type=\"text\" name=\"LoginId\" readonly=\"true\" value=\""
                            + resetUser.getRequiredEMailAddress() + "\"/></td></tr>");
            out.println(
                    "<tr><th style=\"text-align:left\">New Password:</th><td><input type=\"password\" name=\"Password\"/></td></tr>");
            out.println(
                    "<tr><th style=\"text-align:left\">Confirm New Password:</th><td><input type=\"password\" name=\"ConfirmPassword\"/></td></tr>");
            out.println(
                    "<tr><td colspan=\"2\" style=\"text-align:center\"><button type=\"submit\" name=\"Ok\"\">Ok</button></td></tr>");
            out.println(
                    "<tr><td colSpan=\"2\" style=\"text-align:center\"><A HRef=\"CFAstSMWarLoginHtml\">Take me to the "
                            + clusterDescription + " Security Manager Login</A></td></tr>");
            out.println("</table>");
            out.println("</center>");
            out.println("</form>");
            out.println("</BODY>");
            out.println("</HTML>");
            return;
        }

        if (!confirmPassword.equals(password)) {
            response.setContentType("text/html");
            PrintWriter out = response.getWriter();
            out.println("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01//EN\">");
            out.println("<HTML>");
            out.println("<BODY>");
            out.println("<form method=\"post\" formaction=\"CFAstSMWarResetPasswordHtml\">");
            out.println("<H1 style=\"text-align:center\">" + clusterDescription + " Security Manager</H1>");
            out.println("<H2 style=\"text-align:center\">ERROR</H2>");
            out.println("<p style=\"text-align:center\">");
            out.println("New Password and Confirm New Password do not match.");
            out.println("<p>");
            out.println("<center>");
            out.println("<table style=\"width:75%\">");
            out.println(
                    "<tr><th style=\"text-align:left\">Reset UUID:</th><td><input type=\"text\" name=\"ResetUUID\" readonly=\"true\" value=\""
                            + resetUUID.toString() + "\"/></td></tr>");
            out.println(
                    "<tr><th style=\"text-align:left\">Login Id:</th><td><input type=\"text\" name=\"LoginId\" readonly=\"true\" value=\""
                            + resetUser.getRequiredEMailAddress() + "\"/></td></tr>");
            out.println(
                    "<tr><th style=\"text-align:left\">New Password:</th><td><input type=\"password\" name=\"Password\"/></td></tr>");
            out.println(
                    "<tr><th style=\"text-align:left\">Confirm New Password:</th><td><input type=\"password\" name=\"ConfirmPassword\"/></td></tr>");
            out.println(
                    "<tr><td colspan=\"2\" style=\"text-align:center\"><button type=\"submit\" name=\"Ok\"\">Ok</button></td></tr>");
            out.println(
                    "<tr><td colSpan=\"2\" style=\"text-align:center\"><A HRef=\"CFAstSMWarLoginHtml\">Take me to the "
                            + clusterDescription + " Security Manager Login</A></td></tr>");
            out.println("</table>");
            out.println("</center>");
            out.println("</form>");
            out.println("</BODY>");
            out.println("</HTML>");
            return;
        }

        MessageDigest msgDigest = MessageDigest.getInstance("SHA-512");
        msgDigest.update(password.getBytes("UTF-8"));
        byte[] hash = msgDigest.digest();
        byte[] encodedHash = Base64.encodeBase64(hash);
        msgDigest.update(encodedHash);
        hash = msgDigest.digest();
        encodedHash = Base64.encodeBase64(hash);
        String hashedAndEncodedPassword = new String(encodedHash);

        ICFAstClusterObj systemCluster = schemaObj.getClusterTableObj().readClusterByUDomainNameIdx("system");
        ICFAstTenantObj systemTenant = schemaObj.getTenantTableObj()
                .readTenantByUNameIdx(systemCluster.getRequiredId(), "system");
        ICFAstSecSessionObj systemSession = schemaObj.getSecSessionTableObj().newInstance();
        ICFAstSecSessionEditObj editSystemSession = (ICFAstSecSessionEditObj) systemSession.beginEdit();
        editSystemSession.setRequiredContainerSecUser(systemUser);
        editSystemSession.setRequiredStart(Calendar.getInstance());
        systemSession = editSystemSession.create();
        editSystemSession.endEdit();

        auth = new CFAstAuthorization();
        auth.setSecCluster(systemCluster);
        auth.setSecTenant(systemTenant);
        auth.setSecSession(systemSession);
        schemaObj.setAuthorization(auth);

        ICFAstSecUserEditObj editResetUser = resetUser.beginEdit();
        editResetUser.setRequiredPasswordHash(hashedAndEncodedPassword);
        editResetUser.setOptionalPasswordResetUuid(null);
        editResetUser.update();
        editResetUser.endEdit();

        editSystemSession = (ICFAstSecSessionEditObj) systemSession.beginEdit();
        editSystemSession.setOptionalFinish(Calendar.getInstance());
        editSystemSession.update();
        editSystemSession.endEdit();

        schemaObj.commit();

        schemaObj.setAuthorization(null);

        response.setContentType("text/html");
        PrintWriter out = response.getWriter();
        out.println("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01//EN\">");
        out.println("<HTML>");
        out.println("<BODY>");
        out.println("<form method=\"post\" formaction=\"CFAstSMWarConfirmEMailAddressHtml\">");
        out.println("<H1 style=\"text-align:center\">" + clusterDescription + " Security Manager</H1>");
        out.println("<H2 style=\"text-align:center\">Password Set.</H2>");
        out.println("<p>");
        out.println("<center>");
        out.println("<table style=\"width:75%\">");
        out.println(
                "<tr><td colSpan=\"2\" style=\"text-align:center\">You may now <A HRef=\"CFAstSMWarLoginHtml\">log in</A> to the "
                        + clusterDescription + " Security Manager</td></tr>");
        out.println("</table>");
        out.println("</center>");
        out.println("</form>");
        out.println("</BODY>");
        out.println("</HTML>");
    } catch (NoSuchAlgorithmException e) {
        throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), S_ProcName,
                "Caught NoSuchAlgorithmException -- " + e.getMessage(), e);
    } catch (RuntimeException e) {
        throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), S_ProcName,
                "Caught RuntimeException -- " + e.getMessage(), e);
    } finally {
        if (dbSchema != null) {
            try {
                if (schemaObj.isTransactionOpen()) {
                    schemaObj.rollback();
                }
            } catch (RuntimeException e) {
            }
            schemaObj.setBackingStore(null);
            CFAstSchemaPool.getSchemaPool().releaseInstance(dbSchema);
        }
    }
}

From source file:net.sourceforge.msscodefactory.cfasterisk.v2_2.CFAstSMWar.CFAstSMWarCancelResetPasswordHtml.java

/**
 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
 *//*from  w  w w  . j a  va 2s.co  m*/
protected void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    final String S_ProcName = "doPost";

    ICFAstSchemaObj schemaObj;
    HttpSession sess = request.getSession(false);
    if (sess == null) {
        sess = request.getSession(true);
        schemaObj = new CFAstSchemaObj();
        sess.setAttribute("SchemaObj", schemaObj);
    } else {
        schemaObj = (ICFAstSchemaObj) sess.getAttribute("SchemaObj");
        if (schemaObj == null) {
            throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0,
                    "schemaObj");
        }
    }

    ICFAstSchema dbSchema = null;
    try {
        CFAstAuthorization auth = schemaObj.getAuthorization();
        if (auth != null) {
            response.sendRedirect("CFAstSMWarSecurityMainHtml");
            return;
        }

        dbSchema = CFAstSchemaPool.getSchemaPool().getInstance();
        schemaObj.setBackingStore(dbSchema);
        schemaObj.beginTransaction();
        ICFAstSecUserObj systemUser = schemaObj.getSecUserTableObj().readSecUserByULoginIdx("system");
        String passwordHash = systemUser.getRequiredPasswordHash();
        if ((passwordHash == null) || (passwordHash.length() <= 0) || passwordHash.equals("bootstrap")) {
            response.sendRedirect("CFAstSMWarSetSystemPasswordHtml");
            return;
        }

        ICFAstSysClusterObj sysCluster = schemaObj.getSysClusterTableObj().readSysClusterByIdIdx(1, false);
        if (sysCluster == null) {
            throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0,
                    "sysCluster");
        }

        ICFAstClusterObj resolvedCluster = sysCluster.getRequiredContainerCluster();
        if (resolvedCluster == null) {
            throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName,
                    "resolvedCluster");
        }
        String clusterDomainName = resolvedCluster.getRequiredFullDomainName();
        String clusterDescription = resolvedCluster.getRequiredDescription();

        String resetUUIDStr = (String) request.getParameter("ResetUUID");
        if ((resetUUIDStr == null) || (resetUUIDStr.length() <= 0)) {
            response.setContentType("text/html");
            PrintWriter out = response.getWriter();
            out.println("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01//EN\">");
            out.println("<HTML>");
            out.println("<BODY>");
            out.println("<form method=\"post\" formaction=\"CFAstSMWarResetPasswordHtml\">");
            out.println("<H1 style=\"text-align:center\">" + clusterDescription + " Security Manager</H1>");
            out.println("<H2 style=\"text-align:center\">ERROR</H2>");
            out.println("<p>");
            out.println("<center>");
            out.println("<p>");
            out.println(
                    "The ResetUUID parameter was missing in your request.  Please use the link provided by your Password Reset email.");
            out.println("</BODY>");
            out.println("</HTML>");
            return;
        }

        UUID resetUUID = UUID.fromString(resetUUIDStr);
        if (resetUUID == null) {
            response.setContentType("text/html");
            PrintWriter out = response.getWriter();
            out.println("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01//EN\">");
            out.println("<HTML>");
            out.println("<BODY>");
            out.println("<form method=\"post\" formaction=\"CFAstSMWarResetPasswordHtml\">");
            out.println("<H1 style=\"text-align:center\">" + clusterDescription + " Security Manager</H1>");
            out.println("<H2 style=\"text-align:center\">ERROR</H2>");
            out.println("<p>");
            out.println("<center>");
            out.println("<p>");
            out.println("Invalid ResetUUID \"" + resetUUIDStr
                    + "\".  Please use the link provided by your Password Reset email.");
            out.println("</BODY>");
            out.println("</HTML>");
            return;
        }

        ICFAstSecUserObj resetUser = null;
        Iterator<ICFAstSecUserObj> secUserForUUID = schemaObj.getSecUserTableObj()
                .readSecUserByPwdResetIdx(resetUUID).iterator();
        if (secUserForUUID.hasNext()) {
            resetUser = secUserForUUID.next();
            if (secUserForUUID.hasNext()) {
                throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), S_ProcName,
                        "Multiple SecUser instances found for ResetUUID \"" + resetUUIDStr + "\"");
            }
        } else {
            response.setContentType("text/html");
            PrintWriter out = response.getWriter();
            out.println("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01//EN\">");
            out.println("<HTML>");
            out.println("<BODY>");
            out.println("<form method=\"post\" formaction=\"CFAstSMWarResetPasswordHtml\">");
            out.println("<H1 style=\"text-align:center\">" + clusterDescription + " Security Manager</H1>");
            out.println("<H2 style=\"text-align:center\">ERROR</H2>");
            out.println("<p>");
            out.println("<center>");
            out.println("<p>");
            out.println("Invalid ResetUUID \"" + resetUUIDStr
                    + "\".  Please use the link provided by your HTML Passsword Reset email.");
            out.println("</BODY>");
            out.println("</HTML>");
            return;
        }

        String password = (String) request.getParameter("Password");
        if ((password == null) || (password.length() <= 0)) {
            response.setContentType("text/html");
            PrintWriter out = response.getWriter();
            out.println("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01//EN\">");
            out.println("<HTML>");
            out.println("<BODY>");
            out.println("<form method=\"post\" formaction=\"CFAstSMWarResetPasswordHtml\">");
            out.println("<H1 style=\"text-align:center\">" + clusterDescription + " Security Manager</H1>");
            out.println("<H2 style=\"text-align:center\">ERROR</H2>");
            out.println("<p style=\"text-align:center\">");
            out.println("New Password must be specified.");
            out.println("<p>");
            out.println("<center>");
            out.println("<table style=\"width:75%\">");
            out.println(
                    "<tr><th style=\"text-align:left\">Reset UUID:</th><td><input type=\"text\" name=\"ResetUUID\" readonly=\"true\" value=\""
                            + resetUUID.toString() + "\"/></td></tr>");
            out.println(
                    "<tr><th style=\"text-align:left\">Login Id:</th><td><input type=\"text\" name=\"LoginId\" readonly=\"true\" value=\""
                            + resetUser.getRequiredEMailAddress() + "\"/></td></tr>");
            out.println(
                    "<tr><th style=\"text-align:left\">New Password:</th><td><input type=\"password\" name=\"Password\"/></td></tr>");
            out.println(
                    "<tr><th style=\"text-align:left\">Confirm New Password:</th><td><input type=\"password\" name=\"ConfirmPassword\"/></td></tr>");
            out.println(
                    "<tr><td colspan=\"2\" style=\"text-align:center\"><button type=\"submit\" name=\"Ok\"\">Ok</button></td></tr>");
            out.println(
                    "<tr><td colSpan=\"2\" style=\"text-align:center\"><A HRef=\"CFAstSMWarLoginHtml\">Take me to the "
                            + clusterDescription + " Security Manager Login</A></td></tr>");
            out.println("</table>");
            out.println("</center>");
            out.println("</form>");
            out.println("</BODY>");
            out.println("</HTML>");
            return;
        }

        String confirmPassword = (String) request.getParameter("ConfirmPassword");
        if ((confirmPassword == null) || (confirmPassword.length() <= 0)) {
            response.setContentType("text/html");
            PrintWriter out = response.getWriter();
            out.println("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01//EN\">");
            out.println("<HTML>");
            out.println("<BODY>");
            out.println("<form method=\"post\" formaction=\"CFAstSMWarResetPasswordHtml\">");
            out.println("<H1 style=\"text-align:center\">" + clusterDescription + " Security Manager</H1>");
            out.println("<H2 style=\"text-align:center\">ERROR</H2>");
            out.println("<p style=\"text-align:center\">");
            out.println("Confirm New Password must be specified.");
            out.println("<p>");
            out.println("<center>");
            out.println("<table style=\"width:75%\">");
            out.println(
                    "<tr><th style=\"text-align:left\">Reset UUID:</th><td><input type=\"text\" name=\"ResetUUID\" readonly=\"true\" value=\""
                            + resetUUID.toString() + "\"/></td></tr>");
            out.println(
                    "<tr><th style=\"text-align:left\">Login Id:</th><td><input type=\"text\" name=\"LoginId\" readonly=\"true\" value=\""
                            + resetUser.getRequiredEMailAddress() + "\"/></td></tr>");
            out.println(
                    "<tr><th style=\"text-align:left\">New Password:</th><td><input type=\"password\" name=\"Password\"/></td></tr>");
            out.println(
                    "<tr><th style=\"text-align:left\">Confirm New Password:</th><td><input type=\"password\" name=\"ConfirmPassword\"/></td></tr>");
            out.println(
                    "<tr><td colspan=\"2\" style=\"text-align:center\"><button type=\"submit\" name=\"Ok\"\">Ok</button></td></tr>");
            out.println(
                    "<tr><td colSpan=\"2\" style=\"text-align:center\"><A HRef=\"CFAstSMWarLoginHtml\">Take me to the "
                            + clusterDescription + " Security Manager Login</A></td></tr>");
            out.println("</table>");
            out.println("</center>");
            out.println("</form>");
            out.println("</BODY>");
            out.println("</HTML>");
            return;
        }

        if (!confirmPassword.equals(password)) {
            response.setContentType("text/html");
            PrintWriter out = response.getWriter();
            out.println("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01//EN\">");
            out.println("<HTML>");
            out.println("<BODY>");
            out.println("<form method=\"post\" formaction=\"CFAstSMWarResetPasswordHtml\">");
            out.println("<H1 style=\"text-align:center\">" + clusterDescription + " Security Manager</H1>");
            out.println("<H2 style=\"text-align:center\">ERROR</H2>");
            out.println("<p style=\"text-align:center\">");
            out.println("New Password and Confirm New Password do not match.");
            out.println("<p>");
            out.println("<center>");
            out.println("<table style=\"width:75%\">");
            out.println(
                    "<tr><th style=\"text-align:left\">Reset UUID:</th><td><input type=\"text\" name=\"ResetUUID\" readonly=\"true\" value=\""
                            + resetUUID.toString() + "\"/></td></tr>");
            out.println(
                    "<tr><th style=\"text-align:left\">Login Id:</th><td><input type=\"text\" name=\"LoginId\" readonly=\"true\" value=\""
                            + resetUser.getRequiredEMailAddress() + "\"/></td></tr>");
            out.println(
                    "<tr><th style=\"text-align:left\">New Password:</th><td><input type=\"password\" name=\"Password\"/></td></tr>");
            out.println(
                    "<tr><th style=\"text-align:left\">Confirm New Password:</th><td><input type=\"password\" name=\"ConfirmPassword\"/></td></tr>");
            out.println(
                    "<tr><td colspan=\"2\" style=\"text-align:center\"><button type=\"submit\" name=\"Ok\"\">Ok</button></td></tr>");
            out.println(
                    "<tr><td colSpan=\"2\" style=\"text-align:center\"><A HRef=\"CFAstSMWarLoginHtml\">Take me to the "
                            + clusterDescription + " Security Manager Login</A></td></tr>");
            out.println("</table>");
            out.println("</center>");
            out.println("</form>");
            out.println("</BODY>");
            out.println("</HTML>");
            return;
        }

        MessageDigest msgDigest = MessageDigest.getInstance("SHA-512");
        msgDigest.update(password.getBytes("UTF-8"));
        byte[] hash = msgDigest.digest();
        byte[] encodedHash = Base64.encodeBase64(hash);
        String hashedAndEncodedPassword = new String(encodedHash);

        ICFAstClusterObj systemCluster = schemaObj.getClusterTableObj().readClusterByUDomainNameIdx("system");
        ICFAstTenantObj systemTenant = schemaObj.getTenantTableObj()
                .readTenantByUNameIdx(systemCluster.getRequiredId(), "system");
        ICFAstSecSessionObj systemSession = schemaObj.getSecSessionTableObj().newInstance();
        ICFAstSecSessionEditObj editSystemSession = (ICFAstSecSessionEditObj) systemSession.beginEdit();
        editSystemSession.setRequiredContainerSecUser(systemUser);
        editSystemSession.setRequiredStart(Calendar.getInstance());
        systemSession = editSystemSession.create();
        editSystemSession.endEdit();

        auth = new CFAstAuthorization();
        auth.setSecCluster(systemCluster);
        auth.setSecTenant(systemTenant);
        auth.setSecSession(systemSession);
        schemaObj.setAuthorization(auth);

        ICFAstSecUserEditObj editResetUser = resetUser.beginEdit();
        editResetUser.setRequiredPasswordHash(hashedAndEncodedPassword);
        editResetUser.setOptionalPasswordResetUuid(null);
        editResetUser.update();
        editResetUser.endEdit();

        editSystemSession = (ICFAstSecSessionEditObj) systemSession.beginEdit();
        editSystemSession.setOptionalFinish(Calendar.getInstance());
        editSystemSession.update();
        editSystemSession.endEdit();

        schemaObj.commit();

        schemaObj.setAuthorization(null);

        response.setContentType("text/html");
        PrintWriter out = response.getWriter();
        out.println("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01//EN\">");
        out.println("<HTML>");
        out.println("<BODY>");
        out.println("<form method=\"post\" formaction=\"CFAstSMWarConfirmEMailAddressHtml\">");
        out.println("<H1 style=\"text-align:center\">" + clusterDescription + " Security Manager</H1>");
        out.println("<H2 style=\"text-align:center\">Password Set.</H2>");
        out.println("<p>");
        out.println("<center>");
        out.println("<table style=\"width:75%\">");
        out.println(
                "<tr><td colSpan=\"2\" style=\"text-align:center\">You may now <A HRef=\"CFAstSMWarLoginHtml\">log in</A> to the "
                        + clusterDescription + " Security Manager</td></tr>");
        out.println("</table>");
        out.println("</center>");
        out.println("</form>");
        out.println("</BODY>");
        out.println("</HTML>");
    } catch (NoSuchAlgorithmException e) {
        throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), S_ProcName,
                "Caught NoSuchAlgorithmException -- " + e.getMessage(), e);
    } catch (RuntimeException e) {
        throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), S_ProcName,
                "Caught RuntimeException -- " + e.getMessage(), e);
    } finally {
        if (dbSchema != null) {
            try {
                if (schemaObj.isTransactionOpen()) {
                    schemaObj.rollback();
                }
            } catch (RuntimeException e) {
            }
            schemaObj.setBackingStore(null);
            CFAstSchemaPool.getSchemaPool().releaseInstance(dbSchema);
        }
    }
}

From source file:com.microsoft.rightsmanagement.sampleapp.MsipcTaskFragment.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    mApplicationContext = getActivity().getApplicationContext();
    // Retain this fragment across configuration changes.
    setRetainInstance(true);/*from w  w  w  .  ja va2 s .c  o m*/
    updateTaskStatus(new TaskStatus(TaskState.NotStarted, null, false));
    mConsentCallback = getConsentCallback();
    try {
        mRmsAuthCallback = App.getInstance().getRmsAuthenticationCallback(getActivity());
    } catch (NoSuchAlgorithmException e) {
        e.printStackTrace();
        Logger.ie(TAG, e.getMessage());
        updateTaskStatus(new TaskStatus(TaskState.Faulted, e.getLocalizedMessage(), true));
    } catch (InvalidKeySpecException e) {
        e.printStackTrace();
        Logger.ie(TAG, e.getMessage());
        updateTaskStatus(new TaskStatus(TaskState.Faulted, e.getLocalizedMessage(), true));
    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
        Logger.ie(TAG, e.getMessage());
        updateTaskStatus(new TaskStatus(TaskState.Faulted, e.getLocalizedMessage(), true));
    }
}

From source file:de.burlov.amazon.s3.dirsync.DirSync.java

public DirSync(String accessKey, String secretKey, String bucket, String location, char[] encPassword)
        throws DirSyncException {
    super();//from  w w w  . j a  v a  2  s. c  o m
    try {
        shaDigest = MessageDigest.getInstance("SHA-1");
        md5Digest = MessageDigest.getInstance("MD5");
    } catch (NoSuchAlgorithmException e) {
        throw new DirSyncException(e.getMessage());
    }
    this.accessKey = accessKey;
    this.secretKey = secretKey;
    if (encPassword == null) {
        throw new IllegalArgumentException("encryption password is null");
    }
    this.bucket = bucket;
    this.location = location;
    if (StringUtils.equalsIgnoreCase(location, S3Bucket.LOCATION_EUROPE)) {
        this.location = S3Bucket.LOCATION_EUROPE;
    } else {
        this.location = null;
    }
    if (StringUtils.isBlank(this.bucket)) {
        this.bucket = accessKey + ".dirsync";
    }
    cipher = new SerpentEngine();
    pbeKey = generatePbeKey(encPassword);
    try {
        s3Service = new RestS3Service(new AWSCredentials(accessKey, secretKey));
    } catch (S3ServiceException e1) {
        throw new DirSyncException("Connecting to S3 service failed", e1);
    }
}

From source file:org.apache.hc.client5.http.impl.auth.NTLMEngineImpl.java

static MessageDigest getMD5() {
    try {//from   w w  w. ja v  a  2s.c  om
        return MessageDigest.getInstance("MD5");
    } catch (final NoSuchAlgorithmException ex) {
        throw new RuntimeException("MD5 message digest doesn't seem to exist - fatal error: " + ex.getMessage(),
                ex);
    }
}

From source file:org.iavante.sling.gad.hospies.impl.HospiesImpl.java

/**
 * publish the diferent files in the profile "profile" to remote repository -
 * manifest - current - playlist - video list
 * //from www.ja  v a2 s.  c o  m
 * @param manifest
 *          manifest to publish
 * @param playlist
 *          playlist file to publish
 * @param videos
 *          videos file to publish
 * @param profile
 *          profile which update
 * @return the HTML code of the operation
 */
private int publishUpdate(String manifest, List<String> playlist, String videos, String profile,
        String p_code) {

    /* upload objects */
    try {

        /*
         * upload the files of a media update, those are the manifest, the
         * playlist, the videos to download and the update manifest.
         */
        log.info("HOSPIES: start to upload");
        uploadObject(base_manifest + profile + "-" + p_code + ".xml", manifest);
        log.info("HOSPIES: manifest uploaded");
        /*
         * upload playslit. If the format is a playlist per day, has to upload
         * seven playlist, one if not
         */
        int count = 0;
        ListIterator<String> playlists = playlist.listIterator();
        while (playlists.hasNext()) {
            log.info("HOSPIES playlist: " + playlists.next());
            count++;
        }
        log.info("HOSPIES count: " + String.valueOf(count));
        if (count > 1) {
            count = 0;
            playlists = playlist.listIterator();
            while (playlists.hasNext()) {
                log.info("HOSPIES count 2 : " + String.valueOf(count));
                uploadObject(base_playlist + profile + "-" + p_code + "_" + String.valueOf(count) + ".smil",
                        playlists.next());
                log.info("HOSPIES uploading: " + base_playlist + profile + "-" + p_code + "_"
                        + String.valueOf(count) + ".smil");
                count++;
            }
        } else {
            uploadObject(base_playlist + profile + "-" + p_code + ".smil", playlist.get(0));
            log.info("HOSPIES uploading: " + base_playlist + profile + "-" + p_code + ".smil");
        }

        uploadObject(base_videos + profile + "-" + p_code + ".txt", videos);
        log.info("HOSPIES uploading videos.txt");
        uploadObject(base_current + profile, manifest);
        log.info("HOSPIES uploading manifest base.txt");
    } catch (NoSuchAlgorithmException e) {
        log.error("Error sending publish files NoSuchAlgorithmException: " + e.getMessage());
        return 500;
    } catch (IOException e) {
        log.error("Error sending publish files IOException: " + e.getMessage());
        return 500;
    } catch (S3ServiceException e) {
        log.error("Error sending publish files: " + e.getMessage());
        return 500;
    }
    return 200;
}

From source file:com.morphoss.acal.service.connector.AcalRequestor.java

private String md5(String in) {
    // Create MD5 Hash
    MessageDigest digest;//w w w  .j a v  a2 s.  c  o m
    try {
        digest = java.security.MessageDigest.getInstance("MD5");
        digest.update(in.getBytes());
        return StaticHelpers.toHexString(digest.digest());
    } catch (NoSuchAlgorithmException e) {
        Log.e(TAG, e.getMessage());
        Log.println(Constants.LOGV, TAG, Log.getStackTraceString(e));
    }
    return "";
}

From source file:org.lockss.hasher.SimpleHasher.java

/**
 * Performs the hashing of an AU or a URL based on the passed parameters and
 * it stores the result in the passed object.
 * /*from   w  w w. j av  a  2s .c  o m*/
 * @param params
 *          A HasherParams with the parameters that define the hashing
 *          operation.
 * @param result
 *          A HasherResult where to store the result of the hashing operation.
 */
public void hash(HasherParams params, HasherResult result) {
    final String DEBUG_HEADER = "hash(): ";
    if (log.isDebug2())
        log.debug2(DEBUG_HEADER + "Starting...");
    result.setStartTime(TimeBase.nowMs());
    result.setRunnerStatus(HasherStatus.Init);

    processHashTypeParam(params, result);
    if (HasherStatus.Error == result.getRunnerStatus()) {
        return;
    }

    processResultEncodingParam(params, result);
    if (HasherStatus.Error == result.getRunnerStatus()) {
        return;
    }

    processParams(params, result);
    if (HasherStatus.Error == result.getRunnerStatus()) {
        return;
    }

    try {
        try {
            digest = makeDigestAndRecordStream(params.getAlgorithm(), params.isRecordFilteredStream(), result);

            if (digest == null) {
                log.warning(DEBUG_HEADER + "No digest could be obtained");
                result.setRunnerStatus(HasherStatus.Error);
                result.setRunnerError("No digest could be obtained");
            }
        } catch (NoSuchAlgorithmException nsae) {
            log.warning(DEBUG_HEADER, nsae);
            result.setRunnerStatus(HasherStatus.Error);
            result.setRunnerError("Invalid hashing algorithm: " + nsae.getMessage());
        } catch (Exception e) {
            log.warning(DEBUG_HEADER, e);
            result.setRunnerStatus(HasherStatus.Error);
            result.setRunnerError("Error making digest: " + e.getMessage());
        }

        if (HasherStatus.Error == result.getRunnerStatus()) {
            // Clean up an empty block file, if necessary.
            if (result.getBlockFile() != null && result.getBlockFile().length() == 0) {
                FileUtil.safeDeleteFile(result.getBlockFile());
                result.setBlockFile(null);
            }

            return;
        }

        result.setRunnerStatus(HasherStatus.Running);

        try {
            switch (result.getHashType()) {
            case V1Content:
            case V1File:
                doV1(result.getCus().getContentHasher(digest), result);
                break;
            case V1Name:
                doV1(result.getCus().getNameHasher(digest), result);
                break;
            case V3Tree:
            case V3File:
                doV3(params.getMachineName(), params.isExcludeSuspectVersions(), result);
                break;
            }

            result.setBytesHashed(getBytesHashed());
            result.setFilesHashed(getFilesHashed());
            result.setElapsedTime(getElapsedTime());
            result.setRunnerStatus(HasherStatus.Done);
        } catch (Exception e) {
            log.warning("hash()", e);
            result.setRunnerStatus(HasherStatus.Error);
            result.setRunnerError("Error hashing: " + e.getMessage());
        }
    } finally {
        IOUtil.safeClose(result.getRecordStream());
    }

    if (log.isDebug2())
        log.debug2(DEBUG_HEADER + "result = " + result);
}