Home » apache-openwebbeans-1.0.0-incubating-M3-binary » org.apache.webbeans.reservation » beans » [javadoc | source]

    1   /*
    2    *  Licensed to the Apache Software Foundation (ASF) under one or more
    3    *  contributor license agreements.  See the NOTICE file distributed with
    4    *  this work for additional information regarding copyright ownership.
    5    *  The ASF licenses this file to You under the Apache License, Version 2.0
    6    *  (the "License"); you may not use this file except in compliance with
    7    *  the License.  You may obtain a copy of the License at
    8    * 
    9    *       http://www.apache.org/licenses/LICENSE-2.0
   10    * 
   11    *  Unless required by applicable law or agreed to in writing, software
   12    *  distributed under the License is distributed on an "AS IS" BASIS,
   13    *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   14    *  See the License for the specific language governing permissions and
   15    *  limitations under the License.
   16    */
   17   package org.apache.webbeans.reservation.beans;
   18   
   19   import javax.enterprise.context.RequestScoped;
   20   import javax.enterprise.event.Event;
   21   import javax.enterprise.inject.Any;
   22   import javax.inject.Inject;
   23   import javax.inject.Named;
   24   
   25   import org.apache.commons.validator.GenericValidator;
   26   import org.apache.webbeans.reservation.bindings.DatabaseLogin;
   27   import org.apache.webbeans.reservation.controller.LoginController;
   28   import org.apache.webbeans.reservation.entity.User;
   29   import org.apache.webbeans.reservation.events.LoggedInEvent;
   30   import org.apache.webbeans.reservation.util.JSFUtility;
   31   
   32   /**
   33    * Contains login related managed bean functionality.
   34    */
   35   @RequestScoped
   36   @Named
   37   public class LoginBean
   38   {
   39       /**User name*/
   40       private String userName;
   41       
   42       /**Password*/
   43       private String password;
   44   
   45       /**Inject of the event instance*/
   46       private @Inject @Any Event<LoggedInEvent> loggedInEvent;
   47       
   48       /**Database related login controller*/
   49       private @Inject @DatabaseLogin LoginController loginController;
   50   
   51       /**
   52        * Check user login.
   53        * 
   54        * @return navigation result
   55        */
   56       public String login()
   57       {
   58           if(GenericValidator.isBlankOrNull(userName) || GenericValidator.isBlankOrNull(password))
   59           {
   60               JSFUtility.addErrorMessage("User name and password fields can not be empty", "");
   61               
   62               return null;
   63           }
   64           
   65           User result = loginController.checkLogin(userName, password);
   66           
   67           if(result == null)
   68           {
   69               JSFUtility.addErrorMessage("Login failed!,User name or password is not correct. Try again!", "");
   70               
   71               return null;
   72           }
   73           
   74           User user = result;
   75           
   76           //Fire Event
   77           LoggedInEvent event = new LoggedInEvent(user);
   78           loggedInEvent.fire(event);
   79           
   80           
   81           if(user.isAdmin())
   82           {
   83               return "adminHome";
   84           }
   85           
   86           return "userHome";
   87       }
   88       
   89       /**
   90        * Check user logout.
   91        * 
   92        * @return navigation result
   93        */
   94       public String logout()
   95       {
   96           return null;
   97       }
   98   
   99       /**
  100        * @return the userName
  101        */
  102       public String getUserName()
  103       {
  104           return userName;
  105       }
  106   
  107       /**
  108        * @param userName the userName to set
  109        */
  110       public void setUserName(String userName)
  111       {
  112           this.userName = userName;
  113       }
  114   
  115       /**
  116        * @return the password
  117        */
  118       public String getPassword()
  119       {
  120           return password;
  121       }
  122   
  123       /**
  124        * @param password the password to set
  125        */
  126       public void setPassword(String password)
  127       {
  128           this.password = password;
  129       }
  130       
  131       
  132   }

Home » apache-openwebbeans-1.0.0-incubating-M3-binary » org.apache.webbeans.reservation » beans » [javadoc | source]