All Downloads are FREE. Search and download functionalities are using the official Maven repository.

uk.gov.ida.saml.hub.domain.IdpIdaStatus Maven / Gradle / Ivy

There is a newer version: 3.4.6-15872
Show newest version
package uk.gov.ida.saml.hub.domain;

import uk.gov.ida.saml.core.domain.IdaStatus;

import java.util.Optional;

import static java.util.Optional.empty;

public final class IdpIdaStatus implements IdaStatus {

    public enum Status {
        Success,
        NoAuthenticationContext,
        RequesterError,
        AuthenticationFailed,
        AuthenticationCancelled,
        AuthenticationPending,
        UpliftFailed
    }
    public static IdpIdaStatus success() { return new IdpIdaStatus(Status.Success);}

    public static IdpIdaStatus authenticationFailed() { return new IdpIdaStatus(Status.AuthenticationFailed);}
    public static IdpIdaStatus noAuthenticationContext() { return new IdpIdaStatus(Status.NoAuthenticationContext);}
    public static IdpIdaStatus requesterError() { return new IdpIdaStatus(Status.RequesterError);}
    public static IdpIdaStatus requesterError(Optional errorMessage) { return new IdpIdaStatus(Status.RequesterError, errorMessage);}
    public static IdpIdaStatus authenticationCancelled() {
        return new IdpIdaStatus(Status.AuthenticationCancelled);
    }
    public static IdpIdaStatus authenticationPending() { return new IdpIdaStatus(Status.AuthenticationPending); }
    public static IdpIdaStatus upliftFailed() { return new IdpIdaStatus(Status.UpliftFailed); }

    private Status status;
    private Optional message = empty();

    private IdpIdaStatus() {
    }

    private IdpIdaStatus(Status status) {
        this(status, Optional.empty());
    }

    private IdpIdaStatus(Status status, Optional message) {
        this.status = status;
        this.message = message;
    }

    public Status getStatusCode() {
        return status;
    }

    public Optional getMessage() {
        return message;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        IdpIdaStatus idpIdaStatus = (IdpIdaStatus) o;

        return status == idpIdaStatus.status;
    }

    @Override
    public int hashCode() {
        int result = status.hashCode();
        result = 31 * result;
        return result;
    }

    @Override
    public String toString() {
        return "IdaStatus{" +
            "status=" + status +
            ", message=" + message +
            '}';
    }

    public static class IdpIdaStatusFactory implements AuthenticationStatusFactory {
        public IdpIdaStatus create(
                final IdpIdaStatus.Status statusCode,
                final String message) {

            if (!statusCode.equals(Status.RequesterError)) {
                return new IdpIdaStatus(statusCode);
            }

            return new IdpIdaStatus(statusCode, Optional.ofNullable(message));
        }
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy