JAAS at a glance

JAAS at a glance
JAAS generally has the following two steps:
1, Authentication: define principals,  implement LoginModule and callback handler, associate designated principals with the subject object in the commit method of LoginModule implementation, configure the module implementation in a login configuration file, i.e
Sample {
   sample.module.SampleLoginModule required debug=true;
};

lc = new LoginContext("Sample", new MyCallbackHandler());
Subject s = lc.getSubject();
Subject.doAs(s, new PrivilegedAction(){...}); // the authenticated subject s will be associated with the current access control context.

2. Authorization: write policy file to grant principals access right to any critical resources. e.g.
grant
        Principal sample.principal.SamplePrincipal "testUser" {

   permission java.util.PropertyPermission "java.home", "read";
   permission java.util.PropertyPermission "user.home", "read";
   permission java.io.FilePermission "foo.txt", "read";
};

你可能感兴趣的:(JAAS at a glance)