class AuthenticateToServiceCondition extends EntitlementConditionAdaptor {

    @Override
    public ConditionDecision evaluate(String realm, Subject subject, String resourceName, Map<String, Set<String>> env)
            throws EntitlementException {

        if (StringUtils.isBlank(authenticateToService)) {
            if (debug.errorEnabled()) {
                debug.error("AuthenticateToServiceCondition.evaluate(): property value not defined, " +
                AUTHENTICATE_TO_SERVICE);
            }
            throw new EntitlementException(PROPERTY_VALUE_NOT_DEFINED, new Object[]{AUTHENTICATE_TO_SERVICE}, null);
        }

        boolean allowed = false;
        Set<String> requestAuthnServices = new HashSet<String>();
        if (env.get(REQUEST_AUTHENTICATED_TO_SERVICES) != null) {
            requestAuthnServices.addAll(env.get(REQUEST_AUTHENTICATED_TO_SERVICES));
            if (debug.messageEnabled()) {
                debug.message("At AuthenticateToServiceCondition.evaluate(): requestAuthnServices "
                        + "from request = " + requestAuthnServices);
            }
        } else if (subject != null){
            SSOToken token = (SSOToken) subject.getPrivateCredentials().iterator().next();
            Set<String> authenticatedServices = entitlementCoreWrapper.getRealmQualifiedAuthenticatedServices(token);
            if (authenticatedServices != null) {
                requestAuthnServices.addAll(authenticatedServices);
            }
            if (debug.messageEnabled()) {
                debug.message("At AuthenticateToServiceCondition.evaluate(): requestAuthnServices from "
                        + "ssoToken = " + requestAuthnServices);
            }
        }

        if (requestAuthnServices.contains(authenticateToService)) {
            allowed = true;
        } else if (realmEmpty) {
            for (String requestAuthnService : requestAuthnServices) {
                String service = coreWrapper.getDataFromRealmQualifiedData(requestAuthnService);
                if (authenticateToService.equals(service)) {
                    allowed = true;
                    break;
                }
            }
        }

        Map<String, Set<String>> advices = new HashMap<String, Set<String>>();
        final String realmAwareService = getRealmAwareService(authenticateToService, realm);

        if (!allowed) {
            Set<String> adviceMessages = new HashSet<String>(1);

            adviceMessages.add(realmAwareService);
            advices.put(AUTHENTICATE_TO_SERVICE_CONDITION_ADVICE, adviceMessages);
            if (debug.messageEnabled()) {
                debug.message("At AuthenticateToServiceCondition.evaluate():authenticateToService not "
                        + "satisfied = " + realmAwareService);
            }
        }

        if (debug.messageEnabled()) {
            debug.message("At AuthenticateToServiceCondition.evaluate():authenticateToService = "
                    + realmAwareService + "," + " requestAuthnServices = " + requestAuthnServices + ", "
                    + " allowed = " + allowed);
        }
        return new ConditionDecision(allowed, advices);
    }

    public  AuthenticateToServiceCondition();
      AuthenticateToServiceCondition(Debug debug, CoreWrapper coreWrapper, EntitlementCoreWrapper entitlementCoreWrapper);

}