io.helidon.microprofile.security.FeatureConfig Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of helidon-microprofile-security Show documentation
Show all versions of helidon-microprofile-security Show documentation
Integration with Helidon Security
/*
* Copyright (c) 2018, 2023 Oracle and/or its affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.helidon.microprofile.security;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
/**
* Configuration of a Jersey security feature.
*/
public class FeatureConfig {
static final boolean DEFAULT_DEBUG = false;
static final boolean DEFAULT_ATZ_ANNOTATED_ONLY = false;
static final boolean DEFAULT_ATN_ANNOTATED_ONLY = true;
static final boolean DEFAULT_PREMATCHING_ATN = false;
static final boolean DEFAULT_PREMATCHING_ATZ = false;
static final boolean DEFAULT_USE_ABORT_WITH = true;
static final boolean DEFAULT_ATN_FAIL_ON_FAILURE_IF_OPT = false;
private final boolean debug;
private final boolean authorizeAnnotatedOnly;
private final boolean usePrematchingAtn;
private final boolean usePrematchingAtz;
private final List queryParamHandlers = new LinkedList<>();
private final boolean authenticateAnnotatedOnly;
private final boolean useAbortWith;
private final boolean failOnFailureIfOptional;
FeatureConfig() {
this.debug = DEFAULT_DEBUG;
this.authorizeAnnotatedOnly = DEFAULT_ATZ_ANNOTATED_ONLY;
this.usePrematchingAtn = DEFAULT_PREMATCHING_ATN;
this.usePrematchingAtz = DEFAULT_PREMATCHING_ATZ;
this.authenticateAnnotatedOnly = DEFAULT_ATN_ANNOTATED_ONLY;
this.useAbortWith = DEFAULT_USE_ABORT_WITH;
this.failOnFailureIfOptional = DEFAULT_ATN_FAIL_ON_FAILURE_IF_OPT;
}
FeatureConfig(JerseySecurityFeature.Builder builder) {
this.debug = builder.isDebug();
this.authorizeAnnotatedOnly = builder.isAuthorizeAnnotatedOnly();
this.authenticateAnnotatedOnly = builder.isAuthenticateAnnotatedOnly();
this.usePrematchingAtz = builder.isPrematchingAuthorization();
if (this.usePrematchingAtz) {
this.usePrematchingAtn = true;
} else {
this.usePrematchingAtn = builder.isPrematchingAuthentication();
}
this.queryParamHandlers.addAll(builder.queryParamHandlers());
this.useAbortWith = builder.useAbortWith();
this.failOnFailureIfOptional = builder.failOnFailureIfOptional();
}
boolean shouldAuthorizeAnnotatedOnly() {
return authorizeAnnotatedOnly;
}
boolean failOnFailureIfOptional() {
return failOnFailureIfOptional;
}
boolean shouldAuthenticateAnnotatedOnly() {
return authenticateAnnotatedOnly;
}
List getQueryParamHandlers() {
return Collections.unmodifiableList(queryParamHandlers);
}
boolean isDebug() {
return debug;
}
boolean shouldUsePrematchingAuthentication() {
return usePrematchingAtn;
}
boolean shouldUsePrematchingAuthorization() {
return usePrematchingAtz;
}
boolean useAbortWith() {
return useAbortWith;
}
@Override
public String toString() {
return "FeatureConfig(" + authorizeAnnotatedOnly + ", " + queryParamHandlers.size() + ", debug:" + debug + ")";
}
}