IServerContext interface
The IServerContext interface provides a way to access NAS-specific server interfaces from within servlets or EJBs. From servlets, the standard servlet context can be cast to an IServerContext object. From EJBs, a javax.ejb.EJBContext object can be cast to an IServerContext.
IServerContext is often used together with the ICallerContext interface.
Package
com.netscape.server
Methods
Related Topics
com.kivasoft.applogic.AppLogic class (deprecated), com.kivasoft.dlm.GXContext class, com.kivasoft.IContext interface, com.netscape.server.ICallerContext interface,
javax.ejb.EJBContext interface
Writing Secure Applications
createIdentityByString( )
Creates an instance of java.security.Identity.
Syntax
public java.security.Identity createIdentityByString(
String identity)
identity.
The name to associate with the Identity object.
Usage
Neither of the specifications for servlets and EJBs describe a standard way of creating an instance of java.security.Identity. The createIdentityByString( ) method overcomes this limitation. Use this method to create an Identity instance within a NAS 4.0 application.
Once you create the Identity, you can then (for example) pass it to a subsequent test for equality or use it as the role parameter of the isCallerInRole( ) method. The isCallerInRole( ) method is available in both javax.ejb.EJBContext and com.netscape.server.ICallerContext.
Return Value
A java.security.Identity object with the given name.
getCallerContext( )
Retrieves the com.netscape.server.ICallerContext object.
Syntax
public ICallerContext getCallerContext()
Usage
Use this method within servlets to identify the caller context.
Currently, the Servlet API specification provides no way to obtain the caller's principal from within a servlet. By contrast, the EJB specification defines the javax.ejb.EJBContext.getCallerPrincipal( ) method.
The getCallerContext( ) method is provided to add support for programmatic security from servlets. However, after this support is added to the Servlet API specification, the getCallerContext( ) method will be deprecated.
Return Value
The ICallerContext object that identifies the caller context within the servlet.
getContext( )
Retrieves the com.kivasoft.IContext object.
Syntax
public com.kivasoft.IContext getContext()
Usage
Use this method within servlets or EJBs. The getContext( ) method lets you access NAS-specific application modules or extensions that run in a pre-NAS-4.0 environment.
The retrieved IContext object is the old NAS 2.x style context. The getContext( ) method is especially useful when combined with the functions from the com.kivasoft.dlm.GXContext class.
Example
Assume you have declared the following bean member variable containing SessionContext:
public transient javax.ejb.SessionContext m_ctx = null;
The following sample code shows a bean implementation method that needs to invoke some NAS 2.x functionality:
public invokeKivaMethod()
{
// obtain 2.x style KIVA context from standard bean context
com.netscape.server.IServerContext sc;
// cast the standard servlet context or bean context
// to IServerContext
sc = (com.netscape.server.IServerContext) m_ctx;
// acquire 2.x style context
com.kivasoft.IContext gxContext = sc.getContext();
// Use the context with GXContext class to access 2.x functionality.
// In this case, choose a logging operation
com.kivasoft.dlm.GXContext.Log(
gxContext,
com.kivasoft.types.GXLOG.GXEVENTTYPE_INFORMATION,
-1,
"Send this informational message to server log");
...
Return Value
The IContext object that identifies the context within the servlet or EJB.
|