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

io.helidon.security.annotations.Authenticated Maven / Gradle / Ivy

There is a newer version: 4.1.4
Show newest version
/*
 * Copyright (c) 2018, 2021 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.security.annotations;

import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Inherited;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

import io.helidon.security.spi.AuthenticationProvider;

/**
 * An annotation used to specify server resources with enforced authentication and resources accessible without authentication.
 * 

* The following sample shows examples of use of {@link Authenticated} annotation in a JAX-RS/Jersey application: * *

 *  @Authenticated
 *  @ApplicationPath("myApp")
 *  public class SecuredApplication extends jakarta.ws.rs.core.Application { ... }
 *
 *  @Authenticated(false)
 *  @Path("/")
 *  public class PublicResource {
 *    @GET
 *    public String getResourceContent() { ... }
 *
 *    // Only authenticated users can update the content of the public resource
 *    @Authenticated
 *    @PUT
 *    public Response setNewResourceContent(String content) { ... }
 *  }
 * 
*

* Authenticated annotation is not cumulative - e.g. if you define this annotation on a resource method, it will take * ALL values from this instance of Authenticated (so if you want to use a custom authentication provider, you must define it * again in each Authenticated instance). */ @Retention(RetentionPolicy.RUNTIME) @Target({ElementType.METHOD, ElementType.TYPE, ElementType.FIELD}) @Documented @Inherited public @interface Authenticated { /** * Determine whether authentication should be enabled. Defaults to {@code true} * * @return {@code true} if authentication should be enabled. */ boolean value() default true; /** * If set to optional, authentication will be attempted, yet if it fails, we would still be called * without authenticated user/service. * For fine-grained control use configuration of provider flags (e.g. if a service is optional and user is mandatory) * * @return true if authentication should be optional */ boolean optional() default false; /** * Explicit authentication provider to use when processing this Authorized. * Setting this value will ignore security provider configured globally. * Value is the name of a configured {@link AuthenticationProvider}. * * @return name of a configured provider */ String provider() default ""; }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy