本文整理汇总了Java中net.jradius.packet.AccessAccept类的典型用法代码示例。如果您正苦于以下问题:Java AccessAccept类的具体用法?Java AccessAccept怎么用?Java AccessAccept使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
AccessAccept类属于net.jradius.packet包,在下文中一共展示了AccessAccept类的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: authenticate
import net.jradius.packet.AccessAccept; //导入依赖的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.AccessAccept; //导入依赖的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: onPostAuthentication
import net.jradius.packet.AccessAccept; //导入依赖的package包/类
public void onPostAuthentication(JRadiusRequest request) throws RadiusException
{
RadiusPacket rep = request.getReplyPacket();
boolean success = (rep instanceof AccessAccept && request.getReturnValue() != JRadiusServer.RLM_MODULE_REJECT);
RadiusLog.debug("Authentication: " + request + " was" + (success ? "" : " NOT") + " sucessful");
if (success)
{
Long sessionTimeout = (Long)rep.getAttributeValue(Attr_SessionTimeout.TYPE);
if (checkSessionState(ACCT_STARTED))
{
if (sessionTimeout != null)
{
Long sessionTime = getSessionTime();
if (sessionTime != null)
{
// Compensate the sessionTimeout for re-authentications
sessionTimeout = new Long(sessionTimeout.longValue() - sessionTime.longValue());
}
}
}
else
{
setSessionState(AUTH_ACCEPTED);
}
setIdleTimeout((Long)rep.getAttributeValue(Attr_IdleTimeout.TYPE));
setInterimInterval((Long)rep.getAttributeValue(Attr_AcctInterimInterval.TYPE));
setSessionTimeout(sessionTimeout);
}
else
{
setSessionState(AUTH_REJECTED);
}
}
示例4: handle
import net.jradius.packet.AccessAccept; //导入依赖的package包/类
public boolean handle(JRadiusRequest request) throws RadiusException
{
JRadiusSession session = request.getSession();
if (session == null) return noSessionFound(request);
RadiusPacket rep = request.getReplyPacket();
if (!(rep instanceof AccessAccept ||
rep instanceof AccessChallenge)) return false;
Object[] attrs = rep.findAttributes(Attr_Class.TYPE);
if (attrs != null && session.getRadiusClass() == null)
{
byte[][] classes = new byte[attrs.length][];
for (int i = 0; i < attrs.length; i++)
{
RadiusAttribute attribute = (RadiusAttribute) attrs[i];
classes[i] = (byte[]) attribute.getValue().getValueObject();
}
// System.err.println(this.getClass().getName() + " setting radiusClass");
session.setRadiusClass(classes);
}
RadiusAttribute attr = rep.findAttribute(Attr_State.TYPE);
if (attr != null)
{
byte[] val = (byte[]) attr.getValue().getValueObject();
// System.err.println(this.getClass().getName() + " setting radiusState "+val.length+" "+val[0]);
session.setRadiusState(val);
}
rep.overwriteAttribute(AttributeFactory.newAttribute(rep instanceof AccessAccept ? Attr_Class.TYPE : Attr_State.TYPE,
(ClassPrefix + session.getSessionKey()).getBytes(), rep.isRecyclable()));
return false;
}
示例5: authenticate
import net.jradius.packet.AccessAccept; //导入依赖的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;
}
示例6: authenticate
import net.jradius.packet.AccessAccept; //导入依赖的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;
}
示例7: authenticate
import net.jradius.packet.AccessAccept; //导入依赖的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;
}
示例8: onInit
import net.jradius.packet.AccessAccept; //导入依赖的package包/类
/** {@inheritDoc} */
@Override
public void onInit() {
send(request(getNasID(), getUser(), getPassword()), expectValidResponse(AccessAccept.class, AccessChallenge.class, AccessReject.class));
}
示例9: handle
import net.jradius.packet.AccessAccept; //导入依赖的package包/类
public boolean handle(JRadiusRequest jRequest)
{
try
{
/*
* Gather some information about the JRadius request
*/
int type = jRequest.getType();
AttributeList ci = jRequest.getConfigItems();
RadiusPacket req = jRequest.getRequestPacket();
RadiusPacket rep = jRequest.getReplyPacket();
/*
* Find the username in the request packet
*/
String username = (String)req.getAttributeValue(Attr_UserName.TYPE);
/*
* See if this is a local user, otherwise we will reject (though, you may
* want to return "ok" if you have modules configured after jradius in FreeRADIUS)
*/
LocalUser u = (LocalUser) users.get(username);
if (u == null)
{
// Unknown username, so let the RADIUS server sort it out.
RadiusLog.info("Ignoring unknown username: " + username);
return false;
}
switch (type)
{
case JRadiusServer.JRADIUS_authorize:
{
/*
* We know the user, lets inform FreeRADIUS of the user's
* password so that FreeRADIUS may perform the required
* authentication checks.
*/
//ci.add(new Attr_AuthType(Attr_AuthType.Local)); // Auth locally
ci.add(new Attr_UserPassword(u.password)); // FreeRADIUS 1.0
ci.add(new Attr_CleartextPassword(u.password)); // FreeRADIUS 2.0
}
break;
case JRadiusServer.JRADIUS_post_auth:
{
if (rep instanceof AccessAccept)
{
/*
* FreeRADIUS has returned after the authentication checks and the
* user's credentials worked. Since we are now returning an AccessAccept,
* we will the packet with the attributes configured for the user.
*/
rep.addAttributes(u.getAttributeList());
//RadiusLog.info("Authentication successful for username: " + username);
}
else
{
RadiusLog.info("Authentication failed for username: " + username);
}
}
break;
}
}
catch (RadiusException e)
{
e.printStackTrace();
}
/*
* Everything worked out well, from the perspective of this module.
*/
jRequest.setReturnValue(JRadiusServer.RLM_MODULE_UPDATED);
return false;
}
示例10: checkPacket
import net.jradius.packet.AccessAccept; //导入依赖的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);
}
示例11: handle
import net.jradius.packet.AccessAccept; //导入依赖的package包/类
public boolean handle(JRadiusRequest request) throws Exception
{
JRadiusSession session = (JRadiusSession) request.getSession();
if (session == null) return noSessionFound(request);
RadiusPacket req = request.getRequestPacket();
RadiusPacket rep = request.getReplyPacket();
AttributeList ci = request.getConfigItems();
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;
req.addAttribute(new Attr_JRadiusSessionId(session.getSessionKey()));
otpRequest.setAccessRequest((RadiusRequest)req);
RadiusResponse resp = otpRequest.getAccessResponse();
if (resp == null)
{
ci.add(new Attr_AuthType(Attr_AuthType.Reject));
request.setReturnValue(JRadiusServer.RLM_MODULE_REJECT);
return true;
}
RadiusLog.debug(
"------------------------------------------------\n"+
"OTP Proxy Response:\n" + resp.toString()+
"------------------------------------------------\n");
if (resp instanceof AccessAccept)
{
AttributeList attrs = resp.getAttributes();
attrs.remove(Attr_Class.TYPE);
attrs.remove(Attr_State.TYPE);
attrs.remove(Attr_EAPMessage.TYPE);
attrs.remove(Attr_MessageAuthenticator.TYPE);
rep.addAttributes(attrs);
return false;
}
ci.add(new Attr_AuthType(Attr_AuthType.Reject));
request.setReturnValue(JRadiusServer.RLM_MODULE_REJECT);
return true;
}