Parent: [6ccca6] (diff)

Child: [b323f7] (diff)

Download this file

Auth.cc    102 lines (85 with data), 3.2 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with this program. If not, see http://www.gnu.org/licenses/.
//
#include "Auth.h"
Define_Module(Auth);
void Auth::initialize()
{
initSignalsAndListeners();
}
void Auth::initSignalsAndListeners() {
cModule* catcher = this->getParentModule()->getSubmodule(MOD_CDAPCACE);
//Signals emitted by this module
sigAuthRes = registerSignal(SIG_Auth_AuthenticationResponse);
//Signals that this module is processing
//authentication request from CACE module
lisAuthValidate = new LisAuthValidate(this);
catcher->subscribe(SIG_CACE_AuthenticationRequest, lisAuthValidate);
}
void Auth::initParameters() {
AE* iae = dynamic_cast<AE*>(this->getParentModule()->getParentModule()->getSubmodule(MOD_IAE));
//assign authentication parameters from iae
if (iae) {
authType = iae->par("authType");
authName = iae->par("authName").stringValue();
authPassword = iae->par("authPassword").stringValue();
authOther = iae->par("authOther").stringValue();
}
}
void Auth::handleMessage(cMessage *msg)
{
// TODO - Generated method body
}
void Auth::validate(CDAPMessage *cmsg) {
Enter_Method("validate()");
CDAP_M_Connect* cmsgC = check_and_cast<CDAP_M_Connect*>(cmsg);
//create new M_Connect_R for passing parameters to cace
CDAP_M_Connect_R* cmsgCR = new CDAP_M_Connect_R();
result_t result;
//check and validate expected auth type
if (cmsgC->getAuth().authType == authType) {
//none auth option
if (cmsgC->getAuth().authType == AUTH_NONE) {
result.resultReason = "success";
result.resultValue = R_SUCCESS;
}
//passwd auth option
else if (cmsgC->getAuth().authType == AUTH_PASSWD) {
//correct pass
if (!strcmp(cmsgC->getAuth().authValue.authPassword.c_str(), authPassword.c_str())) {
result.resultReason = "success";
result.resultValue = R_SUCCESS;
}
else {
result.resultReason = "fail";
result.resultValue = R_FAIL;
}
}
//TODO: support for other options
}
//unexpected auth
else {
result.resultReason = "fail";
result.resultValue = R_FAIL;
}
cmsgCR->setAbsSyntax(GPB);
cmsgCR->setOpCode(M_CONNECT_R);
cmsgCR->setResult(result);
cmsgCR->setAuth(cmsgC->getAuth());
cmsgCR->setHandle(cmsgC->getHandle());
signalizeAuthResult(cmsgCR);
}
void Auth::signalizeAuthResult(CDAPMessage *cmsg) {
emit(sigAuthRes, cmsg);
}