1 10 11 package org.mule.impl.security; 12 13 import org.apache.commons.logging.Log; 14 import org.apache.commons.logging.LogFactory; 15 import org.mule.MuleManager; 16 import org.mule.config.i18n.Message; 17 import org.mule.config.i18n.Messages; 18 import org.mule.umo.UMOEvent; 19 import org.mule.umo.endpoint.UMOEndpoint; 20 import org.mule.umo.endpoint.UMOImmutableEndpoint; 21 import org.mule.umo.lifecycle.InitialisationException; 22 import org.mule.umo.security.CryptoFailureException; 23 import org.mule.umo.security.EncryptionStrategyNotFoundException; 24 import org.mule.umo.security.SecurityException; 25 import org.mule.umo.security.SecurityProviderNotFoundException; 26 import org.mule.umo.security.UMOCredentialsAccessor; 27 import org.mule.umo.security.UMOEndpointSecurityFilter; 28 import org.mule.umo.security.UMOSecurityManager; 29 import org.mule.umo.security.UMOSecurityProvider; 30 import org.mule.umo.security.UnknownAuthenticationTypeException; 31 import org.mule.util.StringUtils; 32 33 40 41 public abstract class AbstractEndpointSecurityFilter implements UMOEndpointSecurityFilter 42 { 43 46 protected transient Log logger = LogFactory.getLog(getClass()); 47 48 private UMOSecurityManager securityManager; 49 private String securityProviders; 50 private UMOImmutableEndpoint endpoint; 51 private boolean inbound = false; 52 private boolean authenticate; 53 private UMOCredentialsAccessor credentialsAccessor; 54 55 public final void initialise() throws InitialisationException 56 { 57 if (securityManager == null) 58 { 59 securityManager = MuleManager.getInstance().getSecurityManager(); 60 } 61 if (securityManager == null) 62 { 63 throw new InitialisationException(new Message(Messages.AUTH_SECURITY_MANAGER_NOT_SET), this); 64 } 65 if (endpoint == null) 66 { 67 throw new InitialisationException(new Message(Messages.X_IS_NULL, "Endpoint"), this); 68 } 69 if (securityProviders != null) 72 { 73 UMOSecurityManager localManager = new MuleSecurityManager(); 74 String [] sp = StringUtils.splitAndTrim(securityProviders, ","); 75 for (int i = 0; i < sp.length; i++) 76 { 77 UMOSecurityProvider provider = securityManager.getProvider(sp[i]); 78 if (provider != null) 79 { 80 localManager.addProvider(provider); 81 } 82 else 83 { 84 throw new InitialisationException(new Message(Messages.X_NOT_REGISTERED_WITH_MANAGER, 85 "Security Provider '" + sp[i] + "'"), this); 86 } 87 } 88 securityManager = localManager; 89 } 90 if (endpoint.getType().equals(UMOEndpoint.ENDPOINT_TYPE_RECEIVER)) 91 { 92 inbound = true; 93 } 94 else if (endpoint.getType().equals(UMOEndpoint.ENDPOINT_TYPE_SENDER)) 95 { 96 inbound = false; 97 } 98 else 99 { 100 throw new InitialisationException(new Message( 101 Messages.AUTH_ENDPOINT_TYPE_FOR_FILTER_MUST_BE_X_BUT_IS_X, 102 UMOEndpoint.ENDPOINT_TYPE_SENDER + " or " + UMOEndpoint.ENDPOINT_TYPE_RECEIVER, 103 endpoint.getType()), this); 104 } 105 doInitialise(); 106 } 107 108 public boolean isAuthenticate() 109 { 110 return authenticate; 111 } 112 113 public void setAuthenticate(boolean authenticate) 114 { 115 this.authenticate = authenticate; 116 } 117 118 121 public void setSecurityManager(UMOSecurityManager manager) 122 { 123 securityManager = manager; 124 } 125 126 public UMOSecurityManager getSecurityManager() 127 { 128 return securityManager; 129 } 130 131 public String getSecurityProviders() 132 { 133 return securityProviders; 134 } 135 136 public void setSecurityProviders(String providers) 137 { 138 securityProviders = providers; 139 } 140 141 public UMOImmutableEndpoint getEndpoint() 142 { 143 return endpoint; 144 } 145 146 public void setEndpoint(UMOImmutableEndpoint endpoint) 147 { 148 this.endpoint = endpoint; 149 } 150 151 public void authenticate(UMOEvent event) 152 throws SecurityException , UnknownAuthenticationTypeException, CryptoFailureException, 153 SecurityProviderNotFoundException, EncryptionStrategyNotFoundException 154 { 155 if (inbound) 156 { 157 authenticateInbound(event); 158 } 159 else 160 { 161 authenticateOutbound(event); 162 } 163 } 164 165 public UMOCredentialsAccessor getCredentialsAccessor() 166 { 167 return credentialsAccessor; 168 } 169 170 public void setCredentialsAccessor(UMOCredentialsAccessor credentialsAccessor) 171 { 172 this.credentialsAccessor = credentialsAccessor; 173 } 174 175 protected abstract void authenticateInbound(UMOEvent event) 176 throws SecurityException , CryptoFailureException, SecurityProviderNotFoundException, 177 EncryptionStrategyNotFoundException, UnknownAuthenticationTypeException; 178 179 protected abstract void authenticateOutbound(UMOEvent event) 180 throws SecurityException , SecurityProviderNotFoundException, CryptoFailureException; 181 182 protected abstract void doInitialise() throws InitialisationException; 183 184 } 185 | Popular Tags |