-
Notifications
You must be signed in to change notification settings - Fork 79
Expand file tree
/
Copy pathAuthTest.java
More file actions
35 lines (33 loc) · 989 Bytes
/
Copy pathAuthTest.java
File metadata and controls
35 lines (33 loc) · 989 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
package auth;
import java.security.*;
import javax.security.auth.*;
import javax.security.auth.login.*;
/**
* This program authenticates a user via a custom login and then executes the SysPropAction with the
* user's privileges.
* @version 1.01 2007-10-06
* @author Cay Horstmann
*/
public class AuthTest
{
public static void main(final String[] args)
{
System.setSecurityManager(new SecurityManager());
try
{
LoginContext context = new LoginContext("Login1");
context.login();
System.out.println("Authentication successful.");
Subject subject = context.getSubject();
System.out.println("subject=" + subject);
PrivilegedAction<String> action = new SysPropAction("user.home");
String result = Subject.doAsPrivileged(subject, action, null);
System.out.println(result);
context.logout();
}
catch (LoginException e)
{
e.printStackTrace();
}
}
}