1 16 package org.apache.cocoon.webapps.authentication.user; 17 18 import java.util.ArrayList ; 19 import java.util.List ; 20 21 import org.apache.cocoon.ProcessingException; 22 import org.apache.cocoon.webapps.authentication.configuration.ApplicationConfiguration; 23 import org.apache.cocoon.webapps.authentication.configuration.HandlerConfiguration; 24 import org.apache.cocoon.webapps.authentication.context.AuthenticationContext; 25 26 32 public final class UserHandler 33 implements java.io.Serializable { 34 35 36 private HandlerConfiguration handler; 37 38 39 private boolean appsLoaded = false; 40 41 42 private AuthenticationContext context; 43 44 45 private List loadedApps = new ArrayList (3); 46 47 48 private List applicationContexts; 49 50 51 private String userID; 52 53 56 public UserHandler(HandlerConfiguration handler, AuthenticationContext context) { 57 this.context = context; 58 this.handler = handler; 59 this.context.init(this); 60 } 61 62 65 public boolean getApplicationsLoaded() { 66 if ( this.handler.getApplications().isEmpty() ) { 67 return true; 68 } 69 return this.appsLoaded; 70 } 71 72 75 public AuthenticationContext getContext() { 76 return this.context; 77 } 78 79 82 public String getHandlerName() { 83 return this.handler.getName(); 84 } 85 86 89 public HandlerConfiguration getHandlerConfiguration() { 90 return this.handler; 91 } 92 93 96 public boolean isApplicationLoaded(ApplicationConfiguration appConf) { 97 return this.loadedApps.contains( appConf ); 98 } 99 100 103 public void setApplicationIsLoaded(ApplicationConfiguration appConf) { 104 this.loadedApps.add( appConf ); 105 this.appsLoaded = (this.loadedApps.size() == this.handler.getApplications().size()); 106 } 107 108 111 public String getUserId() { 112 if ( null == this.userID) { 113 try { 114 this.userID = (String ) this.context.getContextInfo().get("ID"); 115 } catch (ProcessingException ignore) { 116 this.userID = ""; 117 } 118 } 119 return this.userID; 120 } 121 122 126 public boolean isUserInRole(String role) { 127 return this.context.isUserInRole(role); 128 } 129 130 public void addApplicationContext(String name) { 131 if ( this.applicationContexts == null) { 132 this.applicationContexts = new ArrayList (3); 133 } 134 this.applicationContexts.add( name ); 135 } 136 137 140 public List getApplicationContexts() { 141 return this.applicationContexts; 142 } 143 } 144 | Popular Tags |