io.micronaut.security.annotation.PermitAllAnnotationMapper Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of micronaut-security Show documentation
Show all versions of micronaut-security Show documentation
Official Security Solution for Micronaut
/*
* Copyright 2017-2019 original authors
*
* 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.micronaut.security.annotation;
import io.micronaut.core.annotation.AnnotationValue;
import io.micronaut.core.annotation.Internal;
import io.micronaut.inject.annotation.TypedAnnotationMapper;
import io.micronaut.inject.visitor.VisitorContext;
import io.micronaut.security.rules.SecurityRule;
import javax.annotation.security.PermitAll;
import java.util.ArrayList;
import java.util.List;
/**
* Allows using the {@link javax.annotation.security.PermitAll} annotation in Micronaut.
*
* @author Sergio del Amo
* @since 1.0
*/
// tag::clazz[]
@Internal
public class PermitAllAnnotationMapper implements TypedAnnotationMapper { // <1>
@Override
public Class annotationType() {
return PermitAll.class;
}
@Override
public List> map(AnnotationValue annotation, VisitorContext visitorContext) { // <2>
List> annotationValues = new ArrayList<>(1);
annotationValues.add(
AnnotationValue.builder(Secured.class) // <3>
.value(SecurityRule.IS_ANONYMOUS) // <4>
.build()
);
return annotationValues;
}
}
// end::clazz[]