Search in sources :

Example 6 with User

use of com.thinkbiganalytics.security.rest.model.User in project kylo by Teradata.

the class KyloRestLoginModule method doLogin.

@Override
protected boolean doLogin() throws Exception {
    final LoginJerseyClientConfig userConfig = createClientConfig(true);
    final User user;
    try {
        user = retrieveUser(userConfig);
    } catch (final NotAuthorizedException e) {
        log.debug("Received unauthorized response from Login API for user: {}", userConfig.getUsername());
        throw new CredentialException("The username and password combination do not match.");
    } catch (final ProcessingException e) {
        log.error("Failed to process response from Login API for user: {}", userConfig.getUsername(), e);
        throw new FailedLoginException("The login service is unavailable.");
    } catch (final WebApplicationException e) {
        log.error("Received unexpected response from Login API for user: {}", userConfig.getUsername(), e);
        throw new FailedLoginException("The login service is unavailable.");
    }
    // Parse response
    if (user == null) {
        log.debug("No account exists with the name: {}", userConfig.getUsername());
        throw new AccountNotFoundException("No account exists with the name: " + userConfig.getUsername());
    } else if (!user.isEnabled()) {
        log.debug("User from Login API is disabled: {}", userConfig.getUsername());
        throw new AccountLockedException("The account \"" + userConfig.getUsername() + "\" is currently disabled");
    }
    addNewUserPrincipal(user.getSystemName());
    user.getGroups().forEach(this::addNewGroupPrincipal);
    return true;
}
Also used : AccountLockedException(javax.security.auth.login.AccountLockedException) User(com.thinkbiganalytics.security.rest.model.User) FailedLoginException(javax.security.auth.login.FailedLoginException) CredentialException(javax.security.auth.login.CredentialException) WebApplicationException(javax.ws.rs.WebApplicationException) NotAuthorizedException(javax.ws.rs.NotAuthorizedException) AccountNotFoundException(javax.security.auth.login.AccountNotFoundException) ProcessingException(javax.ws.rs.ProcessingException)

Example 7 with User

use of com.thinkbiganalytics.security.rest.model.User in project kylo by Teradata.

the class KyloRestLoginModuleTest method test.

/**
 * Verify logging in by querying a REST API.
 */
@Test
public void test() throws Exception {
    // Mock REST client
    final User user = new User();
    user.setEnabled(true);
    user.setGroups(ImmutableSet.of("designers", "operators"));
    user.setSystemName("dladmin");
    final JerseyRestClient client = Mockito.mock(JerseyRestClient.class);
    Mockito.when(client.get(any(Invocation.Builder.class), eq(User.class))).thenReturn(user);
    // Mock callback handler
    final CallbackHandler callbackHandler = callbacks -> Arrays.stream(callbacks).forEach(callback -> {
        if (callback instanceof NameCallback) {
            ((NameCallback) callback).setName("dladmin");
        } else if (callback instanceof PasswordCallback) {
            ((PasswordCallback) callback).setPassword("thinkbig".toCharArray());
        }
    });
    // Mock login module
    final KyloRestLoginModule module = new KyloRestLoginModule() {

        @Nonnull
        @Override
        JerseyRestClient getClient(@Nonnull LoginJerseyClientConfig config) {
            return client;
        }
    };
    // Test login
    final Subject subject = new Subject();
    Map<String, Object> options = new HashMap<>();
    options.put(KyloRestLoginModule.REST_CLIENT_CONFIG, new LoginJerseyClientConfig());
    options.put(KyloRestLoginModule.SERVICES_LOGOUT, false);
    module.initialize(subject, callbackHandler, Collections.emptyMap(), options);
    Assert.assertTrue(module.login());
    Assert.assertTrue(module.commit());
    // Verify subject
    final Principal[] principals = subject.getPrincipals().toArray(new Principal[0]);
    Assert.assertEquals(3, principals.length);
    Arrays.sort(principals, Comparator.comparing(Principal::getName));
    Assert.assertEquals("designers", principals[0].getName());
    Assert.assertEquals("dladmin", principals[1].getName());
    Assert.assertEquals("operators", principals[2].getName());
}
Also used : Arrays(java.util.Arrays) PasswordCallback(javax.security.auth.callback.PasswordCallback) ImmutableSet(com.google.common.collect.ImmutableSet) Test(org.junit.Test) HashMap(java.util.HashMap) Invocation(javax.ws.rs.client.Invocation) JerseyRestClient(com.thinkbiganalytics.rest.JerseyRestClient) Subject(javax.security.auth.Subject) Matchers.any(org.mockito.Matchers.any) Mockito(org.mockito.Mockito) Principal(java.security.Principal) CallbackHandler(javax.security.auth.callback.CallbackHandler) NameCallback(javax.security.auth.callback.NameCallback) Matchers.eq(org.mockito.Matchers.eq) Map(java.util.Map) User(com.thinkbiganalytics.security.rest.model.User) Assert(org.junit.Assert) Comparator(java.util.Comparator) Collections(java.util.Collections) Nonnull(javax.annotation.Nonnull) CallbackHandler(javax.security.auth.callback.CallbackHandler) User(com.thinkbiganalytics.security.rest.model.User) Nonnull(javax.annotation.Nonnull) HashMap(java.util.HashMap) JerseyRestClient(com.thinkbiganalytics.rest.JerseyRestClient) Subject(javax.security.auth.Subject) NameCallback(javax.security.auth.callback.NameCallback) PasswordCallback(javax.security.auth.callback.PasswordCallback) Principal(java.security.Principal) Test(org.junit.Test)

