io.micronaut.security.annotation.RolesAllowedAnnotationMapper 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 javax.annotation.security.RolesAllowed;
import java.util.ArrayList;
import java.util.List;
/**
* Allows using the {@link javax.annotation.security.RolesAllowed} annotation in Micronaut.
*
* @author Sergio del Amo
* @since 1.0
*/
@Internal
public class RolesAllowedAnnotationMapper implements TypedAnnotationMapper {
@Override
public Class annotationType() {
return RolesAllowed.class;
}
@Override
public List> map(AnnotationValue annotation, VisitorContext visitorContext) {
String[] values = annotation.get("value", String[].class).orElse(new String[0]);
List> annotationValues = new ArrayList<>(1);
annotationValues.add(
AnnotationValue.builder(Secured.class)
.values(values)
.build()
);
return annotationValues;
}
}