001/*
002 * acme4j - Java ACME client
003 *
004 * Copyright (C) 2015 Richard "Shred" Körber
005 *   http://acme4j.shredzone.org
006 *
007 * Licensed under the Apache License, Version 2.0 (the "License");
008 * you may not use this file except in compliance with the License.
009 *
010 * This program is distributed in the hope that it will be useful,
011 * but WITHOUT ANY WARRANTY; without even the implied warranty of
012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
013 */
014package org.shredzone.acme4j;
015
016import java.util.Arrays;
017
018/**
019 * Status codes of challenges and authorizations.
020 */
021public enum Status {
022
023    /**
024     * The server has created the resource, and is waiting for the client to process it.
025     */
026    PENDING,
027
028    /**
029     * The {@link Order} is ready to be finalized. Invoke {@link Order#execute(byte[])}.
030     */
031    READY,
032
033    /**
034     * The server is processing the resource. The client should invoke
035     * {@link AcmeJsonResource#update()} and re-check the status.
036     */
037    PROCESSING,
038
039    /**
040     * The resource is valid and can be used as intended.
041     */
042    VALID,
043
044    /**
045     * An error or authorization/validation failure has occured. The client should check
046     * for error messages.
047     */
048    INVALID,
049
050    /**
051     * The {@link Authorization} has been revoked by the server.
052     */
053    REVOKED,
054
055    /**
056     * The {@link Account} or {@link Authorization} has been deactivated by the client.
057     */
058    DEACTIVATED,
059
060    /**
061     * The {@link Authorization} is expired.
062     */
063    EXPIRED,
064
065    /**
066     * An auto-renewing {@link Order} is canceled.
067     *
068     * @since 2.3
069     */
070    CANCELED,
071
072    /**
073     * The server did not provide a status, or the provided status is not a specified ACME
074     * status.
075     */
076    UNKNOWN;
077
078    /**
079     * Parses the string and returns a corresponding Status object.
080     *
081     * @param str
082     *            String to parse
083     * @return {@link Status} matching the string, or {@link Status#UNKNOWN} if there was
084     *         no match
085     */
086    public static Status parse(String str) {
087        String check = str.toUpperCase();
088        return Arrays.stream(values())
089                .filter(s -> s.name().equals(check))
090                .findFirst()
091                .orElse(Status.UNKNOWN);
092    }
093
094}