Search in sources :

Example 46 with AtlasException

use of org.apache.atlas.AtlasException in project incubator-atlas by apache.

the class SimpleAtlasAuthorizer method init.

@Override
public void init() {
    if (isDebugEnabled) {
        LOG.debug("==> SimpleAtlasAuthorizer init");
    }
    try {
        PolicyParser parser = new PolicyParser();
        optIgnoreCase = Boolean.valueOf(PropertiesUtil.getProperty("optIgnoreCase", "false"));
        if (isDebugEnabled) {
            LOG.debug("Read from PropertiesUtil --> optIgnoreCase :: {}", optIgnoreCase);
        }
        InputStream policyStoreStream = ApplicationProperties.getFileAsInputStream(ApplicationProperties.get(), "atlas.auth.policy.file", "policy-store.txt");
        List<String> policies = null;
        try {
            policies = FileReaderUtil.readFile(policyStoreStream);
        } finally {
            policyStoreStream.close();
        }
        List<PolicyDef> policyDef = parser.parsePolicies(policies);
        userReadMap = PolicyUtil.createPermissionMap(policyDef, AtlasActionTypes.READ, AtlasAccessorTypes.USER);
        userWriteMap = PolicyUtil.createPermissionMap(policyDef, AtlasActionTypes.CREATE, AtlasAccessorTypes.USER);
        userUpdateMap = PolicyUtil.createPermissionMap(policyDef, AtlasActionTypes.UPDATE, AtlasAccessorTypes.USER);
        userDeleteMap = PolicyUtil.createPermissionMap(policyDef, AtlasActionTypes.DELETE, AtlasAccessorTypes.USER);
        groupReadMap = PolicyUtil.createPermissionMap(policyDef, AtlasActionTypes.READ, AtlasAccessorTypes.GROUP);
        groupWriteMap = PolicyUtil.createPermissionMap(policyDef, AtlasActionTypes.CREATE, AtlasAccessorTypes.GROUP);
        groupUpdateMap = PolicyUtil.createPermissionMap(policyDef, AtlasActionTypes.UPDATE, AtlasAccessorTypes.GROUP);
        groupDeleteMap = PolicyUtil.createPermissionMap(policyDef, AtlasActionTypes.DELETE, AtlasAccessorTypes.GROUP);
        if (isDebugEnabled) {
            LOG.debug("\n\nUserReadMap :: {}\nGroupReadMap :: {}", userReadMap, groupReadMap);
            LOG.debug("\n\nUserWriteMap :: {}\nGroupWriteMap :: {}", userWriteMap, groupWriteMap);
            LOG.debug("\n\nUserUpdateMap :: {}\nGroupUpdateMap :: {}", userUpdateMap, groupUpdateMap);
            LOG.debug("\n\nUserDeleteMap :: {}\nGroupDeleteMap :: {}", userDeleteMap, groupDeleteMap);
        }
    } catch (IOException | AtlasException e) {
        if (LOG.isErrorEnabled()) {
            LOG.error("SimpleAtlasAuthorizer could not be initialized properly due to : ", e);
        }
        throw new RuntimeException(e);
    }
}
Also used : InputStream(java.io.InputStream) IOException(java.io.IOException) AtlasException(org.apache.atlas.AtlasException)

Example 47 with AtlasException

use of org.apache.atlas.AtlasException in project incubator-atlas by apache.

the class AtlasAuthorizerFactory method getAtlasAuthorizer.

public static AtlasAuthorizer getAtlasAuthorizer() throws AtlasAuthorizationException {
    Configuration configuration = null;
    try {
        configuration = ApplicationProperties.get();
    } catch (AtlasException e) {
        if (LOG.isErrorEnabled()) {
            LOG.error("Exception while fetching configuration. ", e);
        }
    }
    AtlasAuthorizer ret = INSTANCE;
    if (ret == null) {
        synchronized (AtlasAuthorizerFactory.class) {
            if (INSTANCE == null) {
                String authorizerClass = configuration != null ? configuration.getString("atlas.authorizer.impl") : "SIMPLE";
                if (StringUtils.isNotEmpty(authorizerClass)) {
                    if (StringUtils.equalsIgnoreCase(authorizerClass, "SIMPLE")) {
                        authorizerClass = SIMPLE_AUTHORIZER;
                    } else if (StringUtils.equalsIgnoreCase(authorizerClass, "RANGER")) {
                        authorizerClass = RANGER_AUTHORIZER;
                    }
                } else {
                    authorizerClass = SIMPLE_AUTHORIZER;
                }
                if (isDebugEnabled) {
                    LOG.debug("Initializing Authorizer :: {}", authorizerClass);
                }
                try {
                    Class authorizerMetaObject = Class.forName(authorizerClass);
                    if (authorizerMetaObject != null) {
                        INSTANCE = (AtlasAuthorizer) authorizerMetaObject.newInstance();
                    }
                } catch (Exception e) {
                    LOG.error("Error while creating authorizer of type '{}", authorizerClass, e);
                    throw new AtlasAuthorizationException("Error while creating authorizer of type '" + authorizerClass + "'", e);
                }
                ret = INSTANCE;
            }
        }
    }
    return ret;
}
Also used : Configuration(org.apache.commons.configuration.Configuration) AtlasException(org.apache.atlas.AtlasException) AtlasException(org.apache.atlas.AtlasException)

Example 48 with AtlasException

