本文整理汇总了Java中net.jradius.packet.AccessRequest类的典型用法代码示例。如果您正苦于以下问题:Java AccessRequest类的具体用法?Java AccessRequest怎么用?Java AccessRequest使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
AccessRequest类属于net.jradius.packet包,在下文中一共展示了AccessRequest类的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: authenticate
import net.jradius.packet.AccessRequest; //导入依赖的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;
}
示例2: checkPacket
import net.jradius.packet.AccessRequest; //导入依赖的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);
}
示例3: setupRequest
import net.jradius.packet.AccessRequest; //导入依赖的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);
}
}
示例4: getRequestSessionKey
import net.jradius.packet.AccessRequest; //导入依赖的package包/类
/**
* Generates the session key for the given session. If the key is changing, as
* in the case when we move from authentication to accounting, this method will
* return an Object[2] which instructs the session manage to "rehash" the session
* under a new key (for uniqueness).
*
* @param request The JRadiusRequest
* @return the session key, or an array of 2 keys, the second replacing the first
* as the session hash key.
* @throws RadiusException
*/
public Serializable getRequestSessionKey(JRadiusRequest request) throws RadiusException
{
RadiusPacket req = request.getRequestPacket();
if (req == null)
{
return null;
}
else if (req instanceof AccessRequest)
{
return getAccessRequestKey(request);
}
else if (req instanceof DHCPPacket)
{
return getDHCPRequestKey(request);
}
else if (req instanceof AccountingRequest)
{
int type = request.getType();
int status = ((AccountingRequest)req).getAccountingStatusType();
Serializable key = getAccountingRequestKey(request);
if (type == JRadiusServer.JRADIUS_preacct &&
( status == AccountingRequest.ACCT_STATUS_START ||
status == AccountingRequest.ACCT_STATUS_ACCOUNTING_ON) )
{
// rekey the request during pre-accounting
return new Serializable[] { getAccessRequestKey(request), key };
}
return key;
}
return null;
}
示例5: handle
import net.jradius.packet.AccessRequest; //导入依赖的package包/类
public boolean handle(JRadiusRequest request) throws Exception
{
JRadiusSession session = request.getSession();
if (session == null) return noSessionFound(request);
// System.err.println(this.getClass().getName());
RadiusPacket req = request.getRequestPacket();
byte[] packetClass = (byte[])req.getAttributeValue(Attr_Class.TYPE);
byte[][] sessionClass = session.getRadiusClass();
if (packetClass != null || sessionClass != null)
{
if (sessionClass == null)
{
session.addLogMessage(request, "Request has Class attribute when it should not");
}
else
{
session.addLogMessage(request, "Missing Class Attribute (added)");
req.removeAttribute(Attr_Class.TYPE);
for (byte[] a : sessionClass) {
req.addAttribute(AttributeFactory.newAttribute(Attr_Class.TYPE, a, req.isRecyclable()));
}
}
}
if (req instanceof AccessRequest)
{
byte[] sessionState = session.getRadiusState();
if (sessionState != null)
{
// System.out.println("Missing State Attribute (added) "+sessionState.length+" "+sessionState[0]);
req.overwriteAttribute(AttributeFactory.newAttribute(Attr_State.TYPE, sessionState, req.isRecyclable()));
}
}
return false;
}
示例6: setupRequest
import net.jradius.packet.AccessRequest; //导入依赖的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();
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);
tunnelAuth.processRequest(tunnelRequest);
}
示例7: authenticate
import net.jradius.packet.AccessRequest; //导入依赖的package包/类
@Override
public RadiusResponse 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));
if (StringUtils.isNotBlank(this.nasIpAddress)) {
attributeList.add(new Attr_NASIPAddress(this.nasIpAddress));
}
if (StringUtils.isNotBlank(this.nasIpv6Address)) {
attributeList.add(new Attr_NASIPv6Address(this.nasIpv6Address));
}
if (StringUtils.isNotBlank(this.nasIdentifier)) {
attributeList.add(new Attr_NASIdentifier(this.nasIdentifier));
}
if (this.nasPort != -1) {
attributeList.add(new Attr_NASPort(this.nasPort));
}
if (this.nasPortId != -1) {
attributeList.add(new Attr_NASPortId(this.nasPortId));
}
if (this.nasRealPort != -1) {
attributeList.add(new Attr_NASRealPort(this.nasRealPort));
}
if (this.nasPortType != -1) {
attributeList.add(new Attr_NASPortType(this.nasPortType));
}
RadiusClient client = null;
try {
client = this.radiusClientFactory.newInstance();
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) {
final AccessAccept acceptedResponse = (AccessAccept) response;
return new RadiusResponse(acceptedResponse.getCode(),
acceptedResponse.getIdentifier(),
acceptedResponse.getAttributes().getAttributeList());
}
} catch (final Exception e) {
throw new PreventedException(e);
} finally {
if (client != null) {
client.close();
}
}
return null;
}
示例8: authenticate
import net.jradius.packet.AccessRequest; //导入依赖的package包/类
@Override
public RadiusResponse 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));
if (StringUtils.isNotBlank(this.nasIpAddress)) {
attributeList.add(new Attr_NASIPAddress(this.nasIpAddress));
}
if (StringUtils.isNotBlank(this.nasIpv6Address)) {
attributeList.add(new Attr_NASIPv6Address(this.nasIpv6Address));
}
if (this.nasPort != -1) {
attributeList.add(new Attr_NASPort(this.nasPort));
}
if (this.nasPortId != -1) {
attributeList.add(new Attr_NASPortId(this.nasPortId));
}
if (this.nasIdentifier != -1) {
attributeList.add(new Attr_NASIdentifier(this.nasIdentifier));
}
if (this.nasRealPort != -1) {
attributeList.add(new Attr_NASRealPort(this.nasRealPort));
}
if (this.nasPortType != -1) {
attributeList.add(new Attr_NASPortType(this.nasPortType));
}
RadiusClient client = null;
try {
client = this.radiusClientFactory.newInstance();
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) {
final AccessAccept acceptedResponse = (AccessAccept) response;
return new RadiusResponse(acceptedResponse.getCode(),
acceptedResponse.getIdentifier(),
acceptedResponse.getAttributes().getAttributeList());
}
} catch (final Exception e) {
throw new PreventedException(e);
} finally {
if (client != null) {
client.close();
}
}
return null;
}
示例9: authenticate
import net.jradius.packet.AccessRequest; //导入依赖的package包/类
@Override
public RadiusResponse authenticate(final String username, final String password) throws Exception {
final AttributeList attributeList = new AttributeList();
attributeList.add(new Attr_UserName(username));
attributeList.add(new Attr_UserPassword(password));
if (StringUtils.isNotBlank(this.nasIpAddress)) {
attributeList.add(new Attr_NASIPAddress(this.nasIpAddress));
}
if (StringUtils.isNotBlank(this.nasIpv6Address)) {
attributeList.add(new Attr_NASIPv6Address(this.nasIpv6Address));
}
if (this.nasPort != -1) {
attributeList.add(new Attr_NASPort(this.nasPort));
}
if (this.nasPortId != -1) {
attributeList.add(new Attr_NASPortId(this.nasPortId));
}
if (StringUtils.isNotBlank(this.nasIdentifier)) {
attributeList.add(new Attr_NASIdentifier(this.nasIdentifier));
}
if (this.nasRealPort != -1) {
attributeList.add(new Attr_NASRealPort(this.nasRealPort));
}
if (this.nasPortType != -1) {
attributeList.add(new Attr_NASPortType(this.nasPortType));
}
RadiusClient client = null;
try {
client = this.radiusClientFactory.newInstance();
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) {
final List<RadiusAttribute> attributes = response.getAttributes().getAttributeList();
LOGGER.debug("Radius response code [{}] accepted with attributes [{}] and identifier [{}]",
response.getCode(), attributes, response.getIdentifier());
return new RadiusResponse(response.getCode(),
response.getIdentifier(),
attributes);
}
LOGGER.debug("Response is not recognized");
} finally {
if (client != null) {
client.close();
}
}
return null;
}
示例10: sendRequest
import net.jradius.packet.AccessRequest; //导入依赖的package包/类
public RadiusPacket sendRequest(final AttributeList attributes) throws Exception {
final AccessRequest request = new AccessRequest(m_radiusClient, attributes);
return m_radiusClient.authenticate(request, getAuthenticator(), 0);
}
示例11: checkPacket
import net.jradius.packet.AccessRequest; //导入依赖的package包/类
/**
* @see net.jradius.standard.RadiusStandard#checkPacket(net.jradius.packet.RadiusPacket)
*/
public void checkPacket(RadiusPacket p, long[] ignore) throws StandardViolatedException
{
LinkedList missing = new LinkedList();
boolean testAs8021X = false;
if (isIEEE8021XRequired()) testAs8021X = true;
else testAs8021X = p.findAttribute(Attr_EAPMessage.TYPE) != null;
switch(p.getCode())
{
case AccessRequest.CODE:
checkMissing(p, missing, requiredAccessRequest, ignore);
checkMissing(p, missing, testAs8021X ? requiredEAPAccessRequest : requiredUAMAccessRequest, ignore);
break;
case AccessChallenge.CODE:
if (testAs8021X) checkMissing(p, missing, requiredEAPAccessChallenge, ignore);
break;
case AccessAccept.CODE:
checkMissing(p, missing, requiredAccessAccept, ignore);
if (testAs8021X) checkMissing(p, missing, requiredEAPAccessAccept, ignore);
break;
case AccountingRequest.CODE:
{
checkMissing(p, missing, requiredAccountingRequest, ignore);
switch(((AccountingRequest)p).getAccountingStatusType())
{
case AccountingRequest.ACCT_STATUS_START:
// no additional requirements
break;
case AccountingRequest.ACCT_STATUS_STOP:
checkMissing(p, missing, requiredAccountingStopRequest, ignore);
// fall through
case AccountingRequest.ACCT_STATUS_INTERIM:
checkMissing(p, missing, requiredAccountingInterimRequest, ignore);
break;
}
}
break;
}
if (!missing.isEmpty())
throw new StandardViolatedException(this.getClass(), missing);
}
示例12: run
import net.jradius.packet.AccessRequest; //导入依赖的package包/类
public void run()
{
try
{
writer.write(getOtpName());
writer.write("\n");
writer.write(getOtpPassword());
writer.write("\n");
writer.flush();
RadiusRequest request = getAccessRequest();
if (request == null)
{
RadiusLog.error("we never got the access request");
abort(null);
return;
}
AttributeList attrs = request.getAttributes();
for (Iterator i=attrs.getAttributeList().iterator(); i.hasNext();)
{
RadiusAttribute at = (RadiusAttribute)i.next();
long type = at.getFormattedType();
if (type == Attr_CalledStationId.TYPE ||
type == Attr_CallingStationId.TYPE ||
type == Attr_NASIPAddress.TYPE ||
type == Attr_NASIdentifier.TYPE ||
type == Attr_ServiceType.TYPE ||
type == Attr_JRadiusSessionId.TYPE ||
type == Attr_NASPortType.TYPE ||
type == Attr_NASPort.TYPE)
reqList.add(AttributeFactory.newAttribute(type, at.getValue().getBytes(), false));
}
reqList.add(new Attr_UserName(userName));
reqList.add(new Attr_AcctSessionId(RadiusRandom.getRandomString(16)));
AccessRequest realRequest = new AccessRequest(radiusClient, reqList);
RadiusLog.debug(
"------------------------------------------------\n"+
"OTP Proxy Request:\n" + realRequest.toString()+
"------------------------------------------------\n");
RadiusResponse reply = radiusClient.authenticate(realRequest, new EAPRelayAuthenticator(), 5);
setAccessResponse(reply);
}
catch (Exception e)
{
RadiusLog.warn(e.getMessage(), e);
abort(e);
}
}