Example usage for java.util Calendar before

List of usage examples for java.util Calendar before

Introduction

In this page you can find the example usage for java.util Calendar before.

Prototype

public boolean before(Object when) 

Source Link

Document

Returns whether this Calendar represents a time before the time represented by the specified Object.

Usage

From source file:com.aimluck.eip.schedule.util.ScheduleUtils.java

/**
 * ????//  w  ww  . ja  v  a 2 s. com
 *
 * @param start_date
 * @param end_date
 * @param repeat_type
 * @param is_repeat
 * @param is_span
 * @param week_0
 * @param week_1
 * @param week_2
 * @param week_3
 * @param week_4
 * @param week_5
 * @param week_6
 * @param repeat_week
 * @param limit_flag
 * @param limit_start_date
 * @param limit_end_date
 * @param month_day
 * @param login_user
 * @param entityid
 * @param msgList
 *          
 * @param isCellPhone
 *          ?????
 * @return
 * @throws ALDBErrorException
 * @throws ALPageNotFoundException
 */
public static boolean validateDelegate(ALDateTimeField start_date, ALDateTimeField end_date,
        ALStringField repeat_type, boolean is_repeat, boolean is_span, ALStringField week_0,
        ALStringField week_1, ALStringField week_2, ALStringField week_3, ALStringField week_4,
        ALStringField week_5, ALStringField week_6, ALStringField repeat_week, ALStringField limit_flag,
        ALDateField limit_start_date, ALDateField limit_end_date, ALNumberField month_day,
        ALNumberField year_month, ALNumberField year_day, ALEipUser login_user, String entityid,
        List<String> msgList, boolean isCellPhone) throws ALDBErrorException, ALPageNotFoundException {

    int YEAR_FIRST = 2004;
    int YEAR_END = 2016;
    boolean dayexist = true;

    switch ((int) year_month.getValue()) {
    case 2:
        if (year_day.getValue() == 30 || year_day.getValue() == 31) {
            dayexist = false;
        }
        break;

    case 4:
    case 6:
    case 9:
    case 11:
        if (year_day.getValue() == 31) {
            dayexist = false;
        }
        break;

    default:
        break;
    }

    if (end_date == null) {
        msgList.add(ALLocalizationUtils.getl10n("SCHEDULE_MESSAGE_TYPE_RIGHT_END_DATE"));
        end_date = start_date;
    }

    Calendar startDate = Calendar.getInstance();
    startDate.setTime(start_date.getValue());
    Calendar endDate = Calendar.getInstance();
    endDate.setTime(end_date.getValue());

    if (is_repeat) {
        //  ?  ?? ????
        Calendar tmp_end_date = Calendar.getInstance();
        tmp_end_date.set(Calendar.YEAR, Integer.valueOf(start_date.getYear()));
        tmp_end_date.set(Calendar.MONTH, Integer.valueOf(start_date.getMonth()) - 1);
        tmp_end_date.set(Calendar.DATE, Integer.valueOf(start_date.getDay()));
        tmp_end_date.set(Calendar.HOUR_OF_DAY, Integer.valueOf(end_date.getHour()));
        tmp_end_date.set(Calendar.MINUTE, Integer.valueOf(end_date.getMinute()));
        tmp_end_date.set(Calendar.SECOND, 0);
        end_date.setValue(tmp_end_date.getTime());
    }

    if (is_span) {
        //  ?  ? 000 ??
        Calendar tmp_start_date = Calendar.getInstance();
        tmp_start_date.setTime(start_date.getValue());
        tmp_start_date.set(Calendar.HOUR_OF_DAY, 0);
        tmp_start_date.set(Calendar.MINUTE, 0);
        tmp_start_date.set(Calendar.SECOND, 0);
        start_date.setValue(tmp_start_date.getTime());

        Calendar tmp_end_date = Calendar.getInstance();
        tmp_end_date.setTime(end_date.getValue());
        tmp_end_date.set(Calendar.HOUR_OF_DAY, 0);
        tmp_end_date.set(Calendar.MINUTE, 0);
        tmp_end_date.set(Calendar.SECOND, 0);
        end_date.setValue(tmp_end_date.getTime());
    }

    // 
    start_date.validate(msgList);
    int startyear = startDate.get(Calendar.YEAR);
    if ((startyear < YEAR_FIRST || startyear > YEAR_END) && isCellPhone) {
        // ???
        msgList.add(ALLocalizationUtils.getl10nFormat("SCHEDULE_MESSAGE_SELECT_RIGHT_START_DATE", YEAR_FIRST,
                YEAR_END));
    }
    if (startDate.get(Calendar.MINUTE) % 15.0 != 0 && isCellPhone) {
        // ???
        msgList.add(ALLocalizationUtils.getl10n("SCHEDULE_MESSAGE_SELECT_START_TIME_PER15"));
    }

    // 
    end_date.validate(msgList);
    int endyear = endDate.get(Calendar.YEAR);
    if ((endyear < YEAR_FIRST || endyear > YEAR_END) && isCellPhone) {
        // ???
        msgList.add(ALLocalizationUtils.getl10nFormat("SCHEDULE_MESSAGE_SELECT_RIGHT_START_END_DATE",
                YEAR_FIRST, YEAR_END));
    }
    if (endDate.get(Calendar.MINUTE) % 15.0 != 0 && isCellPhone) {
        // ???
        msgList.add(ALLocalizationUtils.getl10n("SCHEDULE_MESSAGE_SELECT_END_TIME_PER15"));
    }

    // 
    if (end_date.getValue().before(start_date.getValue())) {
        msgList.add(ALLocalizationUtils.getl10n("SCHEDULE_MESSAGE_SELECT_END_DATE_TO_START_DATE"));
    }

    if (is_repeat) {
        try {
            if ("W".equals(repeat_type.getValue())) {
                // ,??
                if (week_0.getValue() == null && week_1.getValue() == null && week_2.getValue() == null
                        && week_3.getValue() == null && week_4.getValue() == null && week_5.getValue() == null
                        && week_6.getValue() == null) {
                    switch (repeat_week.getValue()) {
                    case "0":
                        msgList.add(ALLocalizationUtils.getl10n("SCHEDULE_MESSAGE_SELECT_EVERY_WEEKLY"));
                        break;
                    case "1":
                        msgList.add(ALLocalizationUtils.getl10n("SCHEDULE_MESSAGE_SELECT_1ST_WEEKLY"));
                        break;
                    case "2":
                        msgList.add(ALLocalizationUtils.getl10n("SCHEDULE_MESSAGE_SELECT_2ND_WEEKLY"));
                        break;
                    case "3":
                        msgList.add(ALLocalizationUtils.getl10n("SCHEDULE_MESSAGE_SELECT_3RD_WEEKLY"));
                        break;
                    case "4":
                        msgList.add(ALLocalizationUtils.getl10n("SCHEDULE_MESSAGE_SELECT_4TH_WEEKLY"));
                        break;
                    case "5":
                        msgList.add(ALLocalizationUtils.getl10n("SCHEDULE_MESSAGE_SELECT_5TH_WEEKLY"));
                        break;
                    default:
                        break;
                    }
                }
            } else if ("M".equals(repeat_type.getValue())) {
                // ??
                if (month_day.getValue() == 0 && isCellPhone) {
                    // ???
                    msgList.add(ALLocalizationUtils.getl10n("SCHEDULE_MESSAGE_SELECT_EVERY_MONTHLY"));
                } else {
                    month_day.validate(msgList);
                }
            } else if ("Y".equals(repeat_type.getValue())) {
                // ??
                if (year_month.getValue() == 0 && isCellPhone) {
                    // ????
                    msgList.add(ALLocalizationUtils.getl10n("SCHEDULE_MESSAGE_SELECT_EVERY_YEARLY_MONTH"));
                } else if (year_day.getValue() == 0 && isCellPhone) {
                    // ????
                    msgList.add(ALLocalizationUtils.getl10n("SCHEDULE_MESSAGE_SELECT_EVERY_YEARLY_DAY"));
                } else if (!dayexist) {
                    msgList.add(ALLocalizationUtils.getl10n("SCHEDULE_MESSAGE_SELECT_EVERY_YEARLY_DAY_EXIST"));
                } else {
                    year_month.validate(msgList);
                    year_day.validate(msgList);
                }
            }

            if ("ON".equals(limit_flag.getValue())) {
                if (!ScheduleUtils.equalsToDate(limit_start_date.getValue().getDate(),
                        limit_end_date.getValue().getDate(), false)
                        && limit_start_date.getValue().getDate().after(limit_end_date.getValue().getDate())) {
                    msgList.add(
                            ALLocalizationUtils.getl10n("SCHEDULE_MESSAGE_SELECT_REPEAT_END_DAY_TO_START_DAY"));
                }

                if (isCellPhone) {
                    // ???
                    Calendar limitStartDate = Calendar.getInstance();
                    limitStartDate.setTime(limit_start_date.getValue().getDate());
                    int limitstartyear = limitStartDate.get(Calendar.YEAR);
                    if ((limitstartyear < YEAR_FIRST || limitstartyear > YEAR_END)) {
                        msgList.add(ALLocalizationUtils.getl10nFormat(
                                "SCHEDULE_MESSAGE_SELECT_START_DATE_IN_THIS_TERM", YEAR_FIRST, YEAR_END));
                    }
                    Calendar limitEndDate = Calendar.getInstance();
                    limitEndDate.setTime(limit_end_date.getValue().getDate());
                    int limitendyear = limitEndDate.get(Calendar.YEAR);
                    if ((limitendyear < YEAR_FIRST || limitendyear > YEAR_END)) {
                        msgList.add(ALLocalizationUtils.getl10nFormat(
                                "SCHEDULE_MESSAGE_SELECT_END_DATE_IN_THIS_TERM", YEAR_FIRST, YEAR_END));
                    }
                }

                // ???
                // ?
                char lim = 'N';
                Calendar cal = Calendar.getInstance();
                cal.setTime(end_date.getValue());
                if ("ON".equals(limit_flag.getValue())) {
                    lim = 'L';
                }
                String repeat_pattern;
                int date_count = 0;
                if ("D".equals(repeat_type.getValue())) {
                    repeat_pattern = new StringBuffer().append('D').append(lim).toString();
                } else if ("W".equals(repeat_type.getValue())) {
                    if ("0".equals(repeat_week.getValue())) {
                        repeat_pattern = new StringBuffer().append('W')
                                .append(week_0.getValue() != null ? 1 : 0)
                                .append(week_1.getValue() != null ? 1 : 0)
                                .append(week_2.getValue() != null ? 1 : 0)
                                .append(week_3.getValue() != null ? 1 : 0)
                                .append(week_4.getValue() != null ? 1 : 0)
                                .append(week_5.getValue() != null ? 1 : 0)
                                .append(week_6.getValue() != null ? 1 : 0).append(lim).toString();
                        date_count = (week_0.getValue() != null ? 1 : 0) + (week_1.getValue() != null ? 1 : 0)
                                + (week_2.getValue() != null ? 1 : 0) + (week_3.getValue() != null ? 1 : 0)
                                + (week_4.getValue() != null ? 1 : 0) + (week_5.getValue() != null ? 1 : 0)
                                + (week_6.getValue() != null ? 1 : 0);
                    } else {
                        repeat_pattern = new StringBuffer().append('W')
                                .append(week_0.getValue() != null ? 1 : 0)
                                .append(week_1.getValue() != null ? 1 : 0)
                                .append(week_2.getValue() != null ? 1 : 0)
                                .append(week_3.getValue() != null ? 1 : 0)
                                .append(week_4.getValue() != null ? 1 : 0)
                                .append(week_5.getValue() != null ? 1 : 0)
                                .append(week_6.getValue() != null ? 1 : 0)
                                .append(repeat_week.getValue().charAt(0)).append(lim).toString();
                        date_count = (week_0.getValue() != null ? 1 : 0) + (week_1.getValue() != null ? 1 : 0)
                                + (week_2.getValue() != null ? 1 : 0) + (week_3.getValue() != null ? 1 : 0)
                                + (week_4.getValue() != null ? 1 : 0) + (week_5.getValue() != null ? 1 : 0)
                                + (week_6.getValue() != null ? 1 : 0);
                    }
                } else if ("M".equals(repeat_type.getValue())) {
                    DecimalFormat format = new DecimalFormat("00");
                    if (32 == month_day.getValue()) {
                        repeat_pattern = new StringBuffer().append('M').append("XX").append(lim).toString();
                    } else {
                        repeat_pattern = new StringBuffer().append('M')
                                .append(format.format(month_day.getValue())).append(lim).toString();
                    }
                    date_count = 1;
                } else {
                    DecimalFormat format = new DecimalFormat("00");
                    repeat_pattern = new StringBuffer().append('Y').append(format.format(year_month.getValue()))
                            .append(format.format(year_day.getValue())).append(lim).toString();
                    date_count = 1;
                }
                // (?)
                Calendar sDate = new GregorianCalendar();
                sDate.set(Calendar.YEAR, Integer.valueOf(limit_start_date.getYear()));
                sDate.set(Calendar.MONTH, Integer.valueOf(limit_start_date.getMonth()) - 1);
                sDate.set(Calendar.DATE, Integer.valueOf(limit_start_date.getDay()));
                sDate.set(Calendar.HOUR_OF_DAY, 0);
                sDate.set(Calendar.MINUTE, 0);
                sDate.set(Calendar.SECOND, 0);
                // ??
                Calendar finalDate = new GregorianCalendar();
                finalDate.set(Calendar.YEAR, Integer.valueOf(limit_end_date.getYear()));
                finalDate.set(Calendar.MONTH, Integer.valueOf(limit_end_date.getMonth()) - 1);
                finalDate.set(Calendar.DATE, Integer.valueOf(limit_end_date.getDay()));
                finalDate.set(Calendar.HOUR_OF_DAY, 23);
                finalDate.set(Calendar.MINUTE, 59);
                finalDate.set(Calendar.SECOND, 59);
                int countAvailableDate = 0;
                while (sDate.before(finalDate) || sDate.equals(finalDate)) {
                    if (ScheduleUtils.matchDay(sDate, repeat_pattern)) {
                        countAvailableDate++;
                        if (countAvailableDate >= date_count) {
                            break;
                        }
                    }
                    sDate.add(Calendar.DATE, 1);
                }
                if (countAvailableDate < date_count) {
                    msgList.add(
                            ALLocalizationUtils.getl10n("SCHEDULE_MESSAGE_SELECT_REPEAT_SPAN_IN_THIS_TERM"));
                }
            }

        } catch (NumberFormatException nfe) {
            logger.error("[ScheduleFormData] NumberFormatException: Limit Date is wrong.");
            throw new ALPageNotFoundException();
        } catch (ALIllegalDateException ad) {
            logger.error("[ScheduleFormData] ALIllegalDateException: Limit Date is wrong.");
            throw new ALPageNotFoundException();
        }
    }

    return (msgList.size() == 0);
}