use of org.apache.atlas.AtlasException in project incubator-atlas by apache.

the class DefaultTypeSystem method createEntity.

@Override
public String createEntity(ResourceDefinition definition, Request request) throws ResourceAlreadyExistsException {
    String typeName = definition.getTypeName();
    try {
        createClassType(definition, typeName, typeName + " Definition");
    } catch (ResourceAlreadyExistsException e) {
    // ok if type already exists
    }
    try {
        Referenceable entity = new Referenceable(typeName, request.getQueryProperties());
        //add Taxonomy Namespace
        entity.set(TaxonomyResourceProvider.NAMESPACE_ATTRIBUTE_NAME, TaxonomyResourceProvider.TAXONOMY_NS);
        ITypedReferenceableInstance typedInstance = metadataService.getTypedReferenceableInstance(entity);
        ITypedReferenceableInstance[] entitiesToCreate = Collections.singletonList(typedInstance).toArray(new ITypedReferenceableInstance[1]);
        final List<String> entities = metadataService.createEntities(entitiesToCreate).getCreatedEntities();
        return entities != null && entities.size() > 0 ? entities.get(0) : null;
    } catch (EntityExistsException e) {
        throw new ResourceAlreadyExistsException("Attempted to create an entity which already exists: " + request.getQueryProperties());
    } catch (AtlasException e) {
        throw new CatalogRuntimeException("An expected exception occurred creating an entity: " + e, e);
    }
}
Also used : Referenceable(org.apache.atlas.typesystem.Referenceable) ITypedReferenceableInstance(org.apache.atlas.typesystem.ITypedReferenceableInstance) CatalogRuntimeException(org.apache.atlas.catalog.exception.CatalogRuntimeException) ResourceAlreadyExistsException(org.apache.atlas.catalog.exception.ResourceAlreadyExistsException) AtlasException(org.apache.atlas.AtlasException) EntityExistsException(org.apache.atlas.typesystem.exception.EntityExistsException)

Example 49 with AtlasException

use of org.apache.atlas.AtlasException in project incubator-atlas by apache.

the class DefaultPropertyMapper method toFullyQualifiedName.

@Override
public String toFullyQualifiedName(String propName, String type) {
    HierarchicalType dataType = getDataType(type);
    String replacement = m_cleanToQualifiedMap.get(propName);
    if (replacement == null && dataType != null) {
        FieldMapping fieldMap = dataType.fieldMapping();
        if (fieldMap.fields.containsKey(propName)) {
            try {
                replacement = dataType.getQualifiedName(propName);
            } catch (AtlasException e) {
                throw new CatalogRuntimeException(String.format("Unable to resolve fully qualified property name for type '%s': %s", type, e), e);
            }
        }
    }
    if (replacement == null) {
        replacement = propName;
    }
    return replacement;
}
Also used : FieldMapping(org.apache.atlas.typesystem.types.FieldMapping) CatalogRuntimeException(org.apache.atlas.catalog.exception.CatalogRuntimeException) AtlasException(org.apache.atlas.AtlasException) HierarchicalType(org.apache.atlas.typesystem.types.HierarchicalType)

Example 50 with AtlasException

use of org.apache.atlas.AtlasException in project incubator-atlas by apache.

the class InMemoryJAASConfiguration method init.

public static void init(org.apache.commons.configuration.Configuration atlasConfiguration) throws AtlasException {
    LOG.debug("==> InMemoryJAASConfiguration.init()");
    if (atlasConfiguration != null && !atlasConfiguration.isEmpty()) {
        Properties properties = ConfigurationConverter.getProperties(atlasConfiguration);
        init(properties);
    } else {
        throw new AtlasException("Failed to load JAAS application properties: configuration NULL or empty!");
    }
    LOG.debug("<== InMemoryJAASConfiguration.init()");
}
Also used : Properties(java.util.Properties) AtlasException(org.apache.atlas.AtlasException)

Aggregations

AtlasException (org.apache.atlas.AtlasException)101 AttributeInfo (org.apache.atlas.typesystem.types.AttributeInfo)26 AtlasBaseException (org.apache.atlas.exception.AtlasBaseException)19 IOException (java.io.IOException)13 ITypedReferenceableInstance (org.apache.atlas.typesystem.ITypedReferenceableInstance)13 RepositoryException (org.apache.atlas.repository.RepositoryException)12 JSONObject (org.codehaus.jettison.json.JSONObject)12 CreateUpdateEntitiesResult (org.apache.atlas.CreateUpdateEntitiesResult)9 EntityNotFoundException (org.apache.atlas.typesystem.exception.EntityNotFoundException)9 Configuration (org.apache.commons.configuration.Configuration)9 ArrayList (java.util.ArrayList)7 EntityMutationResponse (org.apache.atlas.model.instance.EntityMutationResponse)7 AtlasVertex (org.apache.atlas.repository.graphdb.AtlasVertex)6 Id (org.apache.atlas.typesystem.persistence.Id)6 AtlasPerfTracer (org.apache.atlas.utils.AtlasPerfTracer)6 HashMap (java.util.HashMap)5 GraphTransaction (org.apache.atlas.annotation.GraphTransaction)5 CatalogRuntimeException (org.apache.atlas.catalog.exception.CatalogRuntimeException)5 Referenceable (org.apache.atlas.typesystem.Referenceable)5 EntityExistsException (org.apache.atlas.typesystem.exception.EntityExistsException)5