Returns an {@link AuthnRequest} which is mapped to the specified identity provider.
6517
private AuthnRequest createAuthRequest(SamlIdentityProviderConfig idp, String defaultHostname) {
        requireNonNull(idp, "idp");

        final AuthnRequest authnRequest = build(AuthnRequest.DEFAULT_ELEMENT_NAME);

        final Issuer issuer = build(Issuer.DEFAULT_ELEMENT_NAME);
        issuer.setValue(myEntityId);
        authnRequest.setIssuer(issuer);

        authnRequest.setIssueInstant(DateTime.now());
        authnRequest.setDestination(idp.ssoEndpoint().toUriString());
        authnRequest.setID(requestIdManager.newId());

        // The ProtocolBinding attribute is mutually exclusive with the AssertionConsumerServiceIndex attribute
        // and is typically accompanied by the AssertionConsumerServiceURL attribute.
        final SamlPortConfig portConfig = portConfigHolder.config().get();
        final SamlEndpoint acsEndpoint = idp.acsEndpoint()
                                            .orElse(sp.defaultAcsConfig().endpoint());
        authnRequest.setAssertionConsumerServiceURL(acsEndpoint.toUriString(portConfig.scheme().uriText(),
                                                                            defaultHostname,
                                                                            portConfig.port()));
        authnRequest.setProtocolBinding(acsEndpoint.bindingProtocol().urn());

        final SamlNameIdPolicy policy = idp.nameIdPolicy();
        final NameIDPolicy nameIdPolicy = build(NameIDPolicy.DEFAULT_ELEMENT_NAME);
        nameIdPolicy.setFormat(policy.format().urn());
        nameIdPolicy.setAllowCreate(policy.isCreatable());
        authnRequest.setNameIDPolicy(nameIdPolicy);

        final AuthnContextClassRef passwordAuthnCtxRef = build(AuthnContextClassRef.DEFAULT_ELEMENT_NAME);
        passwordAuthnCtxRef.setAuthnContextClassRef(AuthnContext.PASSWORD_AUTHN_CTX);

        final RequestedAuthnContext requestedAuthnContext = build(RequestedAuthnContext.DEFAULT_ELEMENT_NAME);
        requestedAuthnContext.setComparison(AuthnContextComparisonTypeEnumeration.EXACT);
        requestedAuthnContext.getAuthnContextClassRefs().add(passwordAuthnCtxRef);

        authnRequest.setRequestedAuthnContext(requestedAuthnContext);

        return authnRequest;
    }
1262036
private String getAuthTokenFromRequest(HttpServletRequest httpRequest) {
        String authToken = httpRequest.getHeader(AUTH_TOKEN_HEADER_KEY);

        if (authToken == null) {
            // token can also exist as request parameter
            authToken = httpRequest.getParameter(AUTH_TOKEN_PARAMETER_KEY);
        }

        return authToken;
    }
311148
public GetInstanceVncResponse getInstanceVnc(GetInstanceVncRequest request) {
        checkNotNull(request, "request should not be null.");
        checkStringNotEmpty(request.getInstanceId(), "request instanceId should not be empty.");
        InternalRequest internalRequest = this.createRequest(
                request, HttpMethodName.GET, INSTANCE_PREFIX, request.getInstanceId(), "vnc");
        return this.invokeHttpClient(internalRequest, GetInstanceVncResponse.class);
    }
583527
func (s *ServiceProviderSettings) GetAuthnRequest() *AuthnRequest {
	r := NewAuthnRequest()
	r.AssertionConsumerServiceURL = s.AssertionConsumerServiceURL
	r.Destination = s.IDPSSOURL
	r.Issuer.Url = s.IDPSSODescriptorURL
	r.Signature.KeyInfo.X509Data.X509Certificate.Cert = s.PublicCert()

	if !s.SPSignRequest {
		r.SAMLSIG = ""
		r.Signature = nil
	}

	return r
}
1081161
public static Endpoint determineEndpointForRequest(final RequestAbstractType authnRequest,
                                                       final SamlRegisteredServiceServiceProviderMetadataFacade adaptor,
                                                       final String binding) {
        var endpoint = (Endpoint) null;
        if (authnRequest instanceof LogoutRequest) {
            endpoint = adaptor.getSingleLogoutService(binding);
        } else {
            val endpointReq = getAssertionConsumerServiceFromRequest(authnRequest, binding);
            endpoint = endpointReq == null
                ? adaptor.getAssertionConsumerService(binding)
                : endpointReq;
        }

        if (endpoint == null || StringUtils.isBlank(endpoint.getBinding())) {
            throw new SamlException("Assertion consumer service does not define a binding");
        }
        val location = StringUtils.isBlank(endpoint.getResponseLocation()) ? endpoint.getLocation() : endpoint.getResponseLocation();
        if (StringUtils.isBlank(location)) {
            throw new SamlException("Assertion consumer service does not define a target location");
        }
        return endpoint;
    }
