Accesses the protected resource and logs in successfully, ensuring that a JWT SSO cookie is included in the result.
9952
public Cookie logInAndObtainJwtCookie(String testName, String protectedUrl, String username, String password) throws Exception {
        return logInAndObtainJwtCookie(testName, new WebClient(), protectedUrl, username, password);
    }
377460
def authenticate(self):
        """"""
        postdata = self.authentication_postdata
        jar = requests.cookies.cookielib.CookieJar()
        self.cookies = jar
        resp = self.get(self.authentication_base_url)
        authtok = _extract_authenticity_token(resp.content)
        if postdata is None:
            # This works for GitHub
            postdata = {"login": self.oauth2_username,
                        "password": self._oauth2_password,
                        "authenticity_token": authtok,
                        "commit": "Sign+in",
                        "utf8": u"\u2713",
                        }  # pylint: disable=bad-continuation
            self.authentication_postdata = postdata
        if self.authentication_session_url is None:
            # This is also for GitHub
            authentication_session_url = "https://github.com/session"
            self.authentication_session_url = authentication_session_url
        self.post(self.authentication_session_url, data=postdata)
1324258
@SuppressWarnings("unchecked")
    public void handleLoginResult(Map<String, Object> jsonFields) {
        if (jsonFields.containsKey("result")) {
            Map<String, Object> result = (Map<String, Object>) jsonFields
                    .get(DdpMessageField.RESULT);
            mResumeToken = (String) result.get("token");
            saveResumeToken(mResumeToken);
            mUserId = (String) result.get("id");
            mDDPState = DDPSTATE.LoggedIn;
            broadcastConnectionState(mDDPState);
        } else if (jsonFields.containsKey("error")) {
            Map<String, Object> error = (Map<String, Object>) jsonFields
                    .get(DdpMessageField.ERROR);
            broadcastDDPError((String) error.get("message"));
        }
    }
1173936
def after_request(response)
      unless @authenticating
        if captcha_required(response) # rubocop:disable Style/GuardClause
          raise Jiralicious::CaptchaRequired, "Captacha is required. Try logging into Jira via the web interface"
        elsif cookie_invalid(response)
          # Can usually be fixed by logging in again
          clear_session
          raise Jiralicious::CookieExpired
        end
      end
      @authenticating = false
    end
575083
protected void asLoginRequired(LoginHandlingResource resource) throws LoginRequiredException {
        logger.debug("...Checking login status for login required");
        if (tryAlreadyLoginOrRememberMe(resource)) {
            checkPermission(resource); // throws if denied
            return; // Good
        }
        if (needsSavingRequestedLoginRedirect(resource)) {
            saveRequestedLoginRedirectInfo();
        }
        throwLoginRequiredException("Cannot access the action: " + resource);
    }
874549
function mustBeLoggedIn(req, res, next) {
  if (req.session && req.session.user) {
    next();
  }
  else {
    res.status(401).send('You must be logged-in to access this resource');
  }
}
730105
function authenticateUser (req, res, next) {
  // Check for verified access token
  if (req.claims && req.claims.sub) {
    User.get(req.claims.sub, function (err, user) {
      if (err) {
        return next(err)
      }

      if (!user) {
        return next(new UnauthorizedError({
          realm: 'user',
          error: 'unknown_user',
          error_description: 'Unknown user',
          statusCode: 401
        }))
      }

      req.user = user
      next()
    })

  // User is not authenticated.
  } else if (!req.user) {
    next(new UnauthorizedError({
      statusCode: 401
    }))

  // User is authenticated.
  } else {
    next()
  }
}
1088270
function verifyConfiguration (req, sessionKey, cookie) {
  if (!getSecretBag(req, sessionKey, cookie)) {
    return false
  }

  if (cookie && cookie.signed && !req.secret) {
    return false
  }

  return true
}
1066753
def auth_complete(self, *args, **kwargs):
        """"""
        if SESSION_VAR not in self.strategy.request.session:
            # This is the only protection layer when people
            # go directly to the passthrough login view.
            logger.warn("Auth data for passthrough provider not found in session. Raising 404.")
            raise PermissionDenied
        auth_data = self.strategy.request.session[SESSION_VAR]
        kwargs.update({'response': auth_data, 'backend': self})
        return self.strategy.authenticate(*args, **kwargs)
