当前位置: 首页>>代码示例>>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;未经允许,请勿转载。