use of com.sun.messaging.jmq.jmsserver.service.imq.IMQService in project openmq by eclipse-ee4j.
the class BrokerInstanceImpl method getJMSService.
private JMSService getJMSService(String serviceName) throws IllegalStateException {
ServiceManager sm = Globals.getServiceManager();
Service svc;
IMQService imqSvc;
IMQDirectService imqDirectSvc;
if (sm == null) {
return (null);
}
svc = sm.getService(serviceName);
if (svc == null) {
return (null);
}
if (!(svc instanceof IMQService)) {
return (null);
}
imqSvc = (IMQService) svc;
if (!imqSvc.isDirect()) {
return (null);
}
if (!(imqSvc instanceof IMQDirectService)) {
return (null);
}
imqDirectSvc = (IMQDirectService) imqSvc;
return imqDirectSvc.getJMSService();
}
use of com.sun.messaging.jmq.jmsserver.service.imq.IMQService in project openmq by eclipse-ee4j.
the class ServiceConfig method updateService.
private void updateService(int port, int min, int max) throws IOException, PropertyUpdateException, BrokerException {
ServiceManager sm = Globals.getServiceManager();
Service svc = sm.getService(getName());
IMQService stsvc;
if (svc == null) {
throw new BrokerException(rb.getString(rb.X_NO_SUCH_SERVICE, getName()));
}
if (!(svc instanceof IMQService)) {
throw new BrokerException("Internal Error: can updated non-standard Service");
}
stsvc = (IMQService) svc;
stsvc.updateService(port, min, max);
}
use of com.sun.messaging.jmq.jmsserver.service.imq.IMQService in project openmq by eclipse-ee4j.
the class UpdateServiceHandler method handle.
/**
* Handle the incomming administration message.
*
* @param con The Connection the message came in on.
* @param cmd_msg The administration message
* @param cmd_props The properties from the administration message
*/
@Override
public boolean handle(IMQConnection con, Packet cmd_msg, Hashtable cmd_props) {
if (DEBUG) {
logger.log(Logger.DEBUG, this.getClass().getName() + ": " + cmd_props);
}
ServiceInfo info = (ServiceInfo) getBodyObject(cmd_msg);
int status = Status.OK;
String errMsg = null;
ServiceManager sm = Globals.getServiceManager();
Service svc = null;
HAMonitorService hamonitor = Globals.getHAMonitorService();
if (hamonitor != null && hamonitor.inTakeover()) {
status = Status.ERROR;
errMsg = rb.getString(rb.E_CANNOT_PROCEED_TAKEOVER_IN_PROCESS);
logger.log(Logger.ERROR, this.getClass().getName() + ": " + errMsg);
} else {
if (info.name == null || ((svc = sm.getService(info.name)) == null)) {
status = Status.ERROR;
errMsg = rb.getString(rb.X_NO_SUCH_SERVICE, (info.name == null ? "<null>" : info.name));
}
}
// OK .. set the service information
if (status == Status.OK) {
if (!(svc instanceof IMQService)) {
status = Status.ERROR;
errMsg = "Internal Error: can updated non-standard Service";
} else {
// to repair this by fcs
try {
IMQService stsvc = (IMQService) svc;
int port = -1;
int min = -1;
int max = -1;
if (info.isModified(info.PORT)) {
port = info.port;
}
if (info.isModified(info.MIN_THREADS)) {
min = info.minThreads;
}
if (info.isModified(info.MAX_THREADS)) {
max = info.maxThreads;
}
if (port != -1 || min != -1 || max != -1) {
stsvc.updateService(port, min, max);
} else {
status = Status.ERROR;
errMsg = rb.getString(rb.X_NO_SERVICE_PROPS_SET, info.name);
}
} catch (Exception ex) {
logger.logStack(Logger.WARNING, rb.W_ERROR_UPDATING_SERVICE, svc.getName(), ex);
status = Status.ERROR;
errMsg = getMessageFromException(ex);
}
}
}
// Send reply
Packet reply = new Packet(con.useDirectBuffers());
reply.setPacketType(PacketType.OBJECT_MESSAGE);
setProperties(reply, MessageType.UPDATE_SERVICE_REPLY, status, errMsg);
parent.sendReply(con, cmd_msg, reply);
return true;
}
use of com.sun.messaging.jmq.jmsserver.service.imq.IMQService in project openmq by eclipse-ee4j.
the class AuthHandler method handle.
/**
* Method to handle Authentication messages
*/
@Override
public boolean handle(IMQConnection con, Packet msg) throws BrokerException {
byte[] resp = null;
ByteBuffer bbuf = msg.getMessageBodyByteBuffer();
int size = bbuf.remaining();
resp = new byte[size];
bbuf.get(resp);
String reason = null;
AccessController ac = con.getAccessController();
boolean isIndemp = msg.getIndempotent();
byte[] req = null;
int status = Status.ERROR;
String username = null;
if (con.isAuthenticated()) {
if (!isIndemp) {
// already authenticated
reason = "already authenticated";
logger.log(Logger.WARNING, "Received unexpected authentication " + con.getRemoteConnectionString() + ":" + con.getConnectionUID());
status = Status.ERROR;
} else {
status = Status.OK;
}
resp = null;
} else if (!con.setConnectionState(Connection.STATE_AUTH_RESPONSED)) {
reason = "bad connection state";
status = Status.UNAVAILABLE;
resp = null;
}
if (resp != null) {
try {
req = ac.handleResponse(resp, msg.getSequence());
status = Status.OK;
// 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) {
// 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", Integer.valueOf(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", Integer.valueOf(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.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, GoodbyeReason.CON_FATAL_ERROR, Globals.getBrokerResources().getKString(BrokerResources.M_AUTH_FAIL_CLOSE));
} else {
Agent agent = Globals.getAgent();
if (agent != null) {
agent.registerConnection(con.getConnectionUID().longValue());
agent.notifyConnectionOpen(con.getConnectionUID().longValue());
}
}
return true;
}
use of com.sun.messaging.jmq.jmsserver.service.imq.IMQService in project openmq by eclipse-ee4j.
the class JMSRA_BrokerProcess method getJMSService.
/**
* Return the named JMS Service that supports 'DIRECT' in-JVM Java EEJMS clients.
*
* @param serviceName The name of the service to return
*
* @throws IllegalStateException if the broker is already stopped
*/
@Override
public JMSService getJMSService(String serviceName) throws IllegalStateException {
ServiceManager sm = Globals.getServiceManager();
Service svc;
IMQService imqSvc;
IMQDirectService imqDirectSvc;
if (sm == null) {
return (null);
}
svc = sm.getService(serviceName);
if (svc == null) {
return (null);
}
if (!(svc instanceof IMQService)) {
return (null);
}
imqSvc = (IMQService) svc;
if (!imqSvc.isDirect()) {
return (null);
}
if (!(imqSvc instanceof IMQDirectService)) {
return (null);
}
imqDirectSvc = (IMQDirectService) imqSvc;
return imqDirectSvc.getJMSService();
}
Aggregations