503536
@Override
    public AuthenticationResult authenticate(WebRequest webRequest) {
        AuthenticationResult authResult = handleTAI(webRequest, true);
        if ((authResult.getStatus() == AuthResult.CONTINUE) && continueAfterUnprotectedURI(webRequest)) {
            authResult = handleSSO(webRequest, null);
            if (authResult.getStatus() == AuthResult.CONTINUE) {
                webRequest.setCallAfterSSO(true);
                authResult = handleTAI(webRequest, false);
            }
        }

        return authResult;

    }
611164
public Request<List<Enrollment>> getEnrollments(String userId) {
        Asserts.assertNotNull(userId, "user id");

        String url = baseUrl
                .newBuilder()
                .addPathSegments("api/v2/users")
                .addPathSegment(userId)
                .addPathSegment("enrollments")
                .build()
                .toString();

        CustomRequest<List<Enrollment>> request = new CustomRequest<>(client, url, "GET", new TypeReference<List<Enrollment>>() {
        });
        request.addHeader("Authorization", "Bearer " + apiToken);
        return request;
    }
747064
@Override
    public AuthInterface getAuthInterface() {
        if (authInterface == null) {
            authInterface = new AuthInterface(apiKey, sharedSecret, transport);
        }
        return authInterface;
    }
724929
public Auth retrieve(String nsid) {
    	Auth auth =  this.auths.get(nsid);
    	if(auth != null)
    		return auth;
    	else
    		return this.authsByUser.get(nsid);
    }
508283
public SetRequestAuthResponse setRequestAuth(SetRequestAuthRequest request) {
        checkNotNull(request, "The parameter request should NOT be null.");
        InternalRequest internalRequest = 
                createRequest(request, HttpMethodName.PUT, DOMAIN, request.getDomain(), "config");
        internalRequest.addParameter("requestAuth", "");
        this.attachRequestToBody(request, internalRequest);
        return invokeHttpClient(internalRequest, SetRequestAuthResponse.class);
    }
928642
public AuthenticationResult authenticate(HttpServletRequest request) {
        HttpSession session = null;
        AuthenticationResult authResult = null;
        if (!HTTP_DONT_USE_SESSION && !m_dontUseSession) {
            try {
                session = request.getSession();
                if (session != null) {
                    if (session.isNew()) {
                        session.setMaxInactiveInterval(MAX_SESSION_INACTIVITY_SECONDS);
                    }
                    authResult = (AuthenticationResult )session.getAttribute(AUTH_USER_SESSION_KEY);
                }
            } catch (Exception ex) {
                //Use no session mode meaning whatever VMC sends as hashed password is used to authenticate.
                session = null;
                m_rate_limited_log.log(EstTime.currentTimeMillis(), Level.ERROR, ex, "Failed to get or create HTTP Session. authenticating user explicitely.");
            }
        }
        if (authResult == null) {
            authResult = getAuthenticationResult(request);
            if (!authResult.isAuthenticated()) {
                if (session != null) {
                    session.removeAttribute(AUTH_USER_SESSION_KEY);
                }
                m_rate_limited_log.log("JSON interface exception: " + authResult.m_message, EstTime.currentTimeMillis());
            } else {
                if (session != null) {
                    //Cache the authResult in session so we dont authenticate again.
                    session.setAttribute(AUTH_USER_SESSION_KEY, authResult);
                }
            }
        }
        return authResult;
    }
1310828
public UpdateIdentityProviderRequest withAttributeMapping(java.util.Map<String, String> attributeMapping) {
        setAttributeMapping(attributeMapping);
        return this;
    }
