當前位置: 首頁>>代碼示例>>Java>>正文


Java CallbackHandler類代碼示例

本文整理匯總了Java中javax.security.auth.callback.CallbackHandler的典型用法代碼示例。如果您正苦於以下問題:Java CallbackHandler類的具體用法?Java CallbackHandler怎麽用?Java CallbackHandler使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


CallbackHandler類屬於javax.security.auth.callback包,在下文中一共展示了CallbackHandler類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: initialize

import javax.security.auth.callback.CallbackHandler; //導入依賴的package包/類
@Override
public void initialize(Subject subject,
        CallbackHandler handler,
        Map<String, ?> sharedState,
        Map<String, ?> options) {
    this.subject = subject;
    this.handler = handler;
    this.options = options;

    String debugOption = (String) this.options.get("debug");
    if (debugOption != null && "true".equalsIgnoreCase(debugOption)) {
        debug = true;
    }

    attributes = new HashMap<String, Set<String>>();

    if (debug) {
        logger.debug("login module initialised: {}", this.getClass().getName());
    }
}
 
開發者ID:discoverygarden,項目名稱:fcrepo3-security-jaas,代碼行數:21,代碼來源:XmlUsersFileModule.java

示例2: initialize

import javax.security.auth.callback.CallbackHandler; //導入依賴的package包/類
/**
 * Initialize this <code>LoginModule</code> with the specified
 * configuration information.
 *
 * @param subject The <code>Subject</code> to be authenticated
 * @param callbackHandler A <code>CallbackHandler</code> for communicating
 *  with the end user as necessary
 * @param sharedState State information shared with other
 *  <code>LoginModule</code> instances
 * @param options Configuration information for this specific
 *  <code>LoginModule</code> instance
 */
public void initialize(Subject subject, CallbackHandler callbackHandler,
                       Map sharedState, Map options) {
    log.debug("Init");

    // Save configuration values
    this.subject = subject;
    this.callbackHandler = callbackHandler;
    this.sharedState = sharedState;
    this.options = options;

    // Perform instance-specific initialization
    if (options.get("pathname") != null)
        this.pathname = (String) options.get("pathname");

    // Load our defined Principals
    load();

}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:31,代碼來源:JAASMemoryLoginModule.java

示例3: login

import javax.security.auth.callback.CallbackHandler; //導入依賴的package包/類
/**
 * Authenticate using the login module from the specified
 * configuration entry.
 *
 * @param caller the caller of JAAS Login
 * @param mech the mech to be used
 * @return the authenticated subject
 */
