/*
 * JBoss, Home of Professional Open Source
 *
 * Distributable under LGPL license.
 * See terms of license at gnu.org.
 */
package org.jboss.ejb3.test.security;

import java.security.Principal;

import javax.annotation.EJB;
import javax.annotation.EJBs;
import javax.annotation.Resource;
import javax.annotation.security.RolesAllowed;
import javax.ejb.CreateException;
import javax.ejb.Remote;
import javax.ejb.SessionBean;
import javax.ejb.SessionContext;
import javax.ejb.Stateless;

import org.jboss.annotation.ejb.RemoteBinding;
import org.jboss.annotation.security.SecurityDomain;

/** An implmentation of the Session interface that should not
be accessible by external users.

@author Scott.Stark@jboss.org
@version $Revision: 1.1.2.2 $ 
*/
@Stateless(name="PrivateSession")
@Remote(org.jboss.ejb3.test.security.Session.class)
@RemoteBinding(jndiBinding = "spec.PrivateSession")
@SecurityDomain("spec-test")
@RolesAllowed({"InternalUser"})
public class PrivateSessionBean
{
   @Resource SessionContext sessionContext;

    public String echo(String arg)
    {
        System.out.println("PrivateSessionBean.echo, arg="+arg);
        Principal p = sessionContext.getCallerPrincipal();
        System.out.println("PrivateSessionBean.echo, callerPrincipal="+p);
        System.out.println("PrivateSessionBean.echo, isCallerInRole('InternalUser')="+sessionContext.isCallerInRole("InternalUser"));
        return arg;
    }
    public void noop() 
    {
        System.out.println("PrivateSessionBean.noop");
        Principal p = sessionContext.getCallerPrincipal();
        System.out.println("PrivateSessionBean.noop, callerPrincipal="+p);
    }
    public void restricted() 
    {
        System.out.println("PrivateSessionBean.restricted");
        Principal p = sessionContext.getCallerPrincipal();
        System.out.println("PrivateSessionBean.restricted, callerPrincipal="+p);
    }
}
