/* (non-Javadoc)
@see com.att.authz.certman.mapper.Mapper#toDrop(com.att.authz.env.AuthzTrans, java.lang.Object)
774475
@Override
	public Result<CertDrop> toDrop(AuthzTrans trans, BaseRequest req) {
		return Result.err(Result.ERR_NotImplemented,"Not Implemented... yet");
	}
58562
function initAuth (req, res, next) {
  const params = {
    session: false,
    state: state.serialize(req),
    scope: req.authProvider.scope
  };

  // noinspection JSUnresolvedFunction
  passport.authenticate(
    req.params.provider,
    params
  )(req, res, next);
}
1152278
private <TResponse> TResponse callServiceOwnerGetApi(
            String path, Map<String, String> queryParams,
            Class<TResponse> responseClass) throws AuthleteApiException
    {
        return callGetApi(mServiceOwnerCredentials, path, queryParams, responseClass);
    }
106705
private <TResponse> void callDeleteApi(
            BasicCredentials credentials, String path,
            Map<String, String> queryParams) throws AuthleteApiException
    {
        callApi(HttpMethod.DELETE, credentials, path, queryParams, (Object)null, (Class<TResponse>)null);
    }
1261307
private static Map<String, Object> toMap(ObjectMapper objectMapper, JsonNode object) {
        return objectMapper.convertValue(object, new TypeReference<Map<String, Object>>() {
        });
    }
762445
public void setTransientMap(Map<String, byte[]> transientMap) throws InvalidArgumentException {
        if (null == transientMap) {

            throw new InvalidArgumentException("Transient map may not be set to null");

        }
        this.transientMap = transientMap;
    }
172557
@Override
    @Scheduled(initialDelayString = "${cas.authn.throttle.schedule.startDelay:PT10S}",
        fixedDelayString = "${cas.authn.throttle.schedule.repeatInterval:PT15S}")
    public void run() {
        val handlers = authenticationThrottlingExecutionPlan.getAuthenticationThrottleInterceptors();
        handlers
            .stream()
            .filter(handler -> handler instanceof ThrottledSubmissionHandlerInterceptor)
            .map(handler -> (ThrottledSubmissionHandlerInterceptor) handler)
            .forEach(ThrottledSubmissionHandlerInterceptor::decrement);
    }
200811
@Override
	public void error(AuthzTrans trans, HttpServletResponse response, Result<?> result) {
		String msg = result.details==null?"%s":"%s - " + result.details.trim();
		String msgId;
		String[] detail;
		if(result.variables==null) {
			detail = new String[1];
		} else {
			int l = result.variables.length;
			detail=new String[l+1];
			System.arraycopy(result.variables, 0, detail, 1, l);
		}
		//int httpstatus;
		
		switch(result.status) {
			case ERR_ActionNotCompleted:
				msgId = "SVC1202";
				detail[0] = "Accepted, Action not complete";
				response.setStatus(/*httpstatus=*/202);
				break;

			case ERR_Policy:
				msgId = "SVC3403";
				detail[0] = FORBIDDEN;
				response.setStatus(/*httpstatus=*/403);
				break;
			case ERR_Security:
				msgId = "SVC2403";
				detail[0] = FORBIDDEN;
				response.setStatus(/*httpstatus=*/403);
				break;
			case ERR_Denied:
				msgId = "SVC1403";
				detail[0] = FORBIDDEN;
				response.setStatus(/*httpstatus=*/403);
				break;
			// This is still forbidden to directly impact, but can be Requested when passed
			// with "request=true" query Param
			case ERR_FutureNotRequested:
				msgId = "SVC2403";
				detail[0] = msg;
				response.setStatus(/*httpstatus=*/403);
				break;
				
			case ERR_NsNotFound:
				msgId = "SVC2404";
				detail[0] = NOT_FOUND;
				response.setStatus(/*httpstatus=*/404);
				break;
			case ERR_RoleNotFound:
				msgId = "SVC3404";
				detail[0] = NOT_FOUND;
				response.setStatus(/*httpstatus=*/404);
				break;
			case ERR_PermissionNotFound:
				msgId = "SVC4404";
				detail[0] = NOT_FOUND;
				response.setStatus(/*httpstatus=*/404);
				break;
			case ERR_UserNotFound:
				msgId = "SVC5404";
				detail[0] = NOT_FOUND;
				response.setStatus(/*httpstatus=*/404);
				break;
			case ERR_UserRoleNotFound:
				msgId = "SVC6404";
				detail[0] = NOT_FOUND;
				response.setStatus(/*httpstatus=*/404);
				break;
			case ERR_DelegateNotFound:
				msgId = "SVC7404";
				detail[0] = NOT_FOUND;
				response.setStatus(/*httpstatus=*/404);
				break;
			case ERR_NotFound:
				msgId = "SVC1404";
				detail[0] = NOT_FOUND;
				response.setStatus(/*httpstatus=*/404);
				break;

			case ERR_InvalidDelegate:
				msgId="SVC2406";
				detail[0] = NOT_ACCEPTABLE;
				response.setStatus(/*httpstatus=*/406);
				break;
			case ERR_BadData:
				msgId="SVC1406";
				detail[0] = NOT_ACCEPTABLE;
				response.setStatus(/*httpstatus=*/406);
				break;
				
			case ERR_ConflictAlreadyExists:
				msgId = "SVC1409";
				detail[0] = "Conflict Already Exists";
				response.setStatus(/*httpstatus=*/409);
				break;
			
			case ERR_DependencyExists:
				msgId = "SVC1424";
				detail[0] = "Failed Dependency";
				response.setStatus(/*httpstatus=*/424);
				break;
			
			case ERR_NotImplemented:
				msgId = "SVC1501";
				detail[0] = "Not Implemented"; 
				response.setStatus(/*httpstatus=*/501);
				break;
				
			case Status.ACC_Future:
				msgId = "SVC1202";
				detail[0] = "Accepted for Future, pending Approvals";
				response.setStatus(/*httpstatus=*/202);
				break;
			case ERR_ChoiceNeeded:
				msgId = "SVC1300";
				detail = result.variables;
				response.setStatus(/*httpstatus=*/300);
				break;
			case ERR_Backend: 
				msgId = "SVC2500";
				detail[0] = GENERAL_SERVICE_ERROR;
				response.setStatus(/*httpstatus=*/500);
				break;

			default: 
				msgId = "SVC1500";
				detail[0] = GENERAL_SERVICE_ERROR;
				response.setStatus(/*httpstatus=*/500);
				break;
		}

		try {
			StringBuilder holder = new StringBuilder();
			errDF.newData(trans).load(
				service.mapper()
					.errorFromMessage(holder,msgId,msg,detail))
						.to(response.getOutputStream());
			trans.checkpoint(
					holder.toString(),
//					String.format("ErrResp [" +	msgId +	"] " + msg,(Object[])detail),
					Env.ALWAYS);
		} catch (Exception e) {
			trans.error().log(e,"unable to send response for",msg);
		}
	}
