use of org.jivesoftware.openfire.user.UserManager in project Openfire by igniterealtime.
the class UserProperties method populateResponseFields.
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());
}
}
use of org.jivesoftware.openfire.user.UserManager in project Openfire by igniterealtime.
the class EmailTranscriptEvent method chatSupportFinished.
public void chatSupportFinished(Workgroup workgroup, String sessionID) {
Log.debug("Chat Support Finished, sending transcripts");
final EmailService emailService = EmailService.getInstance();
String property = JiveGlobals.getProperty("mail.configured");
if (!ModelUtil.hasLength(property)) {
Log.debug("Mail settings are not configured, transcripts will not be sent.");
return;
}
final ChatSession chatSession = ChatTranscriptManager.getChatSession(sessionID);
if (chatSession == null || chatSession.getFirstSession() == null) {
return;
}
final StringBuilder builder = new StringBuilder();
SimpleDateFormat formatter = new SimpleDateFormat("MM/dd/yyy hh:mm a");
// Get duration of conversation
Date date = new Date(chatSession.getFirstSession().getStartTime());
int duration = getChatDuration(date, chatSession);
TreeMap<String, List<String>> map = new TreeMap<String, List<String>>(chatSession.getMetadata());
String body = JiveGlobals.getProperty("chat.transcript.body");
if (ModelUtil.hasLength(body)) {
builder.append(body).append("\n\n");
}
builder.append("formname=chat transcript\n");
extractAndDisplay(builder, "question", map);
display(builder, "fullname", chatSession.getCustomerName());
extractAndDisplay(builder, "email", map);
extractAndDisplay(builder, "Location", map);
extractAndDisplay(builder, "userID", map);
extractAndDisplay(builder, "username", map);
extractAndDisplay(builder, "workgroup", map);
display(builder, "chatduration", String.valueOf(duration));
display(builder, "chatdate", formatter.format(date));
if (chatSession.getFirstSession() != null && chatSession.getFirstSession().getAgentJID() != null) {
try {
display(builder, "agent", new JID(chatSession.getFirstSession().getAgentJID()).toBareJID());
} catch (Exception e) {
Log.debug("Could not display agent in transcript.", e);
}
}
for (Iterator<Map.Entry<String, List<String>>> iterator = map.entrySet().iterator(); iterator.hasNext(); ) {
Map.Entry<String, List<String>> entry = iterator.next();
display(builder, entry.getKey(), getListItem(entry.getValue()));
}
builder.append("ctranscript=\n");
builder.append(ChatTranscriptManager.getTextTranscriptFromSessionID(sessionID));
String subject = JiveGlobals.getProperty("chat.transcript.subject");
String from = JiveGlobals.getProperty("chat.transcript.from");
String to = JiveGlobals.getProperty("chat.transcript.to");
if (!ModelUtil.hasLength(subject) || !ModelUtil.hasLength(from)) {
Log.debug("Transcript settings (chat.transcript.subject, chat.transcript.from) are not configured, " + "transcripts will not be sent.");
return;
}
if (ModelUtil.hasLength(to)) {
emailService.sendMessage("Chat Transcript", to, "Chat Transcript", from, subject, builder.toString(), null);
Log.debug("Transcript sent to " + to);
}
// NOTE: Do not sent to the customer. They will receive a prompt for a seperate chat transcript
// that does not contain agent information.
// Send to Agents
UserManager um = UserManager.getInstance();
for (Iterator<AgentChatSession> iterator = chatSession.getAgents(); iterator.hasNext(); ) {
AgentChatSession agentSession = iterator.next();
try {
User user = um.getUser(new JID(agentSession.getAgentJID()).getNode());
emailService.sendMessage("Chat Transcript", user.getEmail(), "Chat Transcript", from, subject, builder.toString(), null);
Log.debug("Transcript sent to agent " + agentSession.getAgentJID());
} catch (UserNotFoundException e) {
Log.error("Email Transcript Not Sent:" + "Could not load agent user object for jid " + agentSession.getAgentJID());
}
}
}
use of org.jivesoftware.openfire.user.UserManager in project Openfire by igniterealtime.
the class BookmarkInterceptor method addBookmarkElement.
/**
* Adds a Bookmark to the users defined list of bookmarks.
*
* @param jid the users jid.
* @param bookmark the bookmark to be added.
* @param element the storage element to append to.
*/
private void addBookmarkElement(JID jid, Bookmark bookmark, Element element) {
final UserManager userManager = UserManager.getInstance();
try {
userManager.getUser(jid.getNode());
} catch (UserNotFoundException e) {
return;
}
// do not add duplicate bookmarks.
if (bookmark.getType() == Bookmark.Type.url) {
Element urlBookmarkElement = urlExists(element, bookmark.getValue());
if (urlBookmarkElement == null) {
urlBookmarkElement = element.addElement("url");
urlBookmarkElement.addAttribute("name", bookmark.getName());
urlBookmarkElement.addAttribute("url", bookmark.getValue());
// Add an RSS attribute to the bookmark if it's defined. RSS isn't an
// official part of the Bookmark JEP, but we define it as a logical
// extension.
boolean rss = Boolean.valueOf(bookmark.getProperty("rss"));
if (rss) {
urlBookmarkElement.addAttribute("rss", Boolean.toString(rss));
}
}
appendSharedElement(urlBookmarkElement);
} else // Otherwise it's a conference bookmark.
{
try {
Element conferenceElement = conferenceExists(element, bookmark.getValue());
// reply.
if (conferenceElement == null) {
conferenceElement = element.addElement("conference");
conferenceElement.addAttribute("name", bookmark.getName());
boolean autojoin = Boolean.valueOf(bookmark.getProperty("autojoin"));
conferenceElement.addAttribute("autojoin", Boolean.toString(autojoin));
conferenceElement.addAttribute("jid", bookmark.getValue());
boolean nameasnick = Boolean.valueOf(bookmark.getProperty("nameasnick"));
if (nameasnick) {
User currentUser = userManager.getUser(jid.getNode());
Element nick = conferenceElement.addElement("nick");
nick.addText(currentUser.getName());
}
}
appendSharedElement(conferenceElement);
} catch (Exception e) {
Log.error(e.getMessage(), e);
}
}
}
use of org.jivesoftware.openfire.user.UserManager in project Openfire by igniterealtime.
the class NativeAuthProvider method authenticate.
@Override
public void authenticate(String username, String password) throws UnauthorizedException {
if (username.contains("@")) {
// Check that the specified domain matches the server's domain
int index = username.indexOf("@");
String domain = username.substring(index + 1);
if (domain.equals(XMPPServer.getInstance().getServerInfo().getXMPPDomain())) {
username = username.substring(0, index);
} else {
// Unknown domain. Return authentication failed.
throw new UnauthorizedException();
}
}
try {
// very well. Therefore, synchronize access to Shaj to throttle auth checks.
synchronized (this) {
if (!Shaj.checkPassword(domain, username, password)) {
throw new UnauthorizedException();
}
}
} catch (UnauthorizedException ue) {
throw ue;
} catch (Exception e) {
throw new UnauthorizedException(e);
}
// See if the user exists in the database. If not, automatically create them.
UserManager userManager = UserManager.getInstance();
try {
userManager.getUser(username);
} catch (UserNotFoundException unfe) {
try {
Log.debug("Automatically creating new user account for " + username);
// Create user; use a random password for better safety in the future.
// Note that we have to go to the user provider directly -- because the
// provider is read-only, UserManager will usually deny access to createUser.
UserProvider provider = UserManager.getUserProvider();
if (!(provider instanceof NativeUserProvider)) {
Log.error("Error: not using NativeUserProvider so authentication with " + "NativeAuthProvider will likely fail. Using: " + provider.getClass().getName());
}
UserManager.getUserProvider().createUser(username, StringUtils.randomString(8), null, null);
} catch (UserAlreadyExistsException uaee) {
// Ignore.
}
}
}
use of org.jivesoftware.openfire.user.UserManager in project Openfire by igniterealtime.
the class WorkgroupPropertiesProvider method executeGet.
public void executeGet(IQ packet, Workgroup workgroup) {
IQ reply = IQ.createResultIQ(packet);
// Retrieve the sound settings.
String authRequired = workgroup.getProperties().getProperty("authRequired");
Element returnPacket = reply.setChildElement("workgroup-properties", "http://jivesoftware.com/protocol/workgroup");
if (ModelUtil.hasLength(authRequired)) {
returnPacket.addElement("authRequired").setText(authRequired);
} else {
returnPacket.addElement("authRequired").setText("false");
}
Element iq = packet.getChildElement();
Attribute attr = iq.attribute("jid");
if (attr != null && ModelUtil.hasLength(iq.attribute("jid").getText())) {
String jid = iq.attribute("jid").getText();
UserManager userManager = UserManager.getInstance();
try {
User user = userManager.getUser(new JID(jid).getNode());
String email = user.getEmail();
String fullName = user.getName();
returnPacket.addElement("email").setText(email);
returnPacket.addElement("name").setText(fullName);
} catch (UserNotFoundException e) {
Log.error(e.getMessage(), e);
}
}
workgroup.send(reply);
}
Aggregations