void isReadable(SelectionKey k) { EventableChannel ec = (EventableChannel) k.attachment(); long b = ec.getBinding(); if (ec.isWatchOnly()) { if (ec.isNotifyReadable()) eventCallback(b, EM_CONNECTION_NOTIFY_READABLE, null); } else { myReadBuffer.clear(); try { ec.readInboundData(myReadBuffer); myReadBuffer.flip(); if (myReadBuffer.limit() > 0) { if (ProxyConnections != null) { EventableChannel target = ProxyConnections.get(b); if (target != null) { ByteBuffer myWriteBuffer = ByteBuffer.allocate(myReadBuffer.limit()); myWriteBuffer.put(myReadBuffer); myWriteBuffer.flip(); target.scheduleOutboundData(myWriteBuffer); } else { eventCallback(b, EM_CONNECTION_READ, myReadBuffer); } } else { eventCallback(b, EM_CONNECTION_READ, myReadBuffer); } } } catch (IOException e) { UnboundConnections.add(b); } } }
public SocketChannel detachChannel(long sig) { EventableSocketChannel ec = (EventableSocketChannel) Connections.get(sig); if (ec != null) { UnboundConnections.add(sig); return ec.getChannel(); } else { return null; } }
/** * Returns true if the user represented by the current request plays the named role. * * @param role the named role to test. * @return true if the user plays the role. */ public boolean isUserInRole(String role) { ServletInvocation invocation = getInvocation(); if (invocation == null) { if (getRequest() != null) return getRequest().isUserInRole(role); else return false; } HashMap<String, String> roleMap = invocation.getSecurityRoleMap(); if (roleMap != null) { String linkRole = roleMap.get(role); if (linkRole != null) role = linkRole; } String runAs = getRunAs(); if (runAs != null) return runAs.equals(role); WebApp webApp = getWebApp(); Principal user = getUserPrincipal(); if (user == null) { if (log.isLoggable(Level.FINE)) log.fine(this + " no user for isUserInRole"); return false; } RoleMapManager roleManager = webApp != null ? webApp.getRoleMapManager() : null; if (roleManager != null) { Boolean result = roleManager.isUserInRole(role, user); if (result != null) { if (log.isLoggable(Level.FINE)) log.fine(this + " userInRole(" + role + ")->" + result); return result; } } Login login = webApp == null ? null : webApp.getLogin(); boolean inRole = login != null && login.isUserInRole(user, role); if (log.isLoggable(Level.FINE)) { if (login == null) log.fine(this + " no Login for isUserInRole"); else if (user == null) log.fine(this + " no user for isUserInRole"); else if (inRole) log.fine(this + " " + user + " is in role: " + role); else log.fine(this + " failed " + user + " in role: " + role); } return inRole; }
public boolean startProxy(long from, long to) { // lazy init for proxy support check quickly in isReadable if (ProxyConnections == null) { ProxyConnections = new HashMap<Long, EventableChannel>(); } EventableChannel target = Connections.get(to); if (target != null) { ProxyConnections.put(from, target); return true; } else { return false; } }
/** * Construct a "simplified name" based on the subject DN from the certificate. The purpose is to * have something shorter to display in the list. The name used is one of the following DN parts, * if available, otherwise the complete DN: 'CN', 'OU' or else 'O'. * * @param cert to read subject DN from * @return the simplified name */ private static String getSimplifiedName(X509Certificate cert) { final HashMap<String, String> parts = new HashMap<String, String>(); try { for (Rdn name : new LdapName(cert.getSubjectX500Principal().getName()).getRdns()) { if (name.getType() != null && name.getValue() != null) { parts.put(name.getType(), name.getValue().toString()); } } } catch (InvalidNameException ignored) // NOPMD { } String result = parts.get("CN"); if (result == null) { result = parts.get("OU"); } if (result == null) { result = parts.get("O"); } if (result == null) { result = cert.getSubjectX500Principal().getName(); } return result; }
/** Get a class loader. Create in a restricted context */ synchronized AppletClassLoader getClassLoader(final URL codebase, final String key) { AppletClassLoader c = classloaders.get(key); if (c == null) { AccessControlContext acc = getAccessControlContext(codebase); c = AccessController.doPrivileged( new PrivilegedAction<AppletClassLoader>() { @Override public AppletClassLoader run() { AppletClassLoader ac = createClassLoader(codebase); /* Should the creation of the classloader be * within the class synchronized block? Since * this class is used by the plugin, take care * to avoid deadlocks, or specialize * AppletPanel within the plugin. It may take * an arbitrary amount of time to create a * class loader (involving getting Jar files * etc.) and may block unrelated applets from * finishing createAppletThread (due to the * class synchronization). If * createAppletThread does not finish quickly, * the applet cannot process other messages, * particularly messages such as destroy * (which timeout when called from the browser). */ synchronized (getClass()) { AppletClassLoader res = classloaders.get(key); if (res == null) { classloaders.put(key, ac); return ac; } else { return res; } } } }, acc); } return c; }
void addNewConnections() { ListIterator<EventableSocketChannel> iter = DetachedConnections.listIterator(0); while (iter.hasNext()) { EventableSocketChannel ec = iter.next(); ec.cleanup(); } DetachedConnections.clear(); ListIterator<Long> iter2 = NewConnections.listIterator(0); while (iter2.hasNext()) { long b = iter2.next(); EventableChannel ec = Connections.get(b); if (ec != null) { try { ec.register(); } catch (ClosedChannelException e) { UnboundConnections.add(ec.getBinding()); } } } NewConnections.clear(); }
public boolean isNotifyWritable(long sig) { return Connections.get(sig).isNotifyWritable(); }
public void setNotifyWritable(long sig, boolean mode) { ((EventableSocketChannel) Connections.get(sig)).setNotifyWritable(mode); }
public Object[] getPeerName(long sig) { return Connections.get(sig).getPeerName(); }
public void startTls(long sig) throws NoSuchAlgorithmException, KeyManagementException { Connections.get(sig).startTls(); }
public void closeConnection(long sig, boolean afterWriting) { EventableChannel ec = Connections.get(sig); if (ec != null) if (ec.scheduleClose(afterWriting)) UnboundConnections.add(sig); }
public void setCommInactivityTimeout(long sig, long mills) { Connections.get(sig).setCommInactivityTimeout(mills); }
public void sendData(long sig, ByteBuffer bb) throws IOException { EventableChannel channel = Connections.get(sig); if (channel != null) { channel.scheduleOutboundData(bb); } }
public void sendDatagram(long sig, ByteBuffer bb, String recipAddress, int recipPort) { (Connections.get(sig)).scheduleOutboundDatagram(bb, recipAddress, recipPort); }
private int getVKCode(int charCode, int keyCode) { int keyboardCode = 0; if (charCode >= 32) { // if it is printable, then it lives in our hashmap KeyEvent event = (KeyEvent) charMap.get(new Integer(charCode)); keyboardCode = event.getKeyCode(); } else { switch (keyCode) { case 13: keyboardCode = KeyEvent.VK_ENTER; break; case 8: keyboardCode = KeyEvent.VK_BACK_SPACE; break; case 25: // shift tab for Safari case 9: keyboardCode = KeyEvent.VK_TAB; break; case 12: keyboardCode = KeyEvent.VK_CLEAR; break; case 16: keyboardCode = KeyEvent.VK_SHIFT; break; case 17: keyboardCode = KeyEvent.VK_CONTROL; break; case 18: keyboardCode = KeyEvent.VK_ALT; break; case 63250: case 19: keyboardCode = KeyEvent.VK_PAUSE; break; case 20: keyboardCode = KeyEvent.VK_CAPS_LOCK; break; case 27: keyboardCode = KeyEvent.VK_ESCAPE; break; case 32: log("it's a space"); keyboardCode = KeyEvent.VK_SPACE; break; case 63276: case 33: keyboardCode = KeyEvent.VK_PAGE_UP; break; case 63277: case 34: keyboardCode = KeyEvent.VK_PAGE_DOWN; break; case 63275: case 35: keyboardCode = KeyEvent.VK_END; break; case 63273: case 36: keyboardCode = KeyEvent.VK_HOME; break; /** Constant for the <b>left</b> arrow key. */ case 63234: case 37: keyboardCode = KeyEvent.VK_LEFT; break; /** Constant for the <b>up</b> arrow key. */ case 63232: case 38: keyboardCode = KeyEvent.VK_UP; break; /** Constant for the <b>right</b> arrow key. */ case 63235: case 39: keyboardCode = KeyEvent.VK_RIGHT; break; /** Constant for the <b>down</b> arrow key. */ case 63233: case 40: keyboardCode = KeyEvent.VK_DOWN; break; case 63272: case 46: keyboardCode = KeyEvent.VK_DELETE; break; case 63289: case 144: keyboardCode = KeyEvent.VK_NUM_LOCK; break; case 63249: case 145: keyboardCode = KeyEvent.VK_SCROLL_LOCK; break; /** Constant for the F1 function key. */ case 63236: case 112: keyboardCode = KeyEvent.VK_F1; break; /** Constant for the F2 function key. */ case 63237: case 113: keyboardCode = KeyEvent.VK_F2; break; /** Constant for the F3 function key. */ case 63238: case 114: keyboardCode = KeyEvent.VK_F3; break; /** Constant for the F4 function key. */ case 63239: case 115: keyboardCode = KeyEvent.VK_F4; break; /** Constant for the F5 function key. */ case 63240: case 116: keyboardCode = KeyEvent.VK_F5; break; /** Constant for the F6 function key. */ case 63241: case 117: keyboardCode = KeyEvent.VK_F6; break; /** Constant for the F7 function key. */ case 63242: case 118: keyboardCode = KeyEvent.VK_F7; break; /** Constant for the F8 function key. */ case 63243: case 119: keyboardCode = KeyEvent.VK_F8; break; /** Constant for the F9 function key. */ case 63244: case 120: keyboardCode = KeyEvent.VK_F9; break; /** Constant for the F10 function key. */ case 63245: case 121: keyboardCode = KeyEvent.VK_F10; break; /** Constant for the F11 function key. */ case 63246: case 122: keyboardCode = KeyEvent.VK_F11; break; /** Constant for the F12 function key. */ case 63247: case 123: keyboardCode = KeyEvent.VK_F12; break; /** * Constant for the F13 function key. * * @since 1.2 */ /* * F13 - F24 are used on IBM 3270 keyboard; break; use * random range for constants. */ case 124: keyboardCode = KeyEvent.VK_F13; break; /** * Constant for the F14 function key. * * @since 1.2 */ case 125: keyboardCode = KeyEvent.VK_F14; break; /** * Constant for the F15 function key. * * @since 1.2 */ case 126: keyboardCode = KeyEvent.VK_F15; break; case 63302: case 45: keyboardCode = KeyEvent.VK_INSERT; break; case 47: keyboardCode = KeyEvent.VK_HELP; break; } } log("Attempting to type " + (char) charCode + ":" + charCode + " " + keyCode); log("Converted to " + keyboardCode); return keyboardCode; }
public void sendData(long sig, ByteBuffer bb) throws IOException { Connections.get(sig).scheduleOutboundData(bb); }