php How to use Java JAAS actual production point registration guide. In the main text, we have a general introduction to JAAS, how to arrange and use JAAS, and since then, there are various items in the middle of the use technique. If you are a beginner, you will not be able to read the text.
Single sign-on (SSO) is a mechanism that allows you to use the same username and password to log in to multiple applications. JAAS allows you to use various methods to configure SSO. The most common method is to use Kerberos. Kerberos is a distributed authentication system for authenticating users on a network. Kerberos allows users to log in once and access all other applications within the same Kerberos domain.
The authentication and authorization process using JAAS consists of the following steps:
The code example below is the code to authenticate a user using JAAS.
import javax.security.auth.Subject; import javax.security.auth.login.LoginContext; public class JAASAuthentication { public static void main(String[] args) { // ログインコンテキストを作成します。 LoginContext loginContext = new LoginContext("LoginModule"); // ログインします。 loginContext.login(); // サブジェクトを取得します。 Subject subject = loginContext.getSubject(); // サブジェクトに含まれるプリンシパルをすべて表示します。 for (Principal principal : subject.getPrincipals()) { System.out.println(principal.getName()); } // ログアウトします。 loginContext.loGout(); } }
The following code example uses JAAS to obtain user authorization information.
import javax.security.auth.Subject; import javax.security.auth.login.LoginContext; import javax.security.auth.authorization.Policy; import javax.security.auth.authorization.PolicyProvider; public class JAASAuthorization { public static void main(String[] args) { // ログインコンテキストを作成します。 LoginContext loginContext = new LoginContext("LoginModule"); // ログインします。 loginContext.login(); // サブジェクトを取得します。 Subject subject = loginContext.getSubject(); // ポリシープロバイダーを取得します。 PolicyProvider policyProvider = PolicyProvider.getPolicyProvider(); // ポリシーを取得します。 Policy policy = policyProvider.getPolicy(subject, null); // ポリシーに含まれるパーミッションをすべて表示します。 for (Permission permission : policy.getPermissions()) { System.out.println(permission.getName()); } // ログアウトします。 loginContext.logout(); } }
The above is the detailed content of A guide to implementing single sign-on with Java JAAS. For more information, please follow other related articles on the PHP Chinese website!