use of alluxio.security.User in project alluxio by Alluxio.
the class SimpleUserState method login.
@Override
public User login() throws UnauthenticatedException {
String username = "";
if (mConf.isSet(PropertyKey.SECURITY_LOGIN_USERNAME)) {
username = mConf.getString(PropertyKey.SECURITY_LOGIN_USERNAME);
}
try {
// Use the class loader of User.class to construct the LoginContext. LoginContext uses this
// class loader to dynamically instantiate login modules. This enables
// Subject#getPrincipals to use reflection to search for User.class instances.
LoginContext loginContext = SecurityUtils.createLoginContext(AuthType.SIMPLE, mSubject, User.class.getClassLoader(), new LoginModuleConfiguration(), new AppLoginModule.AppCallbackHandler(username));
loginContext.login();
} catch (LoginException e) {
throw new UnauthenticatedException("Failed to login: " + e.getMessage(), e);
}
LOG.debug("login subject: {}", mSubject);
Set<User> userSet = mSubject.getPrincipals(User.class);
if (userSet.isEmpty()) {
throw new UnauthenticatedException("Failed to login: No Alluxio User is found.");
}
if (userSet.size() > 1) {
StringBuilder msg = new StringBuilder("Failed to login: More than one Alluxio Users are found:");
for (User user : userSet) {
msg.append(" ").append(user.toString());
}
throw new UnauthenticatedException(msg.toString());
}
return userSet.iterator().next();
}
use of alluxio.security.User in project alluxio by Alluxio.
the class AuthenticatedClientUserResourceTest method userRestored.
@Test
public void userRestored() throws Exception {
InstancedConfiguration conf = ConfigurationTestUtils.defaults();
AuthenticatedClientUser.set(ORIGINAL_USER);
User original = AuthenticatedClientUser.get(conf);
new AuthenticatedClientUserResource(TESTCASE_USER, conf).close();
assertSame(original, AuthenticatedClientUser.get(conf));
}
use of alluxio.security.User in project alluxio by Alluxio.
the class OutStreamOptionsTest method defaults.
/**
* Tests that building an {@link OutStreamOptions} with the defaults works.
*/
@Test
public void defaults() throws IOException {
AlluxioStorageType alluxioType = AlluxioStorageType.STORE;
UnderStorageType ufsType = UnderStorageType.SYNC_PERSIST;
mConf.set(PropertyKey.USER_BLOCK_SIZE_BYTES_DEFAULT, "64MB");
mConf.set(PropertyKey.USER_FILE_WRITE_TYPE_DEFAULT, WriteType.CACHE_THROUGH.toString());
mConf.set(PropertyKey.USER_FILE_WRITE_TIER_DEFAULT, Constants.LAST_TIER);
mConf.set(PropertyKey.SECURITY_GROUP_MAPPING_CLASS, FakeUserGroupsMapping.class.getName());
Subject subject = new Subject();
subject.getPrincipals().add(new User("test_user"));
ClientContext clientContext = ClientContext.create(subject, mConf);
OutStreamOptions options = OutStreamOptions.defaults(clientContext);
assertEquals(alluxioType, options.getAlluxioStorageType());
assertEquals(64 * Constants.MB, options.getBlockSizeBytes());
assertTrue(options.getLocationPolicy() instanceof LocalFirstPolicy);
assertEquals("test_user", options.getOwner());
assertEquals("test_group", options.getGroup());
assertEquals(ModeUtils.applyFileUMask(Mode.defaults(), mConf.getString(PropertyKey.SECURITY_AUTHORIZATION_PERMISSION_UMASK)), options.getMode());
assertEquals(Constants.NO_TTL, options.getCommonOptions().getTtl());
assertEquals(TtlAction.DELETE, options.getCommonOptions().getTtlAction());
assertEquals(ufsType, options.getUnderStorageType());
assertEquals(WriteType.CACHE_THROUGH, options.getWriteType());
assertEquals(Constants.LAST_TIER, options.getWriteTier());
}
use of alluxio.security.User in project alluxio by Alluxio.
the class FileSystemCacheTest method createTestFSKey.
private Key createTestFSKey(String username) {
User user = new User(username);
Set<Principal> principals = new HashSet<>();
principals.add(user);
return new FileSystemCache.Key(new Subject(false, principals, new HashSet<>(), new HashSet<>()), new InstancedConfiguration(ConfigurationUtils.defaults()));
}
use of alluxio.security.User in project alluxio by Alluxio.
the class FileSystemFactoryTest method createTestSubject.
private Subject createTestSubject(String username) {
User user = new User(username);
Set<Principal> principals = new HashSet<>();
principals.add(user);
return new Subject(false, principals, new HashSet<>(), new HashSet<>());
}
Aggregations