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


Java PasswordCallback類代碼示例

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


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

示例1: map

import javax.security.auth.callback.PasswordCallback; //導入依賴的package包/類
@Override
public Optional<Subject> map(final Optional<Object> wrapper) {
    try {
        LOG.info("logging in user as {}", username);
        LoginContext lc = new LoginContext("PropertyFile", callbacks -> {
            LOG.info("Callback Handler invoked ");
            Stream.of(callbacks).forEach(cb -> {
                if (cb instanceof NameCallback) {
                    ((NameCallback) cb).setName(username);
                } else if (cb instanceof PasswordCallback) {
                    ((PasswordCallback) cb).setPassword(password.toCharArray());
                }
            });
        });
        lc.login();
        return Optional.of(lc.getSubject());
    } catch (LoginException e) {
        LOG.error("Authentication failed", e);
        return Optional.empty();
    }
}
 
開發者ID:gmuecke,項目名稱:boutique-de-jus,代碼行數:22,代碼來源:LoginModuleAuthSupport.java

示例2: handle

import javax.security.auth.callback.PasswordCallback; //導入依賴的package包/類
public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException {
    for (Callback c: callbacks) {
        if (c instanceof NameCallback) {
            ((NameCallback) c).setName(username);
        } else if (c instanceof PasswordCallback) {
            ((PasswordCallback) c).setPassword(password.toCharArray());
        }
        else if (c instanceof KeyChoiceCallback) {
            KeyChoiceCallback kcc = (KeyChoiceCallback)c;
            try {
                int idx = kcc.lookupKey(key);
                kcc.setSelectedIndex(idx);
            }
            catch (IllegalArgumentException e) {
                throw new MissingCredsException(kcc);
            }
        }
        else {
            throw new UnsupportedCallbackException(c);
        }
    }
}
 
開發者ID:discoverygarden,項目名稱:fcrepo3-security-jaas,代碼行數:23,代碼來源:AuthFilterJAAS.java

示例3: login

import javax.security.auth.callback.PasswordCallback; //導入依賴的package包/類
@Override
public boolean login() throws LoginException {
    final Callback[] callbacks = new Callback[] {new NameCallback("f"), new PasswordCallback("f", false)};
    try {
        this.callbackHandler.handle(callbacks);
    } catch (final Exception e) {
        throw new LoginException();
    }

    final String userName = ((NameCallback) callbacks[0]).getName();
    final String password = new String(((PasswordCallback) callbacks[1]).getPassword());

    if ("test".equals(userName) && "test".equals(password)) {
        return true;
    }

    throw new LoginException();
}
 
開發者ID:hsj-xiaokang,項目名稱:springboot-shiro-cas-mybatis,代碼行數:19,代碼來源:MockLoginModule.java

示例4: login

import javax.security.auth.callback.PasswordCallback; //導入依賴的package包/類
public boolean login() throws LoginException {
    final Callback[] callbacks = new Callback[] {new NameCallback("f"), new PasswordCallback("f", false)};
    try {
        this.callbackHandler.handle(callbacks);
    } catch (final Exception e) {
        throw new LoginException();
    }

    final String userName = ((NameCallback) callbacks[0]).getName();
    final String password = new String(((PasswordCallback) callbacks[1]).getPassword());

    if ("test".equals(userName) && "test".equals(password)) {
        return true;
    }

    throw new LoginException();
}
 
開發者ID:hsj-xiaokang,項目名稱:springboot-shiro-cas-mybatis,代碼行數:18,代碼來源:MockLoginModule.java

示例5: handle

import javax.security.auth.callback.PasswordCallback; //導入依賴的package包/類
public void handle(Callback[] callbacks)
        throws UnsupportedCallbackException {
    boolean didSetName = false;
    boolean didSetPassword = false;
    for (Callback cb : callbacks)
        if (cb instanceof NameCallback) {
            ((NameCallback) cb).setName(u);
            didSetName = true;
        } else if (cb instanceof PasswordCallback) {
            ((PasswordCallback) cb).setPassword(p);
            didSetPassword = true;
        } else {
            throw new UnsupportedCallbackException(cb,
                    "Unsupported Callback type: "
                    + cb.getClass().getName());
        }
    if (!didSetName)
        throw new IllegalStateException(
                "Supplied Callbacks does not include a NameCallback");
    if (!didSetPassword)
        throw new IllegalStateException("Supplied Callbacks "
                + "does not include a PasswordCallback");
}
 
開發者ID:tiweGH,項目名稱:OpenDiabetes,代碼行數:24,代碼來源:JaasAuthBean.java

示例6: handle

