test_class.declarator: bindResource
test_class.original_string: BindResource bindResource;
test_class.type: BindResource
test_class.var_name: bindResource
test_class.file: tigase-server 7.1.0/src/test/java/tigase/xmpp/impl/BindResourceTest.java
test_class.identifier: BindResourceTest
test_class.superclass: extends ProcessorTestCase
test_case.body: @Test
  	public void testPreProcess() throws TigaseStringprepException, NotAuthorizedException, NoConnectionIdException {
  		JID senderJid = JID.jidInstance("sender@example.com/res-1");
  		JID recipientJid = JID.jidInstance("recipient@example.com/res-2");
  		XMPPResourceConnection senderSession = getSession(JID.jidInstance("c2s@example.com/" + UUID.randomUUID().toString()),
  																											senderJid);
  
  		Element messageEl = new Element("message",
  				new String[] { "from" },
  				new String[] { senderJid.toString() });
  		Packet p = Packet.packetInstance(messageEl);
  		p.setPacketFrom(senderSession.getConnectionId());
  
  		Map<String,Object> settings = new HashMap<>();
  		Queue<Packet> results = new ArrayDeque<>();
  
  		// message / non-presence
  		System.out.println( p.getElement() +"" );
  		System.out.println(  );
  		assertFalse(bindResource.preProcess(p, senderSession, null, results, settings));
  		assertEquals(0, results.size());
  		assertEquals(senderJid, p.getStanzaFrom());
  		System.out.println( p.getStanzaFrom() +"\n" );
  
  		p.getElement().setAttribute( "from", senderJid.getBareJID().toString());
  		System.out.println( p.getElement() +"" );
  		assertFalse(bindResource.preProcess(p, senderSession, null, results, settings));
  		assertEquals(0, results.size());
  		assertEquals(senderJid, p.getStanzaFrom());
  		System.out.println( p.getStanzaFrom() +"\n");
  
  		p.getElement().removeAttribute("from");
  		System.out.println( p.getElement()  +"");
  		assertFalse(bindResource.preProcess(p, senderSession, null, results, settings));
  		assertEquals(0, results.size());
  		assertEquals(senderJid, p.getStanzaFrom());
  		System.out.println( p.getStanzaFrom() +"\n"  );
  
  		// presence -- non-sub
  		System.out.println( "====="  );
  
  		Element presenceEl = new Element("presence",
  				new String[] { "from" },
  				new String[] { senderJid.toString() });
  		p = Packet.packetInstance(presenceEl);
  		p.setPacketFrom(senderSession.getConnectionId());
  
  		System.out.println( p.getElement() +"" );
  		System.out.println(  );
  		assertFalse(bindResource.preProcess(p, senderSession, null, results, settings));
  		assertEquals(0, results.size());
  		assertEquals(senderJid, p.getStanzaFrom());
  		System.out.println( p.getStanzaFrom() +"\n" );
  
  		p.getElement().setAttribute( "from", senderJid.getBareJID().toString());
  		System.out.println( p.getElement() +"" );
  		assertFalse(bindResource.preProcess(p, senderSession, null, results, settings));
  		assertEquals(0, results.size());
  		assertEquals(senderJid, p.getStanzaFrom());
  		System.out.println( p.getStanzaFrom() +"\n");
  
  		p.getElement().removeAttribute("from");
  		System.out.println( p.getElement()  +"");
  		assertFalse(bindResource.preProcess(p, senderSession, null, results, settings));
  		assertEquals(0, results.size());
  		assertEquals(senderJid, p.getStanzaFrom());
  		System.out.println( p.getStanzaFrom() +"\n"  );
  
  		// presence -- sub
  		System.out.println( "====="  );
  
  		p.getElement().setAttribute( "type", "subscribe");
  		p.getElement().setAttribute( "from", senderJid.toString());
  		p = Packet.packetInstance(p.getElement());
  		p.setPacketFrom(senderSession.getConnectionId());
  
  		System.out.println( p.getElement() +"" );
  		assertFalse(bindResource.preProcess(p, senderSession, null, results, settings));
  		assertEquals(0, results.size());
  		assertEquals(JID.jidInstance( senderJid.getBareJID()), p.getStanzaFrom());
  		System.out.println( p.getStanzaFrom() +"\n" );
  
  		p.getElement().setAttribute( "from", senderJid.getBareJID().toString());
  		System.out.println( p.getElement() +"" );
  		assertFalse(bindResource.preProcess(p, senderSession, null, results, settings));
  		assertEquals(0, results.size());
  		assertEquals(JID.jidInstance( senderJid.getBareJID()), p.getStanzaFrom());
  		System.out.println( p.getStanzaFrom() +"\n");
  
  		p.getElement().removeAttribute("from");
  		System.out.println( p.getElement()  +"");
  		assertFalse(bindResource.preProcess(p, senderSession, null, results, settings));
  		assertEquals(0, results.size());
  		assertEquals(JID.jidInstance( senderJid.getBareJID()), p.getStanzaFrom());
  		System.out.println( p.getStanzaFrom() +"\n"  );
  
  
  	}
