Package com.sun.messaging.jmq.jmsserver.auth

Examples of com.sun.messaging.jmq.jmsserver.auth.AccessController


     * ie is it necessary for most cases ?
     */
          throw new SecurityException(errStr);
      }

    AccessController ac = a.getAccessController();

    if (ac != null)  {
        ac.setClientIP(clientIP);
    }
  }

  try {
      a.authenticate(username, passwd);
View Full Code Here


        }
    }

    private boolean checkAccessControl(Packet msg, IMQConnection con,
                                          PacketHandler handler, int pktype) {
        AccessController ac = con.getAccessController();
        if (pktype != PacketType.HELLO && pktype != PacketType.PING &&
                pktype != PacketType.AUTHENTICATE &&
                       pktype != PacketType.GOODBYE) {

            if (!ac.isAuthenticated()) {
                String emsg = Globals.getBrokerResources().getKString(
                        BrokerResources.E_UNEXPECTED_PACKET_NOT_AUTHENTICATED,
                                                 PacketType.getString(pktype));
                if (defaultHandler != null) {
                defaultHandler.sendError(con, msg, emsg, Status.ERROR);
View Full Code Here

          status = Status.UNAVAILABLE;
          String authType = null;
          if (hello_props != null) {
              authType = (String)hello_props.get("JMQAuthType");
          }
          AccessController ac = con.getAccessController();
          pkt = new Packet(con.useDirectBuffers());
          pkt.setPacketType(PacketType.AUTHENTICATE_REQUEST);
          pkt.setConsumerID(msg.getConsumerID());

          hash = new Hashtable();
          hash.put("JMQSequence", new Integer(msg.getSequence()));
          hash.put("JMQChallenge", Boolean.valueOf(true));

          Properties props = new Properties();
          props.setProperty(Globals.IMQ + ".clientIP", msg.getIPString());
          props.setProperty(Globals.IMQ + ".connectionID", con.getConnectionUID().toString());
          byte[] req = null;
          try {
          AuthCacheData acd = ((IMQService)con.getService()).getAuthCacheData();
          req = ac.getChallenge(msg.getSequence(), props,
                                acd.getCacheData(), authType);
          hash.put("JMQAuthType", ac.getAuthType());
          if (con.setConnectionState(Connection.STATE_AUTH_REQUESTED)) {
          status = Status.OK;
          }

          } catch (FailedLoginException e) {
View Full Code Here

        throws BrokerException
    {
        String cid = clientid;
        if (clientid != null) {
            if (clientid.startsWith("${u}")) {
                AccessController ac = con.getAccessController();
                String user = ac.getAuthenticatedName().getName();
                cid = "${u:"+user+"}" +clientid.substring(4);
            }
            else if (clientid.startsWith("${u:")) {
                cid = null;
            } else if (clientid.indexOf("${%%}") != -1){
View Full Code Here

        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) {
                // 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);
View Full Code Here

TOP

Related Classes of com.sun.messaging.jmq.jmsserver.auth.AccessController

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.