Java Code Examples for org.apache.mina.core.session.IoSession#getRemoteAddress()
The following examples show how to use
org.apache.mina.core.session.IoSession#getRemoteAddress() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RTMPMinaConnection.java From red5-server-common with Apache License 2.0 | 6 votes |
/** * Setter for MINA I/O session (connection). * * @param protocolSession * Protocol session */ public void setIoSession(IoSession protocolSession) { SocketAddress remote = protocolSession.getRemoteAddress(); if (remote instanceof InetSocketAddress) { remoteAddress = ((InetSocketAddress) remote).getAddress().getHostAddress(); remotePort = ((InetSocketAddress) remote).getPort(); } else { remoteAddress = remote.toString(); remotePort = -1; } remoteAddresses = new ArrayList<String>(1); remoteAddresses.add(remoteAddress); remoteAddresses = Collections.unmodifiableList(remoteAddresses); this.ioSession = protocolSession; if (log.isTraceEnabled()) { log.trace("setIoSession conn: {}", this); } }
Example 2
Source File: ConnectionThrottleFilter.java From neoscada with Eclipse Public License 1.0 | 5 votes |
/** * Method responsible for deciding if a connection is OK * to continue * * @param session * The new session that will be verified * @return * True if the session meets the criteria, otherwise false */ protected boolean isConnectionOk(IoSession session) { SocketAddress remoteAddress = session.getRemoteAddress(); if (remoteAddress instanceof InetSocketAddress) { InetSocketAddress addr = (InetSocketAddress) remoteAddress; long now = System.currentTimeMillis(); if (clients.containsKey(addr.getAddress().getHostAddress())) { LOGGER.debug("This is not a new client"); Long lastConnTime = clients.get(addr.getAddress().getHostAddress()); clients.put(addr.getAddress().getHostAddress(), now); // if the interval between now and the last connection is // less than the allowed interval, return false if (now - lastConnTime < allowedInterval) { LOGGER.warn("Session connection interval too short"); return false; } return true; } clients.put(addr.getAddress().getHostAddress(), now); return true; } return false; }
Example 3
Source File: BlacklistFilter.java From neoscada with Eclipse Public License 1.0 | 5 votes |
private boolean isBlocked(IoSession session) { SocketAddress remoteAddress = session.getRemoteAddress(); if (remoteAddress instanceof InetSocketAddress) { InetAddress address = ((InetSocketAddress) remoteAddress).getAddress(); // check all subnets for (Subnet subnet : blacklist) { if (subnet.inSubnet(address)) { return true; } } } return false; }
Example 4
Source File: GameSession.java From GameServer with Apache License 2.0 | 5 votes |
public GameSession(IoSession session){ this.session = session; this.session.setAttribute(KEY_PLAYER_SESSION, this); SocketAddress socketaddress = session.getRemoteAddress(); InetSocketAddress s = (InetSocketAddress) socketaddress; address = s.getAddress().getHostAddress(); }
Example 5
Source File: MinaNetServerHandler.java From Lealone-Plugins with Apache License 2.0 | 5 votes |
@Override public void exceptionCaught(IoSession session, Throwable cause) { session.closeNow(); String msg = "RemoteAddress " + session.getRemoteAddress(); logger.error(msg + " exception: " + cause.getMessage()); logger.info(msg + " closed"); }
Example 6
Source File: MinaWritableChannel.java From Lealone-Plugins with Apache License 2.0 | 5 votes |
public MinaWritableChannel(IoSession session) { this.session = session; SocketAddress sa = session.getRemoteAddress(); if (sa instanceof InetSocketAddress) { address = (InetSocketAddress) sa; } else { address = null; } }
Example 7
Source File: MinaNetClientHandler.java From Lealone-Plugins with Apache License 2.0 | 5 votes |
@Override public void exceptionCaught(IoSession session, Throwable cause) { session.closeNow(); String msg = "RemoteAddress " + session.getRemoteAddress(); logger.error(msg + " exception: " + cause.getMessage(), cause); logger.info(msg + " closed"); client.removeConnection(session); }
Example 8
Source File: ServerModel.java From MiniWeChat-Server with MIT License | 5 votes |
/** * 从iosession生成Key * * @param ioSession * @return * @throws NoIpException */ public static String getIoSessionKey(IoSession ioSession) throws NoIpException { // System.err.println("1.2 " + (ioSession.getRemoteAddress() == null)); if (ioSession.getRemoteAddress() == null) throw new NoIpException(); return ((InetSocketAddress) ioSession.getRemoteAddress()).getAddress().toString() + ":" + ((InetSocketAddress) ioSession.getRemoteAddress()).getPort(); }
Example 9
Source File: MinaServerHandler.java From java-study with Apache License 2.0 | 4 votes |
@Override public void sessionCreated(IoSession iosession) throws Exception{ InetSocketAddress sa=(InetSocketAddress)iosession.getRemoteAddress(); String address=sa.getAddress().getHostAddress(); //访问的ip logger.info("服务端与客户端创建连接..."+"访问的IP:"+address); }
Example 10
Source File: MyFilter.java From mina with Apache License 2.0 | 4 votes |
@Override public void messageReceived(NextFilter nextFilter, IoSession session, Object message) throws Exception { InetSocketAddress socketAddress = (InetSocketAddress) session.getRemoteAddress(); log.debug("远程服务器地址:" + socketAddress.getAddress().getHostAddress()); nextFilter.messageReceived(session, message); }
Example 11
Source File: MinaNetClient.java From Lealone-Plugins with Apache License 2.0 | 4 votes |
private InetSocketAddress getInetSocketAddress(IoSession session) { return (InetSocketAddress) session.getRemoteAddress(); }
Example 12
Source File: TftpServerProtocolHandler.java From tftp4j with Apache License 2.0 | 4 votes |
@Override public void messageReceived(IoSession session, Object message) throws Exception { TftpPacket packet = (TftpPacket) message; SocketAddress address = session.getRemoteAddress(); LOG.info("Address is " + address); switch (packet.getOpcode()) { case RRQ: { TftpRequestPacket request = (TftpRequestPacket) packet; TftpData source = provider.open(request.getFilename()); if (source == null) { session.write(new TftpErrorPacket(address, TftpErrorCode.FILE_NOT_FOUND), address); session.close(false); } else { final NioDatagramConnector connector = new NioDatagramConnector(); TftpTransfer transfer = new TftpReadTransfer(address, source, request.getBlockSize()); TftpTransferProtocolHandler handler = new TftpTransferProtocolHandler(connector, transfer); connector.getFilterChain().addLast("codec", new ProtocolCodecFilter(new TftpProtocolCodecFactory())); connector.getFilterChain().addLast("logger-packet", new LoggingFilter("tftp-transfer-packet")); connector.setHandler(handler); ConnectFuture future = connector.connect(address); future.addListener(handler); } break; } case WRQ: { session.write(new TftpErrorPacket(address, TftpErrorCode.PERMISSION_DENIED), address); session.close(false); break; } case ACK: { break; } case DATA: { LOG.warn("Unexpected TFTP " + packet.getOpcode() + " packet: " + packet); session.write(new TftpErrorPacket(address, TftpErrorCode.ILLEGAL_OPERATION), address); session.close(false); break; } case ERROR: { TftpErrorPacket error = (TftpErrorPacket) packet; LOG.error("Received TFTP error packet: " + error); session.close(true); break; } } }
Example 13
Source File: TftpProtocolCodecFactory.java From tftp4j with Apache License 2.0 | 4 votes |
@Override public void decode(IoSession session, IoBuffer in, ProtocolDecoderOutput out) throws Exception { TftpPacket packet = super.decode(session.getRemoteAddress(), in.buf()); out.write(packet); }
Example 14
Source File: DhcpProtocolHandler.java From dhcp4j with Apache License 2.0 | 4 votes |
@Override public void messageReceived(IoSession session, Object message) throws Exception { if (LOG.isDebugEnabled()) LOG.debug("{} -> {} RCVD: {}", session.getRemoteAddress(), session.getLocalAddress(), message); DhcpMessage request = (DhcpMessage) message; InetSocketAddress remoteAddress = (InetSocketAddress) session.getRemoteAddress(); // This doesn't work in practice. Pass the InterfaceAddress to the constructor. // InetSocketAddress localSocketAddress = (InetSocketAddress) session.getLocalAddress(); // InterfaceAddress localAddress = new InterfaceAddress(localSocketAddress.getAddress(), 0); DhcpRequestContext context = interfaceManager.newRequestContext( (InetSocketAddress) session.getServiceAddress(), (InetSocketAddress) session.getLocalAddress(), (InetSocketAddress) session.getRemoteAddress(), request); if (context == null) { debug("IGNQUERY", session.getRemoteAddress(), session.getLocalAddress(), request); return; } MDCUtils.init(context, request); try { DhcpMessage reply = dhcpService.getReplyFor(context, request); if (reply == null) { debug("NOREPLY", session.getRemoteAddress(), session.getLocalAddress(), request); return; } InterfaceAddress localAddress = interfaceManager.getResponseInterface( request.getRelayAgentAddress(), request.getCurrentClientAddress(), session.getRemoteAddress(), reply ); if (localAddress == null) { debug("NOIFACE", session.getRemoteAddress(), session.getLocalAddress(), reply); return; } InetSocketAddress isa = DhcpInterfaceUtils.determineMessageDestination( request, reply, localAddress, remoteAddress.getPort()); session.write(reply, isa); } finally { MDCUtils.fini(); } }
Example 15
Source File: AWSIAMAuthenticator.java From aws-iam-ldap-bridge with Apache License 2.0 | 4 votes |
@Override public LdapPrincipal authenticate(BindOperationContext bindContext) throws Exception { if (!isAWSAccount(bindContext) || disabled) { LOG.debug("Skipping " + bindContext.getDn() + " - not an AWS account"); if (delegatedAuth == null) { LOG.error("Delegated auth is null"); return null; } return delegatedAuth.authenticate(bindContext); } LOG.debug("Authenticating " + bindContext.getDn()); byte[] password = bindContext.getCredentials(); LookupOperationContext lookupContext = new LookupOperationContext( getDirectoryService().getAdminSession(), bindContext.getDn(), SchemaConstants.ALL_USER_ATTRIBUTES, SchemaConstants.ALL_OPERATIONAL_ATTRIBUTES); Entry userEntry = getDirectoryService().getPartitionNexus().lookup( lookupContext ); if (validator.verifyIAMPassword(userEntry, new String(password))) { LdapPrincipal principal = new LdapPrincipal( getDirectoryService().getSchemaManager(), bindContext.getDn(), AuthenticationLevel.SIMPLE, password); IoSession session = bindContext.getIoSession(); if ( session != null ) { SocketAddress clientAddress = session.getRemoteAddress(); principal.setClientAddress( clientAddress ); SocketAddress serverAddress = session.getServiceAddress(); principal.setServerAddress( serverAddress ); } bindContext.setEntry( new ClonedServerEntry( userEntry ) ); return principal; } else { // Bad password ... String message = I18n.err( I18n.ERR_230, bindContext.getDn().getName() ); LOG.info( message ); throw new LdapAuthenticationException( message ); } }
Example 16
Source File: DhcpProtocolHandler.java From dhcp4j with Apache License 2.0 | 4 votes |
@Override public void messageReceived(IoSession session, Object message) throws Exception { if (LOG.isDebugEnabled()) LOG.debug("{} -> {} RCVD: {}", session.getRemoteAddress(), session.getLocalAddress(), message); DhcpMessage request = (DhcpMessage) message; InetSocketAddress remoteAddress = (InetSocketAddress) session.getRemoteAddress(); // This doesn't work in practice. Pass the InterfaceAddress to the constructor. // InetSocketAddress localSocketAddress = (InetSocketAddress) session.getLocalAddress(); // InterfaceAddress localAddress = new InterfaceAddress(localSocketAddress.getAddress(), 0); DhcpRequestContext context = interfaceManager.newRequestContext( (InetSocketAddress) session.getServiceAddress(), (InetSocketAddress) session.getLocalAddress(), (InetSocketAddress) session.getRemoteAddress(), request); if (context == null) { debug("IGNQUERY", session.getRemoteAddress(), session.getLocalAddress(), request); return; } MDCUtils.init(context, request); try { DhcpMessage reply = dhcpService.getReplyFor(context, request); if (reply == null) { debug("NOREPLY", session.getRemoteAddress(), session.getLocalAddress(), request); return; } InterfaceAddress localAddress = interfaceManager.getResponseInterface( request.getRelayAgentAddress(), request.getCurrentClientAddress(), session.getRemoteAddress(), reply ); if (localAddress == null) { debug("NOIFACE", session.getRemoteAddress(), session.getLocalAddress(), reply); return; } InetSocketAddress isa = DhcpInterfaceUtils.determineMessageDestination( request, reply, localAddress, remoteAddress.getPort()); session.write(reply, isa); } finally { MDCUtils.fini(); } }