[ 
https://issues.apache.org/jira/browse/NIFI-1553?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15230901#comment-15230901
 ] 

ASF GitHub Bot commented on NIFI-1553:
--------------------------------------

Github user markap14 commented on a diff in the pull request:

    https://github.com/apache/nifi/pull/330#discussion_r58930317
  
    --- Diff: 
nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-file-authorizer/src/main/java/org/apache/nifi/authorization/FileAuthorizer.java
 ---
    @@ -0,0 +1,278 @@
    +/*
    + * Licensed to the Apache Software Foundation (ASF) under one or more
    + * contributor license agreements.  See the NOTICE file distributed with
    + * this work for additional information regarding copyright ownership.
    + * The ASF licenses this file to You 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 org.apache.nifi.authorization;
    +
    +import org.apache.nifi.authorization.annotation.AuthorizerContext;
    +import 
org.apache.nifi.authorization.exception.AuthorizationAccessException;
    +import org.apache.nifi.authorization.exception.ProviderCreationException;
    +import org.apache.nifi.authorization.generated.Authorization;
    +import org.apache.nifi.authorization.generated.Resource;
    +import org.apache.nifi.authorization.generated.Resources;
    +import org.apache.nifi.components.PropertyValue;
    +import org.apache.nifi.util.NiFiProperties;
    +import org.apache.nifi.util.StringUtils;
    +import org.apache.nifi.util.file.FileUtils;
    +import org.apache.nifi.util.file.monitor.MD5SumMonitor;
    +import org.apache.nifi.util.file.monitor.SynchronousFileWatcher;
    +import org.slf4j.Logger;
    +import org.slf4j.LoggerFactory;
    +import org.xml.sax.SAXException;
    +
    +import javax.xml.XMLConstants;
    +import javax.xml.bind.JAXBContext;
    +import javax.xml.bind.JAXBElement;
    +import javax.xml.bind.JAXBException;
    +import javax.xml.bind.Unmarshaller;
    +import javax.xml.transform.stream.StreamSource;
    +import javax.xml.validation.Schema;
    +import javax.xml.validation.SchemaFactory;
    +import java.io.File;
    +import java.io.IOException;
    +import java.util.Date;
    +import java.util.EnumSet;
    +import java.util.HashMap;
    +import java.util.Map;
    +import java.util.Set;
    +import java.util.concurrent.Executors;
    +import java.util.concurrent.ScheduledExecutorService;
    +import java.util.concurrent.ThreadFactory;
    +import java.util.concurrent.TimeUnit;
    +import java.util.concurrent.atomic.AtomicReference;
    +
    +/**
    + * Provides identity checks and grants authorities.
    + */
    +public class FileAuthorizer implements Authorizer {
    +
    +    private static final Logger logger = 
LoggerFactory.getLogger(FileAuthorizer.class);
    +    private static final String READ_CODE = "R";
    +    private static final String WRITE_CODE = "W";
    +    private static final String USERS_XSD = "/authorizations.xsd";
    +    private static final String JAXB_GENERATED_PATH = 
"org.apache.nifi.authorization.generated";
    +    private static final JAXBContext JAXB_CONTEXT = 
initializeJaxbContext();
    +
    +    /**
    +     * Load the JAXBContext.
    +     */
    +    private static JAXBContext initializeJaxbContext() {
    +        try {
    +            return JAXBContext.newInstance(JAXB_GENERATED_PATH, 
FileAuthorizer.class.getClassLoader());
    +        } catch (JAXBException e) {
    +            throw new RuntimeException("Unable to create JAXBContext.");
    +        }
    +    }
    +
    +    private NiFiProperties properties;
    +    private File authorizationsFile;
    +    private File restoreAuthorizationsFile;
    +    private SynchronousFileWatcher fileWatcher;
    +    private ScheduledExecutorService fileWatcherExecutorService;
    +
    +    private final AtomicReference<Map<String, Map<String, 
Set<RequestAction>>>> authorizations = new AtomicReference<>();
    +
    +    @Override
    +    public void initialize(final AuthorizerInitializationContext 
initializationContext) throws ProviderCreationException {
    +    }
    +
    +    @Override
    +    public void onConfigured(final AuthorizerConfigurationContext 
configurationContext) throws ProviderCreationException {
    +        try {
    +            final PropertyValue authorizationsPath = 
configurationContext.getProperty("Authorizations File");
    +            if (authorizationsPath == null || 
StringUtils.isBlank(authorizationsPath.getValue())) {
    +                throw new ProviderCreationException("The authorized users 
file must be specified.");
    +            }
    +
    +            authorizationsFile = new File(authorizationsPath.getValue());
    +            final File authorizationsFileDirectory = 
authorizationsFile.getParentFile();
    --- End diff --
    
    If authorizationsFile is set to something like "myFile.txt" without a 
directory, calling getParentFile() will return null. This would then cause a 
NullPointerException below. We should probably instead use:
    {code}
    final File authorizationsFileDirectory = 
authorizationsFile.getAbsoluteFile().getParentFile();
    {code}


> Implement File Based Authorizer
> -------------------------------
>
>                 Key: NIFI-1553
>                 URL: https://issues.apache.org/jira/browse/NIFI-1553
>             Project: Apache NiFi
>          Issue Type: Sub-task
>          Components: Extensions
>            Reporter: Matt Gilman
>            Assignee: Matt Gilman
>             Fix For: 1.0.0
>
>
> - Create a file based implementation of the Authorizer API.
> - Reloads on an interval.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to