/*
 * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
 * or more contributor license agreements. Licensed under the Elastic License;
 * you may not use this file except in compliance with the Elastic License.
 */
package org.elasticsearch.license.plugin.core;

import org.elasticsearch.ElasticsearchException;
import org.elasticsearch.common.collect.Tuple;

public class LicenseUtils {

    public final static String EXPIRED_FEATURE_HEADER = "es.license.expired.feature";

    /**
     * Exception to be thrown when a feature action requires a valid license, but license
     * has expired
     *
     * <code>feature</code> accessible through {@link #EXPIRED_FEATURE_HEADER} in the
     * exception's rest header
     */
    public static ElasticsearchException newExpirationException(String feature) {
        // TODO: after https://github.com/elastic/elasticsearch/pull/12006 use ElasicsearchException with addHeader(EXPIRED_FEATURE_HEADER, feature)
        return new ElasticsearchException.WithRestHeadersException("license expired for feature [" + feature + "]",
                Tuple.tuple(EXPIRED_FEATURE_HEADER, new String[] {feature}));
    }
}

@@ -313,32 +313,40 @@
 ch.Elasticsearch
+Security
 Exception;%0Aimpor
@@ -369,28 +369,23 @@
 rch.
-common.collect.Tuple
+rest.RestStatus
 ;%0A%0Ap
@@ -771,32 +771,40 @@
 ic Elasticsearch
+Security
 Exception newExp
@@ -850,341 +850,219 @@
     
-// TODO: after https://github.com/elastic/elasticsearch/pull/12006 use ElasicsearchException with addHeader(EXPIRED_FEATURE_HEADER, feature)%0A        return new ElasticsearchException.WithRestHeadersException(%22license expired for feature %5B%22 + feature + %22%5D%22,%0A                Tuple.tuple(EXPIRED_FEATURE_HEADER, new String%5B%5D %7Bfeature%7D))
+ElasticsearchSecurityException e = new ElasticsearchSecurityException(%22license expired for feature %5B%7B%7D%5D%22, RestStatus.UNAUTHORIZED, feature);%0A        e.addHeader(EXPIRED_FEATURE_HEADER, feature);%0A        return e
 ;%0A  

Changed the license expiration exception to ElasticsearchSecurityException