1 11 12 package org.jivesoftware.messenger.auth; 13 14 import org.jivesoftware.util.*; 15 import org.jivesoftware.util.JiveGlobals; 16 17 import java.security.MessageDigest ; 18 import java.security.NoSuchAlgorithmException ; 19 20 37 public class AuthFactory { 38 39 private static AuthProvider authProvider = null; 40 private static MessageDigest digest; 41 42 static { 43 String className = JiveGlobals.getXMLProperty("provider.auth.className", 45 "org.jivesoftware.messenger.auth.DefaultAuthProvider"); 46 try { 47 Class c = ClassUtils.forName(className); 48 authProvider = (AuthProvider)c.newInstance(); 49 } 50 catch (Exception e) { 51 Log.error("Error loading auth provider: " + className, e); 52 authProvider = new DefaultAuthProvider(); 53 } 54 try { 56 digest = MessageDigest.getInstance("SHA"); 57 } 58 catch (NoSuchAlgorithmException e) { 59 Log.error(LocaleUtils.getLocalizedString("admin.error"), e); 60 } 61 } 62 63 70 public static boolean isPlainSupported() { 71 return authProvider.isPlainSupported(); 72 } 73 74 80 public static boolean isDigestSupported() { 81 return authProvider.isDigestSupported(); 82 } 83 84 94 public static AuthToken authenticate(String username, String password) 95 throws UnauthorizedException 96 { 97 authProvider.authenticate(username, password); 98 return new AuthToken(username); 99 } 100 101 115 public static AuthToken authenticate(String username, String token, String digest) 116 throws UnauthorizedException 117 { 118 authProvider.authenticate(username, token, digest); 119 return new AuthToken(username); 120 } 121 122 129 public static String createDigest(String token, String password) { 130 synchronized (digest) { 131 digest.update(token.getBytes()); 132 return StringUtils.encodeHex(digest.digest(password.getBytes())); 133 } 134 } 135 } | Popular Tags |