From source file:br.gov.jfrj.siga.ex.bl.ExBL.java

@SuppressWarnings("unchecked")
public String finalizar(final DpPessoa cadastrante, final DpLotacao lotaCadastrante, ExDocumento doc,
        String realPath) throws Exception {

    if (doc.isFinalizado())
        throw new AplicacaoException("Documento j est finalizado.");

    if (!doc.getExClassificacao().isAtivo())
        throw new AplicacaoException("Classificao documental encerrada. Selecione outra na tela de edio.");

    if (doc.getExModelo() != null && doc.getExModelo().isFechado()) {
        throw new AplicacaoException("Este modelo no est mais em uso. Selecione outro na tela de edio");
    }/*from   ww  w .j  a v  a  2s .co  m*/

    if (doc.getExModelo() != null && !doc.getExModelo().isAtivo()) {
        throw new AplicacaoException("Este modelo foi alterado. Edite-o para atualiz-lo");
    }

    if (!doc.isEletronico() && doc.isProcesso() && doc.getExMobilPai() != null
            && doc.getExMobilPai().getExDocumento().isProcesso()
            && doc.getExMobilPai().getExDocumento().isEletronico())
        throw new AplicacaoException("No  possvel criar Subprocesso fsico de processo eletrnico.");

    if (!getComp().podeSerSubscritor(doc))
        throw new AplicacaoException("O usurio no pode ser subscritor do documento");

    if (doc.isProcesso() && doc.getMobilGeral().temAnexos())
        throw new AplicacaoException(
                "Processos no podem possuir anexos antes da finalizao. Exclua todos os anexos para poder finalizar. Os anexos podero ser includos no primeiro volume aps a finalizao.");

    Set<ExVia> setVias = doc.getSetVias();

    try {
        iniciarAlteracao();

        Date dt = dao().dt();
        Calendar c = Calendar.getInstance();
        c.setTime(dt);

        if (doc.getDtDoc() != null) {
            Calendar dtDocCalendar = Calendar.getInstance();
            dtDocCalendar.setTime(doc.getDtDoc());

            if (c.before(dtDocCalendar))
                throw new Exception("No  permitido criar documento com data futura");
        }

        // Pega a data sem horas, minutos e segundos...
        if (doc.getDtDoc() == null) {
            c.set(c.get(Calendar.YEAR), c.get(Calendar.MONTH), c.get(Calendar.DAY_OF_MONTH));
            doc.setDtDoc(c.getTime());
        }

        if (doc.getOrgaoUsuario() == null)
            doc.setOrgaoUsuario(doc.getLotaCadastrante().getOrgaoUsuario());

        if (doc.getNumExpediente() == null)
            doc.setNumExpediente(obterProximoNumero(doc));

        doc.setDtFinalizacao(dt);

        if (doc.getExMobilPai() != null) {
            if (doc.getExMobilPai().doc().isProcesso() && doc.isProcesso()) {
                if (getComp().podeCriarSubprocesso(cadastrante, doc.getLotaCadastrante(),
                        doc.getExMobilPai())) {
                    int n = dao().obterProximoNumeroSubdocumento(doc.getExMobilPai());
                    doc.setNumSequencia(n);
                } else {
                    throw new AplicacaoException("Documento filho no pode ser criado nessas condies.");
                }
            }
        }

        processar(doc, false, false, realPath);

        doc.setNumPaginas(doc.getContarNumeroDePaginas());
        dao().gravar(doc);

        if (doc.getExFormaDocumento().getExTipoFormaDoc().isExpediente()) {
            for (final ExVia via : setVias) {
                Integer numVia = null;
                if (via.getCodVia() != null)
                    numVia = Integer.parseInt(via.getCodVia());
                if (numVia == null) {
                    numVia = 1;
                }
                criarVia(cadastrante, lotaCadastrante, doc, numVia);
            }
        } else {
            criarVolume(cadastrante, lotaCadastrante, doc);
        }
        concluirAlteracao(doc);

        if (setVias == null || setVias.size() == 0)
            criarVia(cadastrante, lotaCadastrante, doc, null);

        String s = processarComandosEmTag(doc, "finalizacao");

        alimentaFilaIndexacao(doc, true);

        return s;
    } catch (final Exception e) {
        cancelarAlteracao();
        throw new AplicacaoException("Erro ao finalizar o documento: " + e.getMessage(), 0, e);
    }
}

