Ejemplo n.º 1
0
 @Override
 public boolean validCredentials(
     RealmModel realm, UserModel user, List<UserCredentialModel> input) {
   UserFederationProvider link = getFederationLink(realm, user);
   if (link != null) {
     validateUser(realm, user);
     Set<String> supportedCredentialTypes = link.getSupportedCredentialTypes(user);
     if (supportedCredentialTypes.size() > 0) {
       List<UserCredentialModel> fedCreds = new ArrayList<UserCredentialModel>();
       List<UserCredentialModel> localCreds = new ArrayList<UserCredentialModel>();
       for (UserCredentialModel cred : input) {
         if (supportedCredentialTypes.contains(cred.getType())) {
           fedCreds.add(cred);
         } else {
           localCreds.add(cred);
         }
       }
       if (!link.validCredentials(realm, user, fedCreds)) {
         return false;
       }
       return session.userStorage().validCredentials(realm, user, localCreds);
     }
   }
   return session.userStorage().validCredentials(realm, user, input);
 }
Ejemplo n.º 2
0
  @Override
  public CredentialValidationOutput validCredentials(
      RealmModel realm, UserCredentialModel... input) {
    List<UserFederationProviderModel> fedProviderModels = realm.getUserFederationProviders();
    List<UserFederationProvider> fedProviders = new ArrayList<UserFederationProvider>();
    for (UserFederationProviderModel fedProviderModel : fedProviderModels) {
      fedProviders.add(getFederationProvider(fedProviderModel));
    }

    CredentialValidationOutput result = null;
    for (UserCredentialModel cred : input) {
      UserFederationProvider providerSupportingCreds = null;

      // Find first provider, which supports required credential type
      for (UserFederationProvider fedProvider : fedProviders) {
        if (fedProvider.getSupportedCredentialTypes().contains(cred.getType())) {
          providerSupportingCreds = fedProvider;
          break;
        }
      }

      if (providerSupportingCreds == null) {
        logger.warn("Don't have provider supporting credentials of type " + cred.getType());
        return CredentialValidationOutput.failed();
      }

      logger.debug(
          "Found provider ["
              + providerSupportingCreds
              + "] supporting credentials of type "
              + cred.getType());
      CredentialValidationOutput currentResult =
          providerSupportingCreds.validCredentials(realm, cred);
      result = (result == null) ? currentResult : result.merge(currentResult);
    }

    // For now, validCredentials(realm, input) is not supported for local userProviders
    return (result != null) ? result : CredentialValidationOutput.failed();
  }