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


Java SaslServer.evaluateResponse方法代碼示例

本文整理匯總了Java中javax.security.sasl.SaslServer.evaluateResponse方法的典型用法代碼示例。如果您正苦於以下問題:Java SaslServer.evaluateResponse方法的具體用法?Java SaslServer.evaluateResponse怎麽用?Java SaslServer.evaluateResponse使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在javax.security.sasl.SaslServer的用法示例。


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

示例1: runNegotiation

import javax.security.sasl.SaslServer; //導入方法依賴的package包/類
private void runNegotiation(CallbackHandler clientCbh,
                            CallbackHandler serverCbh)
                                throws SaslException {
  String mechanism = AuthMethod.PLAIN.getMechanismName();

  SaslClient saslClient = Sasl.createSaslClient(
      new String[]{ mechanism }, null, null, null, null, clientCbh);
  assertNotNull(saslClient);

  SaslServer saslServer = Sasl.createSaslServer(
      mechanism, null, "localhost", null, serverCbh);
  assertNotNull("failed to find PLAIN server", saslServer);
  
  byte[] response = saslClient.evaluateChallenge(new byte[0]);
  assertNotNull(response);
  assertTrue(saslClient.isComplete());

  response = saslServer.evaluateResponse(response);
  assertNull(response);
  assertTrue(saslServer.isComplete());
  assertNotNull(saslServer.getAuthorizationID());
}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:23,代碼來源:TestSaslRPC.java

示例2: authenticate

import javax.security.sasl.SaslServer; //導入方法依賴的package包/類
/**
 * @see org.wso2.andes.server.security.auth.manager.AuthenticationManager#authenticate(SaslServer, byte[])
 */
public AuthenticationResult authenticate(SaslServer server, byte[] response)
{
    try
    {
        // Process response from the client
        byte[] challenge = server.evaluateResponse(response != null ? response : new byte[0]);

        if (server.isComplete())
        {
            final Subject subject = new Subject();
            subject.getPrincipals().add(new UsernamePrincipal(server.getAuthorizationID()));
            return new AuthenticationResult(subject);
        }
        else
        {
            return new AuthenticationResult(challenge, AuthenticationResult.AuthenticationStatus.CONTINUE);
        }
    }
    catch (SaslException e)
    {
        return new AuthenticationResult(AuthenticationResult.AuthenticationStatus.ERROR, e);
    }
}
 
開發者ID:wso2,項目名稱:andes,代碼行數:27,代碼來源:PrincipalDatabaseAuthenticationManager.java

示例3: secure

import javax.security.sasl.SaslServer; //導入方法依賴的package包/類
protected void secure(final SaslServer ss, final Connection conn, final byte[] response)
{
    try
    {
        byte[] challenge = ss.evaluateResponse(response);
        if (ss.isComplete())
        {
            ss.dispose();
            tuneAuthorizedConnection(conn);
        }
        else
        {
            connectionAuthContinue(conn, challenge);
        }
    }
    catch (SaslException e)
    {
        connectionAuthFailed(conn, e);
    }
}
 
開發者ID:wso2,項目名稱:andes,代碼行數:21,代碼來源:ServerDelegate.java

示例4: processData