public static Subject login(GSSCaller caller, Oid mech) throws LoginException {

    CallbackHandler cb = null;
    if (caller instanceof HttpCaller) {
        cb = new sun.net.www.protocol.http.spnego.NegotiateCallbackHandler(
                ((HttpCaller)caller).info());
    } else {
        String defaultHandler =
                java.security.Security.getProperty(DEFAULT_HANDLER);
        // get the default callback handler
        if ((defaultHandler != null) && (defaultHandler.length() != 0)) {
            cb = null;
        } else {
            cb = new ConsoleCallbackHandler();
        }
    }

    // New instance of LoginConfigImpl must be created for each login,
    // since the entry name is not passed as the first argument, but
    // generated with caller and mech inside LoginConfigImpl
    LoginContext lc = new LoginContext("", null, cb,
            new LoginConfigImpl(caller, mech));
    lc.login();
    return lc.getSubject();
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:34,代碼來源:GSSUtil.java

示例4: createSaslClient

import javax.security.auth.callback.CallbackHandler; //導入依賴的package包/類
/**
 * Returns a new instance of the DIGEST-MD5 SASL client mechanism.
 *
 * @throws SaslException If there is an error creating the DigestMD5
 * SASL client.
 * @returns a new SaslClient ; otherwise null if unsuccessful.
 */
public SaslClient createSaslClient(String[] mechs,
     String authorizationId, String protocol, String serverName,
     Map<String,?> props, CallbackHandler cbh)
     throws SaslException {

     for (int i=0; i<mechs.length; i++) {
        if (mechs[i].equals(myMechs[DIGEST_MD5]) &&
            PolicyUtils.checkPolicy(mechPolicies[DIGEST_MD5], props)) {

            if (cbh == null) {
                throw new SaslException(
                    "Callback handler with support for RealmChoiceCallback, " +
                    "RealmCallback, NameCallback, and PasswordCallback " +
                    "required");
            }

            return new DigestMD5Client(authorizationId,
                protocol, serverName, props, cbh);
        }
    }
    return null;
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:30,代碼來源:FactoryImpl.java

示例5: process

import javax.security.auth.callback.CallbackHandler; //導入依賴的package包/類
@Override
protected Document process(Document document) throws WSSecurityException {
    WSSecurityEngine secEngine = new WSSecurityEngine();

    WSHandlerResult results = secEngine.processSecurityHeader(document, null, 
        new CallbackHandler() {
            public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException {
                for (Callback callback : callbacks) {
                    if (callback instanceof WSPasswordCallback) {
                        ((WSPasswordCallback)callback).setPassword(getCertPassword());
                    }
                }
            }
        }, getCrypto());

    return document;
}
 
開發者ID:tilln,項目名稱:jmeter-wssecurity,代碼行數:18,代碼來源:WSSDecryptionPostProcessor.java

示例6: testLogin

import javax.security.auth.callback.CallbackHandler; //導入依賴的package包/類
public static void testLogin(String confName, char[] passwd,
        Configuration cf, boolean expectException) {
    try {
        CallbackHandler ch = new MyCallbackHandler("testUser", passwd);
        LoginContext lc = new LoginContext(confName, new Subject(),
                ch, cf);
        lc.login();
        if (expectException) {
            throw new RuntimeException("Login Test failed: "
                    + "expected LoginException not thrown");
        }
    } catch (LoginException le) {
        if (!expectException) {
            System.out.println("Login Test failed: "
                    + "received Unexpected exception.");
            throw new RuntimeException(le);
        }
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:20,代碼來源:DynamicConfigurationTest.java

示例7: initialize

import javax.security.auth.callback.CallbackHandler; //導入依賴的package包/類
/**
 * Initialize this {@code LoginModule}.
 *
 * @param subject the {@code Subject} to be authenticated.
 *
 * @param callbackHandler a {@code CallbackHandler} for communicating
 *                  with the end user (prompting for usernames and
 *                  passwords, for example),
 *                  which may be {@code null}.
 *
 * @param sharedState shared {@code LoginModule} state.
 *
 * @param options options specified in the login
 *                  {@code Configuration} for this particular
 *                  {@code LoginModule}.
 */
// Unchecked warning from (Map<String, Object>)sharedState is safe
// since javax.security.auth.login.LoginContext passes a raw HashMap.
@SuppressWarnings("unchecked")
public void initialize(Subject subject,
                       CallbackHandler callbackHandler,
                       Map<String,?> sharedState,
                       Map<String,?> options)
{
    this.subject = subject;
    this.callbackHandler = callbackHandler;
    this.sharedState = (Map<String, Object>)sharedState;
    this.options = options;

    processOptions();
    status = INITIALIZED;
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:33,代碼來源:KeyStoreLoginModule.java

示例8: login

import javax.security.auth.callback.CallbackHandler; //導入依賴的package包/類
static void login(CallbackHandler callback, Object... options)
        throws Exception {
    Krb5LoginModule krb5 = new Krb5LoginModule();
    Subject subject = new Subject();
    Map<String, String> map = new HashMap<>();
    Map<String, Object> shared = new HashMap<>();

    int count = options.length / 2;
    for (int i = 0; i < count; i++) {
        String key = (String) options[2 * i];
        Object value = options[2 * i + 1];
        if (key.startsWith("javax")) {
            shared.put(key, value);
        } else {
            map.put(key, (String) value);
        }
    }
    krb5.initialize(subject, callback, shared, map);
    krb5.login();
    krb5.commit();
    if (!subject.getPrincipals().iterator().next()
            .getName().startsWith(OneKDC.USER)) {
        throw new Exception("The authenticated is not " + OneKDC.USER);
    }
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:26,代碼來源:LoginModuleOptions.java

示例9: initialize

import javax.security.auth.callback.CallbackHandler; //導入依賴的package包/類
/**
 * Initialize this <code>LoginModule</code> with the specified
 * configuration information.
 *
 * @param subject The <code>Subject</code> to be authenticated
 * @param callbackHandler A <code>CallbackHandler</code> for communicating
 *  with the end user as necessary
 * @param sharedState State information shared with other
 *  <code>LoginModule</code> instances
 * @param options Configuration information for this specific
 *  <code>LoginModule</code> instance
 */
@Override
public void initialize(Subject subject, CallbackHandler callbackHandler,
                       Map<String,?> sharedState, Map<String,?> options) {
    log.debug("Init");

    // Save configuration values
    this.subject = subject;
    this.callbackHandler = callbackHandler;
    this.sharedState = sharedState;
    this.options = options;

    // Perform instance-specific initialization
    if (options.get("pathname") != null)
        this.pathname = (String) options.get("pathname");

    // Load our defined Principals
    load();

}
 
開發者ID:liaokailin,項目名稱:tomcat7,代碼行數:32,代碼來源:JAASMemoryLoginModule.java

示例10: createSaslServer

import javax.security.auth.callback.CallbackHandler; //導入依賴的package包/類
/**
 * Returns a new instance of the DIGEST-MD5 SASL server mechanism.
 *
 * @throws SaslException If there is an error creating the DigestMD5
 * SASL server.
 * @returns a new SaslServer ; otherwise null if unsuccessful.
 */
public SaslServer createSaslServer(String mech,
     String protocol, String serverName, Map<String,?> props, CallbackHandler cbh)
     throws SaslException {

     if (mech.equals(myMechs[DIGEST_MD5]) &&
         PolicyUtils.checkPolicy(mechPolicies[DIGEST_MD5], props)) {

            if (cbh == null) {
                throw new SaslException(
                    "Callback handler with support for AuthorizeCallback, "+
                    "RealmCallback, NameCallback, and PasswordCallback " +
                    "required");
            }

            return new DigestMD5Server(protocol, serverName, props, cbh);
     }
     return null;
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:26,代碼來源:FactoryImpl.java

示例11: DigestMD5Client

import javax.security.auth.callback.CallbackHandler; //導入依賴的package包/類
/**
   * Constructor for DIGEST-MD5 mechanism.
   *
   * @param authzid A non-null String representing the principal
   * for which authorization is being granted..
   * @param digestURI A non-null String representing detailing the
   * combined protocol and host being used for authentication.
   * @param props The possibly null properties to be used by the SASL
   * mechanism to configure the authentication exchange.
   * @param cbh The non-null CallbackHanlder object for callbacks
   * @throws SaslException if no authentication ID or password is supplied
   */
 DigestMD5Client(String authzid, String protocol, String serverName,
     Map<String, ?> props, CallbackHandler cbh) throws SaslException {

     super(props, MY_CLASS_NAME, 2, protocol + "/" + serverName, cbh);

     // authzID can only be encoded in UTF8 - RFC 2222
     if (authzid != null) {
         this.authzid = authzid;
         try {
             authzidBytes = authzid.getBytes("UTF8");

         } catch (UnsupportedEncodingException e) {
             throw new SaslException(
                 "DIGEST-MD5: Error encoding authzid value into UTF-8", e);
         }
     }

     if (props != null) {
         specifiedCipher = (String)props.get(CIPHER_PROPERTY);

         logger.log(Level.FINE, "DIGEST60:Explicitly specified cipher: {0}",
             specifiedCipher);
     }
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:37,代碼來源:DigestMD5Client.java

示例12: createSaslClient

import javax.security.auth.callback.CallbackHandler; //導入依賴的package包/類
/**
 * Returns a new instance of the DIGEST-MD5 SASL client mechanism.
 *
 * @throws SaslException If there is an error creating the DigestMD5
 * SASL client.
 * @return a new SaslClient; otherwise null if unsuccessful.
 */
public SaslClient createSaslClient(String[] mechs,
     String authorizationId, String protocol, String serverName,
     Map<String,?> props, CallbackHandler cbh)
     throws SaslException {

     for (int i=0; i<mechs.length; i++) {
        if (mechs[i].equals(myMechs[DIGEST_MD5]) &&
            PolicyUtils.checkPolicy(mechPolicies[DIGEST_MD5], props)) {

            if (cbh == null) {
                throw new SaslException(
                    "Callback handler with support for RealmChoiceCallback, " +
                    "RealmCallback, NameCallback, and PasswordCallback " +
                    "required");
            }

            return new DigestMD5Client(authorizationId,
                protocol, serverName, props, cbh);
        }
    }
    return null;
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:30,代碼來源:FactoryImpl.java

示例13: createSaslServer

import javax.security.auth.callback.CallbackHandler; //導入依賴的package包/類
/**
 * Returns a new instance of the NTLM SASL server mechanism.
 * Argument checks are performed in SaslServer's constructor.
 * @returns a new SaslServer ; otherwise null if unsuccessful.
 * @throws SaslException If there is an error creating the NTLM
 * SASL server.
 */
public SaslServer createSaslServer(String mech,
     String protocol, String serverName, Map<String,?> props, CallbackHandler cbh)
     throws SaslException {

     if (mech.equals("NTLM") &&
             PolicyUtils.checkPolicy(mechPolicies[0], props)) {
         if (props != null) {
             String qop = (String)props.get(Sasl.QOP);
             if (qop != null && !qop.equals("auth")) {
                 throw new SaslException("NTLM only support auth");
             }
         }
         if (cbh == null) {
             throw new SaslException(
                 "Callback handler with support for " +
                 "RealmCallback, NameCallback, and PasswordCallback " +
                 "required");
         }
         return new NTLMServer(mech, protocol, serverName, props, cbh);
     }
     return null;
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:30,代碼來源:FactoryImpl.java

示例14: createSaslClient

import javax.security.auth.callback.CallbackHandler; //導入依賴的package包/類
public SaslClient createSaslClient(String[] mechs,
    String authorizationId,
    String protocol,
    String serverName,
    Map<String,?> props,
    CallbackHandler cbh) throws SaslException {

        for (int i = 0; i < mechs.length; i++) {
            if (mechs[i].equals(myMechs[GSS_KERB_V5])
                && PolicyUtils.checkPolicy(mechPolicies[GSS_KERB_V5], props)) {
                return new GssKrb5Client(
                    authorizationId,
                    protocol,
                    serverName,
                    props,
                    cbh);
            }
        }
        return null;
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:21,代碼來源:FactoryImpl.java

示例15: login

import javax.security.auth.callback.CallbackHandler; //導入依賴的package包/類
private void login(CallbackHandler handler) throws LoginException {
    if ((token.tokenInfo.flags & CKF_PROTECTED_AUTHENTICATION_PATH) == 0) {
        token.provider.login(null, handler);
    } else {
        // token supports protected authentication path
        // (external pin-pad, for example)
        if (handler != null &&
            !token.config.getKeyStoreCompatibilityMode()) {
            throw new LoginException("can not specify password if token " +
                            "supports protected authentication path");
        }

        // must rely on application-set or default handler
        // if one is necessary
        token.provider.login(null, null);
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:18,代碼來源:P11KeyStore.java


注:本文中的javax.security.auth.callback.CallbackHandler類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。