test_case.class_method_signature: BindResourceTest.testPreProcess()
test_case.full_signature: @Test public void testPreProcess()
test_case.identifier: testPreProcess
test_case.invocations: jidInstance jidInstance getSession jidInstance toString randomUUID toString packetInstance setPacketFrom getConnectionId println getElement println assertFalse preProcess assertEquals size assertEquals getStanzaFrom println getStanzaFrom setAttribute getElement toString getBareJID println getElement assertFalse preProcess assertEquals size assertEquals getStanzaFrom println getStanzaFrom removeAttribute getElement println getElement assertFalse preProcess assertEquals size assertEquals getStanzaFrom println getStanzaFrom println toString packetInstance setPacketFrom getConnectionId println getElement println assertFalse preProcess assertEquals size assertEquals getStanzaFrom println getStanzaFrom setAttribute getElement toString getBareJID println getElement assertFalse preProcess assertEquals size assertEquals getStanzaFrom println getStanzaFrom removeAttribute getElement println getElement assertFalse preProcess assertEquals size assertEquals getStanzaFrom println getStanzaFrom println setAttribute getElement setAttribute getElement toString packetInstance getElement setPacketFrom getConnectionId println getElement assertFalse preProcess assertEquals size assertEquals jidInstance getBareJID getStanzaFrom println getStanzaFrom setAttribute getElement toString getBareJID println getElement assertFalse preProcess assertEquals size assertEquals jidInstance getBareJID getStanzaFrom println getStanzaFrom removeAttribute getElement println getElement assertFalse preProcess assertEquals size assertEquals jidInstance getBareJID getStanzaFrom println getStanzaFrom
test_case.modifiers: @Test public
test_case.parameters: ()
test_case.return: void
test_case.signature: void testPreProcess()
focal_class.declarator: COMPRESS_PATH   = { "compress" }
focal_class.modifier: private static final
focal_class.original_string: private static final String[]   COMPRESS_PATH   = { "compress" };
focal_class.type: String[]
focal_class.var_name: COMPRESS_PATH
focal_class.declarator: DEF_RESOURCE_PREFIX_PROP_KEY = "def-resource-prefix"
focal_class.modifier: public static final
focal_class.original_string: public static final String      DEF_RESOURCE_PREFIX_PROP_KEY = "def-resource-prefix";
focal_class.type: String
focal_class.var_name: DEF_RESOURCE_PREFIX_PROP_KEY
focal_class.declarator: EL_NAME                      = "bind"
focal_class.modifier: private static final
focal_class.original_string: private static final String     EL_NAME                      = "bind";
focal_class.type: String
focal_class.var_name: EL_NAME
focal_class.declarator: ELEMENTS                     = {
  		Iq.IQ_BIND_PATH
  	}
focal_class.modifier: private static final
focal_class.original_string: private static final String[][] ELEMENTS                     = {
  		Iq.IQ_BIND_PATH
  	};
