// audit logging for successful authentication
Globals.getAuditSession().authentication(con.getUserName(), con.remoteHostString(), true);
if (req == null) {
IMQService s = (IMQService)con.getService();
String stype = ServiceType.getServiceTypeString(s.getServiceType());
try {
AuthCacheData acd = s.getAuthCacheData();
acd.setCacheData(ac.getCacheData());
ac.checkConnectionPermission(s.getName(), stype);
// audit logging for connection authorization
Globals.getAuditSession().connectionAuth(con.getUserName(), con.remoteHostString(), stype, s.getName(), true);
} catch (AccessControlException e) {
reason = "Forbidden";
status = Status.FORBIDDEN;
ac.logout();
logger.log(Logger.WARNING,
Globals.getBrokerResources().getKString(
BrokerResources.W_SERVICE_ACCESS_DENIED,
s.getName(), stype)+ " - " + e.getMessage(), e);
// audit logging for authentication failure
Globals.getAuditSession().connectionAuth(con.getUserName(), con.remoteHostString(), stype, s.getName(), false);
username = con.getUserName();
}
}
} catch (FailedLoginException e) {
IMQService s = (IMQService)con.getService();
Globals.getAuditSession().authentication(e.getUser(),con.remoteHostString(), false);
username = e.getUser();
status = Status.INVALID_LOGIN;
reason = e.getMessage();
logger.log(Logger.WARNING, BrokerResources.W_LOGIN_FAILED, e);
} catch (OutOfMemoryError err) {
// if we get an out of memory error, throw it
// up so that memory is freed and the message is
// re-processed
throw err;
} catch (Throwable w) {
status = Status.FORBIDDEN;
reason = w.getMessage();
logger.log(Logger.ERROR, w.getMessage(), w);
}
}
// XXX - for now simple returns granted authenticate reply
Packet pkt = new Packet(con.useDirectBuffers());
pkt.setConsumerID(msg.getConsumerID());
Hashtable hash = new Hashtable();
if (reason != null)
hash.put("JMQReason", reason);
if (resp == null) {
pkt.setPacketType(PacketType.AUTHENTICATE_REPLY);
hash.put("JMQStatus", new Integer(status));
pkt.setProperties(hash);
} else {
if (req != null) {
if (!con.setConnectionState(Connection.STATE_AUTH_REQUESTED)) {
status = Status.UNAVAILABLE;
req = null;
}
}
if (req == null) {
if (status == Status.OK) {
if (!con.setConnectionState(Connection.STATE_AUTHENTICATED)) {
status = Status.UNAVAILABLE;
}
}
pkt.setPacketType(PacketType.AUTHENTICATE_REPLY);
hash.put("JMQStatus", new Integer(status));
if (((IMQBasicConnection)con).getDumpPacket() ||
((IMQBasicConnection)con).getDumpOutPacket())
hash.put("JMQReqID", msg.getSysMessageID().toString());
pkt.setProperties(hash);
} else {
pkt.setPacketType(PacketType.AUTHENTICATE_REQUEST);
hash.put("JMQAuthType", ac.getAuthType());
hash.put("JMQChallenge", Boolean.valueOf(false));
if (((IMQBasicConnection)con).getDumpPacket() ||
((IMQBasicConnection)con).getDumpOutPacket())
hash.put("JMQReqID", msg.getSysMessageID().toString());
pkt.setProperties(hash);
pkt.setMessageBody(req);
}
}
con.sendControlMessage(pkt);
if (status != Status.OK) {
IMQService s = (IMQService)con.getService();
Agent agent = Globals.getAgent();
if (agent != null) {
agent.notifyConnectionReject(s.getName(),
username,
con.remoteHostString());
}
con.closeConnection(true,