import javax.security.auth.callback.PasswordCallback; //導入依賴的package包/類
@Override
public void handle(final Callback[] callbacks) throws UnsupportedCallbackException {
    Arrays.stream(callbacks).filter(callback -> {
        if (callback.getClass().equals(NameCallback.class)) {
            ((NameCallback) callback).setName(this.userName);
            return false;
        }
        if (callback.getClass().equals(PasswordCallback.class)) {
            ((PasswordCallback) callback).setPassword(this.password.toCharArray());
            return false;
        }
        return true;
    }).findFirst().ifPresent(callback -> {
        throw new RuntimeException(new UnsupportedCallbackException(callback, "Unrecognized Callback"));
    });
}
 
開發者ID:mrluo735,項目名稱:cas-5.1.0,代碼行數:17,代碼來源:JaasAuthenticationHandler.java

示例7: login

import javax.security.auth.callback.PasswordCallback; //導入依賴的package包/類
public boolean login() throws LoginException {
    final Callback[] callbacks = new Callback[] {new NameCallback("f"), new PasswordCallback("f", false)};
    try {
        this.callbackHandler.handle(callbacks);
    } catch (final Exception e) {
        throw new LoginException();
    }

    final String userName = ((NameCallback) callbacks[0]).getName();
    final String password = new String(((PasswordCallback) callbacks[1]).getPassword());

    if (userName.equals("test") && password.equals("test")) {
        return true;
    }

    throw new LoginException();
}
 
開發者ID:luotuo,項目名稱:cas4.0.x-server-wechat,代碼行數:18,代碼來源:MockLoginModule.java

示例8: handle

import javax.security.auth.callback.PasswordCallback; //導入依賴的package包/類
@Override
public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException {
    if (callbacks != null) {
        for (Callback callback : callbacks) {
            if (callback instanceof NameCallback) {
                ((NameCallback) callback).setName(username);
            } else if (callback instanceof PasswordCallback) {
                ((PasswordCallback) callback).setPassword(password);
            } else {
                throw new UnsupportedCallbackException(callback);

            }
        }
        clearCredentials();
    }
}
 
開發者ID:wso2,項目名稱:message-broker,代碼行數:17,代碼來源:PlainSaslCallbackHandler.java

示例9: handle

import javax.security.auth.callback.PasswordCallback; //導入依賴的package包/類
/**
 * Retrieve or display the information requested in the provided Callbacks.
 * 
 * @param callbacks
 *            an array of <code>Callback</code> objects provided by an
 *            underlying security service which contains the information
 *            requested to be retrieved or displayed.
 * 
 * @throws IOException
 *             if an input or output error occurs.
 * 
 * @throws UnsupportedCallbackException
 *             if the implementation of this method does not support one or
 *             more of the Callbacks specified in the <code>callbacks</code>
 *             parameter.
 */
@Override
public void handle(Callback[] callbacks) throws IOException,
        UnsupportedCallbackException {
    for (Callback callback : callbacks) {
        if (callback instanceof NameCallback) {
            ((NameCallback) callback).setName(wsProxyInfo
                    .getUserCredentials().getUser());
        } else if (callback instanceof PasswordCallback) {
            ((PasswordCallback) callback).setPassword(wsProxyInfo
                    .getUserCredentials().getPassword().toCharArray());
        } else {
            throw new UnsupportedCallbackException(callback,
                    "Unrecognized Callback");
        }
    }
}
 
開發者ID:servicecatalog,項目名稱:oscm,代碼行數:33,代碼來源:UserCredentialsHandler.java

示例10: handle

import javax.security.auth.callback.PasswordCallback; //導入依賴的package包/類
public void handle(Callback[] callbacks)
        throws IOException, UnsupportedCallbackException {
    System.out.println("Callback Handler - handle called");
    for (int i = 0; i < callbacks.length; i++) {
        if (callbacks[i] instanceof NameCallback) {
            NameCallback nameCallback = (NameCallback) callbacks[i];
            nameCallback.setName(name);
        } else if (callbacks[i] instanceof PasswordCallback) {
            PasswordCallback passwordCallback = (PasswordCallback) callbacks[i];
            passwordCallback.setPassword(password.toCharArray());
        } else {
            throw new UnsupportedCallbackException(callbacks[i],
                    "The submitted Callback is unsupported");
        }
    }
}
 
開發者ID:servicecatalog,項目名稱:oscm,代碼行數:17,代碼來源:WSCallbackHandler.java

示例11: createSaslClient

import javax.security.auth.callback.PasswordCallback; //導入依賴的package包/類
static SaslClient createSaslClient(final String user, final String password) throws SaslException {
    return Sasl.createSaslClient(new String[]{"PLAIN"}, user, null, null, null,
            new CallbackHandler() {
                @Override
                public void handle(final Callback[] callbacks)
                        throws IOException, UnsupportedCallbackException {
                    for (final Callback callback : callbacks) {
                        if (callback instanceof PasswordCallback) {
                            ((PasswordCallback) callback).setPassword(password.toCharArray());
                        } else if (callback instanceof NameCallback) {
                            ((NameCallback) callback).setName(user);
                        }
                    }
                }
            });
}
 
