Search in sources :

Example 11 with User

use of alluxio.security.User in project alluxio by Alluxio.

the class S3RestServiceHandler method getFileSystem.

private FileSystem getFileSystem(String authorization) {
    final String user = getUserFromAuthorization(authorization);
    if (user == null) {
        return mFileSystem;
    }
    final Subject subject = new Subject();
    subject.getPrincipals().add(new User(user));
    return FileSystem.Factory.get(subject, mSConf);
}
Also used : User(alluxio.security.User) Subject(javax.security.auth.Subject)

Example 12 with User

use of alluxio.security.User in project alluxio by Alluxio.

the class S3ClientRestApiTest method listAllMyBuckets.

@Test
public void listAllMyBuckets() throws Exception {
    Mode mode = ModeParser.parse("777");
    SetAttributePOptions options = SetAttributePOptions.newBuilder().setMode(mode.toProto()).setRecursive(true).build();
    mFileSystem.setAttribute(new AlluxioURI("/"), options);
    Subject subject = new Subject();
    subject.getPrincipals().add(new User("user0"));
    AlluxioURI bucketPath = new AlluxioURI("/bucket0");
    FileSystem fs1 = sResource.get().getClient(FileSystemContext.create(subject, ServerConfiguration.global()));
    fs1.createDirectory(bucketPath);
    SetAttributePOptions setAttributeOptions = SetAttributePOptions.newBuilder().setOwner("user0").build();
    mFileSystem.setAttribute(new AlluxioURI("/bucket0"), setAttributeOptions);
    URIStatus bucket0Status = fs1.getStatus(bucketPath);
    subject = new Subject();
    subject.getPrincipals().add(new User("user1"));
    AlluxioURI bucket1Path = new AlluxioURI("/bucket1");
    FileSystem fs2 = sResource.get().getClient(FileSystemContext.create(subject, ServerConfiguration.global()));
    fs2.createDirectory(bucket1Path);
    setAttributeOptions = SetAttributePOptions.newBuilder().setOwner("user1").build();
    mFileSystem.setAttribute(new AlluxioURI("/bucket1"), setAttributeOptions);
    URIStatus bucket1Status = fs2.getStatus(bucket1Path);
    ListAllMyBucketsResult expected = new ListAllMyBucketsResult(Collections.emptyList());
    final TestCaseOptions requestOptions = TestCaseOptions.defaults().setContentType(TestCaseOptions.XML_CONTENT_TYPE);
    new TestCase(mHostname, mPort, S3_SERVICE_PREFIX + "/", NO_PARAMS, HttpMethod.GET, expected, requestOptions).run();
    expected = new ListAllMyBucketsResult(Lists.newArrayList(bucket0Status));
    requestOptions.setAuthorization("AWS4-HMAC-SHA256 Credential=user0/20210631");
    new TestCase(mHostname, mPort, S3_SERVICE_PREFIX + "/", NO_PARAMS, HttpMethod.GET, expected, requestOptions).run();
    expected = new ListAllMyBucketsResult(Lists.newArrayList(bucket1Status));
    requestOptions.setAuthorization("AWS4-HMAC-SHA256 Credential=user1/20210631");
    new TestCase(mHostname, mPort, S3_SERVICE_PREFIX + "/", NO_PARAMS, HttpMethod.GET, expected, requestOptions).run();
}
Also used : User(alluxio.security.User) SetAttributePOptions(alluxio.grpc.SetAttributePOptions) Mode(alluxio.security.authorization.Mode) FileSystem(alluxio.client.file.FileSystem) URIStatus(alluxio.client.file.URIStatus) ListAllMyBucketsResult(alluxio.proxy.s3.ListAllMyBucketsResult) Subject(javax.security.auth.Subject) AlluxioURI(alluxio.AlluxioURI) Test(org.junit.Test)

Example 13 with User

use of alluxio.security.User in project alluxio by Alluxio.

the class UserStateTest method getCustomLoginUserProvidedByApp.

/**
 * Tests whether we can get login user with conf in CUSTOM mode, when user name is provided by
 * the application through configuration.
 */
@Test
public void getCustomLoginUserProvidedByApp() throws Exception {
    mConfiguration.set(PropertyKey.SECURITY_AUTHENTICATION_TYPE, AuthType.CUSTOM.getAuthName());
    mConfiguration.set(PropertyKey.SECURITY_LOGIN_USERNAME, "alluxio-user");
    UserState s = UserState.Factory.create(mConfiguration);
    User loginUser = s.getUser();
    assertNotNull(loginUser);
    assertEquals("alluxio-user", loginUser.getName());
}
Also used : User(alluxio.security.User) Test(org.junit.Test)

Example 14 with User

use of alluxio.security.User in project alluxio by Alluxio.

the class UserStateTest method getCustomLoginUser.

/**
 * Tests whether we can get login user with conf in CUSTOM mode.
 */
@Test
public void getCustomLoginUser() throws Exception {
    mConfiguration.set(PropertyKey.SECURITY_AUTHENTICATION_TYPE, AuthType.CUSTOM.getAuthName());
    UserState s = UserState.Factory.create(mConfiguration);
    User loginUser = s.getUser();
    assertNotNull(loginUser);
    assertEquals(System.getProperty("user.name"), loginUser.getName());
}
Also used : User(alluxio.security.User) Test(org.junit.Test)

Example 15 with User

use of alluxio.security.User in project alluxio by Alluxio.

the class UserStateTest method getSimpleLoginUserListProvidedByApp.

/**
 * Tests whether we can get login user with conf in SIMPLE mode, when a user list is provided by
 * by the application through configuration.
 */
@Test
public void getSimpleLoginUserListProvidedByApp() throws Exception {
    mConfiguration.set(PropertyKey.SECURITY_AUTHENTICATION_TYPE, AuthType.SIMPLE.getAuthName());
    mConfiguration.set(PropertyKey.SECURITY_LOGIN_USERNAME, "alluxio-user, superuser");
    UserState s = UserState.Factory.create(mConfiguration);
    User loginUser = s.getUser();
    // The user list is considered as a single user name.
    assertNotNull(loginUser);
    assertEquals("alluxio-user, superuser", loginUser.getName());
}
Also used : User(alluxio.security.User) Test(org.junit.Test)

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