import javax.security.sasl.SaslServer; //導入方法依賴的package包/類
private byte[] processData(byte[] data, SaslEndpoint endpoint,
        SaslServer server) throws SaslException, IOException {
    try {
        return server.evaluateResponse(data);
    } catch (SaslException e) {
        endpoint.send(new Message(SaslStatus.FAILURE, null));
        System.out.println("Error while processing data");
        throw e;
    }
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:11,代碼來源:ClientServerTest.java

示例5: testSaslServerClient

import javax.security.sasl.SaslServer; //導入方法依賴的package包/類
private void testSaslServerClient(SaslServer server, SaslClient client) throws SaslException {
    byte[] message = new byte[]{};
    if (client.hasInitialResponse()) message = client.evaluateChallenge(message);
    while(!server.isComplete() || !client.isComplete()) {
        if (!server.isComplete()) message = server.evaluateResponse(message);
        if (!client.isComplete()) message = client.evaluateChallenge(message);
    }
}
 
開發者ID:wildfly,項目名稱:wildfly-core,代碼行數:9,代碼來源:SaslTestCase.java

示例6: main

import javax.security.sasl.SaslServer; //導入方法依賴的package包/類
public static void main(String[] args) throws Exception {

        Map<String, String> props = new TreeMap<String, String>();
        props.put(Sasl.QOP, "auth");

        // client
        SaslClient client = Sasl.createSaslClient(new String[]{ DIGEST_MD5 },
            "user1", "xmpp", "127.0.0.1", props, authCallbackHandler);
        if (client == null) {
            throw new Exception("Unable to find client implementation for: " +
                DIGEST_MD5);
        }

        byte[] response = client.hasInitialResponse()
            ? client.evaluateChallenge(EMPTY) : EMPTY;
        logger.info("initial: " + new String(response));

        // server
        byte[] challenge = null;
        SaslServer server = Sasl.createSaslServer(DIGEST_MD5, "xmpp",
          "127.0.0.1", props, authCallbackHandler);
        if (server == null) {
            throw new Exception("Unable to find server implementation for: " +
                DIGEST_MD5);
        }

        if (!client.isComplete() || !server.isComplete()) {
            challenge = server.evaluateResponse(response);

            logger.info("challenge: " + new String(challenge));

            if (challenge != null) {
                response = client.evaluateChallenge(challenge);
            }
        }

        String challengeString = new String(challenge, "UTF-8").toLowerCase();

        if (challengeString.indexOf("\"md5-sess\"") > 0 ||
            challengeString.indexOf("\"utf-8\"") > 0) {
            throw new Exception("The challenge string's charset and " +
                "algorithm values must not be enclosed within quotes");
        }

        client.dispose();
        server.dispose();
    }
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:48,代碼來源:NoQuoteParams.java

示例7: main

import javax.security.sasl.SaslServer; //導入方法依賴的package包/類
public static void main(String[] args) throws Exception {
    if (args.length == 0) {
        pwfile = "pw.properties";
        namesfile = "names.properties";
        auto = true;
    } else {
        int i = 0;
        if (args[i].equals("-m")) {
            i++;
            auto = false;
        }
        if (args.length > i) {
            pwfile = args[i++];

            if (args.length > i) {
                namesfile = args[i++];
            }
        } else {
            pwfile = "pw.properties";
            namesfile = "names.properties";
        }
    }

    CallbackHandler clntCbh = new ClientCallbackHandler(auto);

    CallbackHandler srvCbh =
        new PropertiesFileCallbackHandler(pwfile, namesfile, null);

    SaslClient clnt = Sasl.createSaslClient(
        new String[]{MECH}, null, PROTOCOL, SERVER_FQDN, null, clntCbh);

    SaslServer srv = Sasl.createSaslServer(MECH, PROTOCOL, SERVER_FQDN, null,
        srvCbh);

    if (clnt == null) {
        throw new IllegalStateException(
            "Unable to find client impl for " + MECH);
    }
    if (srv == null) {
        throw new IllegalStateException(
            "Unable to find server impl for " + MECH);
    }

    byte[] response = (clnt.hasInitialResponse()?
        clnt.evaluateChallenge(EMPTY) : EMPTY);
    byte[] challenge;

    while (!clnt.isComplete() || !srv.isComplete()) {
        challenge = srv.evaluateResponse(response);

        if (challenge != null) {
            response = clnt.evaluateChallenge(challenge);
        }
    }

    if (clnt.isComplete() && srv.isComplete()) {
        if (verbose) {
            System.out.println("SUCCESS");
            System.out.println("authzid is " + srv.getAuthorizationID());
        }
    } else {
        throw new IllegalStateException("FAILURE: mismatched state:" +
            " client complete? " + clnt.isComplete() +
            " server complete? " + srv.isComplete());
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:67,代碼來源:Cram.java

示例8: saslAuth

import javax.security.sasl.SaslServer; //導入方法依賴的package包/類
private boolean saslAuth(final Map<String, Object> props)
				throws AuthorizationException {
	try {
		SaslServer ss = (SaslServer) props.get("SaslServer");

		if (ss == null) {
			Map<String, String> sasl_props = new TreeMap<String, String>();

			sasl_props.put(Sasl.QOP, "auth");
			ss = Sasl.createSaslServer((String) props.get(MACHANISM_KEY), "xmpp",
					(String) props.get(SERVER_NAME_KEY), sasl_props, new SaslCallbackHandler(
					props));
			props.put("SaslServer", ss);
		}    // end of if (ss == null)

		String data_str = (String) props.get(DATA_KEY);
		byte[] in_data  = ((data_str != null)
				? Base64.decode(data_str)
				: new byte[0]);

		if (log.isLoggable(Level.FINEST)) {
			log.finest("response: " + new String(in_data));
		}

		byte[] challenge = ss.evaluateResponse(in_data);

		if (log.isLoggable(Level.FINEST)) {
			log.finest("challenge: " + ((challenge != null)
					? new String(challenge)
					: "null"));
		}

		String challenge_str = (((challenge != null) && (challenge.length > 0))
				? Base64.encode(challenge)
				: null);

		props.put(RESULT_KEY, challenge_str);
		if (ss.isComplete()) {
			return true;
		} else {
			return false;
		}    // end of if (ss.isComplete()) else
	} catch (SaslException e) {
		throw new AuthorizationException("Sasl exception.", e);
	}      // end of try-catch
}
 
開發者ID:kontalk,項目名稱:tigase-server,代碼行數:47,代碼來源:AuthRepositoryImpl.java

示例9: saslAuth

import javax.security.sasl.SaslServer; //導入方法依賴的package包/類
private boolean saslAuth(final Map<String, Object> props) throws AuthorizationException {
	try {
		SaslServer ss = (SaslServer) props.get("SaslServer");

		if (ss == null) {
			Map<String, String> sasl_props = new TreeMap<String, String>();

			sasl_props.put(Sasl.QOP, "auth");
			ss =
					Sasl.createSaslServer((String) props.get(MACHANISM_KEY), "xmpp",
							(String) props.get(SERVER_NAME_KEY), sasl_props, new SaslCallbackHandler(
									props));
			props.put("SaslServer", ss);
		} // end of if (ss == null)

		String data_str = (String) props.get(DATA_KEY);
		byte[] in_data = ((data_str != null) ? Base64.decode(data_str) : new byte[0]);

		if (log.isLoggable(Level.FINEST)) {
			log.log(Level.FINEST, "response: {0}", new String(in_data));
		}

		byte[] challenge = ss.evaluateResponse(in_data);

		if (log.isLoggable(Level.FINEST)) {
			log.log(Level.FINEST, "challenge: {0}", ((challenge != null) ? new String(
					challenge) : "null"));
		}

		String challenge_str =
				(((challenge != null) && (challenge.length > 0)) ? Base64.encode(challenge)
						: null);

		props.put(RESULT_KEY, challenge_str);

		if (ss.isComplete()) {
			return true;
		} else {
			return false;
		} // end of if (ss.isComplete()) else
	} catch (SaslException e) {
		throw new AuthorizationException("Sasl exception.", e);
	} // end of try-catch
}
 
開發者ID:kontalk,項目名稱:tigase-server,代碼行數:45,代碼來源:TigaseCustomAuth.java


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