forked from hacker85/JavaLessons
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUserAuthLesson.java
More file actions
31 lines (28 loc) · 1.08 KB
/
UserAuthLesson.java
File metadata and controls
31 lines (28 loc) · 1.08 KB
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
package security;
import javax.security.auth.Subject;
import javax.security.auth.login.LoginContext;
import javax.security.auth.login.LoginException;
import java.security.PrivilegedAction;
/**
* Created by max on 2/16/17.
*/
public class UserAuthLesson {
public static void main(String[] args) throws LoginException {
System.setProperty("java.security.policy", "src/MyApp.policy");
System.setProperty("java.security.auth.login.config", "src/jaas.config");
System.setSecurityManager(new SecurityManager());
//System.out.println(System.getProperty("os.name"));
LoginContext context = new LoginContext("Login1"); // defined in JAAS configuration file
context.login();
Subject subject = context.getSubject();
System.out.println("user is auth");
Subject.doAsPrivileged(subject, new PrivilegedAction<Object>() {
@Override
public Object run() {
System.out.println(System.getProperty("os.name"));
return null;
}
}, null);
context.logout();
}
}