Example 8 with User

use of com.thinkbiganalytics.security.rest.model.User in project kylo by Teradata.

the class IntegrationTestBase method makeCreateFeedRequest.

protected FeedMetadata makeCreateFeedRequest(FeedCategory category, ImportTemplate template, String feedName, String testFile) {
    FeedMetadata feed = new FeedMetadata();
    feed.setFeedName(feedName);
    feed.setSystemFeedName(feedName.toLowerCase());
    feed.setCategory(category);
    feed.setTemplateId(template.getTemplateId());
    feed.setTemplateName(template.getTemplateName());
    feed.setDescription("Created by functional test");
    feed.setInputProcessorType("org.apache.nifi.processors.standard.GetFile");
    List<NifiProperty> properties = new ArrayList<>();
    NifiProperty fileFilter = new NifiProperty("764d053d-015e-1000-b8a2-763cd17080e1", "cffa8f24-d097-3c7a-7d04-26b7feff81ab", "File Filter", testFile);
    fileFilter.setProcessGroupName("NiFi Flow");
    fileFilter.setProcessorName("GetFile");
    fileFilter.setProcessorType("org.apache.nifi.processors.standard.GetFile");
    fileFilter.setTemplateValue("mydata\\d{1,3}.csv");
    fileFilter.setInputProperty(true);
    fileFilter.setUserEditable(true);
    properties.add(fileFilter);
    feed.setProperties(properties);
    FeedSchedule schedule = new FeedSchedule();
    schedule.setConcurrentTasks(1);
    schedule.setSchedulingPeriod("15 sec");
    schedule.setSchedulingStrategy("TIMER_DRIVEN");
    feed.setSchedule(schedule);
    feed.setDataOwner("Marketing");
    List<Tag> tags = new ArrayList<>();
    tags.add(new DefaultTag("functional tests"));
    tags.add(new DefaultTag("for category " + category.getName()));
    feed.setTags(tags);
    User owner = new User();
    owner.setSystemName("dladmin");
    owner.setDisplayName("Data Lake Admin");
    Set<String> groups = new HashSet<>();
    groups.add("admin");
    groups.add("user");
    owner.setGroups(groups);
    feed.setOwner(owner);
    return feed;
}
Also used : User(com.thinkbiganalytics.security.rest.model.User) FeedSchedule(com.thinkbiganalytics.feedmgr.rest.model.FeedSchedule) FeedMetadata(com.thinkbiganalytics.feedmgr.rest.model.FeedMetadata) ArrayList(java.util.ArrayList) NifiProperty(com.thinkbiganalytics.nifi.rest.model.NifiProperty) Tag(com.thinkbiganalytics.discovery.schema.Tag) DefaultTag(com.thinkbiganalytics.discovery.model.DefaultTag) DefaultTag(com.thinkbiganalytics.discovery.model.DefaultTag) HashSet(java.util.HashSet)

Example 9 with User

use of com.thinkbiganalytics.security.rest.model.User in project kylo by Teradata.

the class FeedITBase method getCreateFeedRequest.

