📄 authenticate.java
字号:
* @exception XmlBlasterException Access denied */ public SessionInfo check(String secretSessionId) throws XmlBlasterException { // even the corba client should get a communication exception when the server is shutting down // (before this change he was getting "access denided" since the sessions were already killed). /* Removed check, Marcel 2003-03-26: This should be handled by loading specific plugins in xmlBlasterPlugins.xml if (glob.getRunlevelManager().getCurrentRunlevel() < RunlevelManager.RUNLEVEL_STANDBY) { String text = "The run level " + RunlevelManager.toRunlevelStr(glob.getRunlevelManager().getCurrentRunlevel()) + " of xmlBlaster is not handling any communication anymore. " + glob.getId() + "."; log.warn(ME+".communication.noconnection", text); throw new XmlBlasterException(glob, ErrorCode.COMMUNICATION_NOCONNECTION, ME, text); } */ Object obj = null; synchronized(this.sessionInfoMap) { obj = this.sessionInfoMap.get(secretSessionId); } if (obj == null) { log.warning("SessionId '" + secretSessionId + "' is invalid, no access to xmlBlaster."); throw new XmlBlasterException(glob, ErrorCode.USER_SECURITY_AUTHENTICATION_ACCESSDENIED, ME, "Your secretSessionId is invalid, no access to " + glob.getId() + "."); } SessionInfo sessionInfo = (SessionInfo)obj; sessionInfo.refreshSession(); // touch the session, expiry timer is spaned if (log.isLoggable(Level.FINE)) log.fine("Succesfully granted access for " + sessionInfo.toString()); return sessionInfo; } /** * Adds the specified client listener to receive login/logout events. * <p /> * This listener needs to implement the I_ClientListener interface. */ public void addClientListener(I_ClientListener l) { if (l == null) { return; } synchronized (clientListenerSet) { clientListenerSet.add(l); } } /** * Removes the specified listener */ public synchronized void removeClientListener(I_ClientListener l) { if (l == null) { return; } synchronized (clientListenerSet) { clientListenerSet.remove(l); } } public int getMaxSubjects() { return Integer.MAX_VALUE; // TODO: allow to limit max number of different clients (or login sessions?) } /** * Get a current snapshot of all known subjects. * @return The subjects known */ public SubjectInfo[] getSubjectInfoArr() { synchronized(this.loginNameSubjectInfoMap) { return (SubjectInfo[])this.loginNameSubjectInfoMap.values().toArray(new SubjectInfo[this.loginNameSubjectInfoMap.size()]); } } /** * Access a list of login names e.g. "joe","jack","averell","william" * @return An array of length 0 if no clients available */ public String[] getSubjects() { SubjectInfo[] arr = getSubjectInfoArr(); if (arr == null || arr.length == 0) return new String[0]; String[] ret = new String[arr.length]; for (int i=0; i<arr.length; i++) { ret[i] = arr[i].getLoginName(); } return ret; } /** * Access a list of login names e.g. "joe,jack,averell,william" * @return An empty string if no clients available */ public String getSubjectList() { int numSubjects = getNumSubjects(); if (numSubjects < 1) return ""; StringBuffer sb = new StringBuffer(numSubjects * 30); synchronized(this.loginNameSubjectInfoMap) { Iterator iterator = this.loginNameSubjectInfoMap.values().iterator(); while (iterator.hasNext()) { if (sb.length() > 0) sb.append(","); SubjectInfo subjectInfo = (SubjectInfo)iterator.next(); sb.append(subjectInfo.getLoginName()); } } return sb.toString(); } /** * Enforced by I_RunlevelListener */ public String getName() { return this.ME; } /** * Helper method where protocol layers may report a lost connection. * @see I_Authenticate#connectionState(String, ConnectionStateEnum) */ public void connectionState(String secretSessionId, ConnectionStateEnum state) { if (state == ConnectionStateEnum.DEAD) { SessionInfo sessionInfo = getSessionInfo(secretSessionId); if (sessionInfo != null) sessionInfo.lostClientConnection(); } else { log.warning("Ignoring unexpected connectionState notification + " + state.toString() + ", handling is not implemented"); } } /** * Invoked on run level change, see RunlevelManager.RUNLEVEL_HALTED and RunlevelManager.RUNLEVEL_RUNNING * <p /> * Enforced by I_RunlevelListener */ public void runlevelChange(int from, int to, boolean force) throws org.xmlBlaster.util.XmlBlasterException { //if (log.isLoggable(Level.FINER)) log.call(ME, "Changing from run level=" + from + " to level=" + to + " with force=" + force); if (to == from) return; if (to > from) { // startup if (to == RunlevelManager.RUNLEVEL_CLEANUP_PRE) { } } if (to < from) { // shutdown if (to == RunlevelManager.RUNLEVEL_HALTED) { if (log.isLoggable(Level.FINE)) log.fine("Killing " + this.sessionInfoMap.size() + " login sessions"); SessionInfo[] sessionInfoArr = getSessionInfoArr(); for (int ii=0; ii<sessionInfoArr.length; ii++) { try { boolean clearQueue = false; boolean forceShutdownEvenIfEntriesExist = true; resetSessionInfo(sessionInfoArr[ii], clearQueue, forceShutdownEvenIfEntriesExist, false); } catch (Throwable e) { log.severe("Problem on session shutdown, we ignore it: " + e.getMessage()); if (!(e instanceof XmlBlasterException)) e.printStackTrace(); } } // for } } }/* private I_SessionPersistencePlugin getSessionPersistencePlugin() { return ((I_SessionPersistencePlugin)this.glob.getPluginRegistry().getPlugin(I_SessionPersistencePlugin.ID)); } private void persistenceConnect(SessionInfo info) throws XmlBlasterException { I_SessionPersistencePlugin plugin = getSessionPersistencePlugin(); if (plugin == null) { log.error(ME, "persistenceConnect: the session persistence plugin is not registered (yet): can't make connection persistent"); Thread.dumpStack(); return; } ClientEvent event = new ClientEvent(info); plugin.sessionAdded(event); } private void persistenceDisConnect(SessionInfo info) throws XmlBlasterException { I_SessionPersistencePlugin plugin = getSessionPersistencePlugin(); if (plugin == null) { log.error(ME, "persistenceConnect: the session persistence plugin is not registered (yet): can't make connection persistent"); Thread.dumpStack(); return; } ClientEvent event = new ClientEvent(info); plugin.sessionRemoved(event); }*/ /** * Dump state of this object into a XML ASCII string. * <br> * @return internal state of Authenticate as a XML ASCII string */ public final String toXml() { return toXml((String)null); } /** * Dump state of this object into a XML ASCII string. * <br> * @param extraOffset indenting of tags for nice output * @return internal state of Authenticate as a XML ASCII string */ public final String toXml(String extraOffset) { StringBuffer sb = new StringBuffer(1000); if (extraOffset == null) extraOffset = ""; String offset = Constants.OFFSET + extraOffset; log.info("Client maps, sessionInfoMap.size()=" + this.sessionInfoMap.size() + " and loginNameSubjectInfoMap.size()=" + getNumSubjects()); synchronized(this.loginNameSubjectInfoMap) { Iterator iterator = this.loginNameSubjectInfoMap.values().iterator(); sb.append(offset).append("<Authenticate>"); while (iterator.hasNext()) { SubjectInfo subjectInfo = (SubjectInfo)iterator.next(); sb.append(subjectInfo.toXml(extraOffset+Constants.INDENT)); } sb.append(offset).append("</Authenticate>\n"); } return sb.toString(); } /** For JMX MBean: The number of different users, the sessions may be higher */ public int getNumClients() { return getNumSubjects(); } /** For JMX MBean: The maximum number of different users, the sessions may be higher */ public int getMaxClients() { return getMaxSubjects(); } /** For JMX MBean: These are the login names returned, every client may be logged in multiple times which you can't see here */ public String getClientList() { return getSubjectList(); } /** * Authorization check (TODO: generic approach) * @param sessionInfo can be null to get the general setting * @return true: We accept wrong sender address in PublishQos.getSender() (not myself) */ public boolean isAcceptWrongSenderAddress(SessionInfo sessionInfo) { if (this.acceptWrongSenderAddress) return this.acceptWrongSenderAddress; if (sessionInfo != null) return sessionInfo.isAcceptWrongSenderAddress(); return this.acceptWrongSenderAddress; } /** * @param acceptWrongSenderAddress the acceptWrongSenderAddress to set */ public void setAcceptWrongSenderAddress(boolean acceptWrongSenderAddress) { boolean old = this.acceptWrongSenderAddress; this.acceptWrongSenderAddress = acceptWrongSenderAddress; String tmp = "Changed acceptWrongSenderAddress from " + old + " to " + this.acceptWrongSenderAddress + "."; if (this.acceptWrongSenderAddress == true) log.warning(tmp + " Caution: All clients can now publish messages using anothers login name as sender"); else log.info(tmp + " Faking anothers publisher address is not possible, but specific clients may allow it"); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -