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


Java RadiusPacket类代码示例

本文整理汇总了Java中net.jradius.packet.RadiusPacket的典型用法代码示例。如果您正苦于以下问题:Java RadiusPacket类的具体用法?Java RadiusPacket怎么用?Java RadiusPacket使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: authenticate

import net.jradius.packet.RadiusPacket; //导入依赖的package包/类
@Override
public boolean authenticate(final String username, final String password) throws PreventedException {

    final AttributeList attributeList = new AttributeList();
    attributeList.add(new Attr_UserName(username));
    attributeList.add(new Attr_UserPassword(password));

    RadiusClient client = null;
    try {
        client = this.radiusClientFactory.newInstance();
        LOGGER.debug("Created RADIUS client instance {}", client);

        final AccessRequest request = new AccessRequest(client, attributeList);
        final RadiusPacket response = client.authenticate(
                request,
                RadiusClient.getAuthProtocol(this.protocol.getName()),
                this.retries);

        LOGGER.debug("RADIUS response from {}: {}",
                client.getRemoteInetAddress().getCanonicalHostName(),
                response.getClass().getName());

        if (response instanceof AccessAccept) {
            return true;
        }
    } catch (final Exception e) {
        throw new PreventedException(e);
    } finally {
        if (client != null) {
            client.close();
        }
    }
    return false;
}
 
开发者ID:luotuo,项目名称:cas4.0.x-server-wechat,代码行数:35,代码来源:JRadiusServerImpl.java

示例2: getKeyFromAttributeType

import net.jradius.packet.RadiusPacket; //导入依赖的package包/类
protected Serializable getKeyFromAttributeType(RadiusPacket req, long type, boolean required) throws RadiusException
{
    RadiusAttribute a = req.findAttribute(type);

    if (a == null) 
    {
        if (required)
        {
            a = AttributeFactory.newAttribute(type, null, false);
            throw new RadiusException("Missing required attribute: " + a.getAttributeName());
        }
        return null;
    }

    AttributeValue v = a.getValue();
    return v.toString();
}
 
开发者ID:coova,项目名称:jradius,代码行数:18,代码来源:RadiusSessionKeyProvider.java

示例3: checkPacket

import net.jradius.packet.RadiusPacket; //导入依赖的package包/类
/** 
 * @see net.jradius.standard.RadiusStandard#checkPacket(net.jradius.packet.RadiusPacket)
 */
public void checkPacket(RadiusPacket p, long[] ignore) throws StandardViolatedException
{
    LinkedList missing = new LinkedList();
    
    switch(p.getCode())
    {
    	case AccessRequest.CODE:
    	    checkMissing(p, missing, requiredAccessRequest, ignore);
    		break;

    	case AccessAccept.CODE:
    	    checkMissing(p, missing, requiredAccessAccept, ignore);
			break;

    	case AccessReject.CODE:
			break;

    	case AccountingRequest.CODE:
    	    checkMissing(p, missing, requiredAccounting, ignore);
    		break;
    }
    if (!missing.isEmpty())
        throw new StandardViolatedException(this.getClass(), missing);
}
 
开发者ID:coova,项目名称:jradius,代码行数:28,代码来源:WISPrStandard.java

示例4: setupRequest

import net.jradius.packet.RadiusPacket; //导入依赖的package包/类
/**
 * @throws NoSuchAlgorithmException 
 * @see net.jradius.client.auth.RadiusAuthenticator#setupRequest(net.jradius.client.RadiusClient, net.jradius.packet.RadiusPacket)
 */
public void setupRequest(RadiusClient c, RadiusPacket p) throws RadiusException, NoSuchAlgorithmException
{
    super.setupRequest(c, p);
    tunnelRequest = new AccessRequest(tunneledAttributes);
    AttributeList attrs = tunnelRequest.getAttributes();
    if (attrs.get(Attr_UserName.TYPE) == null) 
    	attrs.add(AttributeFactory.copyAttribute(username, false));
    if (attrs.get(Attr_UserPassword.TYPE) == null) 
    	attrs.add(AttributeFactory.copyAttribute(password, false));
    tunnelAuth.setupRequest(c, tunnelRequest);
    if (!(tunnelAuth instanceof PAPAuthenticator)) // do not encode pap password
    {
        tunnelAuth.processRequest(tunnelRequest);
    }
}
 
开发者ID:coova,项目名称:jradius,代码行数:20,代码来源:EAPTTLSAuthenticator.java

示例5: checkStandard

import net.jradius.packet.RadiusPacket; //导入依赖的package包/类
private void checkStandard(RadiusStandard radiusStandard, RadiusPacket p)
{
    if (radiusStandard != null)
    {
        try
        {
            radiusStandard.checkPacket(p);
        }
        catch (StandardViolatedException e)
        {
            setStatus(radiusStandard.getName() + " standard violated");
            logErr.println(radiusStandard.getName() + " Standard Violated: " + p.getClass().getName());
            logErr.println(logSepLine);
            logErr.println("Missing attributes:");
            logErr.println(e.listAttributes("\n") + "\n");
            logErr.flush();
        }
    }
}
 
开发者ID:coova,项目名称:jradius,代码行数:20,代码来源:JRadiusSimulator.java

示例6: writeResponse

import net.jradius.packet.RadiusPacket; //导入依赖的package包/类
public void writeResponse(JRadiusRequest request, ByteBuffer buffer, OutputStream outputStream) throws IOException, RadiusException, InvalidKeyException, NoSuchAlgorithmException 
  {
      if (Configuration.isDebug()) 
          request.printDebugInfo();

      RadiusPacket[] rp = request.getPackets();

      RadiusRequest req = (RadiusRequest) rp[0];
      RadiusResponse res = (RadiusResponse) rp[1];
      
      String sharedSecret = (String) req.getAttributeValue(Attr_SharedSecret.TYPE);
      
      RadiusFormat format = RadiusFormat.getInstance();

MessageAuthenticator.generateResponseMessageAuthenticator(req, res, sharedSecret);
res.generateAuthenticator(req.getAuthenticator(), sharedSecret);

buffer.clear();
format.packPacket(res, sharedSecret, buffer, true);
      
      outputStream.write(buffer.array(), 0, buffer.position());
      outputStream.flush();
  }
 
开发者ID:coova,项目名称:jradius,代码行数:24,代码来源:RadSecProcessor.java

示例7: handle

import net.jradius.packet.RadiusPacket; //导入依赖的package包/类
public boolean handle(JRadiusRequest request) throws Exception
{
    JRadiusSession session = (JRadiusSession) request.getSession();
    if (session == null) return noSessionFound(request);

    RadiusPacket req = request.getRequestPacket();
    
    String username = (String)req.getAttributeValue(Attr_UserName.TYPE);
    
    if (request.getApplicationContext() == null)
    {
        RadiusLog.error(this.getClass().getName()+" can only run when configured with Spring");
        return false;
    }
    
    WebServiceListener wsListener = (WebServiceListener)request.getApplicationContext().getBean(listenerBean);
    if (wsListener == null) return false;
    OTPProxyRequest otpRequest = (OTPProxyRequest)wsListener.get(username);
    if (otpRequest == null) return false;

    otpRequest.updateAccounting((AccountingRequest)req);

    return false;
}
 
开发者ID:coova,项目名称:jradius,代码行数:25,代码来源:OTPProxyAccountingHandler.java

示例8: packPacket