protected FeedMetadata getCreateFeedRequest(FeedCategory category, ImportTemplate template, String name) throws Exception {
    FeedMetadata feed = new FeedMetadata();
    feed.setFeedName(name);
    feed.setSystemFeedName(name.toLowerCase());
    feed.setCategory(category);
    feed.setTemplateId(template.getTemplateId());
    feed.setTemplateName(template.getTemplateName());
    feed.setDescription("Created by functional test");
    feed.setInputProcessorType("org.apache.nifi.processors.standard.GetFile");
    List<NifiProperty> properties = new ArrayList<>();
    NifiProperty fileFilter = new NifiProperty("305363d8-015a-1000-0000-000000000000", "1f67e296-2ff8-4b5d-0000-000000000000", "File Filter", getFileName());
    fileFilter.setProcessGroupName("NiFi Flow");
    fileFilter.setProcessorName("Filesystem");
    fileFilter.setProcessorType("org.apache.nifi.processors.standard.GetFile");
    fileFilter.setTemplateValue(getFileTemplateValue());
    fileFilter.setInputProperty(true);
    fileFilter.setUserEditable(true);
    properties.add(fileFilter);
    NifiProperty inputDir = new NifiProperty("305363d8-015a-1000-0000-000000000000", "1f67e296-2ff8-4b5d-0000-000000000000", "Input Directory", VAR_DROPZONE);
    inputDir.setProcessGroupName("NiFi Flow");
    inputDir.setProcessorName("Filesystem");
    inputDir.setProcessorType("org.apache.nifi.processors.standard.GetFile");
    inputDir.setInputProperty(true);
    inputDir.setUserEditable(true);
    properties.add(inputDir);
    NifiProperty loadStrategy = new NifiProperty("305363d8-015a-1000-0000-000000000000", "6aeabec7-ec36-4ed5-0000-000000000000", "Load Strategy", "FULL_LOAD");
    loadStrategy.setProcessGroupName("NiFi Flow");
    loadStrategy.setProcessorName("GetTableData");
    loadStrategy.setProcessorType("com.thinkbiganalytics.nifi.v2.ingest.GetTableData");
    properties.add(loadStrategy);
    feed.setProperties(properties);
    FeedSchedule schedule = new FeedSchedule();
    schedule.setConcurrentTasks(1);
    schedule.setSchedulingPeriod("15 sec");
    schedule.setSchedulingStrategy("TIMER_DRIVEN");
    feed.setSchedule(schedule);
    TableSetup table = new TableSetup();
    DefaultTableSchema schema = new DefaultTableSchema();
    schema.setName("test1");
    schema.setFields(getFields());
    table.setTableSchema(schema);
    table.setSourceTableSchema(schema);
    table.setFeedTableSchema(schema);
    table.setTargetMergeStrategy("DEDUPE_AND_MERGE");
    table.setFeedFormat(getFeedFormat());
    table.setTargetFormat("STORED AS ORC");
    List<FieldPolicy> policies = getFieldPolicies();
    table.setFieldPolicies(policies);
    table.setTargetSourceFieldMap(getTargetSourceFieldMap());
    List<PartitionField> partitions = getPartitionFields();
    table.setPartitions(partitions);
    TableOptions options = new TableOptions();
    options.setCompressionFormat("SNAPPY");
    options.setAuditLogging(true);
    table.setOptions(options);
    table.setTableType("SNAPSHOT");
    feed.setTable(table);
    feed.setOptions(new FeedProcessingOptions());
    feed.getOptions().setSkipHeader(true);
    feed.setDataOwner("Marketing");
    List<Tag> tags = getTags();
    feed.setTags(tags);
    User owner = new User();
    owner.setSystemName("dladmin");
    owner.setDisplayName("Data Lake Admin");
    Set<String> groups = new HashSet<>();
    groups.add("admin");
    groups.add("user");
    owner.setGroups(groups);
    feed.setOwner(owner);
    return feed;
}
Also used : FeedProcessingOptions(com.thinkbiganalytics.feedmgr.rest.model.schema.FeedProcessingOptions) User(com.thinkbiganalytics.security.rest.model.User) FieldPolicy(com.thinkbiganalytics.policy.rest.model.FieldPolicy) FeedMetadata(com.thinkbiganalytics.feedmgr.rest.model.FeedMetadata) PartitionField(com.thinkbiganalytics.feedmgr.rest.model.schema.PartitionField) TableOptions(com.thinkbiganalytics.feedmgr.rest.model.schema.TableOptions) FeedSchedule(com.thinkbiganalytics.feedmgr.rest.model.FeedSchedule) NifiProperty(com.thinkbiganalytics.nifi.rest.model.NifiProperty) TableSetup(com.thinkbiganalytics.feedmgr.rest.model.schema.TableSetup) DefaultTableSchema(com.thinkbiganalytics.discovery.model.DefaultTableSchema) Tag(com.thinkbiganalytics.discovery.schema.Tag) DefaultTag(com.thinkbiganalytics.discovery.model.DefaultTag)

