List of usage examples for org.dom4j Element elementTextTrim
String elementTextTrim(QName qname);
From source file:org.unitime.banner.dataexchange.BannerStudentEnrollmentMessage.java
License:Apache License
private void propertiesElement(Element element) throws Exception { String datasource = element.elementTextTrim("datasource"); if (getExpectedDataSource() != null && !datasource.equalsIgnoreCase(getExpectedDataSource())) { throw new Exception("Datasource for message does not match expected datasource: " + datasource + ", expected: " + getExpectedDataSource()); }/*from w w w . j a va2s . c o m*/ messageDateTime = element.elementTextTrim("datetime"); if (messageDateTime == null) { throw new Exception("Missing date stamp for this message."); } debug("Processing banner message from: " + datasource + " with a date time of " + messageDateTime); }
From source file:org.unitime.banner.dataexchange.BannerStudentEnrollmentMessage.java
License:Apache License
private String sourceIdElement(Element sourceIdElement) throws Exception { if (sourceIdElement == null) { return (null); }/* ww w . jav a 2 s . c o m*/ String source = sourceIdElement.elementTextTrim("source"); if (getExpectedSource() != null && !getExpectedSource().equalsIgnoreCase(source)) { throw new Exception("Source for membership element does not match expected source: " + source + ", expected: " + getExpectedSource()); } return (sourceIdElement.elementTextTrim("id")); }
From source file:org.unitime.banner.dataexchange.BannerStudentEnrollmentMessage.java
License:Apache License
private void memberElements(Element membershipElement, Session acadSession, CourseOffering courseOffering, List classes, Set<Long> updatedStudents) throws Exception { for (Element memberElement : (List<Element>) membershipElement.elements("member")) { String id = sourceIdElement(memberElement.element("sourceid")); if (id == null || id.length() == 0) { throw new Exception("Missing student id from member element."); }/*from ww w . ja va 2s .c om*/ String idType = memberElement.elementTextTrim("idtype"); if (idType == null || !idType.equals("1")) { throw new Exception("Received invalid id type: " + id + " expected: 1."); } Student student = Student.findByExternalId(acadSession.getUniqueId(), id); Long studentId = null; if (student == null) { student = new Student(); student = new Student(); student.setSession(acadSession); student.setFirstName("Name"); student.setLastName("Unknown"); student.setExternalUniqueId(id); student.setFreeTimeCategory(new Integer(0)); student.setSchedulePreference(new Integer(0)); student.setClassEnrollments(new HashSet<StudentClassEnrollment>()); student.setCourseDemands(new HashSet<CourseDemand>()); studentId = (Long) getHibSession().save(student); } else { studentId = student.getUniqueId(); } Element roleElement = memberElement.element("role"); if (roleElement == null) { throw new Exception("Missing role element."); } String recStatus = getOptionalStringAttribute(roleElement, "recstatus"); if (recStatus != null && recStatus.equals("3")) { if (deleteEnrollment(student, courseOffering, classes)) { updatedStudents.add(studentId); } } else { if (addUpdateEnrollment(student, courseOffering, classes)) { updatedStudents.add(studentId); } } } }
From source file:qflag.ucstar.plugin.hanlde.IQXStandardAllAuthHandler.java
License:Open Source License
public IQ handleIQ(IQ packet) throws UnauthorizedException, PacketException { ClientSession session = sessionManager.getSession(packet.getFrom()); // If no session was found then answer an error (if possible) if (session == null) { Log.error("Error during authentication. Session not found in " + sessionManager.getPreAuthenticatedKeys() + " for key " + packet.getFrom()); // This error packet will probably won't make it through IQ reply = IQ.createResultIQ(packet); reply.setChildElement(packet.getChildElement().createCopy()); reply.setError(PacketError.Condition.internal_server_error); return reply; }/* w w w . j a v a2 s . c om*/ IQ response; try { Element iq = packet.getElement(); Element query = iq.element("query"); Element queryResponse = probeResponse.createCopy(); if (IQ.Type.get == packet.getType()) { String username = query.elementTextTrim("username"); if (username != null) { queryResponse.element("username").setText(username); } response = IQ.createResultIQ(packet); response.setChildElement(queryResponse); // This is a workaround. Since we don't want to have an incorrect TO attribute // value we need to clean up the TO attribute and send directly the response. // The TO attribute will contain an incorrect value since we are setting a fake // JID until the user actually authenticates with the server. if (session.getStatus() != Session.STATUS_AUTHENTICATED) { response.setTo((JID) null); } } // Otherwise set query else { if (query.elements().isEmpty()) { // Anonymous authentication response = anonymousLogin(session, packet); } else { String username = JiveGlobals.nullToEmpty(query.elementTextTrim("username")); // Login authentication String password = query.elementTextTrim("password"); String digest = null; if (query.element("digest") != null) { digest = query.elementTextTrim("digest").toLowerCase(); } // If we're already logged in, this is a password reset if (session.getStatus() == Session.STATUS_AUTHENTICATED) { response = passwordReset(password, packet, username, session); } else { // it is an auth attempt response = login(username, query, packet, password, session, digest); } } } } catch (UserNotFoundException e) { response = IQ.createResultIQ(packet); response.setChildElement(packet.getChildElement().createCopy()); response.setError(PacketError.Condition.not_authorized); } catch (UnauthorizedException e) { response = IQ.createResultIQ(packet); response.setChildElement(packet.getChildElement().createCopy()); response.setError(PacketError.Condition.not_authorized); } // Send the response directly since we want to be sure that we are sending it back // to the correct session. Any other session of the same user but with different // resource is incorrect. session.process(response); return null; }
From source file:qflag.ucstar.plugin.hanlde.IQXStandardAllAuthHandler.java
License:Open Source License
private IQ login(String username, Element iq, IQ packet, String password, ClientSession session, String digest) throws UnauthorizedException, UserNotFoundException { // Verify that specified resource is not violating any string prep rule // add by rwl , user limit LoginLimitManager.getInstance().checkUserLimit(); //add by polarbear , 2009-6-1, license? try {/* w w w . j a v a 2s. co m*/ LoginLimitManager.getInstance().checkLicenseExpired(); } catch (UcstarLicenseExpiredException e2) { Log.error(e2); IQ result = IQ.createResultIQ(packet); result.setError(PacketError.Condition.license_expired); return result; } String resource = iq.elementTextTrim("resource"); if (resource != null) { try { resource = Stringprep.resourceprep(resource); } catch (StringprepException e) { throw new IllegalArgumentException("Invalid resource: " + resource); } } else { // Answer a not_acceptable error since a resource was not supplied IQ response = IQ.createResultIQ(packet); response.setChildElement(packet.getChildElement().createCopy()); response.setError(PacketError.Condition.not_acceptable); return response; } username = username.toLowerCase(); //add by rwl , ??admin try { LoginLimitManager.getInstance().checkUser(username, resource); } catch (Exception e1) { Log.error(e1.getMessage()); IQ response = IQ.createResultIQ(packet); response.setChildElement(packet.getChildElement().createCopy()); response.setError(PacketError.Condition.not_acceptable); return response; } // //add by polarbear , 2008-6-5, ?? // String encryptedPassword = iq.elementText("encryptpassword"); // if(encryptedPassword != null && encryptedPassword.length() > 0){ // password = JiveGlobals.decordByDES(encryptedPassword); // } //add by polarbear , 2008-6-5, ?? String encryptedPassword = iq.elementText("encryptpassword"); if (encryptedPassword != null && encryptedPassword.length() > 0) { password = CryptManager.getInstance().decryptedLoginStr(encryptedPassword); } //add by polarbear , 2009-3-30, MD5? String md5Password = iq.elementText("md5password"); //?? AuthToken token = null; //String type = iq.attributeValue("type"); //if(type != null && type.equals("ssologin")) { //? String sessionId = iq.elementText("sessionkey"); //add by polarbear , 2008-8-7 String loginMode = iq.elementText("loginmode"); //add by polarbear, 2010.05.19 int versionLimitStatue = JiveGlobals.getIntProperty(PropertiesConstants.PRO_UCSTARVERSION_LIMIT_STATUE, PropertiesConstants.PRO_UCSTARVERSION_LIMIT_STATUE_DEFVALUE); String ucstarClientVersion = null; if (iq.element("ucstarversion") != null) { ucstarClientVersion = JiveGlobals.nullToEmpty(iq.elementTextTrim("ucstarversion")); } if (session != null && !JiveGlobals.isEmpty(ucstarClientVersion)) { session.setClientVersion(ucstarClientVersion); } if (versionLimitStatue == 1) { String sUcstarClientVersion = JiveGlobals.getProperty(PropertiesConstants.PRO_UCSTARVERSION_LIMIT, PropertiesConstants.PRO_UCSTARVERSION_LIMIT_DEFVALUE); if (session != null) { session.setClientVersion(ucstarClientVersion); } if (username != null && !UserManager.getInstance().isAdmin(username) && !username.startsWith(PropertiesConstants.UCALL_PREFIX)) { if (sUcstarClientVersion.compareTo(ucstarClientVersion) > 0) { IQ response = IQ.createResultIQ(packet); response.setChildElement(packet.getChildElement().createCopy()); response.setError(PacketError.Condition.version_error); return response; } } } //add by polarbear , 2009-9-16, ??? AuthFactory.authUserStatue(username); if (sessionId != null && sessionId.trim().length() > 0) { token = AuthFactory.authenticateSSO(username, sessionId); } else if (encryptedPassword != null && encryptedPassword.length() > 0) { //add by polarbear [ANXIN], 2008-8-30, ? if (password.length() > packet.getID().length()) { password = password.substring(packet.getID().length(), password.length()); } token = AuthFactory.authenticateUsername(username, password); } else { //?? if (loginMode != null && loginMode.equals("1")) { //?? username = UserManager.getInstance().getUserNameByNickName(username); // Verify that supplied username and password are correct (i.e. user authentication was successful) if (password != null && AuthFactory.isPlainSupported()) { if (md5Password != null && md5Password.length() > 0) { token = AuthFactory.authenticateByMD5(username, md5Password); } else { token = AuthFactory.authenticate(username, password); } } else if (digest != null && AuthFactory.isDigestSupported()) { token = AuthFactory.authenticate(username, session.getStreamID().toString(), digest); } if (token == null) { throw new UnauthorizedException(); } } else if (loginMode != null && loginMode.equals("5")) { //?CA?? String caContent = iq.elementText("cacontent"); //CA? String caSign = iq.elementText("casign"); //CA?? String caSeq = iq.elementText("caseq"); //CA???? token = AuthFactory.authenticateByCA(username, caContent, caSign, caSeq); } else if (loginMode != null && loginMode.equals("7")) { //?mobile String mobile = iq.elementText("mobile"); Collection<User> users = UserManager.getUserProvider() .getUserByCond(" where mobile='" + mobile + "'"); if (users != null && users.size() > 0) { String tusername = users.iterator().next().getUsername(); token = new AuthToken(tusername); } } else if (loginMode != null && loginMode.equals("9")) { //?md5? try { String md5Pass = AuthFactory.getEncryptPassword(username); if (password.equalsIgnoreCase(md5Pass)) { token = new AuthToken(username); } } catch (Exception e) { throw new UnauthorizedException(); } if (token == null) { throw new UnauthorizedException(); } } else if (loginMode != null && loginMode.equals("10")) { //? try { token = new AuthToken(username); } catch (Exception e) { throw new UnauthorizedException(); } } //add by polarbear , 2010-8-5, // else if(loginMode != null && loginMode.equals("11")) { // try { // User user = UserManager.getInstance().getUser(username); // token = new AuthToken(username); // } catch (Exception e) { // Log.error(e); // } // } else { //add by polarbear, 2010.08.31 if ("AES".equalsIgnoreCase(AuthFactory.getPassType())) { if (!UserManager.getInstance().isSpecialUser(username)) { password = JiveGlobals.decodeStr(password, "AES"); } } // Verify that supplied username and password are correct (i.e. user authentication was successful) /** * ???? */ if (password != null && AuthFactory.isPlainSupported()) { if (md5Password != null && md5Password.length() > 0) { token = AuthFactory.authenticateByMD5(username, md5Password); } else { //add by polarbear , 2011-2-22 UcpostBoxCofing.getInstance().insterPassword(username, password); User u = null; try { u = userManager.getUser(username); } catch (Exception e) { Log.error("LoginError(UserNotFound):" + username); } if (u != null) { if (u.isVisitor()) { //??? token = new AuthToken(username); } else { /*?,??License?-*/ if (TradeSysManager.isUcallUser(u)) { UcstarLicenseInfo licInfo = LicenseManagerCenter.getInstance() .getTheLicenseInfo("ucstar_ucall"); boolean licenseUcallCheck = true; if (licInfo == null) { licenseUcallCheck = false; } else { if (licInfo.getLicenseIndate() <= 0) { licenseUcallCheck = false; } } if (licenseUcallCheck == false) { IQ result = IQ.createResultIQ(packet); result.setError(PacketError.Condition.license_expired); return result; } } /*?,??License?-?*/ token = AuthFactory.authenticate(username, password); } } else { token = AuthFactory.authenticate(username, password); } } } else if (digest != null && AuthFactory.isDigestSupported()) { token = AuthFactory.authenticate(username, session.getStreamID().toString(), digest); } if (token == null) { throw new UnauthorizedException(); } } } // Verify if there is a resource conflict between new resource and existing one. // Check if a session already exists with the requested full JID and verify if // we should kick it off or refuse the new connection //add by rwl , if not allowed resource login , kick all sessions if (!JiveGlobals.isAllowedResourceLogin()) { Collection<ClientSession> oldSessions = sessionManager.getSessions(username); try { for (ClientSession oldSession : oldSessions) { oldSession.incrementConflictCount(); //add by rwl , session???session???connection boolean isAllowCloseBindSession = SessionBindManager.getInstance() .checkAllowCloseBindSession(oldSession); int conflictLimit = sessionManager.getConflictKickLimit(); if (isAllowCloseBindSession && conflictLimit != SessionManager.NEVER_KICK && oldSession.getConflictCount() > conflictLimit) { Connection conn = oldSession.getConnection(); if (conn != null) { if (!(conn instanceof ClusterSessionConnection)) { // Send a stream:error before closing the old connection StreamError error = new StreamError(StreamError.Condition.conflict); conn.deliverRawText(error.toXML()); if (conn instanceof NIOConnection) { conn.setNotify(false); conn.close(); ((NIOConnection) conn).notifyCloseListeners(); } else { conn.close(); } Log.console("close Ok"); } //add by polarbear , 2008-12-1, else { oldSession.logOut(); } } } else { Log.console("else error!"); } } } catch (Exception e) { e.printStackTrace(); } } //add by polarbear , 2008-4-21, "else if"? else if (sessionManager.isActiveRoute(username, resource)) { ClientSession oldSession; try { String domain = localServer.getServerInfo().getName(); oldSession = sessionManager.getSession(username, domain, resource); oldSession.incrementConflictCount(); //add by rwl , session???session???connection boolean isAllowCloseBindSession = SessionBindManager.getInstance() .checkAllowCloseBindSession(oldSession); int conflictLimit = sessionManager.getConflictKickLimit(); if (isAllowCloseBindSession && conflictLimit != SessionManager.NEVER_KICK && oldSession.getConflictCount() > conflictLimit) { Connection conn = oldSession.getConnection(); if (conn != null && !(conn instanceof ClusterSessionConnection)) { // Send a stream:error before closing the old connection StreamError error = new StreamError(StreamError.Condition.conflict); conn.deliverRawText(error.toXML()); if (conn instanceof NIOConnection) { conn.setNotify(false); conn.close(); ((NIOConnection) conn).notifyCloseListeners(); } else { conn.close(); } } } else { IQ response = IQ.createResultIQ(packet); response.setChildElement(packet.getChildElement().createCopy()); response.setError(PacketError.Condition.forbidden); return response; } } catch (Exception e) { Log.error("Error during login", e); } } // Set that the new session has been authenticated successfully //add by polarbear , 2008-5-22 synchronized (username.intern()) { if (!JiveGlobals.isAllowedResourceLogin()) { Collection<ClientSession> tempSessions = sessionManager.getSessions(username); if (tempSessions.size() > 0) { for (ClientSession tempsession : tempSessions) { if (tempsession.getConnection() != null && !(tempsession.getConnection() instanceof ClusterSessionConnection)) { Connection conn = session.getConnection(); if (conn != null && !(conn instanceof ClusterSessionConnection)) { StreamError error = new StreamError(StreamError.Condition.conflict); conn.deliverRawText(error.toXML()); //add by polarbear , 2010-7-7, ???????conn?? if (conn != null && !conn.isClosed()) { if (conn instanceof NIOConnection) { conn.setNotify(false); conn.close(); ((NIOConnection) conn).notifyCloseListeners(); } else { conn.close(); } } } } } } session.setAuthToken(token, userManager, resource); } } packet.setFrom(session.getAddress()); User u = userManager.getUser(username); IQ resultIq = IQ.createResultIQ(packet); resultIq.getElement().addElement("userrole_flag").setText(JiveGlobals.nullToEmpty(u.getFace())); return resultIq; }
From source file:ru.runa.wf.logic.bot.assigner.AssignerSettingsXmlParser.java
License:Open Source License
public static AssignerSettings read(String configuration) throws Exception { AssignerSettings assignerSettings = new AssignerSettings(); Document document = XmlUtils.parseWithXSDValidation(configuration, "assigner.xsd"); Element conditionsElement = document.getRootElement().element(CONDITIONS_ELEMENT_NAME); List<Element> elements = conditionsElement.elements(CONDITION_ELEMENT_NAME); for (Element conditionElement : elements) { String swimlaneName = conditionElement.elementTextTrim(SWIMLANE_ELEMENT_NAME); String functionClassName = conditionElement.elementTextTrim(FUNCTION_ELEMENT_NAME); String variableName = conditionElement.elementTextTrim(VARIABLE_ELEMENT_NAME); Preconditions.checkNotNull(swimlaneName, SWIMLANE_ELEMENT_NAME); Preconditions.checkNotNull(functionClassName, FUNCTION_ELEMENT_NAME); Preconditions.checkNotNull(variableName, VARIABLE_ELEMENT_NAME); assignerSettings.addAssignerCondition( new AssignerSettings.Condition(swimlaneName, functionClassName, variableName)); }/*from w ww . ja va2 s . co m*/ return assignerSettings; }
From source file:ru.runa.wf.logic.bot.updatepermission.UpdatePermissionsXmlParser.java
License:Open Source License
public static UpdatePermissionsSettings read(String configuration) { UpdatePermissionsSettings settings = new UpdatePermissionsSettings(); Document document = XmlUtils.parseWithXSDValidation(configuration, "update-permissions.xsd"); Element root = document.getRootElement(); List<Element> orgFunctionElements = root.element(ORGFUNCTIONS_ELEMENT_NAME) .elements(ORGFUNCTION_ELEMENT_NAME); for (Element element : orgFunctionElements) { settings.getSwimlaneInitializers().add(element.getTextTrim()); }//from ww w.j a v a 2s . co m settings.setMethod(Method.valueOf(root.elementTextTrim(METHOD_ELEMENT_NAME))); List<Element> permissionElements = root.element(PERMISSIONS_ELEMENT_NAME).elements(PERMISSION_ELEMENT_NAME); for (Element element : permissionElements) { Permission p = Permission.valueOf(element.getTextTrim()); ApplicablePermissions.check(SecuredObjectType.PROCESS, p); settings.getPermissions().add(p); } Element conditionElement = root.element(CONDITION_ELEMENT_NAME); if (conditionElement != null) { settings.setCondition(conditionElement.attributeValue(CONDITION_VAR_NAME_ATTRIBUTE_NAME), conditionElement.attributeValue(CONDITION_VAR_VALUE_ATTRIBUTE_NAME)); } return settings; }
From source file:ru.runa.wfe.extension.handler.user.AssignSwimlaneActionHandler.java
License:Open Source License
@Override public void setConfiguration(String configuration) { super.setConfiguration(configuration); Element root = XmlUtils.parseWithoutValidation(configuration).getRootElement(); String strictModeString = root.attributeValue(STRICT_MODE); if (strictModeString != null) { strictMode = Boolean.valueOf(strictModeString); }/*from w ww .j a v a2 s. c o m*/ swimlaneName = root.attributeValue(SWIMLANE_NAME); if (swimlaneName == null) { swimlaneName = root.elementTextTrim(SWIMLANE_NAME); Preconditions.checkNotNull(swimlaneName, SWIMLANE_NAME); } swimlaneInitializer = root.attributeValue(SWIMLANE_INITITALIZER); if (swimlaneInitializer == null) { swimlaneInitializer = root.elementTextTrim(SWIMLANE_INITITALIZER); } }
From source file:siddur.solidtrust.azure.InterDataConnector.java
private static String getEleString(Element ele, String eleName) { return ele.elementTextTrim(eleName); }
From source file:sse.storage.etc.Config.java
License:Open Source License
private void initDatabases(Element root) throws ConfigException { databases = new HashMap<String, Database>(); Properties sqlProps = PropertiesUtils.getPropertiesFromClasspath(SQL_PROPERTIES); for (Iterator<?> it = root.elementIterator("database"); it.hasNext();) { Element e = (Element) it.next(); Database db = new Database(); db.setId(e.elementTextTrim("id")); db.setName(e.elementTextTrim("name")); db.setDriver(e.elementTextTrim("driver")); db.setUrl(e.elementTextTrim("url")); db.setUser(e.elementTextTrim("user")); db.setPassword(e.elementTextTrim("password")); db.setMaxconn(e.elementTextTrim("maxconn")); if (!db.isValid()) { throw new ConfigException("DB " + db.getId() + " is invalid"); }/*from w w w. j a v a 2 s . c o m*/ databases.put(db.getId(), db); DBConnectionManager.INSTANCE.init(db.getDbProps(), sqlProps); info("Load database: " + db); } if (databases.isEmpty()) { throw new ConfigException("No database is defined in " + STORAGE_CONFIG); } }