1 16 package org.apache.cocoon.portal.profile.impl; 17 18 import java.util.HashMap ; 19 import java.util.Map ; 20 21 import org.apache.avalon.framework.configuration.Configuration; 22 import org.apache.avalon.framework.service.ServiceException; 23 import org.apache.avalon.framework.service.ServiceManager; 24 import org.apache.avalon.framework.service.Serviceable; 25 import org.apache.cocoon.ProcessingException; 26 import org.apache.cocoon.webapps.authentication.AuthenticationManager; 27 import org.apache.cocoon.webapps.authentication.configuration.ApplicationConfiguration; 28 import org.apache.cocoon.webapps.authentication.user.RequestState; 29 import org.apache.cocoon.webapps.authentication.user.UserHandler; 30 31 38 public class AuthenticationFWUserInfoProvider 39 implements UserInfoProvider, Serviceable { 40 41 protected ServiceManager manager; 42 43 44 47 public void service(ServiceManager manager) throws ServiceException { 48 this.manager = manager; 49 } 50 51 54 public UserInfo getUserInfo(String portalName, String layoutKey) 55 throws Exception { 56 AuthenticationManager authManager = null; 57 try { 58 authManager = (AuthenticationManager)this.manager.lookup(AuthenticationManager.ROLE); 59 final RequestState state = authManager.getState(); 60 final UserHandler handler = state.getHandler(); 61 62 final UserInfo info = new AFWUserInfo(portalName, layoutKey, handler); 63 64 65 info.setUserName(handler.getUserId()); 66 try { 67 info.setGroup((String )handler.getContext().getContextInfo().get("group")); 68 } catch (ProcessingException pe) { 69 } 71 72 final ApplicationConfiguration ac = state.getApplicationConfiguration(); 73 if ( ac == null ) { 74 throw new ProcessingException("Configuration for portal not found in application configuration."); 75 } 76 final Configuration appConf = ac.getConfiguration("portal"); 77 if ( appConf == null ) { 78 throw new ProcessingException("Configuration for portal not found in application configuration."); 79 } 80 final Configuration config = appConf.getChild("profiles"); 81 final Configuration[] children = config.getChildren(); 82 final Map configs = new HashMap (); 83 if ( children != null ) { 84 for(int i=0; i < children.length; i++) { 85 configs.put(children[i].getName(), children[i].getAttribute("uri")); 86 } 87 } 88 info.setConfigurations(configs); 89 return info; 90 } finally { 91 this.manager.release( authManager ); 92 } 93 } 94 95 public static final class AFWUserInfo extends UserInfo { 96 97 protected final UserHandler handler; 98 102 public AFWUserInfo(String portalName, String layoutKey, UserHandler handler) { 103 super(portalName, layoutKey); 104 this.handler = handler; 105 } 106 107 110 public boolean isUserInRole(String role) { 111 return this.isUserInRole(role); 112 } 113 } 114 } 115 | Popular Tags |