import net.jradius.packet.RadiusPacket; //导入依赖的package包/类
public void packPacket(RadiusPacket packet, String sharedSecret, ByteBuffer buffer, boolean onWire) throws IOException
{
    if (packet == null)
    {
        throw new IllegalArgumentException("Packet is null.");
    }

    int initialPosition = buffer.position();
    buffer.position(initialPosition + 12);
    packAttributeList(packet.getAttributes(), buffer, onWire);

    int finalPosition = buffer.position();
    int totalLength = finalPosition - initialPosition;
    int attributesLength = totalLength - 12;
    
    try
    {
    	buffer.position(initialPosition);
    	packHeader(buffer, packet, attributesLength, sharedSecret);
    	buffer.position(finalPosition);
    }
    catch(Exception e)
    {
        RadiusLog.warn(e.getMessage(), e);
    }
}
 
开发者ID:coova,项目名称:jradius,代码行数:27,代码来源:FreeRadiusFormat.java

示例9: receive

import net.jradius.packet.RadiusPacket; //导入依赖的package包/类
protected RadiusResponse receive(RadiusRequest req) throws Exception
{
    if (statusListener != null)
    {
    	statusListener.onBeforeReceive(this);
    }
    
    byte replyBytes[] = new byte[RadiusPacket.MAX_PACKET_LENGTH];
    DatagramPacket reply = new DatagramPacket(replyBytes, replyBytes.length);
    
    socket.receive(reply);
    
    RadiusPacket replyPacket = PacketFactory.parse(reply, req.isRecyclable());
    
    if (!(replyPacket instanceof RadiusResponse))
    {
        throw new RadiusException("Received something other than a RADIUS Response to a Request");
    }

    if (statusListener != null)
    {
    	statusListener.onAfterReceive(this, replyPacket);
    }
    
    return (RadiusResponse)replyPacket;
}
 
开发者ID:coova,项目名称:jradius,代码行数:27,代码来源:UDPClientTransport.java

示例10: processChallenge

import net.jradius.packet.RadiusPacket; //导入依赖的package包/类
/**
 * EAP requires a challenge/response. The request packet is reset with a new 
 * RADIUS identifier and the EAP-Message is encoded.
 * @throws NoSuchAlgorithmException 
 * @see net.jradius.client.auth.RadiusAuthenticator#processChallenge(net.jradius.packet.RadiusPacket, net.jradius.packet.RadiusPacket)
 */
public void processChallenge(RadiusPacket p, RadiusPacket r)  throws RadiusException, NoSuchAlgorithmException
{
	super.processChallenge(p, r);
	
    p.setIdentifier(-1);

    byte[] eapReply = AttributeFactory.assembleAttributeList(r.getAttributes(), AttributeDictionary.EAP_MESSAGE);
    byte[] eapMessage = doEAP(eapReply);
    
    RadiusAttribute a = p.findAttribute(AttributeDictionary.EAP_MESSAGE);
    if (a != null) p.removeAttribute(a);
    
    AttributeFactory.addToAttributeList(p.getAttributes(), 
    		AttributeDictionary.EAP_MESSAGE, eapMessage, p.isRecyclable());

    RadiusLog.debug("Sending Challenge:\n" + p.toString());
}
 
开发者ID:coova,项目名称:jradius,代码行数:24,代码来源:EAPAuthenticator.java

示例11: processRequest

import net.jradius.packet.RadiusPacket; //导入依赖的package包/类
public void processRequest(RadiusPacket p) throws RadiusException, NoSuchAlgorithmException
{
	if (password == null) throw new RadiusException("no password given");
	
    p.removeAttribute(password);
    
    RadiusAttribute attr;
    byte authChallenge[] = RadiusRandom.getBytes(16);
    byte chapResponse[] = MSCHAP.doMSCHAPv1(password.getValue().getBytes(), authChallenge);

    p.addAttribute(attr = AttributeFactory.newAttribute("MS-CHAP-Challenge"));
    attr.setValue(authChallenge);
    
    p.addAttribute(attr = AttributeFactory.newAttribute("MS-CHAP-Response"));
    attr.setValue(chapResponse);
}
 
开发者ID:coova,项目名称:jradius,代码行数:17,代码来源:MSCHAPv1Authenticator.java

