示例#1
0
文件: Shaj.java 项目: walware/rj-core
 static {
   try {
     System.loadLibrary("shaj");
     sInitOkay = initlibrary(Log.Factory.getInstance());
   } catch (final Throwable e) {
     Log.Factory.getInstance().error("could not load native library, host-auth disabled", e);
   }
 }
  public NativeAuthProvider() {
    // Convert XML based provider setup to Database based
    JiveGlobals.migrateProperty("nativeAuth.domain");

    this.domain = JiveGlobals.getProperty("nativeAuth.domain");

    // Configure the library path so that we can load the shaj native library
    // from the Openfire lib directory.
    // Find the root path of this class.
    try {
      String binaryPath =
          (new URL(Shaj.class.getProtectionDomain().getCodeSource().getLocation(), "."))
              .openConnection()
              .getPermission()
              .getName();
      binaryPath = (new File(binaryPath)).getCanonicalPath();

      // Add the binary path to "java.library.path".
      String newLibPath = binaryPath + File.pathSeparator + System.getProperty("java.library.path");
      System.setProperty("java.library.path", newLibPath);
      Field fieldSysPath = ClassLoader.class.getDeclaredField("sys_paths");
      fieldSysPath.setAccessible(true);
      fieldSysPath.set(System.class.getClassLoader(), null);
    } catch (Exception e) {
      Log.error(e);
    }

    // Configure Shaj to log output to the Openfire logger.
    com.cenqua.shaj.log.Log.Factory.setInstance(
        new com.cenqua.shaj.log.Log() {
          public boolean isDebug() {
            return Log.isDebugEnabled();
          }

          public void error(String string) {
            Log.error(string);
          }

          public void error(String string, Throwable throwable) {
            Log.error(string, throwable);
          }

          public void debug(String string) {
            Log.debug("NativeAuthProvider: " + string);
          }
        });
  }
示例#3
0
文件: Shaj.java 项目: walware/rj-core
 /**
  * Tests if a user is a member of a specific group.
  *
  * @param domain the (platform-specific) domain/service to used to perform the check. May be
  *     <code>null</code> (which has a platform-specific meaning).
  * @param username the username to test for membership
  * @param group the group to look in
  * @return true if the user is a member of the group
  * @throws IllegalArgumentException if <code>username</code> or <code>group</code> are <code>null
  *     </code>.
  * @throws IllegalStateException if Shaj did not load correctly (if {@link Shaj#init()} returns
  *     false).
  */
 public static boolean checkGroupMembership(
     final String domain, final String username, final String group) {
   return Authenticator.getDefault()
       .checkGroupMembership(domain, username, group, Log.Factory.getInstance());
 }
示例#4
0
文件: Shaj.java 项目: walware/rj-core
 /**
  * Checks a user's password.
  *
  * @param domain the (platform-specific) domain/service to used to perform the check. May be
  *     <code>null</code> (which has a platform-specific meaning).
  * @param username the username
  * @param password the password to verify
  * @return true if the password matches the username
  * @throws IllegalArgumentException if <code>username</code> or <code>password</code> are <code>
  *     null</code>.
  * @throws IllegalStateException if Shaj did not load correctly (if {@link Shaj#init()} returns
  *     false).
  */
 public static boolean checkPassword(
     final String domain, final String username, final String password) {
   return Authenticator.getDefault()
       .checkPassword(domain, username, password, Log.Factory.getInstance());
 }