focal_class.type: String[][]
focal_class.var_name: ELEMENTS
focal_class.declarator: log = Logger.getLogger(BindResource.class.getName())
focal_class.modifier: private static final
focal_class.original_string: private static final Logger     log = Logger.getLogger(BindResource.class.getName());
focal_class.type: Logger
focal_class.var_name: log
focal_class.declarator: resGenerator                 = 0
focal_class.modifier: private static
focal_class.original_string: private static int              resGenerator                 = 0;
focal_class.type: int
focal_class.var_name: resGenerator
focal_class.declarator: XMLNS  = "urn:ietf:params:xml:ns:xmpp-bind"
focal_class.modifier: private static final
focal_class.original_string: private static final String    XMLNS  = "urn:ietf:params:xml:ns:xmpp-bind";
focal_class.type: String
focal_class.var_name: XMLNS
focal_class.declarator: ID     = XMLNS
focal_class.modifier: private static final
focal_class.original_string: private static final String    ID     = XMLNS;
focal_class.type: String
focal_class.var_name: ID
focal_class.declarator: XMLNSS = { XMLNS }
focal_class.modifier: private static final
focal_class.original_string: private static final String[]  XMLNSS = { XMLNS };
focal_class.type: String[]
focal_class.var_name: XMLNSS
focal_class.declarator: FEATURES = { new Element(EL_NAME, new String[] {
  			"xmlns" }, new String[] { XMLNS }) }
focal_class.modifier: private static final
focal_class.original_string: private static final Element[] FEATURES = { new Element(EL_NAME, new String[] {
  			"xmlns" }, new String[] { XMLNS }) };
focal_class.type: Element[]
focal_class.var_name: FEATURES
focal_class.declarator: DISCO_FEATURES = { new Element("feature", new String[] {
  			"var" }, new String[] { XMLNS }) }
focal_class.modifier: private static final
focal_class.original_string: private static final Element[] DISCO_FEATURES = { new Element("feature", new String[] {
  			"var" }, new String[] { XMLNS }) };
focal_class.type: Element[]
focal_class.var_name: DISCO_FEATURES
focal_class.declarator: RESOURCE_PREFIX_DEF = "tigase-"
focal_class.modifier: private static final
focal_class.original_string: private static final String RESOURCE_PREFIX_DEF = "tigase-";
focal_class.type: String
focal_class.var_name: RESOURCE_PREFIX_DEF
focal_class.declarator: apnsDBProvider
focal_class.modifier: protected
focal_class.original_string: protected APNSDBProvider apnsDBProvider;
focal_class.type: APNSDBProvider
focal_class.var_name: apnsDBProvider
focal_class.declarator: resourceDefPrefix = RESOURCE_PREFIX_DEF
focal_class.modifier: private
focal_class.original_string: private String resourceDefPrefix = RESOURCE_PREFIX_DEF;
focal_class.type: String
focal_class.var_name: resourceDefPrefix
focal_class.file: tigase-server 7.1.0/src/main/java/tigase/xmpp/impl/BindResource.java
focal_class.identifier: BindResource
focal_class.interfaces: implements XMPPProcessorIfc, XMPPPreprocessorIfc
focal_class.class_method_signature: BindResource.id()
focal_class.full_signature: @Override public String id()
focal_class.identifier: id
focal_class.modifiers: @Override public
focal_class.parameters: ()
focal_class.return: String
focal_class.signature: String id()
focal_class.class_method_signature: BindResource.init(Map<String, Object> settings)
focal_class.full_signature: @Override public void init(Map<String, Object> settings)
focal_class.identifier: init
focal_class.modifiers: @Override public
focal_class.parameters: (Map<String, Object> settings)
focal_class.return: void
focal_class.signature: void init(Map<String, Object> settings)
focal_class.class_method_signature: BindResource.preProcess(Packet packet, XMPPResourceConnection session,
  			NonAuthUserRepository repo, Queue<Packet> results, Map<String, Object> settings)
focal_class.full_signature: @Override public boolean preProcess(Packet packet, XMPPResourceConnection session,
  			NonAuthUserRepository repo, Queue<Packet> results, Map<String, Object> settings)
focal_class.identifier: preProcess
focal_class.modifiers: @Override public
focal_class.parameters: (Packet packet, XMPPResourceConnection session,
  			NonAuthUserRepository repo, Queue<Packet> results, Map<String, Object> settings)