開發者ID:mongodb,項目名稱:mongosql-auth-java,代碼行數:17,代碼來源:Plain.java

示例12: handle

import javax.security.auth.callback.PasswordCallback; //導入依賴的package包/類
public void handle(Callback[] callbacks) throws IOException,
        UnsupportedCallbackException {
    for (Callback callback : callbacks) {
        if (callback instanceof NameCallback) {
            NameCallback ncb = (NameCallback) callback;
            ncb.setName(username);
        } else if (callback instanceof PasswordCallback) {
            PasswordCallback pwcb = (PasswordCallback) callback;
            pwcb.setPassword(password.toCharArray());
        } else {
            throw new UnsupportedCallbackException(
                    callback,
                    "We got a "
                            + callback.getClass().getCanonicalName()
                            + ", but only NameCallback and PasswordCallback is supported");
        }
    }
}
 
開發者ID:Transwarp-DE,項目名稱:Transwarp-Sample-Code,代碼行數:19,代碼來源:KerberosAuthenticator2.java

示例13: engineGetEntry

import javax.security.auth.callback.PasswordCallback; //導入依賴的package包/類
/** {@inheritDoc} */
  @Override
  public KeyStore.Entry engineGetEntry(final String alias,
  		                             final ProtectionParameter protParam) {
  	if (protParam instanceof KeyStore.PasswordProtection) {
   	final PasswordCallback pwc = new CachePasswordCallback(((KeyStore.PasswordProtection)protParam).getPassword());
	this.cryptoCard.setPasswordCallback(pwc);
  	}
  	if (!engineContainsAlias(alias)) {
  		return null;
  	}
  	final PrivateKey key = (PrivateKey) engineGetKey(
	alias,
	null // Le pasamos null porque ya hemos establecido el PasswordCallback o el CallbackHander antes
);
  	return new PrivateKeyEntry(key, engineGetCertificateChain(alias));
  }
 
開發者ID:MiFirma,項目名稱:mi-firma-android,代碼行數:18,代碼來源:CeresKeyStoreImpl.java

示例14: handle

import javax.security.auth.callback.PasswordCallback; //導入依賴的package包/類
/**
 * Retrieve the information requested in the provided Callbacks.  This
 * implementation only recognizes <code>NameCallback</code> and
 * <code>PasswordCallback</code> instances.
 *
 * @param callbacks The set of callbacks to be processed
 *
 * @exception IOException if an input/output error occurs
 * @exception UnsupportedCallbackException if the login method requests
 *  an unsupported callback type
 */
public void handle(Callback callbacks[])
    throws IOException, UnsupportedCallbackException {

    for (int i = 0; i < callbacks.length; i++) {

        if (callbacks[i] instanceof NameCallback) {
            if (realm.getDebug() >= 3)
                realm.log("Returning username " + username);
            ((NameCallback) callbacks[i]).setName(username);
        } else if (callbacks[i] instanceof PasswordCallback) {
            if (realm.getDebug() >= 3)
                realm.log("Returning password " + password);
            ((PasswordCallback) callbacks[i]).setPassword
                (password.toCharArray());
        } else {
            throw new UnsupportedCallbackException(callbacks[i]);
        }


    }

}
 
開發者ID:c-rainstorm,項目名稱:jerrydog,代碼行數:34,代碼來源:JAASCallbackHandler.java

示例15: openSession

import javax.security.auth.callback.PasswordCallback; //導入依賴的package包/類
@Override
public ExchangeSession openSession(ExchangeLogin login) {
    ApiKeyCallback apiKey = new ApiKeyCallback();
    ApiSecretCallback apiSecret = new ApiSecretCallback();
    PasswordCallback password = new PasswordCallback("GDAX passphrase", false);

    Callback[] callbacks = new Callback[]{
            apiKey,
            apiSecret,
            password
    };
    CallbackHandler callbackHandler = login.getCallbackHandler();
    try {
        callbackHandler.handle(callbacks);
    } catch (IOException | UnsupportedCallbackException e) {
        throw new RuntimeException(e);
    }

    String apiKeyTxt = apiKey.getApiKey();
    char[] passphrase = password.getPassword();
    SecretKeySpec keySpec = new SecretKeySpec(apiSecret.getSecretData(), "HmacSHA256");
    return new GdaxExchangeSession(this, apiKeyTxt, keySpec, passphrase);
}
 
開發者ID:cloudwall,項目名稱:libcwfincore,代碼行數:24,代碼來源:GdaxExchangeConnection.java


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