<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    posts - 23,comments - 12,trackbacks - 0
    More than ever before, corporations are clamoring to evaluate their security architectures and identify any gaps. The Java platform, and specifically the J2EE platform, provides some of the most robust application-level security available today. The Java Authentication and Authorization Service (JAAS), which was introduced as an optional security package for the Java 2 SDK, Standard Edition, version 1.3, has been formally included as a part of the standard Java packages as of version 1.4.

    This 10-Minute Solution provides a brief introduction to the JAAS (pronounced "Jazz") architecture, API, and programming model. It covers both authentication and authorization with JAAS, providing full working code examples that demonstrate JAAS security in action.



    How do I implement security, one of the most important aspects of today's software applications, into my Java environment when most security implementations are inflexible, proprietary systems?



    The Java Authentication and Authorization Service (JAAS) is a flexible, standardized API that supports runtime pluggability of security modules.

    What Is JAAS?
    According to Sun's Web site, "The Java Authentication and Authorization Service (JAAS) is a set of packages that enables services to authenticate and enforce access controls upon users. It implements a Java version of the standard Pluggable Authentication Module (PAM) framework, and supports user-based authorization."

    In practice, JAAS represents the new Java security standard, as it has formally been added to the JDK 1.4 code base. From an architectural standpoint, JAAS implements a Java version of the Pluggable Authentication Module (PAM) framework. First released in May 2000 by The PAM Forum, the framework is a modularized architecture designed to support the seamless exchange of one security protocol component for another. The framework allows multiple authentication technologies and/or authentication approaches to be added without changing or interfering with any of the existing login services. PAM can be used to integrate login services with various authentication technologies, such as RSA, DCE, Kerberos, S/Key, and even to support smart card-based authentication systems.

    Authenticating with JAAS
    JAAS authentication is deployed in a pluggable manner, using code modules that implement certain interfaces. This enables Java applications to remain decoupled from the underlying authentication technologies. Additional authentication protocols and updated authentication technologies can be plugged in at runtime without modifying the application or recompiling the source code.

    The JAAS Authentication API is quite extensive. The key interfaces and classes that you need to familiarize yourself with are as follows:

  • Callback – Implementations of this interface encapsulate information (usernames, passwords, error and warning messages) that is exchanged between security services and a CallbackHandler.
  • CallbackHandler – An application implements a CallbackHandler and passes it to underlying security services to facilitate interaction between the security services and the application.
  • LoginContext – The LoginContext class provides the basic methods used to authenticate Subjects in a neutral manner, decoupled from the underlying authentication technology.
  • LoginModule – Authentication technology providers implement this interface to provide a particular type of authentication via a pluggable module.
  • Principal – The Principal interface represents the abstract notion of a principal, which can be used to represent any unique entity (individual, corporation, organization, login id, social security number, etc.) that can be authenticated.
  • Subject – A Subject object represents a grouping of related information for a single entity, such as a person. One or more Principals are bound to a subject. Each Principal represents one identity for the subject (name, social security #, etc.). A Subject also maintains security-related attributes (passwords and cryptographic keys, for example).
  • Authorization with JAAS
    JAAS authorization is built on top of JAAS authentication. It augments the existing code-centric access controls that were introduced with the Java 2 platform (JDK 1.2.x) with new user-centric access controls. In this way, JAAS authorization allows you to grant permissions based not on just what code is running but also on who is running it.

    After a user has been authenticated by JAAS, the authorization API associates the Subject (created to represent the authenticated entity) with an appropriate access control context. Whenever the Subject attempts a restricted operation (database access, local file access, etc.), the Java runtime consults the policy file to determine which Principal(s) may perform the operation. If the Subject in question contains the designated Principal, the Java runtime allows the operation. Otherwise, it throws an exception.

    You don't need to import additional packages to access the JAAS authorization features, because JAAS authorization is built on top of JAAS authentication. In addition to the classes and interfaces used in the authentication piece, one additional interface is of interest for the simple example in this Solution:

  • PrivilegedAction – This interface defines only one member, a method named run(). It accepts no parameters and returns type Object. A class wanting to restrict access to one or more actions implements this interface and puts the calls to the restricted functions within its run() method.
  • See JAAS in Action
    Included with this Solution is a downloadable zip file that contains all the source code and class files necessary to see JAAS authentication and authorization in action.

    advertisement

    Authentication Files

  • SimpleAuth.java – This file contains the main() method. It creates a LoginContext object by passing in a LoginModule configuration id ("JAAS_Module") and an instance of the CallbackHandler interface. The LoginContext reads a configuration file, looking for the configuration ID. Upon finding a match, it instantiates the specified LoginModules. Each LoginModule is initialized with a Subject, a CallbackHandler, shared LoginModule state, and LoginModule-specific options. Finally, the login process is kicked off by calling the login() method on the LoginContext object (which is implemented by the LoginModule class).
  • SimpleJAAS.config – This file associates configuration IDs (simple text string) with LoginModules and optional properties.
  • SimpleCallbackHandler.java – This file implements the CallbackHandler interface and handles the callback events passed by the security service components.
  • SimpleLoginModule.java – This file implements the LoginModule interface and interfaces between the user and the CallbackHandler to authenticate the user. It uses two arrays to maintain the set of possible usernames and passwords. The passwords are then compared by passing a PasswordCallback instance to the SimpleCallbackHandler and using the readPassword() method defined in the SimpleCallbackHandler class.
  • SimplePrincipal.java – This file provides a bare-bones implementation of the Principal interface.

    Authorization Files

  • SimpleAuthz.java – This class is identical to the SimpleAuth.java class in all but one respect. After authenticating the user, it attempts a privileged action. To do this, the code obtains a reference to the current Subject and calls the doAsPrivileged() method from that object reference. We pass the Subject reference and an instance of the SimpleAction class into this method. The Java runtime then will take the supplied Subject reference and attempt to execute the privileged action defined within the run() method of the SimpleAction class.
  • SimpleAction.java – This class implements the PrivilegedAction interface and defines a single method, run(). It attempts to perform a few actions that are restricted to privileged users (as defined by the policy file). If the Subject has the appropriate privileges to perform these actions, the method will execute without any trouble. Otherwise, it throws an exception.
  • SimpleJAAS.policy – This file defines the activities for which permission has been granted and which code has permission to perform them (code-level access). These grant statements can further be narrowed to allow only a particular Principal (user-level access).

    To test the application, run the provided script and indicate whether you want to test just authentication ('run auth') or authentication and authorization ('run authz'). When prompted for a username and password, provide any of the following pairs:

  • guest, sesame
  • user1, pass1
  • user2, pass2

    You will receive verbose output if the debug option in the config file debug property is set to 'true'. The output will be limited if it is set to 'false'.

  • posted on 2005-08-25 13:43 my java 閱讀(940) 評論(0)  編輯  收藏 所屬分類: java身份認證轉帖
    主站蜘蛛池模板: 亚洲精品乱码久久久久久久久久久久| 香蕉视频在线观看免费国产婷婷 | 久9这里精品免费视频| 亚洲精品tv久久久久久久久久| 亚洲av成人一区二区三区在线播放| 嫩草影院免费观看| 亚洲精品9999久久久久无码 | 全黄性性激高免费视频| 国产黄在线播放免费观看| 国产jizzjizz免费视频| 亚洲高清在线视频| 久久亚洲免费视频| 亚洲色成人网一二三区| 99久久99久久精品免费看蜜桃| 亚洲精品成人a在线观看| 一二三四在线观看免费中文在线观看 | 噼里啪啦电影在线观看免费高清| 成人免费视频88| 亚洲黄色网址在线观看| 久久精品国产免费观看三人同眠| 亚洲va精品中文字幕| 中国一级毛片视频免费看| 亚洲AV无码专区亚洲AV伊甸园| 老汉精品免费AV在线播放| 久久精品国产亚洲av麻豆蜜芽| 日本一区免费电影| 黄视频在线观看免费| 亚洲国产精品婷婷久久| 可以免费看黄视频的网站| 色九月亚洲综合网| 成人毛片18女人毛片免费视频未 | 国产精品免费视频一区| 亚洲熟妇自偷自拍另欧美| 亚洲а∨天堂久久精品| 国产免费无码AV片在线观看不卡| 亚洲午夜久久久久久尤物| 在线a亚洲v天堂网2018| 亚洲国产精品美女久久久久| 亚洲黄黄黄网站在线观看| 91人成网站色www免费下载| 相泽南亚洲一区二区在线播放|