406507
private void loginForm(HttpServletResponse response) {
        response.reset();
        response.addHeader("WWW-Authenticate",
                           "Basic realm=\"!!Fedora Repository Server\"");
        response.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
    }
645033
protected function checkAuth()
	{
		try {

			// get the JWT from the headers
			list($jwt) = sscanf($_SERVER["HTTP_AUTHORIZATION"], 'Bearer %s');

			// init the jwt auth class
			$authenticator = new JWTAuthenticator(new User());

			// get the application secret key
			$config     = \Erdiko::getConfig();
			$secretKey  = $config["site"]["secret_key"];

			// collect login params
			$params = array(
				'secret_key'    =>  $secretKey,
				'jwt'           =>  $jwt
			);

			$user = $authenticator->verify($params, 'jwt_auth');

			//TODO check the user's permissions via Resource & Authorization

			// no exceptions? welp, this is a valid request
			return true;
		} catch (\Exception $e) {
			return true;
		}
	}
106466
private void loginForm(HttpServletResponse response) throws IOException {
        response.reset();
        response.addHeader("WWW-Authenticate",
                           "Basic realm=\"!!Fedora Repository Server\"");
        response.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
        OutputStream out = response.getOutputStream();
        out.write("Fedora: 401 ".getBytes());
        out.flush();
        out.close();
    }
966011
public static Expectations jwtCookieExists(String testAction, WebClient webClient, String jwtCookieName, boolean isSecure, boolean isHttpOnly) {
        Expectations expectations = new Expectations();
        expectations.addExpectation(new CookieExpectation(testAction, webClient, jwtCookieName, JwtFatConstants.JWT_REGEX, isSecure, isHttpOnly));
        return expectations;
    }
1186568
function (err, ok, state) {
        if (err) { return self.error(err); }
        if (!ok) { return self.fail(state, 403); }

        if (self._jwt) {
          self._authenticate_jwt(req, state);
        } else {
          self._authenticate_saml(req, state);
        }
      }
675588
public static Expectations successfullyReachedProtectedResourceWithJwtCookie(String testAction, String protectedUrl, String username, String issuerRegex) {
        Expectations expectations = new Expectations();
        expectations.addExpectations(successfullyReachedUrl(testAction, protectedUrl));
        expectations.addExpectations(getResponseTextExpectationsForJwtCookie(testAction, JwtFatConstants.JWT_COOKIE_NAME, username));
        expectations.addExpectations(getJwtPrincipalExpectations(testAction, username, issuerRegex));
        return expectations;
    }
713272
def _Authenticate(self):
		""""""
		super(HttpRpcServer, self)._Authenticate()
		if self.save_cookies:
			StatusUpdate("Saving authentication cookies to %s" % self.cookie_file)
			self.cookie_jar.save()
760710
private AuthenticationResult handleFormLogin(HttpServletRequest req, HttpServletResponse res, WebRequest webRequest) {
        AuthenticationResult authResult = null;
        authResult = ssoAuthenticator.authenticate(webRequest);

        if (authResult != null) {
            authResult.setAuditCredType(AuditEvent.CRED_TYPE_FORM);
        }

        if (authResult != null && authResult.getStatus() != AuthResult.FAILURE) {
            postParameterHelper.restore(req, res);
            return authResult;
        }

        try {
            authResult = providerAuthenticatorProxy.authenticate(req, res, null);
        } catch (Exception e) {
            return new AuthenticationResult(AuthResult.FAILURE, e.getLocalizedMessage());
        }

        if (authResult.getStatus() == AuthResult.CONTINUE) {
            authResult = null;
            if (webRequest.isFormLoginRedirectEnabled()) {
                authResult = handleRedirect(req, res, webRequest);
                if (authResult != null) {
                    authResult.setAuditCredType(AuditEvent.CRED_TYPE_FORM);
                    authResult.setAuditOutcome(AuditEvent.OUTCOME_REDIRECT);
                }

            }
        }
        return authResult;
    }