1172028
public void toDBObject(final Object containingObject, final MappedField mf, final DBObject dbObj, final MapperOptions opts) {
        final Object fieldValue = mf.getFieldValue(containingObject);
        final TypeConverter enc = getEncoder(fieldValue, mf);

        final Object encoded = enc.encode(fieldValue, mf);
        if (encoded != null || opts.isStoreNulls()) {
            dbObj.put(mf.getNameToStore(), encoded);
        }
    }
1176903
@Override
    public void handle(RequestDTO requestDTO, Attachment attachment) {
        if (handler != null) {
            handler.handle(requestDTO, attachment);
        }
        if (attachment != null && attachment.getAppIdToken() != null
                && StringUtil.isNotEmpty(attachment.getAppIdToken().getAppId())
                && StringUtil.isNotEmpty(attachment.getAppIdToken().getToken())) {
            requestDTO.setAppId(attachment.getAppIdToken().getAppId());
            requestDTO.setToken(attachment.getAppIdToken().getToken());
        }
    }
1050070
private <TResponse> TResponse callServiceGetApi(
            String path, Map<String, String> queryParams,
            Class<TResponse> responseClass) throws AuthleteApiException
    {
        return callGetApi(mServiceCredentials, path, queryParams, responseClass);
    }
1093286
public void handleSsoPostProfileRequest(final HttpServletResponse response,
                                            final HttpServletRequest request,
                                            final BaseHttpServletRequestXMLMessageDecoder decoder) throws Exception {
        val authnRequest = getSamlProfileHandlerConfigurationContext().getSamlHttpRequestExtractor()
            .extract(request, decoder, AuthnRequest.class);
        initiateAuthenticationRequest(authnRequest, response, request);
    }
