Commit 31a192b3 authored by Derek DeMoro's avatar Derek DeMoro Committed by derek

Refactoring AuthorizationProvider.

git-svn-id: http://svn.igniterealtime.org/svn/repos/openfire/branches@8218 b35dd754-fafc-0310-a699-88a17e54d16e
parent de340f06
...@@ -13,7 +13,7 @@ package org.jivesoftware.openfire.ldap; ...@@ -13,7 +13,7 @@ package org.jivesoftware.openfire.ldap;
import org.jivesoftware.util.JiveGlobals; import org.jivesoftware.util.JiveGlobals;
import org.jivesoftware.openfire.sasl.AbstractAuthorizationProvider; import org.jivesoftware.openfire.sasl.AbstractAuthorizationProvider;
import org.jivesoftware.openfire.sasl.AuthorizationProvider; import org.jivesoftware.openfire.sasl.AuthorizationPolicy;
import org.xmpp.packet.JID; import org.xmpp.packet.JID;
import javax.naming.directory.Attribute; import javax.naming.directory.Attribute;
...@@ -38,7 +38,7 @@ import java.util.Enumeration; ...@@ -38,7 +38,7 @@ import java.util.Enumeration;
* *
* @author Jay Kline * @author Jay Kline
*/ */
public class LdapAuthorizationProvider extends AbstractAuthorizationProvider implements AuthorizationProvider { public class LdapAuthorizationProvider extends AbstractAuthorizationProvider implements AuthorizationPolicy {
private LdapManager manager; private LdapManager manager;
private String usernameField; private String usernameField;
......
...@@ -33,7 +33,7 @@ package org.jivesoftware.openfire.sasl; ...@@ -33,7 +33,7 @@ package org.jivesoftware.openfire.sasl;
* *
* @author Jay Kline * @author Jay Kline
*/ */
public abstract class AbstractAuthorizationPolicy implements AuthorizationProvider { public abstract class AbstractAuthorizationPolicy implements AuthorizationPolicy {
/** /**
* Returns true if the principal is explicity authorized to the JID * Returns true if the principal is explicity authorized to the JID
...@@ -44,18 +44,6 @@ public abstract class AbstractAuthorizationPolicy implements AuthorizationProvid ...@@ -44,18 +44,6 @@ public abstract class AbstractAuthorizationPolicy implements AuthorizationProvid
*/ */
public abstract boolean authorize(String username, String principal); public abstract boolean authorize(String username, String principal);
/**
* Returns the short name of the Policy
*
* @return The short name of the Policy
*/
public abstract String name();
/**
* Returns a description of the Policy
*
* @return The description of the Policy.
*/
public abstract String description();
} }
\ No newline at end of file
...@@ -36,7 +36,7 @@ import java.util.Collection; ...@@ -36,7 +36,7 @@ import java.util.Collection;
* *
* @author Jay Kline * @author Jay Kline
*/ */
public abstract class AbstractAuthorizationProvider implements AuthorizationProvider { public abstract class AbstractAuthorizationProvider implements AuthorizationPolicy {
/** /**
* Returns true if the principal is explicity authorized to the JID * Returns true if the principal is explicity authorized to the JID
......
...@@ -42,8 +42,8 @@ import java.util.StringTokenizer; ...@@ -42,8 +42,8 @@ import java.util.StringTokenizer;
*/ */
public class AuthorizationManager { public class AuthorizationManager {
private static ArrayList<AuthorizationProvider> providers = private static ArrayList<AuthorizationPolicy> providers =
new ArrayList<AuthorizationProvider>(); new ArrayList<AuthorizationPolicy>();
private static AuthorizationManager instance = new AuthorizationManager(); private static AuthorizationManager instance = new AuthorizationManager();
static { static {
...@@ -54,8 +54,8 @@ public class AuthorizationManager { ...@@ -54,8 +54,8 @@ public class AuthorizationManager {
String s_provider = st.nextToken(); String s_provider = st.nextToken();
try { try {
Class c_provider = ClassUtils.forName(s_provider); Class c_provider = ClassUtils.forName(s_provider);
AuthorizationProvider provider = AuthorizationPolicy provider =
(AuthorizationProvider) (c_provider.newInstance()); (AuthorizationPolicy) (c_provider.newInstance());
Log.debug("AuthorizationManager: Loaded " + s_provider); Log.debug("AuthorizationManager: Loaded " + s_provider);
providers.add(provider); providers.add(provider);
} catch (Exception e) { } catch (Exception e) {
...@@ -81,7 +81,7 @@ public class AuthorizationManager { ...@@ -81,7 +81,7 @@ public class AuthorizationManager {
* *
* @return the current AuthorizationProvider. * @return the current AuthorizationProvider.
*/ */
public static Collection<AuthorizationProvider> getAuthorizationProviders() { public static Collection<AuthorizationPolicy> getAuthorizationProviders() {
return providers; return providers;
} }
...@@ -102,7 +102,7 @@ public class AuthorizationManager { ...@@ -102,7 +102,7 @@ public class AuthorizationManager {
*/ */
public static boolean authorize(String authorId, String authenId) { public static boolean authorize(String authorId, String authenId) {
for (AuthorizationProvider ap : providers) { for (AuthorizationPolicy ap : providers) {
if (ap.authorize(authorId, authenId)) { if (ap.authorize(authorId, authenId)) {
return true; return true;
} }
......
...@@ -14,7 +14,7 @@ package org.jivesoftware.openfire.sasl; ...@@ -14,7 +14,7 @@ package org.jivesoftware.openfire.sasl;
/** /**
* This is the interface the AuthorizationManager uses to * This is the interface the AuthorizationManager uses to
* conduct authorizations. * conduct authorizations.
* * <p/>
* Users that wish to integrate with their own authorization * Users that wish to integrate with their own authorization
* system must implement this interface, and are strongly * system must implement this interface, and are strongly
* encouraged to extend either the AbstractAuthoriationPolicy * encouraged to extend either the AbstractAuthoriationPolicy
...@@ -22,7 +22,7 @@ package org.jivesoftware.openfire.sasl; ...@@ -22,7 +22,7 @@ package org.jivesoftware.openfire.sasl;
* the admin console manage the classes more effectively. * the admin console manage the classes more effectively.
* Register the class with Openfire in the <tt>openfire.xml</tt> * Register the class with Openfire in the <tt>openfire.xml</tt>
* file. An entry in that file would look like the following: * file. An entry in that file would look like the following:
* * <p/>
* <pre> * <pre>
* &lt;provider&gt; * &lt;provider&gt;
* &lt;authorizationpolicy&gt; * &lt;authorizationpolicy&gt;
...@@ -32,7 +32,7 @@ package org.jivesoftware.openfire.sasl; ...@@ -32,7 +32,7 @@ package org.jivesoftware.openfire.sasl;
* *
* @author Jay Kline * @author Jay Kline
*/ */
public interface AuthorizationProvider { public interface AuthorizationPolicy {
/** /**
* Returns true if the principal is explicity authorized to the JID * Returns true if the principal is explicity authorized to the JID
...@@ -43,4 +43,17 @@ public interface AuthorizationProvider { ...@@ -43,4 +43,17 @@ public interface AuthorizationProvider {
*/ */
public boolean authorize(String username, String principal); public boolean authorize(String username, String principal);
/**
* Returns the short name of the Policy
*
* @return The short name of the Policy
*/
public abstract String name();
/**
* Returns a description of the Policy
*
* @return The description of the Policy.
*/
public abstract String description();
} }
\ No newline at end of file
...@@ -22,8 +22,7 @@ import org.jivesoftware.openfire.XMPPServer; ...@@ -22,8 +22,7 @@ import org.jivesoftware.openfire.XMPPServer;
* *
* @author Jay Kline * @author Jay Kline
*/ */
public class DefaultAuthorizationPolicy extends AbstractAuthorizationPolicy public class DefaultAuthorizationPolicy implements AuthorizationPolicy {
implements AuthorizationProvider {
private String serverName; private String serverName;
......
...@@ -30,7 +30,7 @@ import java.util.Collection; ...@@ -30,7 +30,7 @@ import java.util.Collection;
* @author Jay Kline * @author Jay Kline
*/ */
public class DefaultAuthorizationProvider extends AbstractAuthorizationProvider public class DefaultAuthorizationProvider extends AbstractAuthorizationProvider
implements AuthorizationProvider { implements AuthorizationPolicy {
private static final String MATCH_AUTHORIZED = private static final String MATCH_AUTHORIZED =
"SELECT username FROM jiveSASLAuthorized WHERE username=? AND authorized=?"; "SELECT username FROM jiveSASLAuthorized WHERE username=? AND authorized=?";
......
...@@ -19,7 +19,7 @@ package org.jivesoftware.openfire.sasl; ...@@ -19,7 +19,7 @@ package org.jivesoftware.openfire.sasl;
* *
* @author Jay Kline * @author Jay Kline
*/ */
public class LazyAuthorizationPolicy extends AbstractAuthorizationPolicy implements AuthorizationProvider { public class LooseAuthorizationPolicy implements AuthorizationPolicy {
/** /**
* Returns true if the principal is explicity authorized to the JID * Returns true if the principal is explicity authorized to the JID
...@@ -29,7 +29,7 @@ public class LazyAuthorizationPolicy extends AbstractAuthorizationPolicy impleme ...@@ -29,7 +29,7 @@ public class LazyAuthorizationPolicy extends AbstractAuthorizationPolicy impleme
* @return true is the user is authorized to be principal * @return true is the user is authorized to be principal
*/ */
public boolean authorize(String username, String principal) { public boolean authorize(String username, String principal) {
return (principal.startsWith(username+"@")); return (principal.startsWith(username + "@"));
} }
/** /**
...@@ -38,7 +38,7 @@ public class LazyAuthorizationPolicy extends AbstractAuthorizationPolicy impleme ...@@ -38,7 +38,7 @@ public class LazyAuthorizationPolicy extends AbstractAuthorizationPolicy impleme
* @return The short name of the Policy * @return The short name of the Policy
*/ */
public String name() { public String name() {
return "Lazy"; return "Loose Authorization Policy";
} }
/** /**
......
...@@ -15,7 +15,7 @@ import org.jivesoftware.util.JiveGlobals; ...@@ -15,7 +15,7 @@ import org.jivesoftware.util.JiveGlobals;
/** /**
* This policy will authorize any principal who: * This policy will authorize any principal who:
* * <p/>
* <li> Username of principal matches exactly the username of the JID </li> * <li> Username of principal matches exactly the username of the JID </li>
* <li> The user principal's realm matches exactly the realm of the server.</li> * <li> The user principal's realm matches exactly the realm of the server.</li>
* Note that the realm may not match the servername, and in fact for this * Note that the realm may not match the servername, and in fact for this
...@@ -27,7 +27,7 @@ import org.jivesoftware.util.JiveGlobals; ...@@ -27,7 +27,7 @@ import org.jivesoftware.util.JiveGlobals;
* *
* @author Jay Kline * @author Jay Kline
*/ */
public class StrictAuthorizationPolicy extends AbstractAuthorizationPolicy implements AuthorizationProvider { public class StrictAuthorizationPolicy implements AuthorizationPolicy {
/** /**
* Returns true if the principal is explicity authorized to the JID * Returns true if the principal is explicity authorized to the JID
...@@ -37,7 +37,7 @@ public class StrictAuthorizationPolicy extends AbstractAuthorizationPolicy imple ...@@ -37,7 +37,7 @@ public class StrictAuthorizationPolicy extends AbstractAuthorizationPolicy imple
* @return true is the user is authorized to be principal * @return true is the user is authorized to be principal
*/ */
public boolean authorize(String username, String principal) { public boolean authorize(String username, String principal) {
return (principal.equals(username+"@"+JiveGlobals.getXMLProperty("sasl.realm"))); return (principal.equals(username + "@" + JiveGlobals.getXMLProperty("sasl.realm")));
} }
/** /**
......
...@@ -36,7 +36,7 @@ import java.util.Collection; ...@@ -36,7 +36,7 @@ import java.util.Collection;
* *
* @author Jay Kline * @author Jay Kline
*/ */
public class UnixK5LoginProvider extends AbstractAuthorizationProvider implements AuthorizationProvider { public class UnixK5LoginProvider extends AbstractAuthorizationProvider implements AuthorizationPolicy {
/** /**
* Returns true if the principal is explicity authorized to the JID * Returns true if the principal is explicity authorized to the JID
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment