Class 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.RealmBase
    This 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.

    • Nested Class Summary

      • Nested classes/interfaces inherited from class org.apache.catalina.realm.RealmBase

        org.apache.catalina.realm.RealmBase.AllRolesMode
      • Nested classes/interfaces inherited from interface org.apache.catalina.Lifecycle

        org.apache.catalina.Lifecycle.SingleUse
    • Field Summary

      • Fields inherited from class org.apache.catalina.realm.RealmBase

        allRolesMode, container, containerLog, realmPath, sm, stripRealmForGss, support, validate, x509UsernameRetriever, x509UsernameRetrieverClassName
      • Fields inherited from class org.apache.catalina.util.LifecycleMBeanBase

        mserver
      • 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
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      Principal authenticate​(String userName, String credential)  
      Principal authenticate​(String username, String response, String nonce, String nc, String cNonce, String qop, String realmName, String md5)  
      boolean getEnableSaaS()  
      protected String getName()  
      protected String getPassword​(String username)  
      protected Principal getPrincipal​(String userNameWithTenant)  
      Map getSaasRules()  
      void setEnableSaaS​(boolean enableSaaS)  
      void setSaasRules​(String saaSRules)  
      • Methods inherited from class org.apache.catalina.realm.RealmBase

        addPropertyChangeListener, authenticate, authenticate, authenticate, authenticate, backgroundProcess, findSecurityConstraints, getAllRolesMode, getContainer, getCredentialHandler, getDigest, getDomainInternal, getObjectNameKeyProperties, getPrincipal, 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
      • Methods inherited from interface org.apache.catalina.Realm

        isAvailable
    • Constructor Detail

    • 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:
        getPassword in class org.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:
        authenticate in interface org.apache.catalina.Realm
        Overrides:
        authenticate in class org.apache.catalina.realm.RealmBase
      • authenticate

        public Principal authenticate​(String userName,
                                      String credential)
        Specified by:
        authenticate in interface org.apache.catalina.Realm
        Overrides:
        authenticate in class org.apache.catalina.realm.RealmBase
      • getPrincipal

        protected Principal getPrincipal​(String userNameWithTenant)
        Specified by:
        getPrincipal in class org.apache.catalina.realm.RealmBase