1 23 24 package com.sun.enterprise.security.auth.realm.solaris; 25 26 import java.util.*; 27 28 import java.util.logging.Logger ; 29 import java.util.logging.Level ; 30 import com.sun.logging.LogDomains; 31 32 import com.sun.enterprise.security.acl.RoleMapper; 33 import com.sun.enterprise.security.auth.realm.IASRealm; 34 import com.sun.enterprise.security.auth.realm.BadRealmException; 35 import com.sun.enterprise.security.auth.realm.NoSuchUserException; 36 import com.sun.enterprise.security.auth.realm.NoSuchRealmException; 37 import com.sun.enterprise.security.auth.realm.AuthenticationHandler; 38 import com.sun.enterprise.security.auth.realm.InvalidOperationException; 39 40 41 53 public final class SolarisRealm extends IASRealm 54 { 55 public static final String AUTH_TYPE = "solaris"; 57 58 private HashMap groupCache; 59 private Vector emptyVector; 60 61 62 static { 64 System.loadLibrary("solarisauth"); 65 } 66 67 68 80 public synchronized void init(Properties props) 81 throws BadRealmException, NoSuchRealmException 82 { 83 String jaasCtx = props.getProperty(IASRealm.JAAS_CONTEXT_PARAM); 84 if (jaasCtx==null) { 85 _logger.warning("realmconfig.noctx"); 86 String msg = sm.getString("solarisrealm.nojaas"); 87 throw new BadRealmException(msg); 88 } 89 90 this.setProperty(IASRealm.JAAS_CONTEXT_PARAM, jaasCtx); 91 92 _logger.fine("SolarisRealm : "+IASRealm.JAAS_CONTEXT_PARAM+ 93 "="+jaasCtx); 94 95 groupCache = new HashMap(); 96 emptyVector = new Vector(); 97 } 98 99 100 107 public String getAuthType() 108 { 109 return AUTH_TYPE; 110 } 111 112 113 125 public Enumeration getGroupNames (String username) 126 throws InvalidOperationException, NoSuchUserException 127 { 128 Vector v = (Vector)groupCache.get(username); 129 if (v == null) { 130 v = loadGroupNames(username); 131 } 132 133 return v.elements(); 134 } 135 136 137 143 public void setGroupNames(String username, String [] groups) 144 { 145 Vector v = null; 146 147 if (groups == null) { 148 v = emptyVector; 149 150 } else { 151 v = new Vector(groups.length + 1); 152 for (int i=0; i<groups.length; i++) { 153 v.add(groups[i]); 154 } 155 } 156 157 synchronized (this) { 158 groupCache.put(username, v); 159 } 160 } 161 162 163 171 public String [] authenticate(String username, String password) 172 { 173 String [] grps = nativeAuthenticate(username, password); 174 return grps; 175 } 176 177 178 186 private Vector loadGroupNames(String username) 187 { 188 String [] grps = nativeGetGroups(username); 189 if (grps == null) { 190 _logger.fine("No groups returned for user: "+username); 191 } 192 193 setGroupNames(username, grps); 194 return (Vector)groupCache.get(username); 195 } 196 197 198 202 private static native String [] nativeAuthenticate(String user, 203 String password); 204 205 209 private static native String [] nativeGetGroups(String user); 210 211 212 } 213 | Popular Tags |