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;
}
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());
}
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;
}
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;
}
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;
}
Aggregations