当前位置: 首页>>代码示例>>Java>>正文


Java AuthorizeCallback.getAuthorizedID方法代码示例

本文整理汇总了Java中javax.security.sasl.AuthorizeCallback.getAuthorizedID方法的典型用法代码示例。如果您正苦于以下问题:Java AuthorizeCallback.getAuthorizedID方法的具体用法?Java AuthorizeCallback.getAuthorizedID怎么用?Java AuthorizeCallback.getAuthorizedID使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在javax.security.sasl.AuthorizeCallback的用法示例。


在下文中一共展示了AuthorizeCallback.getAuthorizedID方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: assertDeserialized

import javax.security.sasl.AuthorizeCallback; //导入方法依赖的package包/类
public void assertDeserialized(Serializable oref, Serializable otest) {
    AuthorizeCallback ref = (AuthorizeCallback) oref;
    AuthorizeCallback test = (AuthorizeCallback) otest;
    String idC = ref.getAuthenticationID();
    String idZ = ref.getAuthorizationID();
    String id = ref.getAuthorizedID();
    boolean is = ref.isAuthorized();
    if (idC == null) {
        assertNull(test.getAuthenticationID());
    } else {
        assertEquals(test.getAuthenticationID(), idC);
    }
    if (idZ == null) {
        assertNull(test.getAuthorizationID());
    } else {
        assertEquals(test.getAuthorizationID(), idZ);
    }
    if (id == null) {
        assertNull(test.getAuthorizedID());
    } else {
        assertEquals(test.getAuthorizedID(), id);
    }
    assertEquals(test.isAuthorized(), is);

}
 
开发者ID:shannah,项目名称:cn1,代码行数:26,代码来源:AuthorizeCallbackTest.java

示例2: evaluateResponse

import javax.security.sasl.AuthorizeCallback; //导入方法依赖的package包/类
/**
 * Evaluates the response data and generates a challenge.
 *
 * If a response is received from the client during the authentication
 * process, this method is called to prepare an appropriate next
 * challenge to submit to the client. The challenge is null if the
 * authentication has succeeded and no more challenge data is to be sent
 * to the client. It is non-null if the authentication must be continued
 * by sending a challenge to the client, or if the authentication has
 * succeeded but challenge data needs to be processed by the client.
 * <tt>isComplete()</tt> should be called
 * after each call to <tt>evaluateResponse()</tt>,to determine if any further
 * response is needed from the client.
 *
 * @param response The non-null (but possibly empty) response sent
 * by the client.
 *
 * @return The possibly null challenge to send to the client.
 * It is null if the authentication has succeeded and there is
 * no more challenge data to be sent to the client.
 * @exception SaslException If an error occurred while processing
 * the response or generating a challenge.
 */
@Override
public byte[] evaluateResponse(byte[] response)
    throws SaslException {
    if (completed) {
        throw new IllegalStateException("PLAIN authentication already completed");
    }
    if (aborted) {
        throw new IllegalStateException("PLAIN authentication previously aborted due to error");
    }
    try {
        if(response.length != 0) {
            String data = new String(response, StandardCharsets.UTF_8);
            StringTokenizer tokens = new StringTokenizer(data, "\0");
            if (tokens.countTokens() > 2) {
                username = tokens.nextToken();
                principal = tokens.nextToken();
            } else {
                username = tokens.nextToken();
                principal = username;
            }
            password = tokens.nextToken();
            NameCallback ncb = new NameCallback("PLAIN authentication ID: ",principal);
            VerifyPasswordCallback vpcb = new VerifyPasswordCallback(password.toCharArray());
            cbh.handle(new Callback[]{ncb,vpcb});

            if (vpcb.getVerified()) {
                vpcb.clearPassword();
                AuthorizeCallback acb = new AuthorizeCallback(principal,username);
                cbh.handle(new Callback[]{acb});
                if(acb.isAuthorized()) {
                    username = acb.getAuthorizedID();
                    completed = true;
                } else {
                    completed = true;
                    username = null;
                    throw new SaslException("PLAIN: user not authorized: "+principal);
                }
            } else {
                throw new SaslException("PLAIN: user not authorized: "+principal);
            }
        } else {
            //Client gave no initial response
            if( counter++ > 1 ) {
                throw new SaslException("PLAIN expects a response");
            }
            return null;
        }
    } catch (UnsupportedCallbackException | IOException e) {
        aborted = true;
        throw new SaslException("PLAIN authentication failed for: "+username, e);
    }
    return null;
}
 
开发者ID:igniterealtime,项目名称:Openfire,代码行数:77,代码来源:SaslServerPlainImpl.java

示例3: processClientLastMessage

