use of org.xmpp.packet.JID in project Openfire by igniterealtime.
the class LocalMUCRoom method memberAdded.
public void memberAdded(AddMember addMember) {
JID bareJID = addMember.getBareJID();
removeOwner(bareJID);
removeAdmin(bareJID);
removeOutcast(bareJID);
// Associate the reserved nickname with the bareJID
members.put(addMember.getBareJID(), addMember.getNickname().toLowerCase());
}
use of org.xmpp.packet.JID in project Openfire by igniterealtime.
the class LocalMUCRoom method addAdmin.
@Override
public List<Presence> addAdmin(JID jid, MUCRole sendRole) throws ForbiddenException, ConflictException {
final JID bareJID = jid.asBareJID();
lock.writeLock().lock();
try {
MUCRole.Affiliation oldAffiliation = MUCRole.Affiliation.none;
if (MUCRole.Affiliation.owner != sendRole.getAffiliation()) {
throw new ForbiddenException();
}
// Check that the room always has an owner
if (owners.contains(bareJID) && owners.size() == 1) {
throw new ConflictException();
}
// Check if user is already an admin
if (admins.contains(bareJID)) {
// Do nothing
return Collections.emptyList();
}
admins.add(bareJID);
// Remove the user from other affiliation lists
if (removeOwner(bareJID)) {
oldAffiliation = MUCRole.Affiliation.owner;
} else if (removeMember(bareJID)) {
oldAffiliation = MUCRole.Affiliation.member;
} else if (removeOutcast(bareJID)) {
oldAffiliation = MUCRole.Affiliation.outcast;
}
// Update the DB if the room is persistent
MUCPersistenceManager.saveAffiliationToDB(this, bareJID, null, MUCRole.Affiliation.admin, oldAffiliation);
} finally {
lock.writeLock().unlock();
}
// Update other cluster nodes with new affiliation
CacheFactory.doClusterTask(new AddAffiliation(this, jid.toBareJID(), MUCRole.Affiliation.admin));
// based on the group(s) of the affected user(s)
return applyAffiliationChange(getRole(), bareJID, null);
}
use of org.xmpp.packet.JID in project Openfire by igniterealtime.
the class WebDAVLiteServlet method isAuthenticated.
/**
* Verifies that the user is authenticated via some mechanism such as Basic Auth. If the
* authentication fails, this method will alter the HTTP response to include a request for
* auth and send the unauthorized response back to the client.
*
* TODO: Handle some form of special token auth, perhaps provided a room connection?
* TODO: If it's not a local account, we should try message auth access? XEP-0070?
* TODO: Should we support digest auth as well?
*
* @param request Object representing the HTTP request.
* @param response Object representing the HTTP response.
* @return True or false if the user is authenticated.
* @throws ServletException If there was a servlet related exception.
* @throws IOException If there was an IO error while setting the error.
*/
private Boolean isAuthenticated(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String auth = request.getHeader("Authorization");
JID jid;
try {
if (auth == null || !request.getAuthType().equals(HttpServletRequest.BASIC_AUTH)) {
throw new Exception("No authorization or improper authorization provided.");
}
auth = auth.substring(auth.indexOf(" "));
String decoded = new String(Base64.decode(auth));
int i = decoded.indexOf(":");
String username = decoded.substring(0, i);
if (!username.contains("@")) {
throw new Exception("Not a valid JID.");
}
jid = new JID(username);
if (XMPPServer.getInstance().isLocal(jid)) {
String password = decoded.substring(i + 1, decoded.length());
if (AuthFactory.authenticate(username, password) == null) {
throw new Exception("Authentication failed.");
}
} else {
// TODO: Authenticate a remote user, probably via message auth.
throw new Exception("Not a local account.");
}
return true;
} catch (Exception e) {
/**
* This covers all possible authentication issues. Eg:
* - not enough of auth info passed in
* - failed auth
*/
response.setHeader("WWW-Authenticate", "Basic realm=\"Openfire WebDAV\"");
response.sendError(HttpServletResponse.SC_UNAUTHORIZED);
return false;
}
}
use of org.xmpp.packet.JID in project Openfire by igniterealtime.
the class WebDAVLiteServlet method isAuthorized.
/**
* Verifies that the authenticated user is a member of a conference service and room, or else
* they are not entitled to view any of the files in the room.
*
* @param request Object representing the HTTP request.
* @param response Object representing the HTTP response.
* @param service Subdomain of the conference service they are trying to access files for.
* @param room Room in the conference service they are trying to access files for.
* @return True or false if the user is authenticated.
* @throws ServletException If there was a servlet related exception.
* @throws IOException If there was an IO error while setting the error.
*/
private Boolean isAuthorized(HttpServletRequest request, HttpServletResponse response, String service, String room) throws ServletException, IOException {
String auth = request.getHeader("Authorization");
try {
if (auth == null || !request.getAuthType().equals(HttpServletRequest.BASIC_AUTH)) {
throw new Exception("No authorization or improper authorization provided.");
}
auth = auth.substring(auth.indexOf(" "));
String decoded = new String(Base64.decode(auth));
int i = decoded.indexOf(":");
String username = decoded.substring(0, i);
if (!username.contains("@")) {
throw new Exception("Not a valid JID.");
}
final JID bareJID = new JID(username).asBareJID();
XMPPServer.getInstance().getMultiUserChatManager().getMultiUserChatService(service).getChatRoom(room).getOccupantsByBareJID(bareJID);
return true;
} catch (Exception e) {
/**
* This covers all possible authorization issues. Eg:
* - accessing a room that doesn't exist
* - accessing a room that user isn't a member of
*/
response.setHeader("WWW-Authenticate", "Basic realm=\"Openfire WebDAV\"");
response.sendError(HttpServletResponse.SC_FORBIDDEN);
return false;
}
}
use of org.xmpp.packet.JID in project Openfire by igniterealtime.
the class JDBCUserProvider method loadUser.
@Override
public User loadUser(String username) throws UserNotFoundException {
if (username.contains("@")) {
if (!XMPPServer.getInstance().isLocal(new JID(username))) {
throw new UserNotFoundException("Cannot load user of remote server: " + username);
}
username = username.substring(0, username.lastIndexOf("@"));
}
Connection con = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
try {
con = getConnection();
pstmt = con.prepareStatement(loadUserSQL);
pstmt.setString(1, username);
rs = pstmt.executeQuery();
if (!rs.next()) {
throw new UserNotFoundException();
}
String name = rs.getString(1);
String email = rs.getString(2);
return new User(username, name, email, new Date(), new Date());
} catch (Exception e) {
throw new UserNotFoundException(e);
} finally {
DbConnectionManager.closeConnection(rs, pstmt, con);
}
}
Aggregations