Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 1 | /* |
| 2 | * |
| 3 | * * Copyright 2015 AT&T Foundry |
| 4 | * * |
| 5 | * * Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | * * you may not use this file except in compliance with the License. |
| 7 | * * You may obtain a copy of the License at |
| 8 | * * |
| 9 | * * http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | * * |
| 11 | * * Unless required by applicable law or agreed to in writing, software |
| 12 | * * distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | * * See the License for the specific language governing permissions and |
| 15 | * * limitations under the License. |
| 16 | * |
| 17 | */ |
| 18 | |
| 19 | package org.onosproject.aaa.packet; |
| 20 | |
| 21 | import java.nio.ByteBuffer; |
| 22 | |
| 23 | public class RADIUSAttribute { |
| 24 | protected byte type; |
| 25 | protected byte length; |
| 26 | protected byte[] value; |
| 27 | |
| 28 | /* RADIUS attribute types */ |
| 29 | public static final byte RADIUS_ATTR_USERNAME = 1; |
| 30 | public static final byte RADIUS_ATTR_NAS_IP = 4; |
| 31 | public static final byte RADIUS_ATTR_NAS_PORT = 5; |
| 32 | public static final byte RADIUS_ATTR_FRAMED_MTU = 12; |
| 33 | public static final byte RADIUS_ATTR_STATE = 24; |
| 34 | public static final byte RADIUS_ATTR_VENDOR_SPECIFIC = 26; |
| 35 | public static final byte RADIUS_ATTR_CALLING_STATION_ID = 31; |
| 36 | public static final byte RADIUS_ATTR_NAS_ID = 32; |
| 37 | public static final byte RADIUS_ATTR_ACCT_SESSION_ID = 44; |
| 38 | public static final byte RADIUS_ATTR_NAS_PORT_TYPE = 61; |
| 39 | public static final byte RADIUS_ATTR_EAP_MESSAGE = 79; |
| 40 | public static final byte RADIUS_ATTR_MESSAGE_AUTH = 80; |
| 41 | public static final byte RADIUS_ATTR_NAS_PORT_ID = 87; |
| 42 | |
| 43 | public RADIUSAttribute() { |
| 44 | } |
| 45 | |
| 46 | public RADIUSAttribute(final byte type, final byte length, final byte[] value) { |
| 47 | this.type = type; |
| 48 | this.length = length; |
| 49 | this.value = value; |
| 50 | } |
| 51 | |
| 52 | public boolean isValidType() { |
| 53 | return this.type == RADIUS_ATTR_USERNAME || |
| 54 | this.type == RADIUS_ATTR_NAS_IP || |
| 55 | this.type == RADIUS_ATTR_NAS_PORT || |
| 56 | this.type == RADIUS_ATTR_VENDOR_SPECIFIC || |
| 57 | this.type == RADIUS_ATTR_CALLING_STATION_ID || |
| 58 | this.type == RADIUS_ATTR_NAS_ID || |
| 59 | this.type == RADIUS_ATTR_ACCT_SESSION_ID || |
| 60 | this.type == RADIUS_ATTR_NAS_PORT_TYPE || |
| 61 | this.type == RADIUS_ATTR_EAP_MESSAGE || |
| 62 | this.type == RADIUS_ATTR_MESSAGE_AUTH || |
| 63 | this.type == RADIUS_ATTR_NAS_PORT_ID; |
| 64 | } |
| 65 | |
| 66 | /** |
| 67 | * @return the type |
| 68 | */ |
| 69 | public byte getType() { |
| 70 | return this.type; |
| 71 | } |
| 72 | |
| 73 | /** |
| 74 | * @param type |
| 75 | * the code to set |
| 76 | * @return this |
| 77 | */ |
| 78 | public RADIUSAttribute setType(final byte type) { |
| 79 | this.type = type; |
| 80 | return this; |
| 81 | } |
| 82 | |
| 83 | /** |
| 84 | * @return the length |
| 85 | */ |
| 86 | public byte getLength() { |
| 87 | return this.length; |
| 88 | } |
| 89 | |
| 90 | /** |
| 91 | * @param length |
| 92 | * the length to set |
| 93 | * @return this |
| 94 | */ |
| 95 | public RADIUSAttribute setLength(final byte length) { |
| 96 | this.length = length; |
| 97 | return this; |
| 98 | } |
| 99 | |
| 100 | /** |
| 101 | * @return the value |
| 102 | */ |
| 103 | public byte[] getValue() { |
| 104 | return this.value; |
| 105 | } |
| 106 | |
| 107 | /** |
| 108 | * @param value |
| 109 | * the data to set |
| 110 | * @return this |
| 111 | */ |
| 112 | public RADIUSAttribute setValue(final byte[] value) { |
| 113 | this.value = value; |
| 114 | return this; |
| 115 | } |
| 116 | |
| 117 | public byte[] serialize() { |
| 118 | final byte[] data = new byte[this.length]; |
| 119 | final ByteBuffer bb = ByteBuffer.wrap(data); |
| 120 | bb.put(this.type); |
| 121 | bb.put(this.length); |
| 122 | bb.put(this.value); |
| 123 | return data; |
| 124 | } |
| 125 | } |