-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
563 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<classpath> | ||
<classpathentry kind="src" path="src/java"/> | ||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7"/> | ||
<classpathentry combineaccessrules="false" kind="src" path="/ZimbraCommon"/> | ||
<classpathentry combineaccessrules="false" kind="src" path="/ZimbraSoap"/> | ||
<classpathentry kind="lib" path="jars/openfire.jar"> | ||
<classpathentry kind="output" path="bin"/> | ||
</classpath> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<projectDescription> | ||
<name>ZimbraOpenFire</name> | ||
<comment></comment> | ||
<projects> | ||
</projects> | ||
<buildSpec> | ||
<buildCommand> | ||
<name>org.eclipse.jdt.core.javabuilder</name> | ||
<arguments> | ||
</arguments> | ||
</buildCommand> | ||
</buildSpec> | ||
<natures> | ||
<nature>org.eclipse.jdt.core.javanature</nature> | ||
</natures> | ||
</projectDescription> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
<project name="ZimbraOpenFire" default="jar"> | ||
|
||
<import file="../../ant-global.xml" /> | ||
|
||
<!-- Properties --> | ||
<property name="deploy.dir" location="/usr/local/openfire/lib/" /> | ||
<property name="jar.file" value="zimbraopenfire.jar" /> | ||
|
||
<path id="all.java.path"> | ||
<pathelement location="${src.java.dir}" /> | ||
</path> | ||
|
||
<path id="class.path"> | ||
<pathelement location="${common.classes.dir}" /> | ||
<pathelement location="${build.classes.dir}" /> | ||
<pathelement location="${soap.classes.dir}" /> | ||
<fileset dir="${common.jars.dir}"> | ||
<include name="**/*.jar" /> | ||
</fileset> | ||
<fileset dir="${jars.dir}"> | ||
<include name="**/*.jar"/> | ||
</fileset> | ||
</path> | ||
|
||
<!-- Targets --> | ||
<target name="build-init"> | ||
<mkdir dir="${build.classes.dir}" /> | ||
<delete dir="${dist.dir}" failonerror="false" /> | ||
<mkdir dir="${dist.dir}/" /> | ||
</target> | ||
|
||
<target name="compile" depends="build-init" description="Compiles the source code"> | ||
<ant dir="${common.dir}" target="jar" inheritAll="false" /> | ||
<ant dir="${client.dir}" target="jar" inheritAll="false" /> | ||
<javac destdir="${build.classes.dir}" debug="true" classpathref="class.path"> | ||
<src refid="all.java.path" /> | ||
</javac> | ||
</target> | ||
|
||
<target name="jar" depends="compile" description="Creates the jar file"> | ||
<antcall target="zimbra-jar"> | ||
<param name="implementation.title" value="Zimbra Openfire"/> | ||
</antcall> | ||
</target> | ||
|
||
<target name="clean" description="Removes build files and undeploys extension"> | ||
<delete dir="${build.dir}" /> | ||
<delete dir="${dist.dir}" failonerror="false" /> | ||
</target> | ||
|
||
<target name="deploy-jar" depends="jar" description="Copies the jar file into the extension directory"> | ||
<copy file="${build.dir}/${jar.file}" tofile="${deploy.dir}/${jar.file}"/> | ||
<copy file="${common.jarfile}" todir="${deploy.dir}"/> | ||
<copy file="${soap.jarfile}" todir="${deploy.dir}"/> | ||
</target> | ||
<target name="dist" description="place output and all required jars into ./dist folder" depends="jar"> | ||
<copy file="${build.dir}/${jar.file}" tofile="${dist.dir}/${jar.file}"/> | ||
<copy file="${common.jarfile}" todir="${dist.dir}"/> | ||
<copy file="${soap.jarfile}" todir="${dist.dir}"/> | ||
<copy file="${common.jars.dir}/json.jar" todir="${dist.dir}"/> | ||
<copy todir="${dist.dir}"> | ||
<fileset dir="${common.jars.dir}"> | ||
<include name="**/guava*.jar"/> | ||
</fileset> | ||
</copy> | ||
</target> | ||
</project> |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
package com.zimbra.openfire; | ||
|
||
import java.lang.reflect.InvocationTargetException; | ||
|
||
import org.jivesoftware.openfire.XMPPServer; | ||
import org.jivesoftware.openfire.auth.AuthProvider; | ||
import org.jivesoftware.openfire.auth.ConnectionException; | ||
import org.jivesoftware.openfire.auth.InternalUnauthenticatedException; | ||
import org.jivesoftware.openfire.auth.UnauthorizedException; | ||
import org.jivesoftware.openfire.user.UserNotFoundException; | ||
import org.jivesoftware.util.JiveGlobals; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import com.zimbra.common.soap.SoapHttpTransport; | ||
import com.zimbra.soap.account.message.AuthRequest; | ||
import com.zimbra.soap.account.type.AuthToken; | ||
import com.zimbra.soap.type.AccountSelector; | ||
import com.zimbra.soap.util.ZimbraSoapUtils; | ||
/** | ||
* @author Greg Solovyev | ||
*/ | ||
public class ZimbraAuthProvider implements AuthProvider { | ||
private static final Logger Log = LoggerFactory.getLogger(ZimbraAuthProvider.class); | ||
private String soapServerProto = "http"; | ||
private String soapServerPort = "7070"; | ||
private String soapServerHost = "localhost"; | ||
private String soapServerPath = "/service/soap/"; | ||
private SoapHttpTransport mTransport; | ||
private String fallbackProviderClass = null; | ||
private boolean fallback = true; | ||
private AuthProvider fallbackProvider; | ||
|
||
public ZimbraAuthProvider() { | ||
Log.info("Initialized ZimbraAuthProvider "); | ||
soapServerPort = JiveGlobals.getProperty("zimbraAuthProvider.port", "443"); | ||
soapServerHost = JiveGlobals.getProperty("zimbraAuthProvider.host"); | ||
soapServerPath = JiveGlobals.getProperty("zimbraAuthProvider.path", "/service/soap/"); | ||
soapServerProto = JiveGlobals.getProperty("zimbraAuthProvider.protocol", "https"); | ||
String zimbraURL = soapServerProto.concat("://").concat(soapServerHost) | ||
.concat(":").concat(soapServerPort).concat(soapServerPath); | ||
mTransport = new SoapHttpTransport(zimbraURL); | ||
fallback = JiveGlobals.getBooleanProperty("zimbraAuthProvider.fallback", true); | ||
if(fallback) { | ||
fallbackProviderClass = JiveGlobals.getProperty("zimbraAuthProvider.fallbackProviderClass", | ||
"org.jivesoftware.openfire.auth.DefaultAuthProvider"); | ||
try { | ||
Class<?> providerClass = Class.forName(fallbackProviderClass); | ||
fallbackProvider = (AuthProvider) providerClass.getConstructor().newInstance(); | ||
} catch (InstantiationException | IllegalAccessException | ||
| IllegalArgumentException | InvocationTargetException | ||
| NoSuchMethodException | SecurityException | ClassNotFoundException e) { | ||
Log.error("Failed to instantiate fallback provider", e); | ||
} | ||
} | ||
Log.info("Initialized ZimbraAuthProvider with connection string: " + zimbraURL); | ||
} | ||
|
||
public void authenticate(String username, String password) throws UnauthorizedException, ConnectionException, | ||
InternalUnauthenticatedException { | ||
Log.debug("Authenticating " + username + "/" + password); | ||
if (username == null || password == null) { | ||
throw new UnauthorizedException("Empty username or password"); | ||
} | ||
String zimbraName; | ||
if(username.indexOf("@") < 0) { | ||
zimbraName = username + "@" + XMPPServer.getInstance().getServerInfo().getXMPPDomain(); | ||
} else { | ||
zimbraName = username; | ||
} | ||
AuthRequest req = new AuthRequest(); | ||
if (password.length() > 100 | ||
&& password.substring(0, 10).equalsIgnoreCase("__zmauth__")) { | ||
// auth with auth token | ||
req.setAuthToken(new AuthToken(password.substring(10), true)); | ||
} else { | ||
// auth with password | ||
req.setPassword(password); | ||
} | ||
req.setAccount(AccountSelector.fromName(zimbraName)); | ||
try { | ||
// if auth fails, this will throw an exception | ||
ZimbraSoapUtils.invokeJaxb(mTransport, req); | ||
Log.debug("Successfully authenticated user " + zimbraName + " to Zimbra SOAP API"); | ||
} catch (Exception e) { | ||
if(fallback && fallbackProvider != null) { | ||
Log.error("Failed to authenticate " + zimbraName + " via Zimbra SOAP API. Falling back to " + fallbackProviderClass); | ||
fallbackProvider.authenticate(username, password); | ||
} else { | ||
throw new UnauthorizedException("Failed to authenticate " + username + " via Zimbra SOAP API.", e); | ||
} | ||
} | ||
} | ||
|
||
public void authenticate(String arg0, String arg1, String arg2) | ||
throws UnauthorizedException, ConnectionException, InternalUnauthenticatedException { | ||
if(fallback && fallbackProvider != null) { | ||
Log.debug("Digest authentication not supported by Zimbra SOAP API. Falling back to " + fallbackProviderClass); | ||
fallbackProvider.authenticate(arg0, arg1,arg2); | ||
} else { | ||
throw new UnsupportedOperationException(); | ||
} | ||
} | ||
|
||
public String getPassword(String arg0) throws UserNotFoundException, | ||
UnsupportedOperationException { | ||
throw new UnsupportedOperationException(); | ||
} | ||
|
||
public boolean isDigestSupported() { | ||
return false; | ||
} | ||
|
||
public boolean isPlainSupported() { | ||
return true; | ||
} | ||
|
||
public void setPassword(String arg0, String arg1) | ||
throws UserNotFoundException, UnsupportedOperationException { | ||
throw new UnsupportedOperationException(); | ||
} | ||
|
||
public boolean supportsPasswordRetrieval() { | ||
return false; | ||
} | ||
} |
Oops, something went wrong.