Class CarbonTomcatRealm
- java.lang.Object
-
- org.apache.catalina.util.LifecycleBase
-
- org.apache.catalina.util.LifecycleMBeanBase
-
- org.apache.catalina.realm.RealmBase
-
- org.wso2.carbon.tomcat.ext.realms.CarbonTomcatRealm
-
- All Implemented Interfaces:
MBeanRegistration,org.apache.catalina.Contained,org.apache.catalina.JmxEnabled,org.apache.catalina.Lifecycle,org.apache.catalina.Realm
public class CarbonTomcatRealm extends org.apache.catalina.realm.RealmBaseThis is a custom Tomcat realm that uses Carbon realm inside. It is outside the OSGi container so creates a RealmService and RegistryService separately. Registry is needed because it is where we store the user-mgt.xml of each tenant. A classic demonstration of Adaptor Pattern.To enable SaaS for a webapp, add the following to the META-INF/context.xml file
<Realm className="org.wso2.carbon.tomcat.ext.realms.CarbonTomcatRealm" isSaaSEnabled="true" saasRules="*" />1. All tenants can access this app<Realm className="org.wso2.carbon.tomcat.ext.realms.CarbonTomcatRealm" isSaaSEnabled="true" saasRules="*" />2. All tenants except foo.com and bar.com can access this app<Realm className="org.wso2.carbon.tomcat.ext.realms.CarbonTomcatRealm" isSaaSEnabled="true" saasRules="*;!foo.com;!bar.com" />3. Only foo.com and bar.com (all users) can access this app<Realm className="org.wso2.carbon.tomcat.ext.realms.CarbonTomcatRealm" isSaaSEnabled="true" saasRules="foo.com;bar.com" />4. Only users bob and admin in tenant foo.com and all users in tenant bar.com can access this app<Realm className="org.wso2.carbon.tomcat.ext.realms.CarbonTomcatRealm" isSaaSEnabled="true" saasRules="foo.com:users=bob,admin;bar.com" />5. Only user admin in tenant foo.com can access this app and bob from tenant foo.com can't access the app. All users in bar.com can access the app except bob.<Realm className="org.wso2.carbon.tomcat.ext.realms.CarbonTomcatRealm" isSaaSEnabled="true" saasRules="foo.com:users=!bob,admin;bar.com:users=*,!bob" />* 6. Only users alice,bob in tenant foo.com can access this app. Also users who belongs to role devops in tenant foo.com also can access the app and users who belongs to role developers in tenant foo.com can't access the app. All users belong all roles in bar.com can access the app except users belongs to devops.<Realm className="org.wso2.carbon.tomcat.ext.realms.CarbonTomcatRealm" isSaaSEnabled="true" saasRules="foo.com:roles=!developers,devops:users=alice,bob;bar.com:roles=*,!devops" />Note: Denial rules will take precedence.
-
-
Field Summary
-
Fields inherited from class org.apache.catalina.realm.RealmBase
allRolesMode, container, containerLog, realmPath, sm, stripRealmForGss, support, validate, x509UsernameRetriever, x509UsernameRetrieverClassName
-
Fields inherited from interface org.apache.catalina.Lifecycle
AFTER_DESTROY_EVENT, AFTER_INIT_EVENT, AFTER_START_EVENT, AFTER_STOP_EVENT, BEFORE_DESTROY_EVENT, BEFORE_INIT_EVENT, BEFORE_START_EVENT, BEFORE_STOP_EVENT, CONFIGURE_START_EVENT, CONFIGURE_STOP_EVENT, PERIODIC_EVENT, START_EVENT, STOP_EVENT
-
-
Constructor Summary
Constructors Constructor Description CarbonTomcatRealm()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Principalauthenticate(String userName, String credential)Principalauthenticate(String username, String response, String nonce, String nc, String cNonce, String qop, String realmName, String md5)booleangetEnableSaaS()protected StringgetName()protected StringgetPassword(String username)protected PrincipalgetPrincipal(String userNameWithTenant)MapgetSaasRules()voidsetEnableSaaS(boolean enableSaaS)voidsetSaasRules(String saaSRules)-
Methods inherited from class org.apache.catalina.realm.RealmBase
addPropertyChangeListener, authenticate, authenticate, authenticate, backgroundProcess, findSecurityConstraints, getAllRolesMode, getContainer, getCredentialHandler, getDigest, getDomainInternal, getObjectNameKeyProperties, getPrincipal, getPrincipal, getRealmPath, getRealmSuffix, getRoles, getServer, getTransportGuaranteeRedirectStatus, getValidate, getX509UsernameRetrieverClassName, hasMessageDigest, hasResourcePermission, hasRole, hasRoleInternal, hasUserDataPermission, initInternal, isStripRealmForGss, main, removePropertyChangeListener, setAllRolesMode, setContainer, setCredentialHandler, setRealmPath, setStripRealmForGss, setTransportGuaranteeRedirectStatus, setValidate, setX509UsernameRetrieverClassName, startInternal, stopInternal, toString
-
Methods inherited from class org.apache.catalina.util.LifecycleMBeanBase
destroyInternal, getDomain, getObjectName, postDeregister, postRegister, preDeregister, preRegister, register, setDomain, unregister, unregister
-
Methods inherited from class org.apache.catalina.util.LifecycleBase
addLifecycleListener, destroy, findLifecycleListeners, fireLifecycleEvent, getState, getStateName, getThrowOnFailure, init, removeLifecycleListener, setState, setState, setThrowOnFailure, start, stop
-
-
-
-
Method Detail
-
getEnableSaaS
public boolean getEnableSaaS()
-
setEnableSaaS
public void setEnableSaaS(boolean enableSaaS)
-
getSaasRules
public Map getSaasRules()
-
setSaasRules
public void setSaasRules(String saaSRules)
-
getName
protected String getName()
-
getPassword
protected String getPassword(String username)
- Specified by:
getPasswordin classorg.apache.catalina.realm.RealmBase
-
authenticate
public Principal authenticate(String username, String response, String nonce, String nc, String cNonce, String qop, String realmName, String md5)
- Specified by:
authenticatein interfaceorg.apache.catalina.Realm- Overrides:
authenticatein classorg.apache.catalina.realm.RealmBase
-
authenticate
public Principal authenticate(String userName, String credential)
- Specified by:
authenticatein interfaceorg.apache.catalina.Realm- Overrides:
authenticatein classorg.apache.catalina.realm.RealmBase
-
-