focal_class.return: boolean
focal_class.signature: boolean preProcess(Packet packet, XMPPResourceConnection session,
  			NonAuthUserRepository repo, Queue<Packet> results, Map<String, Object> settings)
focal_class.class_method_signature: BindResource.process(final Packet packet, final XMPPResourceConnection session,
  			final NonAuthUserRepository repo, final Queue<Packet> results, final Map<String,
  			Object> settings)
focal_class.full_signature: @Override public void process(final Packet packet, final XMPPResourceConnection session,
  			final NonAuthUserRepository repo, final Queue<Packet> results, final Map<String,
  			Object> settings)
focal_class.identifier: process
focal_class.modifiers: @Override public
focal_class.parameters: (final Packet packet, final XMPPResourceConnection session,
  			final NonAuthUserRepository repo, final Queue<Packet> results, final Map<String,
  			Object> settings)
focal_class.return: void
focal_class.signature: void process(final Packet packet, final XMPPResourceConnection session,
  			final NonAuthUserRepository repo, final Queue<Packet> results, final Map<String,
  			Object> settings)
focal_class.class_method_signature: BindResource.supDiscoFeatures(final XMPPResourceConnection session)
focal_class.full_signature: @Override public Element[] supDiscoFeatures(final XMPPResourceConnection session)
focal_class.identifier: supDiscoFeatures
focal_class.modifiers: @Override public
focal_class.parameters: (final XMPPResourceConnection session)
focal_class.return: Element[]
focal_class.signature: Element[] supDiscoFeatures(final XMPPResourceConnection session)
focal_class.class_method_signature: BindResource.supElementNamePaths()
focal_class.full_signature: @Override public String[][] supElementNamePaths()
focal_class.identifier: supElementNamePaths
focal_class.modifiers: @Override public
focal_class.parameters: ()
focal_class.return: String[][]
focal_class.signature: String[][] supElementNamePaths()
focal_class.class_method_signature: BindResource.supNamespaces()
focal_class.full_signature: @Override public String[] supNamespaces()
focal_class.identifier: supNamespaces
focal_class.modifiers: @Override public
focal_class.parameters: ()
focal_class.return: String[]
focal_class.signature: String[] supNamespaces()
focal_class.class_method_signature: BindResource.supStreamFeatures(final XMPPResourceConnection session)
focal_class.full_signature: @Override public Element[] supStreamFeatures(final XMPPResourceConnection session)
focal_class.identifier: supStreamFeatures
focal_class.modifiers: @Override public
focal_class.parameters: (final XMPPResourceConnection session)
focal_class.return: Element[]
focal_class.signature: Element[] supStreamFeatures(final XMPPResourceConnection session)
focal_class.superclass: extends XMPPProcessor
focal_method.body: @Override
  	public boolean preProcess(Packet packet, XMPPResourceConnection session,
  			NonAuthUserRepository repo, Queue<Packet> results, Map<String, Object> settings) {
  		if ((session == null) || session.isServerSession() || !session.isAuthorized() || C2SDeliveryErrorProcessor.isDeliveryError( packet )) {
  			return false;
  		}
  		
  		try {
  			if (session.getConnectionId().equals(packet.getPacketFrom())) {
  				// After authentication we require resource binding packet and
  				// nothing else:
  				// actually according to XEP-0170:
  				// http://xmpp.org/extensions/xep-0170.html
  				// stream compression might occur between authentication and resource
  				// binding
  				if (session.isResourceSet() || packet.isXMLNSStaticStr(Iq.IQ_BIND_PATH,
  						"urn:ietf:params:xml:ns:xmpp-bind") || packet.isXMLNSStaticStr(COMPRESS_PATH,
  						"http://jabber.org/protocol/compress")) {
  					JID from_jid = session.getJID();
  
  					if (from_jid != null) {
  
  						// http://xmpp.org/rfcs/rfc6120.html#stanzas-attributes-from
  							if ( packet.getElemName() == tigase.server.Presence.ELEM_NAME
  								 && StanzaType.getSubsTypes().contains( packet.getType() )
  								 && ( packet.getStanzaFrom() == null
  											|| !from_jid.getBareJID().equals( packet.getStanzaFrom().getBareJID() )
  											|| packet.getStanzaFrom().getResource() != null ) ){
  							if ( log.isLoggable( Level.FINEST ) ){
  								log.log( Level.FINEST, "Setting correct from attribute: {0}", from_jid );
  							}
  							packet.initVars( JID.jidInstance( from_jid.getBareJID() ), packet.getStanzaTo() );
  						} else if ( ( packet.getStanzaFrom() == null )
  												|| ( ( packet.getElemName() == tigase.server.Presence.ELEM_NAME
  															 && !StanzaType.getSubsTypes().contains( packet.getType() )
  															 || packet.getElemName() != tigase.server.Presence.ELEM_NAME )
  														 && !from_jid.equals( packet.getStanzaFrom() ) ) ){
  							if ( log.isLoggable( Level.FINEST ) ){
  								log.log( Level.FINEST, "Setting correct from attribute: {0}", from_jid );
  							}
  							packet.initVars( from_jid, packet.getStanzaTo() );
  						} else {
  							if (log.isLoggable(Level.FINEST)) {
  								log.log(Level.FINEST,
  										"Skipping setting correct from attribute: {0}, is already correct.",
  										packet.getStanzaFrom());
  							}
  						}
  					} else {
  						log.log(Level.WARNING,
  								"Session is authenticated but session.getJid() is empty: {0}", packet
  								.toStringSecure());
  					}
  				} else {
  
  					// We do not accept anything without resource binding....
  					results.offer(Authorization.NOT_AUTHORIZED.getResponseMessage(packet,
  							"You must bind the resource first: " +
  							"http://www.xmpp.org/rfcs/rfc3920.html#bind", true));
  					if (log.isLoggable(Level.INFO)) {
  						log.log(Level.INFO, "Session details: connectionId={0}, sessionId={1}",
  								new Object[] { session.getConnectionId(),
  								session.getSessionId() });
  					}
  					if (log.isLoggable(Level.FINEST)) {
  						log.log(Level.FINEST, "Session more detais: JID={0}", session.getjid());
  					}
  
  					return true;
  				}			
  			}
  		} catch (PacketErrorTypeException e) {
  
  			// Ignore this packet
  			if (log.isLoggable(Level.FINEST)) {
  				log.log(Level.FINEST,
  						"Ignoring packet with an error to non-existen user session: {0}", packet
  						.toStringSecure());
  			}
  		} catch (Exception e) {
  			log.log(Level.FINEST, "Packet preprocessing exception: ", e);
  
  			return false;
  		}    // end of try-catch	
  		
  		return false;
  	}
