FileDocCategorySizeDatePackage
SecurityInitializerImpl.javaAPI DocphoneME MR2 API (J2ME)4108Wed May 02 18:00:26 BST 2007com.sun.midp.security

SecurityInitializerImpl

public class SecurityInitializerImpl extends Object
The class implements security initializer logic common for core subsystems and for optional JSRs. Using this implmentation JSRs can easily introduce own security initializers for redispatching security tokens within JSR subsystem.

Fields Summary
SecurityToken
internalSecurityToken
Internal security token
private String[]
trustedClasses
List of trusted class names
private int
trustedStart
Index of the first trusted name in the list
Constructors Summary
public SecurityInitializerImpl(SecurityToken token, String[] trusted)
Create instance of SecurityInitializerImpl with a given token and list of trusted class names

param
token security token to hold
param
trusted names of trusted classes

        internalSecurityToken = token;
        trustedClasses = trusted;
    
Methods Summary
booleanisTrusted(java.lang.Object object)
Check whether object is the instance of a trusted class, that means the object owner has the right to request for a security token. The optimized implementation for this method can be provided in VM specific way. Note, the implementation allows only single request for SecurityToken for each trusted class, the class is removed from the trusted list after token hand out.

param
object instance of the trusted class known to the initializer
return
true if the object belongs to trusted class, false otherwise


                                                                                             
       
        if (trustedClasses != null) {
            String className = object.getClass().getName();

            // IMPL_NOTE: Optimize search for trusted class name
            for (int i=trustedStart; i<trustedClasses.length; i++) {
                if (className.equals(trustedClasses[i])) {
                    // Free name of the used trusted class and
                    // move forward the first name index
                    if (trustedStart != i) {
                        trustedClasses[i] =
                            trustedClasses[trustedStart];
                    }
                    trustedClasses[trustedStart] = null;
                    trustedStart++;
                    return true;
                }
            }
        }
        return false;
    
public SecurityTokenrequestToken(ImplicitlyTrustedClass trusted)
Request security token using trusted object instance. Note that the imposibility to create trusted objects for untrusted requesters is the only guarantee of secure tokens dispatching.


        if (!isTrusted(trusted)) {
            throw new SecurityException(
                "Failed request for SecurityToken by " +
                    trusted.getClass().getName());
        }
        // Grant internal security token to trusted requester
        return internalSecurityToken;