import javax.security.sasl.AuthorizeCallback; //导入方法依赖的package包/类
protected byte[] processClientLastMessage(byte[] data) throws SaslException, InvalidKeyException, NoSuchAlgorithmException {
	Matcher r = CLIENT_LAST_MESSAGE.matcher(new String(data, CHARSET));
	if (!r.matches())
		throw new SaslException("Bad challenge syntax");

	final String clmWithoutProof = r.group("withoutProof");
	final byte[] clmCb = Base64.decode(r.group("cb"));
	final String clmNonce = r.group("nonce");
	final String clmProof = r.group("proof");

	byte[] calculatedCb = calculateC();
	if (!(new String(clmCb, CHARSET)).startsWith(cfmGs2header)) {
		throw new XmppSaslException(SaslError.not_authorized, "Invalid GS2 header");
	} else if (!Arrays.equals(clmCb, calculatedCb)) {
		if (log.isLoggable(Level.FINEST))
			log.log(Level.FINEST, "Channel bindings does not match. expected: {0}; received: {1}",
					new Object[]{calculatedCb, clmCb});
		throw new XmppSaslException(SaslError.not_authorized, "Channel bindings does not match");
	}

	if (!clmNonce.equals(sfmNonce)) {
		throw new XmppSaslException(SaslError.not_authorized, "Wrong nonce");
	}

	final String authMessage = cfmBareMessage + "," + sfmMessage + "," + clmWithoutProof;
	byte[] clientSignature = hmac(key(storedKey), authMessage.getBytes());
	byte[] clientProof = xor(clientKey, clientSignature);

	byte[] dcp = Base64.decode(clmProof);
	boolean proofMatch = Arrays.equals(clientProof, dcp);

	if (proofMatch == false) {
		throw new XmppSaslException(SaslError.not_authorized, "Password not verified");
	}

	final AuthorizeCallback ac = new AuthorizeCallback(cfmUsername, cfmAuthzid);
	handleCallbacks(ac);
	if (ac.isAuthorized() == true) {
		authorizedId = ac.getAuthorizedID();
	} else {
		throw new XmppSaslException(SaslError.invalid_authzid, "SCRAM: " + cfmAuthzid + " is not authorized to act as "
				+ cfmAuthzid);
	}

	byte[] serverKey = hmac(key(saltedPassword), serverKeyData);
	byte[] serverSignature = hmac(key(serverKey), authMessage.getBytes());

	final StringBuilder serverStringMessage = new StringBuilder();
	serverStringMessage.append("v=").append(Base64.encode(serverSignature));
	step = Step.finished;
	complete = true;
	return serverStringMessage.toString().getBytes();
}
 
开发者ID:kontalk,项目名称:tigase-server,代码行数:54,代码来源:AbstractSaslSCRAM.java

示例4: evaluateResponse

import javax.security.sasl.AuthorizeCallback; //导入方法依赖的package包/类
@Override
public byte[] evaluateResponse(byte[] response) throws SaslException {

	String[] data = split(response, "");

	if (data.length != 3)
		throw new XmppSaslException(SaslError.malformed_request, "Invalid number of message parts");

	final String authzid = data[0];
	final String authcid = data[1];
	final String passwd = data[2];

	if (authcid.length() < 1)
		throw new XmppSaslException(SaslError.malformed_request, "Authentication identity string is empty");

	if (authcid.length() > 255)
		throw new XmppSaslException(SaslError.malformed_request, "Authentication identity string is too long");

	if (!isEmpty(authzid) && authzid.length() > 255)
		throw new XmppSaslException(SaslError.malformed_request, "Authorization identity string is too long");

	if (passwd.length() > 255)
		throw new XmppSaslException(SaslError.malformed_request, "Password string is too long");

	final NameCallback nc = new NameCallback("Authentication identity", authcid);
	final VerifyPasswordCallback vpc = new VerifyPasswordCallback(passwd);

	handleCallbacks(nc, vpc);

	if (vpc.isVerified() == false) {
		throw new XmppSaslException(SaslError.not_authorized, "Password not verified");
	}

	final String authorizationJID = isEmpty(authzid) ? nc.getName() : authzid;

	final AuthorizeCallback ac = new AuthorizeCallback(nc.getName(), authorizationJID);
	handleCallbacks(ac);

	if (ac.isAuthorized() == true) {
		authorizedId = ac.getAuthorizedID();
	} else {
		throw new XmppSaslException(SaslError.invalid_authzid, "PLAIN: " + authcid + " is not authorized to act as "
				+ authorizationJID);
	}

	complete = true;

	return null;
}
 
开发者ID:kontalk,项目名称:tigase-server,代码行数:50,代码来源:SaslPLAIN.java


注:本文中的javax.security.sasl.AuthorizeCallback.getAuthorizedID方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。