Home » apache-openwebbeans-1.0.0-incubating-M3-binary » org.apache.webbeans.sample » bean » [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.sample.bean;
   18   
   19   
   20   import javax.enterprise.context.RequestScoped;
   21   import javax.enterprise.context.SessionScoped;
   22   import javax.enterprise.event.Event;
   23   import javax.enterprise.event.Observes;
   24   import javax.enterprise.inject.Any;
   25   import javax.enterprise.inject.Default;
   26   import javax.inject.Inject;
   27   import javax.inject.Named;
   28   import javax.enterprise.inject.Produces;
   29   import javax.faces.application.FacesMessage;
   30   
   31   import org.apache.webbeans.sample.bindings.LoggedInUser;
   32   import org.apache.webbeans.sample.dependent.LoginCheck;
   33   import org.apache.webbeans.sample.event.LoggedInEvent;
   34   import org.apache.webbeans.sample.model.User;
   35   import org.apache.webbeans.sample.util.FacesMessageUtil;
   36   
   37   @RequestScoped
   38   @Named
   39   public class LoginBean
   40   {
   41   	private User user = null;
   42   	
   43   	private String userName;
   44   	
   45   	private String password;
   46   	
   47   	private @Inject @Default LoginCheck loginCheck;
   48   	
   49   	private @Inject @Default FacesMessageUtil messageUtil;
   50   	
   51   	private @Inject @Any Event<LoggedInEvent> event;
   52   	
   53   	public LoginBean()
   54   	{
   55   		
   56   	}
   57   	
   58   	public String login()
   59   	{
   60   		if(loginCheck.checkLogin(this.userName, this.password))
   61   		{
   62   			user = new User();
   63   			user.setUserName(this.userName);
   64   			user.setPassword(this.password);
   65   			
   66   			event.fire(new LoggedInEvent(this.user));
   67   			
   68   			return "loginSuccess";
   69   		}
   70   		else
   71   		{
   72   			messageUtil.addMessage(FacesMessage.SEVERITY_ERROR, "Login Failed", "Login failed");
   73   			return null;
   74   		}
   75   	}
   76   	
   77   	public void afterLoggedIn(@Observes LoggedInEvent event)
   78   	{
   79   		messageUtil.addMessage(FacesMessage.SEVERITY_INFO, "Login Successfull", "Login Successfull");
   80   	}
   81   	
   82   	
   83   	@Produces @SessionScoped @LoggedInUser @Named(value="currentUser")
   84   	public User getLoggedInUser()
   85   	{
   86   		return this.user;
   87   	}
   88   
   89   	/**
   90   	 * @return the userName
   91   	 */
   92   	public String getUserName()
   93   	{
   94   		return userName;
   95   	}
   96   
   97   	/**
   98   	 * @param userName the userName to set
   99   	 */
  100   	public void setUserName(String userName)
  101   	{
  102   		this.userName = userName;
  103   	}
  104   
  105   	/**
  106   	 * @return the password
  107   	 */
  108   	public String getPassword()
  109   	{
  110   		return password;
  111   	}
  112   
  113   	/**
  114   	 * @param password the password to set
  115   	 */
  116   	public void setPassword(String password)
  117   	{
  118   		this.password = password;
  119   	}
  120   	
  121   	
  122   }

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