Example 10 with User

use of com.thinkbiganalytics.security.rest.model.User in project kylo by Teradata.

the class FeedTestUtil method getCreateFeedRequest.

public static FeedMetadata getCreateFeedRequest(FeedCategory category, ImportTemplate template, String name, String inputProcessorType, List<NifiProperty> properties) throws Exception {
    FeedMetadata feed = new FeedMetadata();
    feed.setFeedName(name);
    feed.setSystemFeedName(name.toLowerCase());
    feed.setCategory(category);
    feed.setTemplateId(template.getTemplateId());
    feed.setTemplateName(template.getTemplateName());
    feed.setDescription("Created by functional test");
    feed.setInputProcessorType(inputProcessorType);
    feed.setProperties(properties);
    FeedSchedule schedule = new FeedSchedule();
    schedule.setConcurrentTasks(1);
    schedule.setSchedulingPeriod("15 sec");
    schedule.setSchedulingStrategy("TIMER_DRIVEN");
    feed.setSchedule(schedule);
    feed.setDataOwner("Marketing");
    List<Tag> tags = new ArrayList<>();
    tags.add(new DefaultTag("users"));
    tags.add(new DefaultTag("registrations"));
    feed.setTags(tags);
    User owner = new User();
    owner.setSystemName("dladmin");
    owner.setDisplayName("Data Lake Admin");
    Set<String> groups = new HashSet<>();
    groups.add("admin");
    groups.add("user");
    owner.setGroups(groups);
    feed.setOwner(owner);
    return feed;
}
Also used : User(com.thinkbiganalytics.security.rest.model.User) FeedSchedule(com.thinkbiganalytics.feedmgr.rest.model.FeedSchedule) FeedMetadata(com.thinkbiganalytics.feedmgr.rest.model.FeedMetadata) ArrayList(java.util.ArrayList) DefaultTag(com.thinkbiganalytics.discovery.model.DefaultTag) Tag(com.thinkbiganalytics.discovery.schema.Tag) DefaultTag(com.thinkbiganalytics.discovery.model.DefaultTag) HashSet(java.util.HashSet)

Aggregations

User (com.thinkbiganalytics.security.rest.model.User)10 DefaultTag (com.thinkbiganalytics.discovery.model.DefaultTag)6 FeedMetadata (com.thinkbiganalytics.feedmgr.rest.model.FeedMetadata)6 Tag (com.thinkbiganalytics.discovery.schema.Tag)5 ArrayList (java.util.ArrayList)5 FeedSchedule (com.thinkbiganalytics.feedmgr.rest.model.FeedSchedule)4 NifiProperty (com.thinkbiganalytics.nifi.rest.model.NifiProperty)3 HashSet (java.util.HashSet)3 Nonnull (javax.annotation.Nonnull)3 DefaultTableSchema (com.thinkbiganalytics.discovery.model.DefaultTableSchema)2 FeedCategory (com.thinkbiganalytics.feedmgr.rest.model.FeedCategory)2 FeedSummary (com.thinkbiganalytics.feedmgr.rest.model.FeedSummary)2 RegisteredTemplate (com.thinkbiganalytics.feedmgr.rest.model.RegisteredTemplate)2 UserProperty (com.thinkbiganalytics.feedmgr.rest.model.UserProperty)2 FeedProcessingOptions (com.thinkbiganalytics.feedmgr.rest.model.schema.FeedProcessingOptions)2 PartitionField (com.thinkbiganalytics.feedmgr.rest.model.schema.PartitionField)2 TableOptions (com.thinkbiganalytics.feedmgr.rest.model.schema.TableOptions)2 TableSetup (com.thinkbiganalytics.feedmgr.rest.model.schema.TableSetup)2 Category (com.thinkbiganalytics.metadata.api.category.Category)2 UserFieldDescriptor (com.thinkbiganalytics.metadata.api.extension.UserFieldDescriptor)2