focal_method.class_method_signature: BindResource.preProcess(Packet packet, XMPPResourceConnection session,
  			NonAuthUserRepository repo, Queue<Packet> results, Map<String, Object> settings)
focal_method.full_signature: @Override public boolean preProcess(Packet packet, XMPPResourceConnection session,
  			NonAuthUserRepository repo, Queue<Packet> results, Map<String, Object> settings)
focal_method.identifier: preProcess
focal_method.invocations: isServerSession isAuthorized isDeliveryError equals getConnectionId getPacketFrom isResourceSet isXMLNSStaticStr isXMLNSStaticStr getJID getElemName contains getSubsTypes getType getStanzaFrom equals getBareJID getBareJID getStanzaFrom getResource getStanzaFrom isLoggable log initVars jidInstance getBareJID getStanzaTo getStanzaFrom getElemName contains getSubsTypes getType getElemName equals getStanzaFrom isLoggable log initVars getStanzaTo isLoggable log getStanzaFrom log toStringSecure offer getResponseMessage isLoggable log getConnectionId getSessionId isLoggable log getjid isLoggable log toStringSecure log
focal_method.modifiers: @Override public
focal_method.parameters: (Packet packet, XMPPResourceConnection session,
  			NonAuthUserRepository repo, Queue<Packet> results, Map<String, Object> settings)
focal_method.return: boolean
focal_method.signature: boolean preProcess(Packet packet, XMPPResourceConnection session,
  			NonAuthUserRepository repo, Queue<Packet> results, Map<String, Object> settings)