示例12: processRequest

import net.jradius.packet.RadiusPacket; //导入依赖的package包/类
public void processRequest(RadiusPacket p) throws RadiusException, NoSuchAlgorithmException
{
	if (password == null) throw new RadiusException("no password given");

	p.removeAttribute(password);
    
    RadiusAttribute attr;
    byte authChallenge[] = RadiusRandom.getBytes(16);
    byte chapResponse[] = CHAP.chapResponse((byte)p.getIdentifier(), password.getValue().getBytes(), authChallenge);

    p.addAttribute(attr = AttributeFactory.newAttribute("CHAP-Challenge"));
    attr.setValue(authChallenge);
        
    p.addAttribute(attr = AttributeFactory.newAttribute("CHAP-Password"));
    attr.setValue(chapResponse);
}
 
开发者ID:coova,项目名称:jradius,代码行数:17,代码来源:CHAPAuthenticator.java

示例13: setupRequest

import net.jradius.packet.RadiusPacket; //导入依赖的package包/类
/**
 * @param c The RadiusClient context being used
 * @param p Setup the Authenticator with packet data
 * @throws RadiusException
 * @throws NoSuchAlgorithmException 
 */
public void setupRequest(RadiusClient c, RadiusPacket p) throws RadiusException, NoSuchAlgorithmException
{
	RadiusAttribute a;
    client = c;
    
    if (username == null)
    {
    	a = p.findAttribute(AttributeDictionary.USER_NAME);
        
    	if (a == null)
        	throw new RadiusException("You must at least have a User-Name attribute in a Access-Request");

    	username = AttributeFactory.copyAttribute(a, false);
    }
    
    if (password == null)
    {
    	a = p.findAttribute(AttributeDictionary.USER_PASSWORD);

    	if (a != null)
    	{
    		password = AttributeFactory.copyAttribute(a, false);
    	}
    }
}
 
开发者ID:coova,项目名称:jradius,代码行数:32,代码来源:RadiusAuthenticator.java

示例14: printDebugInfo

import net.jradius.packet.RadiusPacket; //导入依赖的package包/类
public void printDebugInfo()
{
    if (Configuration.isDebug())
    {
        RadiusPacket[] rp = this.getPackets();

        StringWriter sw = new StringWriter();
        PrintWriter pw = new PrintWriter(sw);

        // debug info:
        pw.println(">>> packets in request from \"" + getSender() + "\":");

        for (int i=0; i < rp.length; i++)
            if (rp[i] != null)
            {
                pw.println("--- packet " + (i+1) + " of " + rp.length);
                pw.println(rp[i].toString());
            }

        pw.println("Configuration Items:");
        pw.println(getConfigItems().toString());

        pw.flush();
        RadiusLog.debug(sw.toString());
    }
}
 
开发者ID:coova,项目名称:jradius,代码行数:27,代码来源:JRadiusRequest.java

示例15: verifyRequest

import net.jradius.packet.RadiusPacket; //导入依赖的package包/类
public static Boolean verifyRequest(RadiusPacket request, String sharedSecret) throws IOException, InvalidKeyException, NoSuchAlgorithmException
{
    byte[] hash = new byte[16];
    ByteBuffer buffer = ByteBuffer.allocate(4096);

    RadiusAttribute attr = request.findAttribute(AttributeDictionary.MESSAGE_AUTHENTICATOR);
    if (attr == null) return null;
    
    byte[] pval = attr.getValue().getBytes();
    attr.setValue(hash);
    
    format.packPacket(request, sharedSecret, buffer, true);
    System.arraycopy(MD5.hmac_md5(buffer.array(), 0, buffer.position(), sharedSecret.getBytes()), 0, hash, 0, 16);

    attr.setValue(pval);
    
    return new Boolean(Arrays.equals(pval, hash));
}
 
开发者ID:coova,项目名称:jradius,代码行数:19,代码来源:MessageAuthenticator.java


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