use of org.apache.nifi.annotation.behavior.Restricted in project nifi by apache.
the class RestrictedComponentsAuthorizableFactory method getRestrictedComponentsAuthorizable.
public static Set<Authorizable> getRestrictedComponentsAuthorizable(final Class<?> configurableComponentClass) {
final Set<Authorizable> authorizables = new HashSet<>();
final Restricted restricted = configurableComponentClass.getAnnotation(Restricted.class);
if (restricted != null) {
final Restriction[] restrictions = restricted.restrictions();
if (restrictions != null && restrictions.length > 0) {
Arrays.stream(restrictions).forEach(restriction -> authorizables.add(getRestrictedComponentsAuthorizable(restriction.requiredPermission())));
} else {
authorizables.add(getRestrictedComponentsAuthorizable());
}
}
return authorizables;
}
use of org.apache.nifi.annotation.behavior.Restricted in project nifi by apache.
the class HtmlDocumentationWriter method writeRestrictedInfo.
/**
* Write the description of the Restricted annotation if provided in this component.
*
* @param configurableComponent the component to describe
* @param xmlStreamWriter the stream writer to use
* @throws XMLStreamException thrown if there was a problem writing the XML
*/
private void writeRestrictedInfo(ConfigurableComponent configurableComponent, XMLStreamWriter xmlStreamWriter) throws XMLStreamException {
final Restricted restricted = configurableComponent.getClass().getAnnotation(Restricted.class);
writeSimpleElement(xmlStreamWriter, "h3", "Restricted: ");
if (restricted != null) {
final String value = restricted.value();
if (!StringUtils.isBlank(value)) {
xmlStreamWriter.writeCharacters(restricted.value());
}
final Restriction[] restrictions = restricted.restrictions();
if (restrictions != null && restrictions.length > 0) {
xmlStreamWriter.writeStartElement("table");
xmlStreamWriter.writeAttribute("id", "restrictions");
xmlStreamWriter.writeStartElement("tr");
writeSimpleElement(xmlStreamWriter, "th", "Required Permission");
writeSimpleElement(xmlStreamWriter, "th", "Explanation");
xmlStreamWriter.writeEndElement();
for (Restriction restriction : restrictions) {
xmlStreamWriter.writeStartElement("tr");
writeSimpleElement(xmlStreamWriter, "td", restriction.requiredPermission().getPermissionLabel());
writeSimpleElement(xmlStreamWriter, "td", restriction.explanation());
xmlStreamWriter.writeEndElement();
}
xmlStreamWriter.writeEndElement();
} else {
xmlStreamWriter.writeCharacters("This component requires access to restricted components regardless of restriction.");
}
} else {
xmlStreamWriter.writeCharacters("This component is not restricted.");
}
}
use of org.apache.nifi.annotation.behavior.Restricted in project nifi by apache.
the class DtoFactory method getExplicitRestrictions.
private Set<ExplicitRestrictionDTO> getExplicitRestrictions(final Class<?> cls) {
final Restricted restricted = cls.getAnnotation(Restricted.class);
if (restricted == null) {
return null;
}
final Restriction[] restrictions = restricted.restrictions();
if (restrictions == null || restrictions.length == 0) {
return null;
}
return Arrays.stream(restrictions).map(restriction -> {
final RequiredPermissionDTO requiredPermission = new RequiredPermissionDTO();
requiredPermission.setId(restriction.requiredPermission().getPermissionIdentifier());
requiredPermission.setLabel(restriction.requiredPermission().getPermissionLabel());
final ExplicitRestrictionDTO usageRestriction = new ExplicitRestrictionDTO();
usageRestriction.setRequiredPermission(requiredPermission);
usageRestriction.setExplanation(restriction.explanation());
return usageRestriction;
}).collect(Collectors.toSet());
}
Aggregations