475341
public static Map<String, ?> toDataMap(final AuthRequest authRequest) {
        HashMap<String, Object> stringHashMap = new HashMap<>();
        //context
        Map<String, Object> ruleMap = new HashMap<>();
        if (authRequest.environment.equals(createAppEnv())) {
            //app context
            HashMap<String, String> s = new HashMap<>();
            s.put("application", "rundeck");
            stringHashMap.put(CONTEXT_LONG_OPT, s);
        } else {
            String project = authRequest.environment.iterator().next().value;
            HashMap<String, String> s = new HashMap<>();
            s.put("project", project);
            stringHashMap.put(CONTEXT_LONG_OPT, s);
        }

        //subject
        Set<Username> principals = authRequest.subject.getPrincipals(Username.class);
        if (principals.iterator().next().getName().equals("user")) {
            //use groups
            HashMap<String, Object> s = new HashMap<>();
            ArrayList<String> strings = new ArrayList<>();
            for (Group group : authRequest.subject.getPrincipals(Group.class)) {
                strings.add(group.getName());
            }
            s.put("group", strings.size() > 1 ? strings : strings.iterator().next());
            stringHashMap.put("by", s);
        } else {
            HashMap<String, String> s = new HashMap<>();
            s.put("username", principals.iterator().next().getName());
            stringHashMap.put("by", s);
        }

        Map<String, Object> resource = new HashMap<>();
        //resource
        String type = authRequest.resourceMap.get("type").toString();
        resource.putAll(authRequest.resourceMap);
        resource.remove("type");

        //project context type
        HashMap<String, Object> s = new HashMap<>();
        ArrayList<Map<String, Object>> maps = new ArrayList<>();
        s.put(type, maps);
        HashMap<String, Object> r = new HashMap<>();
        if (resource.size() > 0) {
            r.put(authRequest.regexMatch ? "match" : authRequest.containsMatch ? "contains" : "equals", resource);
        }
        if (authRequest.actions != null && authRequest.actions.size() > 0) {

            r.put(
                    "allow",
                    authRequest.actions.size() > 1
                    ? new ArrayList<>(authRequest.actions)
                    : authRequest.actions.iterator().next()
            );
        }
        if (authRequest.denyActions != null && authRequest.denyActions.size() > 0) {
            r.put(
                    "deny",
                    authRequest.denyActions.size() > 1
                    ? new ArrayList<>(authRequest.denyActions)
                    : authRequest.denyActions.iterator().next()
            );
        }
        maps.add(r);
        ruleMap.putAll(s);

        stringHashMap.put("for", ruleMap);
        stringHashMap.put("description", authRequest.description != null ? authRequest.description : "generated");


        return stringHashMap;
    }
1177606
public Event buildAuthenticationRequestEvent(final RequestContext context) {
        val clients = new ArrayList<WsFedClient>();
        val request = WebUtils.getHttpServletRequestFromExternalWebflowContext(context);
        val service = (Service) context.getFlowScope().get(CasProtocolConstants.PARAMETER_SERVICE);
        this.configurations.forEach(cfg -> {
            val c = new WsFedClient();
            c.setName(cfg.getName());
            val id = UUID.randomUUID().toString();
            val rpId = wsFederationHelper.getRelyingPartyIdentifier(service, cfg);
            c.setAuthorizationUrl(cfg.getAuthorizationUrl(rpId, id));
            c.setReplyingPartyId(rpId);
            c.setId(id);
            c.setRedirectUrl(getRelativeRedirectUrlFor(cfg, service, request));
            c.setAutoRedirect(cfg.isAutoRedirect());
            clients.add(c);

            if (cfg.isAutoRedirect()) {
                WebUtils.putDelegatedAuthenticationProviderPrimary(context, cfg);
            }
        });
        context.getFlowScope().put(PARAMETER_NAME_WSFED_CLIENTS, clients);
        return new EventFactorySupport().event(this, CasWebflowConstants.TRANSITION_ID_PROCEED);
    }
597070
public AuthenticationRequest getLoginRequest(AuthenticationAPIClient apiClient, String emailOrNumber) {
        Log.d(TAG, String.format("Generating Passwordless Login request for identity %s", emailOrNumber));
        if (getMode() == PasswordlessMode.EMAIL_CODE || getMode() == PasswordlessMode.EMAIL_LINK) {
            return apiClient.loginWithEmail(emailOrNumber, getCode());
        } else {
            return apiClient.loginWithPhoneNumber(emailOrNumber, getCode());
        }
    }
1168990
public Object getUserFromPrincipal(HttpServletRequest request) {
    Debug.logVerbose("[JdonFramework]--> enter getUserFromPrincipal", module);
    Principal principal = request.getUserPrincipal();
    if (principal == null) {
      Debug.logVerbose("[JdonFramework]principal is null, not login by JAAS", module);
      return null;
    }
    String username = principal.getName();
    Debug.logVerbose("[JdonFramework]--> find the logined username=" + username, module);
    HttpSession session = request.getSession();
    Object model =  session.getAttribute(USERMODEL);
    if (model == null) {
      model = findUserModelIFByName(request, username);
      session.setAttribute(USERMODEL, model);
    }
    return model;
  }
655827
public Response request(final Request request) {
        request.setAuth(username, password);
        return httpClient.reliableRequest(request);
    }