638204
protected Pair<Boolean, Set<Throwable>> evaluateAuthenticationPolicies(final Authentication authentication,
                                                                           final AuthenticationTransaction transaction,
                                                                           final Set<AuthenticationHandler> authenticationHandlers) {
        val failures = new LinkedHashSet<Throwable>();
        val policies = authenticationEventExecutionPlan.getAuthenticationPolicies(transaction);

        policies.forEach(p -> {
            try {
                val simpleName = p.getClass().getSimpleName();
                LOGGER.debug("Executing authentication policy [{}]", simpleName);
                val supportingHandlers = authenticationHandlers
                    .stream()
                    .filter(handler -> transaction.getCredentials().stream().anyMatch(handler::supports))
                    .collect(Collectors.toCollection(LinkedHashSet::new));
                if (!p.isSatisfiedBy(authentication, supportingHandlers)) {
                    failures.add(new AuthenticationException("Unable to satisfy authentication policy " + simpleName));
                }
            } catch (final GeneralSecurityException e) {
                LOGGER.debug(e.getMessage(), e);
                failures.add(e.getCause());
            } catch (final Exception e) {
                LOGGER.debug(e.getMessage(), e);
                failures.add(e);
            }
        });

        return Pair.of(failures.isEmpty(), failures);
    }
585658
private <TResponse> TResponse callServiceOwnerPostApi(
            String path, Object requestBody, Class<TResponse> responseClass) throws AuthleteApiException
    {
        return callServiceOwnerPostApi(path, (Map<String, String>)null, requestBody, responseClass);
    }
1280316
public void setParameter(MethodDescriptor methodDesc, int param, TypeQualifierValue<?> tqv, TypeQualifierAnnotation tqa) {
        Map<TypeQualifierValue<?>, TypeQualifierAnnotation> map = parameterMap.get(methodDesc, param);
        if (map == null) {
            map = new HashMap<>();
            parameterMap.put(methodDesc, param, map);
        }
        map.put(tqv, tqa);

        if (DEBUG) {
            System.out.println("tqdb: " + methodDesc + " parameter " + param + " for " + tqv + " ==> " + tqa);
        }
    }
1102117
@Override
    @SuppressWarnings("nls")
    protected <T> T doInstantiate(Class<T> type, Map<String, String> mapConfig) {
        try {
            Constructor<T> constructor = type.getConstructor(Vertx.class, VertxEngineConfig.class, Map.class);
            return constructor.newInstance(vertx, vxConfig, mapConfig);
        } catch (NoSuchMethodException e) { // If doesn't have constructor, try other method.
        } catch (Exception e ) {
            throw new RuntimeException(e);
        }
        try {
            Constructor<T> constructor = type.getConstructor(Vertx.class, IEngineConfig.class, Map.class);
            return constructor.newInstance(vertx, vxConfig, mapConfig);
        } catch (NoSuchMethodException e) { // If doesn't have constructor, try other method.
        } catch (Exception e ) {
            throw new RuntimeException(e);
        }
        try {
            Constructor<T> constructor = type.getConstructor(Map.class);
            return constructor.newInstance(mapConfig);
        } catch (Exception e) {
        }
        try {
            return type.newInstance();
        } catch (InstantiationException | IllegalAccessException e) {
            throw new RuntimeException(String.format(
                    "Could not instantiate %s. Verify class has valid constructor parameters: %s", type,
                    e.getMessage()), e);
        }
    }
1051442
private RequestDTO makeRequestDTO(String methodName, Object[] args, Class<?>[] prarameterTypes) {
        RequestDTO request = new RequestDTO();
        request.setTraceId(IdGenerator.genUUID());
        request.setMethod(methodName);
        request.setParamterTypes(MethodUtil.getArgsTypeNameArray(prarameterTypes));
        request.setParameters(args);
        return request;
    }