From source file:org.simbasecurity.core.saml.SAMLResponseHandlerImpl.java

@Override
public boolean isValid(String... requestId) {
    try {/*from w  w  w .j a va2s  .c om*/
        Calendar now = Calendar.getInstance(TimeZone.getTimeZone("UTC"));

        if (this.document == null) {
            throw new Exception("SAML Response is not loaded");
        }

        if (this.currentUrl == null || this.currentUrl.isEmpty()) {
            throw new Exception("The URL of the current host was not established");
        }

        // Check SAML version
        if (!rootElement.getAttribute("Version").equals("2.0")) {
            throw new Exception("Unsupported SAML Version.");
        }

        // Check ID in the response
        if (!rootElement.hasAttribute("ID")) {
            throw new Exception("Missing ID attribute on SAML Response.");
        }

        checkStatus();

        if (!this.validateNumAssertions()) {
            throw new Exception("SAML Response must contain 1 Assertion.");
        }

        NodeList signNodes = document.getElementsByTagNameNS(XMLSignature.XMLNS, "Signature");
        ArrayList<String> signedElements = new ArrayList<>();
        for (int i = 0; i < signNodes.getLength(); i++) {
            signedElements.add(signNodes.item(i).getParentNode().getLocalName());
        }
        if (!signedElements.isEmpty()) {
            if (!this.validateSignedElements(signedElements)) {
                throw new Exception("Found an unexpected Signature Element. SAML Response rejected");
            }
        }

        Document res = Utils.validateXML(this.document, "saml-schema-protocol-2.0.xsd");

        if (res == null) {
            throw new Exception("Invalid SAML Response. Not match the saml-schema-protocol-2.0.xsd");
        }

        if (rootElement.hasAttribute("InResponseTo")) {
            String responseInResponseTo = document.getDocumentElement().getAttribute("InResponseTo");
            if (requestId.length > 0 && responseInResponseTo.compareTo(requestId[0]) != 0) {
                throw new Exception("The InResponseTo of the Response: " + responseInResponseTo
                        + ", does not match the ID of the AuthNRequest sent by the SP: " + requestId[0]);
            }
        }

        // Validate Assertion timestamps
        if (!this.validateTimestamps()) {
            throw new Exception("Timing issues (please check your clock settings)");
        }

        // EncryptedAttributes are not supported
        NodeList encryptedAttributeNodes = this
                .queryAssertion("/saml:AttributeStatement/saml:EncryptedAttribute");
        if (encryptedAttributeNodes.getLength() > 0) {
            throw new Exception("There is an EncryptedAttribute in the Response and this SP not support them");
        }

        // Check destination
        //          TODO: lenneh: bktis: currentUrl is http:// and the destination is https://
        //            if (rootElement.hasAttribute("Destination")) {
        //                String destinationUrl = rootElement.getAttribute("Destination");
        //                if (destinationUrl != null) {
        //                    if (!destinationUrl.equals(currentUrl)) {
        //                        throw new Exception("The response was received at " + currentUrl + " instead of " + destinationUrl);
        //                    }
        //                }
        //            }

        // Check Audience
        //          TODO: lenneh: bktis: currentUrl is http:// and audienceUrl is https://
        //            Set<String> validAudiences = this.getAudiences();
        //
        //            if (validAudiences.isEmpty() || !this.audienceUrl.equals(currentUrl)) {
        //                throw new Exception(this.audienceUrl + " is not a valid audience for this Response");
        //            }

        // Check the issuers
        Set<String> issuers = this.getIssuers();
        for (String issuer : issuers) {
            if (issuer.isEmpty()) {
                throw new Exception("Invalid issuer in the Assertion/Response");
            }
        }

        // Check the session Expiration
        Calendar sessionExpiration = this.getSessionNotOnOrAfter();
        if (sessionExpiration != null) {
            if (now.equals(sessionExpiration) || now.after(sessionExpiration)) {
                throw new Exception(
                        "The attributes have expired, based on the SessionNotOnOrAfter of the AttributeStatement of this Response");
            }
        }

        // Check SubjectConfirmation, at least one SubjectConfirmation must be valid
        boolean validSubjectConfirmation = true;
        NodeList subjectConfirmationNodes = this.queryAssertion("/saml:Subject/saml:SubjectConfirmation");
        for (int i = 0; i < subjectConfirmationNodes.getLength(); i++) {
            Node scn = subjectConfirmationNodes.item(i);

            Node method = scn.getAttributes().getNamedItem("Method");
            if (method != null && !method.getNodeValue().equals(SAMLConstants.CM_BEARER)) {
                continue;
            }

            NodeList subjectConfirmationDataNodes = scn.getChildNodes();
            for (int c = 0; c < subjectConfirmationDataNodes.getLength(); c++) {

                Node subjectConfirmationData = subjectConfirmationDataNodes.item(c);
                if (subjectConfirmationData.getNodeType() == Node.ELEMENT_NODE
                        && subjectConfirmationData.getLocalName().equals("SubjectConfirmationData")) {

                    //                      TODO: lenneh: bktis: currentUrl is http:// and the recipient is https://
                    //                        Node recipient = subjectConfirmationData.getAttributes().getNamedItem("Recipient");
                    //                        if (recipient != null && !recipient.getNodeValue().equals(currentUrl)) {
                    //                            validSubjectConfirmation = false;
                    //                        }

                    Node notOnOrAfter = subjectConfirmationData.getAttributes().getNamedItem("NotOnOrAfter");
                    if (notOnOrAfter != null) {
                        Calendar noa = javax.xml.bind.DatatypeConverter
                                .parseDateTime(notOnOrAfter.getNodeValue());
                        if (now.equals(noa) || now.after(noa)) {
                            validSubjectConfirmation = false;
                        }
                    }

                    Node notBefore = subjectConfirmationData.getAttributes().getNamedItem("NotBefore");
                    if (notBefore != null) {
                        Calendar nb = javax.xml.bind.DatatypeConverter.parseDateTime(notBefore.getNodeValue());
                        if (now.before(nb)) {
                            validSubjectConfirmation = false;
                        }
                    }
                }
            }
        }
        if (!validSubjectConfirmation) {
            throw new Exception("A valid SubjectConfirmation was not found on this Response");
        }

        if (signedElements.isEmpty()) {
            throw new Exception("No Signature found. SAML Response rejected");
        } else {
            if (!Utils.validateSign(signNodes.item(0), certificate)) {
                throw new Exception("Signature validation failed. SAML Response rejected");
            }
        }
        return true;
    } catch (Error e) {
        error.append(e.getMessage());
        return false;
    } catch (Exception e) {
        e.printStackTrace();
        error.append(e.getMessage());
        return false;
    }
}