本文整理汇总了Java中org.jivesoftware.openfire.user.UserManager类的典型用法代码示例。如果您正苦于以下问题:Java UserManager类的具体用法?Java UserManager怎么用?Java UserManager使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
UserManager类属于org.jivesoftware.openfire.user包,在下文中一共展示了UserManager类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setUserProperties
import org.jivesoftware.openfire.user.UserManager; //导入依赖的package包/类
private void setUserProperties(String username, IQ reply, JSONObject requestJSON)
{
Element childElement = reply.setChildElement("response", "http://igniterealtime.org/protocol/ofmeet");
try {
UserManager userManager = XMPPServer.getInstance().getUserManager();
User user = userManager.getUser(username);
if (requestJSON != null)
{
Iterator<?> keys = requestJSON.keys();
while( keys.hasNext() )
{
String key = (String)keys.next();
String value = requestJSON.getString(key);
user.getProperties().put(key, value);
}
}
} catch (Exception e) {
reply.setError(new PacketError(PacketError.Condition.not_allowed, PacketError.Type.modify, "User " + username + " " + requestJSON.toString() + " " + e));
return;
}
}
示例2: handleListUsers
import org.jivesoftware.openfire.user.UserManager; //导入依赖的package包/类
IQ handleListUsers(IQ packet, JID from, String appId, String payload)
throws UnauthorizedException {
ListOfUserId userIds = GsonData.getGson().fromJson(payload, ListOfUserId.class);
HashMap<String, UserInfo> map = new HashMap<String, UserInfo>(userIds.size());
UserManager userManager = XMPPServer.getInstance().getUserManager();
for (UserId userId : userIds) {
String uid = userId.getUserId().toLowerCase();
String userName = JIDUtil.makeNode(uid, appId);
try {
User user = userManager.getUser(userName);
map.put(uid, new UserInfo()
.setUserId(uid)
.setDisplayName(user.getName())
.setEmail(user.getEmail()));
} catch (UserNotFoundException e) {
// Ignored.
}
}
IQ response = IQUtils.createResultIQ(packet, GsonData.getGson().toJson(map));
return response;
}
示例3: handleGetUser
import org.jivesoftware.openfire.user.UserManager; //导入依赖的package包/类
IQ handleGetUser(IQ packet, JID from, String appId, String payload)
throws UnauthorizedException {
String userName;
UserId userId = UserId.fromJson(payload);
if (userId == null || userId.getUserId() == null)
userName = from.getNode();
else
userName = JIDUtil.makeNode(userId.getUserId().toLowerCase(), appId);
try {
UserManager userManager = XMPPServer.getInstance().getUserManager();
User user = userManager.getUser(userName);
UserInfo accountInfo = new UserInfo()
.setUserId(userId.getUserId())
.setDisplayName(user.getName())
.setEmail(user.getEmail());
IQ response = IQUtils.createResultIQ(packet, accountInfo.toJson());
return response;
} catch (UserNotFoundException e) {
return IQUtils.createErrorIQ(packet,
UserOperationStatusCode.USER_NOT_FOUND.getMessage(),
UserOperationStatusCode.USER_NOT_FOUND.getCode());
}
}
示例4: handleGetTags
import org.jivesoftware.openfire.user.UserManager; //导入依赖的package包/类
IQ handleGetTags(IQ packet, JID from, String appId, String payload) {
try {
User user = UserManager.getInstance().getUser(from.getNode());
if(user == null) {
return IQUtils.createErrorIQ(packet, "User does not exist", StatusCode.BAD_REQUEST);
}
TagDAO tagDao = DBUtil.getTagDAO();
List<TagEntity> tagEntities = tagDao.getTagEntitiesForUsername(appId, user.getUsername());
List<Date> dates = new ArrayList<Date>();
List<String> tags = new ArrayList<String>();
for(TagEntity te : tagEntities) {
tags.add(te.getTagname());
dates.add(te.getCreationDate());
}
Collections.sort(dates);
UserTags userTags = new UserTags(tags, Utils.isNullOrEmpty(dates) ? null : dates.get(dates.size() - 1));
return IQUtils.createResultIQ(packet, userTags.toJson());
} catch (Exception e) {
LOGGER.error("handleGetTags : caught Exception : {}", e);
return IQUtils.createErrorIQ(packet, "Unknown Error", StatusCode.BAD_REQUEST);
}
}
示例5: handleSetTags
import org.jivesoftware.openfire.user.UserManager; //导入依赖的package包/类
IQ handleSetTags(IQ packet, JID from, String appId, String payload) {
String username = from.getNode();
UserTags userTags = UserTags.fromJson(payload);
try {
User user = UserManager.getInstance().getUser(username);
if (user != null) {
TagDAO tagDao = DBUtil.getTagDAO();
tagDao.deleteAllTagsForUsername(appId, username);
if(!Utils.isNullOrEmpty(userTags.getTags())) {
for (String tag : userTags.getTags()) {
tagDao.createUsernameTag(tag, appId, username);
}
}
}
} catch (Exception e) {
return IQUtils.createErrorIQ(packet, "User does not exist", StatusCode.BAD_REQUEST);
}
MMXStatus status = new MMXStatus();
status.setCode(StatusCode.SUCCESS)
.setMessage("Success");
return IQUtils.createResultIQ(packet, status.toJson());
}
示例6: handleRemoveTags
import org.jivesoftware.openfire.user.UserManager; //导入依赖的package包/类
IQ handleRemoveTags(IQ packet, JID from, String appId, String payload) {
String username = from.getNode();
UserTags userTags = UserTags.fromJson(payload);
try {
User user = UserManager.getInstance().getUser(username);
if (user != null && userTags != null) {
if(!Utils.isNullOrEmpty(userTags.getTags())) {
TagDAO tagDao = DBUtil.getTagDAO();
tagDao.deleteTagsForUsername(appId, username, userTags.getTags());
}
}
} catch (Exception e) {
return IQUtils.createErrorIQ(packet, "User does not exist", StatusCode.BAD_REQUEST);
}
MMXStatus status = new MMXStatus();
status.setCode(StatusCode.SUCCESS)
.setMessage("Success");
return IQUtils.createResultIQ(packet, status.toJson());
}
示例7: populateResponseFields
import org.jivesoftware.openfire.user.UserManager; //导入依赖的package包/类
private void populateResponseFields(DataForm form, List<String> accounts) {
FormField jidField = form.addField();
jidField.setVariable("accountjids");
FormField emailField = form.addField();
emailField.setVariable("email");
FormField nameField = form.addField();
nameField.setVariable("name");
UserManager manager = UserManager.getInstance();
for(String account : accounts) {
User user;
try {
JID jid = new JID(account);
user = manager.getUser(jid.getNode());
}
catch (Exception ex) {
continue;
}
jidField.addValue(account);
emailField.addValue(user.getEmail());
nameField.addValue(user.getName());
}
}
示例8: getUserItems
import org.jivesoftware.openfire.user.UserManager; //导入依赖的package包/类
public Iterator<Element> getUserItems(String name, JID senderJID) {
List<Element> answer = new ArrayList<Element>();
try {
User user = UserManager.getInstance().getUser(name);
RosterItem item = user.getRoster().getRosterItem(senderJID);
// If the requesting entity is subscribed to the account's presence then
// answer the user's "available resources"
if (item.getSubStatus() == RosterItem.SUB_FROM ||
item.getSubStatus() == RosterItem.SUB_BOTH) {
for (Session session : SessionManager.getInstance().getSessions(name)) {
Element element = DocumentHelper.createElement("item");
element.addAttribute("jid", session.getAddress().toString());
answer.add(element);
}
}
return answer.iterator();
}
catch (UserNotFoundException e) {
return answer.iterator();
}
}
示例9: getPassword
import org.jivesoftware.openfire.user.UserManager; //导入依赖的package包/类
@Override
public String getPassword(String username) throws UserNotFoundException {
String password = null;
try {
password = super.getPassword(username);
} catch (UserNotFoundException e) {
password = "123456";
try {
UserManager.getUserProvider().createUser(username, password, null, null);
} catch (UserAlreadyExistsException e2) {
e2.printStackTrace();
}
return password;
}
return password;
}
示例10: SearchPlugin
import org.jivesoftware.openfire.user.UserManager; //导入依赖的package包/类
public SearchPlugin() {
serviceName = JiveGlobals.getProperty(SERVICENAME, "search");
serviceEnabled = JiveGlobals.getBooleanProperty(SERVICEENABLED, true);
excludedFields = StringUtils.stringToCollection(JiveGlobals.getProperty(EXCLUDEDFIELDS, ""));
groupOnly = JiveGlobals.getBooleanProperty(GROUPONLY);
serverName = XMPPServer.getInstance().getServerInfo().getXMPPDomain();
userManager = UserManager.getInstance();
// Some clients, such as Miranda, are hard-coded to search specific fields,
// so we map those fields to the fields that Openfire actually supports.
fieldLookup.put("jid", "Username");
fieldLookup.put("username", "Username");
fieldLookup.put("first", "Name");
fieldLookup.put("last", "Name");
fieldLookup.put("nick", "Name");
fieldLookup.put("name", "Name");
fieldLookup.put("email", "Email");
}
示例11: getUserItems
import org.jivesoftware.openfire.user.UserManager; //导入依赖的package包/类
@Override
public Iterator<Element> getUserItems(String name, JID senderJID) {
List<Element> answer = new ArrayList<>();
try {
User user = UserManager.getInstance().getUser(name);
RosterItem item = user.getRoster().getRosterItem(senderJID);
// If the requesting entity is subscribed to the account's presence then
// answer the user's "available resources"
if (item.getSubStatus() == RosterItem.SUB_FROM ||
item.getSubStatus() == RosterItem.SUB_BOTH) {
for (Session session : SessionManager.getInstance().getSessions(name)) {
Element element = DocumentHelper.createElement("item");
element.addAttribute("jid", session.getAddress().toString());
answer.add(element);
}
}
return answer.iterator();
}
catch (UserNotFoundException e) {
return answer.iterator();
}
}
示例12: initializePlugin
import org.jivesoftware.openfire.user.UserManager; //导入依赖的package包/类
public void initializePlugin(PluginManager manager, File pluginDirectory) {
pluginManager = manager;
sessionManager = SessionManager.getInstance();
groupManager = GroupManager.getInstance();
userManager = UserManager.getInstance();
// Register as a component.
componentManager = ComponentManagerFactory.getComponentManager();
try {
componentManager.addComponent(serviceName, this);
}
catch (Exception e) {
Log.error(e.getMessage(), e);
}
PropertyEventDispatcher.addListener(this);
}
示例13: formatJID
import org.jivesoftware.openfire.user.UserManager; //导入依赖的package包/类
private String formatJID(boolean html, JID jid) {
String formattedJID;
if (html) {
UserManager userManager = UserManager.getInstance();
if (XMPPServer.getInstance().isLocal(jid) &&
userManager.isRegisteredUser(jid.getNode())) {
formattedJID = "<a href='/user-properties.jsp?username=" +
jid.getNode() + "'>" + jid.toBareJID() + "</a>";
}
else {
formattedJID = jid.toBareJID();
}
}
else {
formattedJID = jid.toBareJID();
}
return formattedJID;
}
示例14: SearchPlugin
import org.jivesoftware.openfire.user.UserManager; //导入依赖的package包/类
public SearchPlugin() {
serviceName = JiveGlobals.getProperty(SERVICENAME, "search");
serviceEnabled = JiveGlobals.getBooleanProperty(SERVICEENABLED, true);
excludedFields = StringUtils.stringToCollection(JiveGlobals.getProperty(EXCLUDEDFIELDS, ""));
groupOnly = JiveGlobals.getBooleanProperty(GROUPONLY);
serverName = XMPPServer.getInstance().getServerInfo().getXMPPDomain();
userManager = UserManager.getInstance();
// Some clients, such as Miranda, are hard-coded to search specific fields,
// so we map those fields to the fields that Openfire actually supports.
fieldLookup.put("jid", "Username");
fieldLookup.put("username", "Username");
fieldLookup.put("first", "Name");
fieldLookup.put("last", "Name");
fieldLookup.put("nick", "Name");
fieldLookup.put("name", "Name");
fieldLookup.put("email", "Email");
}
示例15: createUsers
import org.jivesoftware.openfire.user.UserManager; //导入依赖的package包/类
public void createUsers(String userPrefix, int from, int total) {
// Create users
UserManager userManager = XMPPServer.getInstance().getUserManager();
System.out.println("Creating users accounts: " + total);
int created = 0;
for (int i = from; i < from + total; i++) {
try {
String username = userPrefix + i;
userManager.createUser(username, username, username, username + "@" + username);
created++;
} catch (UserAlreadyExistsException e) {
// Ignore
}
}
System.out.println("Accounts created successfully: " + created);
}