use of org.jivesoftware.openfire.auth.UnauthorizedException in project Openfire by igniterealtime.
the class IQvCardHandler method handleIQ.
@Override
public IQ handleIQ(IQ packet) throws UnauthorizedException, PacketException {
IQ result = IQ.createResultIQ(packet);
IQ.Type type = packet.getType();
if (type.equals(IQ.Type.set)) {
try {
User user = userManager.getUser(packet.getFrom().getNode());
Element vcard = packet.getChildElement();
if (vcard != null) {
VCardManager.getInstance().setVCard(user.getUsername(), vcard);
}
} catch (UserNotFoundException e) {
result = IQ.createResultIQ(packet);
result.setChildElement(packet.getChildElement().createCopy());
result.setError(PacketError.Condition.item_not_found);
} catch (Exception e) {
Log.error(e.getMessage(), e);
result.setError(PacketError.Condition.internal_server_error);
}
} else if (type.equals(IQ.Type.get)) {
JID recipient = packet.getTo();
// If no TO was specified then get the vCard of the sender of the packet
if (recipient == null) {
recipient = packet.getFrom();
}
// By default return an empty vCard
result.setChildElement("vCard", "vcard-temp");
// Only try to get the vCard values of non-anonymous users
if (recipient != null) {
if (recipient.getNode() != null && server.isLocal(recipient)) {
VCardManager vManager = VCardManager.getInstance();
Element userVCard = vManager.getVCard(recipient.getNode());
if (userVCard != null) {
// Check if the requester wants to ignore some vCard's fields
Element filter = packet.getChildElement().element(QName.get("filter", "vcard-temp-filter"));
if (filter != null) {
// Create a copy so we don't modify the original vCard
userVCard = userVCard.createCopy();
// Ignore fields requested by the user
for (Iterator toFilter = filter.elementIterator(); toFilter.hasNext(); ) {
Element field = (Element) toFilter.next();
Element fieldToRemove = userVCard.element(field.getName());
if (fieldToRemove != null) {
fieldToRemove.detach();
}
}
}
result.setChildElement(userVCard);
}
} else {
result = IQ.createResultIQ(packet);
result.setChildElement(packet.getChildElement().createCopy());
result.setError(PacketError.Condition.item_not_found);
}
} else {
result = IQ.createResultIQ(packet);
result.setChildElement(packet.getChildElement().createCopy());
result.setError(PacketError.Condition.item_not_found);
}
} else {
result.setChildElement(packet.getChildElement().createCopy());
result.setError(PacketError.Condition.not_acceptable);
}
return result;
}
use of org.jivesoftware.openfire.auth.UnauthorizedException in project Openfire by igniterealtime.
the class HttpBindServlet method createNewSession.
protected void createNewSession(AsyncContext context, Element rootNode) throws IOException {
final long rid = getLongAttribute(rootNode.attributeValue("rid"), -1);
try {
final X509Certificate[] certificates = (X509Certificate[]) context.getRequest().getAttribute("javax.servlet.request.X509Certificate");
final HttpConnection connection = new HttpConnection(rid, context.getRequest().isSecure(), certificates, context);
final InetAddress address = InetAddress.getByName(context.getRequest().getRemoteAddr());
connection.setSession(sessionManager.createSession(address, rootNode, connection));
if (JiveGlobals.getBooleanProperty("log.httpbind.enabled", false)) {
Log.info(new Date() + ": HTTP RECV(" + connection.getSession().getStreamID().getID() + "): " + rootNode.asXML());
}
} catch (UnauthorizedException | HttpBindException e) {
// Server wasn't initialized yet.
sendLegacyError(context, BoshBindingError.internalServerError, "Server has not finished initialization.");
}
}
use of org.jivesoftware.openfire.auth.UnauthorizedException in project Openfire by igniterealtime.
the class ProxyConnectionManager method processConnection.
private void processConnection(Socket connection) throws IOException {
OutputStream out = new DataOutputStream(connection.getOutputStream());
InputStream in = new DataInputStream(connection.getInputStream());
// first byte is version should be 5
int b = in.read();
if (b != 5) {
throw new IOException("Only SOCKS5 supported");
}
// second byte number of authentication methods supported
b = in.read();
int[] auth = new int[b];
for (int i = 0; i < b; i++) {
auth[i] = in.read();
}
int authMethod = -1;
for (int anAuth : auth) {
// only auth method
authMethod = (anAuth == 0 ? 0 : -1);
// supported
if (authMethod == 0) {
break;
}
}
if (authMethod != 0) {
throw new IOException("Authentication method not supported");
}
// No auth method so respond with success
byte[] cmd = new byte[2];
cmd[0] = (byte) 0x05;
cmd[1] = (byte) 0x00;
out.write(cmd);
String responseDigest = processIncomingSocks5Message(in);
try {
synchronized (connectionLock) {
ProxyTransfer transfer = connectionMap.get(responseDigest);
if (transfer == null) {
transfer = createProxyTransfer(responseDigest, connection);
transferManager.registerProxyTransfer(responseDigest, transfer);
connectionMap.put(responseDigest, transfer);
} else {
transfer.setInputStream(connection.getInputStream());
}
}
cmd = createOutgoingSocks5Message(0, responseDigest);
out.write(cmd);
} catch (UnauthorizedException eu) {
cmd = createOutgoingSocks5Message(2, responseDigest);
out.write(cmd);
throw new IOException("Illegal proxy transfer");
}
}
use of org.jivesoftware.openfire.auth.UnauthorizedException in project Openfire by igniterealtime.
the class SessionManager method createIncomingServerSession.
/**
* Creates a session for a remote server. The session should be created only after the
* remote server has been authenticated either using "server dialback" or SASL.
*
* @param conn the connection to the remote server.
* @param id the stream ID used in the stream element when authenticating the server.
* @return the newly created {@link IncomingServerSession}.
* @throws UnauthorizedException if the local server has not been initialized yet.
*/
public LocalIncomingServerSession createIncomingServerSession(Connection conn, StreamID id, String fromDomain) throws UnauthorizedException {
if (serverName == null) {
throw new UnauthorizedException("Server not initialized");
}
LocalIncomingServerSession session = new LocalIncomingServerSession(serverName, conn, id, fromDomain);
conn.init(session);
// Register to receive close notification on this session so we can
// remove its route from the sessions set
conn.registerCloseListener(incomingServerListener, session);
return session;
}
use of org.jivesoftware.openfire.auth.UnauthorizedException in project Openfire by igniterealtime.
the class RoutingTableImpl method routeToComponent.
/**
* Routes packets that are sent to components of the XMPP domain (which are
* subdomains of the XMPP domain)
*
* @param jid
* the recipient of the packet to route.
* @param packet
* the packet to route.
* @throws PacketException
* thrown if the packet is malformed (results in the sender's
* session being shutdown).
* @return <tt>true</tt> if the packet was routed successfully,
* <tt>false</tt> otherwise.
*/
private boolean routeToComponent(JID jid, Packet packet, boolean routed) {
if (!hasComponentRoute(jid) && !ExternalComponentManager.hasConfiguration(jid.getDomain())) {
return false;
}
// First check if the component is being hosted in this JVM
RoutableChannelHandler route = localRoutingTable.getRoute(jid.getDomain());
if (route != null) {
try {
route.process(packet);
routed = true;
} catch (UnauthorizedException e) {
Log.error("Unable to route packet " + packet.toXML(), e);
}
} else {
// Check if other cluster nodes are hosting this component
Set<NodeID> nodes = componentsCache.get(jid.getDomain());
if (nodes != null) {
for (NodeID nodeID : nodes) {
if (server.getNodeID().equals(nodeID)) {
// could have been added after our previous check)
try {
RoutableChannelHandler localRoute = localRoutingTable.getRoute(jid.getDomain());
if (localRoute != null) {
localRoute.process(packet);
routed = true;
break;
}
} catch (UnauthorizedException e) {
Log.error("Unable to route packet " + packet.toXML(), e);
}
} else {
// This is a route to a local component hosted in other node
if (remotePacketRouter != null) {
routed = remotePacketRouter.routePacket(nodeID.toByteArray(), jid, packet);
if (routed) {
break;
}
}
}
}
}
}
return routed;
}
Aggregations