Search in sources :

Example 1 with User

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();
}
Also used : LoginContext(javax.security.auth.login.LoginContext) User(alluxio.security.User) UnauthenticatedException(alluxio.exception.status.UnauthenticatedException) LoginModuleConfiguration(alluxio.security.login.LoginModuleConfiguration) LoginException(javax.security.auth.login.LoginException) AppLoginModule(alluxio.security.login.AppLoginModule)

Example 2 with User

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));
}
Also used : InstancedConfiguration(alluxio.conf.InstancedConfiguration) AuthenticatedClientUser(alluxio.security.authentication.AuthenticatedClientUser) User(alluxio.security.User) Test(org.junit.Test)

Example 3 with User

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());
}
Also used : UnderStorageType(alluxio.client.UnderStorageType) User(alluxio.security.User) ClientContext(alluxio.ClientContext) LocalFirstPolicy(alluxio.client.block.policy.LocalFirstPolicy) AlluxioStorageType(alluxio.client.AlluxioStorageType) Subject(javax.security.auth.Subject) Test(org.junit.Test)

Example 4 with User

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()));
}
Also used : InstancedConfiguration(alluxio.conf.InstancedConfiguration) User(alluxio.security.User) Principal(java.security.Principal) Key(alluxio.client.file.FileSystemCache.Key) Subject(javax.security.auth.Subject) HashSet(java.util.HashSet)

Example 5 with User

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<>());
}
Also used : User(alluxio.security.User) Principal(java.security.Principal) Subject(javax.security.auth.Subject) HashSet(java.util.HashSet)

Aggregations

User (alluxio.security.User)19 Test (org.junit.Test)11 Subject (javax.security.auth.Subject)6 Principal (java.security.Principal)3 LoginException (javax.security.auth.login.LoginException)3 InstancedConfiguration (alluxio.conf.InstancedConfiguration)2 AuthenticatedClientUser (alluxio.security.authentication.AuthenticatedClientUser)2 HashSet (java.util.HashSet)2 AlluxioURI (alluxio.AlluxioURI)1 ClientContext (alluxio.ClientContext)1 AlluxioStorageType (alluxio.client.AlluxioStorageType)1 UnderStorageType (alluxio.client.UnderStorageType)1 LocalFirstPolicy (alluxio.client.block.policy.LocalFirstPolicy)1 FileSystem (alluxio.client.file.FileSystem)1 Key (alluxio.client.file.FileSystemCache.Key)1 URIStatus (alluxio.client.file.URIStatus)1 UnauthenticatedException (alluxio.exception.status.UnauthenticatedException)1 SetAttributePOptions (alluxio.grpc.SetAttributePOptions)1 ListAllMyBucketsResult (alluxio.proxy.s3.ListAllMyBucketsResult)1 Mode (alluxio.security.authorization.Mode)1