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

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

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

    Sealyu

    --- 博客已遷移至: http://www.sealyu.com/blog

      BlogJava :: 首頁 :: 新隨筆 :: 聯(lián)系 :: 聚合  :: 管理 ::
      618 隨筆 :: 87 文章 :: 225 評(píng)論 :: 0 Trackbacks

    原帖地址:http://odyssi.blogspot.com/2008/01/intro-to-jboss-seam-security-part-1.html

    Intro to JBoss Seam Security, Part 1 - Authentication

    Recently, I mentioned how I had just started working with the JBoss Seam application framework. The more I have worked with it, the more impressed I have become at how it makes things that are typically difficult using standard Java EE much simpler and more streamlined. One of the areas in which Seam really shines is security. While Java EE defines JAAS for use in securing applications, it is left up to the developer to ingrain this security down to each facet of the application. With Seam, it is easy to define security constraints at all levels of an application, simply through using annotations. In addition, the complexity of authenticating users with JAAS is reduced through Seam's authenticator mechanism. This article will give an introduction to Seam authentication, and show how to write your own custom authenticator.

    Seam's authenticator construct hides the complexity of managing a JAAS configuration, and allows you to implement authentication how you see fit. Perhaps your organization relies on a simple username/password combination for authenticating user accounts in LDAP. Maybe you use a SecureID token, and the accounts are stored in a SQL database. By writing your own authenticator class, or making use of publicly available ones, you can control the way authentication is done in your organization.

    To get started with your own authenticator, you must first declare it in the components.xml file. This file manages much of the configuration for Seam. To add your authenticator, you simply define the class and method that will be used for authentication. For example:

    1. <components xmlns="http://jboss.com/products/seam/components"  
    2.      xmlns:core="http://jboss.com/products/seam/core"  
    3.      xmlns:security="http://jboss.com/products/seam/security"  
    4.      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
    5.      xsi:schemaLocation=  
    6.          "http://jboss.com/products/seam/components http://jboss.com/products/seam/components-2.0.xsd  
    7.           http://jboss.com/products/seam/security http://jboss.com/products/seam/security-2.0.xsd">           
    8.   
    9. <security:identity method="#{authenticator.authenticate}">  
    10.   
    11. </components>  


    You'll notice the #{} syntax used here. This is JBoss' expression language pointing to a class with the instance name of authenticator, where the authenticate method will be used to login a user. Now that we have declared an authenticator to Seam, we're ready to implement it. Our example will be quite simple. If the user enters a username of admin, with a password of password, they will be authenticated successfully. In addition, we will assign them to the role of admin, so that they can perform some sort of administrative function within our application. The implementation of our authenticator would look like this:

    1. @Name("authenticator")  
    2. public class Authenticator {  
    3.   
    4. private static final String valid_user = "admin";  
    5. private static final String valid_password = "password";  
    6.   
    7. public boolean authenticate() {  
    8. String username = Identity.instance().getUsername();  
    9. String password = Identity.instance().getPassword();  
    10.   
    11. if((username.equals(valid_user)) && (password.equals(valid_password))) {  
    12.      return true;  
    13. }  
    14.   
    15. return false;  
    16. }  
    17.   
    18. }  
    Our example is rather trivial. However, it gives a slight glimpse into how Seam authentication works. The first thing that you should notice is the @Name annotation. This annotation prompts Seam to create a bean with the name specified in the annotation. In this case, the name is authenticator, which is how we arrive at the value specified in our components.xml file. Our authenticate method will return true if authentication was successful, and false otherwise.

    So how does the authenticate method get the username and password? This is done via the Identity class. The standard Identity class that comes with Seam is quite extensive, but basically provides support for a username/password combination. It is possible to subclass Identity, however, to support whatever authentication mechanisms you may need. You could implement code to support getting a SecureID token value from a user, or a SPNEGO ticket. All that is needed to make use of the Identity subclass is to add the following annotations to your implementation:

    1. @Name("org.jboss.seam.security.identity")  
    2. @Scope(SESSION)  
    3. @Install(precedence = APPLICATION)  
    4. @BypassInterceptors  
    5. @Startup  
    6. public class MyCustomIdentity extends Identity  
    7. { ... }  

    Your custom Identity subclass is now ready for use.

    Now that we have our authentication classes in place, we are ready to create our login form. This is trivial to create using Seam, particularly because of Seam's use of the JBoss expression language in forms. Our login form fragment would look like the following:

    1. <div>  
    2.    <h:outputlabel for="name" value="Username">  
    3.    <h:inputtext id="name" value="#{identity.username}">  
    4. </div>  
    5.   
    6. <div>  
    7.    <h:outputlabel for="password" value="Password">  
    8.    <h:inputsecret id="password" value="#{identity.password}">  
    9. </div>  
    10.   
    11. <div>  
    12.    <h:commandbutton value="Login" action="#{identity.login}">  
    13. </div>  


    That's all there is to it. You are now ready to authenticate users via your own custom login form and authenticator. While this is an introduction to the simplified form of authentication in Seam, it should give you a good foundation to learn and explore on your own.

    Next time, we will look at how authentication is used throughout an application, not just at the entry point.

    Posted by WhoAmI? at 11:59 AM  

    posted on 2009-04-23 15:36 seal 閱讀(350) 評(píng)論(0)  編輯  收藏 所屬分類: Seam
    主站蜘蛛池模板: 亚洲AV无码之日韩精品| 一级黄色片免费观看| 国产乱码免费卡1卡二卡3卡| 亚洲综合男人的天堂色婷婷| 91九色老熟女免费资源站| 99久久亚洲精品无码毛片 | **一级一级毛片免费观看| 亚洲AV人人澡人人爽人人夜夜| 99re6热视频精品免费观看 | 亚洲v高清理论电影| 成人免费无码大片A毛片抽搐| 国产青草亚洲香蕉精品久久 | 在线观看免费国产视频| 中文字幕精品亚洲无线码二区| 黄色免费在线观看网址| 久久久久亚洲精品影视| 波多野结衣在线免费视频| 亚洲精品无码不卡在线播放| 无码日韩精品一区二区免费| 亚洲乱人伦精品图片| 妞干网免费视频在线观看| 色九月亚洲综合网| 亚洲国产精品无码久久久久久曰| 一级毛片大全免费播放下载 | 8x网站免费入口在线观看| 亚洲国产日韩在线一区| 青青草国产免费久久久下载| 亚洲成a人无码亚洲成www牛牛| 亚洲?V无码成人精品区日韩| 国产真人无码作爱免费视频| 亚洲视频一区在线播放| 日韩免费视频播播| 最近中文字幕大全免费版在线 | **毛片免费观看久久精品| 亚洲国产无线乱码在线观看| 亚洲情a成黄在线观看| 亚洲黄色免费电影| 男女作爱免费网站| 亚洲欧洲中文日产| 亚洲黄黄黄网站在线观看| 97在线视频免费播放|