visit
Now think about a service provider who uses WSO2 Identity Server to
authenticate users who log into the application and it maintains multiple user stores in IS.
You can understand the second point from the highlighted lines in the
.
if (!authenticated && !domainProvided) {
AbstractUserStoreManager userStoreManager;
if (this instanceof IterativeUserStoreManager) {
IterativeUserStoreManager iterativeUserStoreManager = (IterativeUserStoreManager) this;
userStoreManager = iterativeUserStoreManager.nextUserStoreManager();
} else {
userStoreManager = (AbstractUserStoreManager) abstractUserStoreManager.getSecondaryUserStoreManager();
}
if (userStoreManager != null) {
authenticated = userStoreManager.authenticate(userName, credential, domainProvided);
}
}
Identity Server — Product-IS 5.9.0 (download )
Service provider — travelocity.com (deploy it according to the given instructions )
Three Secondary JDBC user stores Named: “DRIVER”, “MANAGER”, “CUSTOMER” (instructions: )
Add users according to the following table: (instructions: )
Authenticating condition: Only the users in PRIMARY, DRIVER and MANAGER user store can access travelocity.com services. Users in the CUSTOMER user store can’t use services in travelocity.com.
Moreover, users don’t know their user store domain. Thus, they input username without the user store domain. (i.e username is just ‘peter’ not like ‘MANAGER/peter’).Without any further configurations, try to login to travelocity.com app and
using four different username-password combinations in the table. You
will be succeeded.
1. Implement with your own logic to retrieve the allowed user stores.
public interface UserStorePreferenceOrderSupplier <T>{
/**
* Generate the user store order.
* @return
* @throws UserStoreException
*/
T get() throws UserStoreException;
}
2. Then extend and create an object of your custom UserStorePreferenceOrderSupplier.
public class CallBackHandlerFactory {
/**
* Create user store preference order supplier.
*/
public UserStorePreferenceOrderSupplier<List<String>> createUserStorePreferenceOrderSupplier
(AuthenticationContext context, ServiceProvider serviceProvider) {
return new DefaultUserStorePreferenceOrderSupplier(context, serviceProvider);
}
}
CallBackHandlerFactory
.UserStorePreferenceOrderSupplier<List<String>>
.SimpleUserStoreOrderCallbackHandler
.NOTE: In the pom.xml file, you need to update the
org.wso2.carbon.identity.framework
dependency version according to the <dependency>
<groupId>org.wso2.carbon.identity.framework</groupId>
<artifactId>org.wso2.carbon.identity.application.authentication.framework</artifactId>
<version>5.14.97</version>
</dependency>
<carbon.kernel.package.import.version.range>[4.4.0, 5.0.0)</carbon.kernel.package.import.version.range>
1. Build the repository which contains the login using
mvn clean install
command.2. Inside target folder, you will find org.wso2.carbon.identity.custom.callback.userstore-1.0-SNAPSHOT.jar
3. Copy and paste the generated jar file
“
org.wso2.carbon.identity.custom.callback.userstore-1.0-SNAPSHOT.jar
”4. Configure the extended CallBackHandlerFactory in
<IS-HOME>/repository/conf/identity/application-authentication.xml file, under
<ApplicationAuthentication xmlns="//wso2.org/projects/carbon/application-authentication.xml">
<Extensions>
...
<CallbackFactory>org.wso2.carbon.identity.custom.callback.userstore.CustomUserStoreOrderCallbackFactory</CallbackFactory>
…
</Extensions>
NOTE: From IS-5.10.0 onwards this modification should be done through
<IS-HOME>/repository/conf/deployment.toml
file. Add the following lines to deployment.toml.[authentication.framework.extensions]
callback_factory = "org.wso2.carbon.identity.custom.callback.userstore.CustomUserStoreOrderCallbackFactory"
5. Start the server by issuing
./wso2server.sh
(Linux)/ ./wso2server.bat
(Windows) on terminal navigating to <IS-HOME>/bin
6. Navigate
and click on Main -> Registry -> Browse
Browse
.7. Navigate to
_system -> config
. You will find a file named userstore-metadata.xml
(This file is defined in the CustomCallbackUserstoreServiceComponent
class as REG_PATH
) Click on userstore-metadata.xml
.8. Click
+
button in Properties
tab. It will appear as follows. These values will be used when authenticating users.The result:
Previously published at