@Override
    public void initialize(Subject subject, CallbackHandler callbackHandler,
                           Map sharedState, Map options) {
        this.subject = subject;
        this.callbackHandler = callbackHandler;
        this.sharedState = sharedState;
        this.options = options;
        log = Logger.getLogger(getClass());
        log.trace("initialize");


        // Check for a custom Principal implementation
        principalClassName = (String) options.get("principalClass");


        String passwordStacking = (String) options.get("password-stacking");
        if (passwordStacking != null && passwordStacking.equalsIgnoreCase("useFirstPass"))
            useFirstPass = true;


        // Check for unauthenticatedIdentity option.
        String name = (String) options.get("unauthenticatedIdentity");
        if (name != null) {
            try {
                unauthenticatedIdentity = createIdentity(name);
                log.trace("Saw unauthenticatedIdentity=" + name);
            } catch (Exception e) {
                log.warn("Failed to create custom unauthenticatedIdentity", e);
            }
        }

        String kdc = (String) options.get("kdc");
        if (kdc != null) {
            log.trace("Setting KDC to =" + kdc);
            System.setProperty("java.security.krb5.kdc", kdc);
        }

        String realm = (String) options.get("realm");
        if (realm != null) {
            log.trace("Setting Kerberos Realm to =" + realm);
            System.setProperty("java.security.krb5.kdc", kdc);
            System.setProperty("java.security.krb5.realm", realm);
        }

    }