Search in sources :

Example 1 with IdentityProviders

use of org.apache.nifi.registry.security.authentication.generated.IdentityProviders in project nifi-registry by apache.

the class IdentityProviderFactory method loadLoginIdentityProvidersConfiguration.

private IdentityProviders loadLoginIdentityProvidersConfiguration() throws Exception {
    final File loginIdentityProvidersConfigurationFile = properties.getIdentityProviderConfigurationFile();
    // load the users from the specified file
    if (loginIdentityProvidersConfigurationFile.exists()) {
        try {
            // find the schema
            final SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
            final Schema schema = schemaFactory.newSchema(IdentityProviders.class.getResource(LOGIN_IDENTITY_PROVIDERS_XSD));
            // attempt to unmarshal
            XMLStreamReader xsr = XmlUtils.createSafeReader(new StreamSource(loginIdentityProvidersConfigurationFile));
            final Unmarshaller unmarshaller = JAXB_CONTEXT.createUnmarshaller();
            unmarshaller.setSchema(schema);
            final JAXBElement<IdentityProviders> element = unmarshaller.unmarshal(xsr, IdentityProviders.class);
            return element.getValue();
        } catch (SAXException | JAXBException e) {
            throw new Exception("Unable to load the login identity provider configuration file at: " + loginIdentityProvidersConfigurationFile.getAbsolutePath());
        }
    } else {
        throw new Exception("Unable to find the login identity provider configuration file at " + loginIdentityProvidersConfigurationFile.getAbsolutePath());
    }
}
Also used : SchemaFactory(javax.xml.validation.SchemaFactory) XMLStreamReader(javax.xml.stream.XMLStreamReader) Schema(javax.xml.validation.Schema) StreamSource(javax.xml.transform.stream.StreamSource) JAXBException(javax.xml.bind.JAXBException) Unmarshaller(javax.xml.bind.Unmarshaller) File(java.io.File) IdentityProviders(org.apache.nifi.registry.security.authentication.generated.IdentityProviders) SensitivePropertyProtectionException(org.apache.nifi.registry.properties.SensitivePropertyProtectionException) JAXBException(javax.xml.bind.JAXBException) InvocationTargetException(java.lang.reflect.InvocationTargetException) SAXException(org.xml.sax.SAXException) SAXException(org.xml.sax.SAXException)

Example 2 with IdentityProviders

use of org.apache.nifi.registry.security.authentication.generated.IdentityProviders in project nifi-registry by apache.

the class IdentityProviderFactory method getIdentityProvider.

@Bean
@Primary
public IdentityProvider getIdentityProvider() throws Exception {
    if (identityProvider == null) {
        // look up the login identity provider to use
        final String loginIdentityProviderIdentifier = properties.getProperty(NiFiRegistryProperties.SECURITY_IDENTITY_PROVIDER);
        // ensure the login identity provider class name was specified
        if (StringUtils.isNotBlank(loginIdentityProviderIdentifier)) {
            final IdentityProviders loginIdentityProviderConfiguration = loadLoginIdentityProvidersConfiguration();
            // create each login identity provider
            for (final Provider provider : loginIdentityProviderConfiguration.getProvider()) {
                identityProviders.put(provider.getIdentifier(), createLoginIdentityProvider(provider.getIdentifier(), provider.getClazz()));
            }
            // configure each login identity provider
            for (final Provider provider : loginIdentityProviderConfiguration.getProvider()) {
                final IdentityProvider instance = identityProviders.get(provider.getIdentifier());
                instance.onConfigured(loadLoginIdentityProviderConfiguration(provider));
            }
            // get the login identity provider instance
            identityProvider = getIdentityProvider(loginIdentityProviderIdentifier);
            // ensure it was found
            if (identityProvider == null) {
                throw new Exception(String.format("The specified login identity provider '%s' could not be found.", loginIdentityProviderIdentifier));
            }
        }
    }
    return identityProvider;
}
Also used : IdentityProviders(org.apache.nifi.registry.security.authentication.generated.IdentityProviders) SensitivePropertyProtectionException(org.apache.nifi.registry.properties.SensitivePropertyProtectionException) JAXBException(javax.xml.bind.JAXBException) InvocationTargetException(java.lang.reflect.InvocationTargetException) SAXException(org.xml.sax.SAXException) SensitivePropertyProvider(org.apache.nifi.registry.properties.SensitivePropertyProvider) Provider(org.apache.nifi.registry.security.authentication.generated.Provider) Primary(org.springframework.context.annotation.Primary) DisposableBean(org.springframework.beans.factory.DisposableBean) Bean(org.springframework.context.annotation.Bean)

Aggregations

InvocationTargetException (java.lang.reflect.InvocationTargetException)2 JAXBException (javax.xml.bind.JAXBException)2 SensitivePropertyProtectionException (org.apache.nifi.registry.properties.SensitivePropertyProtectionException)2 IdentityProviders (org.apache.nifi.registry.security.authentication.generated.IdentityProviders)2 SAXException (org.xml.sax.SAXException)2 File (java.io.File)1 Unmarshaller (javax.xml.bind.Unmarshaller)1 XMLStreamReader (javax.xml.stream.XMLStreamReader)1 StreamSource (javax.xml.transform.stream.StreamSource)1 Schema (javax.xml.validation.Schema)1 SchemaFactory (javax.xml.validation.SchemaFactory)1 SensitivePropertyProvider (org.apache.nifi.registry.properties.SensitivePropertyProvider)1 Provider (org.apache.nifi.registry.security.authentication.generated.Provider)1 DisposableBean (org.springframework.beans.factory.DisposableBean)1 Bean (org.springframework.context.annotation.Bean)1 Primary (org.springframework.context.annotation.Primary)1