use of org.jivesoftware.openfire.user.UserNotFoundException 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.UserNotFoundException in project Openfire by igniterealtime.
the class ImageServlet method getImage.
/**
* Returns the image bytes of the encoded image.
*
* @param imageName the name of the image.
* @param workgroupName the name of the workgroup.
* @return the image bytes found, otherwise null.
*/
public byte[] getImage(String imageName, String workgroupName) {
WorkgroupManager workgroupManager = WorkgroupManager.getInstance();
JID workgroupJID = new JID(workgroupName);
Workgroup workgroup;
try {
workgroup = workgroupManager.getWorkgroup(workgroupJID);
} catch (UserNotFoundException e) {
Log.error(e.getMessage(), e);
return null;
}
ChatSettings chatSettings = chatSettingsManager.getChatSettings(workgroup);
ChatSetting setting = chatSettings.getChatSetting(imageName);
String encodedValue = setting.getValue();
if (encodedValue == null) {
return null;
}
return StringUtils.decodeBase64(encodedValue);
}
use of org.jivesoftware.openfire.user.UserNotFoundException in project Openfire by igniterealtime.
the class DeleteWorkgroup method execute.
@Override
public void execute(SessionData data, Element command) {
Element note = command.addElement("note");
// Get requested group
WorkgroupManager workgroupManager = WorkgroupManager.getInstance();
// Load the workgroup
try {
Workgroup workgroup = workgroupManager.getWorkgroup(new JID(data.getData().get("workgroup").get(0)));
workgroupManager.deleteWorkgroup(workgroup);
} catch (UserNotFoundException e) {
// Group not found
note.addAttribute("type", "error");
note.setText("Workgroup not found");
return;
} catch (Exception e) {
// Group not found
note.addAttribute("type", "error");
note.setText("Error executing the command");
return;
}
note.addAttribute("type", "info");
note.setText("Operation finished successfully");
}
use of org.jivesoftware.openfire.user.UserNotFoundException in project Openfire by igniterealtime.
the class DefaultAuthProvider method getUserInfo.
private UserInfo getUserInfo(String username, boolean recurse) throws UnsupportedOperationException, UserNotFoundException {
if (!isScramSupported()) {
// Reject the operation since the provider does not support SCRAM
throw new UnsupportedOperationException();
}
Connection con = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
try {
con = DbConnectionManager.getConnection();
pstmt = con.prepareStatement(TEST_PASSWORD);
pstmt.setString(1, username);
rs = pstmt.executeQuery();
if (!rs.next()) {
throw new UserNotFoundException(username);
}
UserInfo userInfo = new UserInfo();
userInfo.plainText = rs.getString(1);
userInfo.encrypted = rs.getString(2);
userInfo.iterations = rs.getInt(3);
userInfo.salt = rs.getString(4);
userInfo.storedKey = rs.getString(5);
userInfo.serverKey = rs.getString(6);
if (userInfo.encrypted != null) {
try {
userInfo.plainText = AuthFactory.decryptPassword(userInfo.encrypted);
} catch (UnsupportedOperationException uoe) {
// Ignore and return plain password instead.
}
}
if (!recurse) {
if (userInfo.plainText != null) {
boolean scramOnly = JiveGlobals.getBooleanProperty("user.scramHashedPasswordOnly");
if (scramOnly || userInfo.salt == null) {
// If we have a password here, but we're meant to be scramOnly, we should reset it.
setPassword(username, userInfo.plainText);
// RECURSE
return getUserInfo(username, true);
}
}
}
// Good to go.
return userInfo;
} catch (SQLException sqle) {
Log.error("User SQL failure:", sqle);
throw new UserNotFoundException(sqle);
} finally {
DbConnectionManager.closeConnection(rs, pstmt, con);
}
}
use of org.jivesoftware.openfire.user.UserNotFoundException in project Openfire by igniterealtime.
the class JDBCAuthProvider method setPasswordValue.
private void setPasswordValue(String username, String password) throws UserNotFoundException {
Connection con = null;
PreparedStatement pstmt = null;
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.
throw new UserNotFoundException();
}
}
try {
con = getConnection();
pstmt = con.prepareStatement(setPasswordSQL);
pstmt.setString(2, username);
password = hashPassword(password);
pstmt.setString(1, password);
pstmt.executeQuery();
} catch (SQLException e) {
Log.error("Exception in JDBCAuthProvider", e);
throw new UserNotFoundException();
} finally {
DbConnectionManager.closeConnection(pstmt, con);
}
}
Aggregations