Package org.cafesip.jiplet

Source Code of org.cafesip.jiplet.JipletRequest

/*
* Created on Nov 16, 2004
*
  * Copyright 2005 CafeSip.org
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*  http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package org.cafesip.jiplet;

import java.security.Principal;

import javax.sip.RequestEvent;

import org.cafesip.jiplet.sip.SipCommunicator;

/**
* This class conatins methods that is used by a jiplet to retrieve information about a request event.
* When a SIP request message is received, the container passes on the request event to the
* jiplets matching the specified selection criteria. The callback method Jiplet.processRequest()
* is called by the container. This object is passed as a parameter.  
*
* @author Amit Chatterjee
*
*/
public class JipletRequest extends JipletEvent
{
    private RequestEvent requestEvent;
    private Principal userPrincipal;
    private String[] roles;
    private Jiplet jiplet;
   
    /**
     *  A constructor for this class.
     *
     * 
     */
    protected JipletRequest()
    {       
    }
   
   
    /**
     * @return Returns the requestEvent. The RequestEvent is a JAIN-SIP object that contains
     * the event information including the parsed request message.
     */
    public RequestEvent getRequestEvent()
    {
        return requestEvent;
    }
   
    /**
     * @param requestEvent The requestEvent to set.
     */
    protected void setRequestEvent(RequestEvent requestEvent)
    {
        this.requestEvent = requestEvent;
    }
   
    /**
     * Get the session object associated with this request. A session identifies the SIP endpoint (UAC).
     * Session-scope variables are supported similar to servlets and this object is used for storing
     * session-scope variables.
     *
     * @param create
     *     create the session object if it does not exist.
     *
     * @return the session object. Null if the create parameter is false and the session object does not
     * exist.
     */
    public JipletSession getSession(boolean create)
    {
        return super.getSession(requestEvent.getRequest(), create);
    }   
   
    /**
     * @return Returns the userPrincipal. A null is returned if the user has not been authenticated.
     */
    public Principal getUserPrincipal()
    {
        return userPrincipal;
    }
    /**
     * @param userPrincipal The userPrincipal to set.
     */
    protected void setUserPrincipal(Principal userPrincipal)
    {
        this.userPrincipal = userPrincipal;
    }
   
    /**
     * Returns a boolean indicating whether the authenticated user is included in the specified logical "role".
     * Roles and role membership can be defined using deployment descriptors.
     * If the user has not been authenticated, the method returns false.
     *
     * @param role a String specifying the name of the role
     * @return a boolean indicating whether the user making this request belongs to a given role;
     *             false if the user has not been authenticated
     */
    public boolean isUserInRole(String role)
    {
        if (roles == null)
        {
            return false;
        }
       
        for (int i = 0; i < roles.length; i++)
        {
            if (role.equals(roles[i]) == true)
            {
                return true;
            }
        }
        return false;
    }
   
    /**
     * @param roles The roles to set.
     */
    protected void setRoles(String[] roles)
    {
        this.roles = roles;
    }
   
    /**
     * @return Returns the jiplet.
     */
    public Jiplet getJiplet()
    {
        return jiplet;
    }
    /**
     * @param jiplet The jiplet to set.
     */
    protected void setJiplet(Jiplet jiplet)
    {
        this.jiplet = jiplet;
    }
   
    /**
     * This method returns a SIP communicator object which can be used to proxy SIP requests, responses,
     * handle proxy timeouts as well as other SIP-related operations.
     * @return
     */
    public SipCommunicator getSipCommunicator()
    {
        return new SipCommunicator(jiplet, requestEvent);
    }
}
TOP

Related Classes of org.cafesip.jiplet.JipletRequest

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.