Examples of OAuth2AccessTokenEntity


Examples of org.mitre.oauth2.model.OAuth2AccessTokenEntity

  }

  @Test
  public void refreshAccessToken_requestingSameScope() {

    OAuth2AccessTokenEntity token = service.refreshAccessToken(refreshTokenValue, tokenRequest);

    assertThat(token.getScope(), equalTo(storedScope));
  }
View Full Code Here

Examples of org.mitre.oauth2.model.OAuth2AccessTokenEntity

    Set<String> lessScope = Sets.newHashSet("openid", "profile");

    tokenRequest.setScope(lessScope);

    OAuth2AccessTokenEntity token = service.refreshAccessToken(refreshTokenValue, tokenRequest);

    assertThat(token.getScope(), equalTo(lessScope));
  }
View Full Code Here

Examples of org.mitre.oauth2.model.OAuth2AccessTokenEntity

    Set<String> emptyScope = Sets.newHashSet();

    tokenRequest.setScope(emptyScope);

    OAuth2AccessTokenEntity token = service.refreshAccessToken(refreshTokenValue, tokenRequest);

    assertThat(token.getScope(), equalTo(storedScope));
  }
View Full Code Here

Examples of org.mitre.oauth2.model.OAuth2AccessTokenEntity

  @Test
  public void refreshAccessToken_requestingNullScope() {

    tokenRequest.setScope(null);

    OAuth2AccessTokenEntity token = service.refreshAccessToken(refreshTokenValue, tokenRequest);

    assertThat(token.getScope(), equalTo(storedScope));

  }
View Full Code Here

Examples of org.mitre.oauth2.model.OAuth2AccessTokenEntity


  @Override
  public OAuth2AccessToken enhance(OAuth2AccessToken accessToken,  OAuth2Authentication authentication) {

    OAuth2AccessTokenEntity token = (OAuth2AccessTokenEntity) accessToken;
    OAuth2Request originalAuthRequest = authentication.getOAuth2Request();

    String clientId = originalAuthRequest.getClientId();
    ClientDetailsEntity client = clientService.loadClientByClientId(clientId);

    JWTClaimsSet claims = new JWTClaimsSet();

    claims.setAudience(Lists.newArrayList(clientId));

    claims.setIssuer(configBean.getIssuer());

    claims.setIssueTime(new Date());

    claims.setExpirationTime(token.getExpiration());

    claims.setJWTID(UUID.randomUUID().toString()); // set a random NONCE in the middle of it

    JWSAlgorithm signingAlg = jwtService.getDefaultSigningAlgorithm();

    SignedJWT signed = new SignedJWT(new JWSHeader(signingAlg), claims);

    jwtService.signJwt(signed);

    token.setJwt(signed);

    /**
     * Authorization request scope MUST include "openid" in OIDC, but access token request
     * may or may not include the scope parameter. As long as the AuthorizationRequest
     * has the proper scope, we can consider this a valid OpenID Connect request. Otherwise,
     * we consider it to be a vanilla OAuth2 request.
     *
     * Also, there must be a user authentication involved in the request for it to be considered
     * OIDC and not OAuth, so we check for that as well.
     */
    if (originalAuthRequest.getScope().contains("openid")
        && !authentication.isClientOnly()) {

      String username = authentication.getName();
      UserInfo userInfo = userInfoService.getByUsernameAndClientId(username, clientId);

      if (userInfo != null) {

        OAuth2AccessTokenEntity idTokenEntity = connectTokenService.createIdToken(client,
            originalAuthRequest, claims.getIssueTime(),
            userInfo.getSub(), token);

        // attach the id token to the parent access token
        token.setIdToken(idTokenEntity);
View Full Code Here

Examples of org.mitre.oauth2.model.OAuth2AccessTokenEntity

      // now save it
      try {
        ClientDetailsEntity savedClient = clientService.saveNewClient(newClient);

        // generate the registration access token
        OAuth2AccessTokenEntity token = connectTokenService.createRegistrationAccessToken(savedClient);
        token = tokenService.saveAccessToken(token);

        // send it all out to the view

        RegisteredClient registered = new RegisteredClient(savedClient, token.getValue(), config.getIssuer() + "register/" + UriUtils.encodePathSegment(savedClient.getClientId(), "UTF-8"));
        m.addAttribute("client", registered);
        m.addAttribute("code", HttpStatus.CREATED); // http 201

        return ClientInformationResponseView.VIEWNAME;
      } catch (UnsupportedEncodingException e) {
View Full Code Here

Examples of org.mitre.oauth2.model.OAuth2AccessTokenEntity

    ClientDetailsEntity client = clientService.loadClientByClientId(clientId);

    if (client != null && client.getClientId().equals(auth.getOAuth2Request().getClientId())) {

      try {
        OAuth2AccessTokenEntity token = fetchValidRegistrationToken(auth, client);
        RegisteredClient registered = new RegisteredClient(client, token.getValue(), config.getIssuer() + "register/" +  UriUtils.encodePathSegment(client.getClientId(), "UTF-8"));

        // send it all out to the view
        m.addAttribute("client", registered);
        m.addAttribute("code", HttpStatus.OK); // http 200
View Full Code Here

Examples of org.mitre.oauth2.model.OAuth2AccessTokenEntity

     
      try {
        // save the client
        ClientDetailsEntity savedClient = clientService.updateClient(oldClient, newClient);

        OAuth2AccessTokenEntity token = fetchValidRegistrationToken(auth, savedClient);

        RegisteredClient registered = new RegisteredClient(savedClient, token.getValue(), config.getIssuer() + "register/" + UriUtils.encodePathSegment(savedClient.getClientId(), "UTF-8"));

        // send it all out to the view
        m.addAttribute("client", registered);
        m.addAttribute("code", HttpStatus.OK); // http 200
View Full Code Here

Examples of org.mitre.oauth2.model.OAuth2AccessTokenEntity

     * @throws IOException
     */
    private void readAccessTokens(JsonReader reader) throws IOException {
        reader.beginArray();
        while (reader.hasNext()) {
            OAuth2AccessTokenEntity token = new OAuth2AccessTokenEntity();
            reader.beginObject();
            Long currentId = null;
            String clientId = null;
            Long authHolderId = null;
            Long refreshTokenId = null;
            Long idTokenId = null;
            while (reader.hasNext()) {
                switch (reader.peek()) {
                    case END_OBJECT:
                        continue;
                    case NAME:
                        String name = reader.nextName();
                        if (reader.peek() == JsonToken.NULL) {
                            reader.skipValue();
                        } else if (name.equals("id")) {
                            currentId = reader.nextLong();
                        } else if (name.equals("expiration")) {
                            Date date = DateUtil.utcToDate(reader.nextString());
                            token.setExpiration(date);
                        } else if (name.equals("value")) {
                            String value = reader.nextString();
                            try {
                                token.setValue(value);
                            } catch (ParseException ex) {
                                logger.error("Unable to set refresh token value to {}", value, ex);
                            }
                        } else if (name.equals("clientId")) {
                            clientId = reader.nextString();
                        } else if (name.equals("authenticationHolderId")) {
                            authHolderId = reader.nextLong();
                        } else if (name.equals("refreshTokenId")) {
                            refreshTokenId = reader.nextLong();
                        } else if (name.equals("idTokenId")) {
                            idTokenId = reader.nextLong();
                        } else if (name.equals("scope")) {
                            Set<String> scope = readSet(reader);
                            token.setScope(scope);
                        } else if (name.equals("type")) {
                            token.setTokenType(reader.nextString());
                        } else {
                            logger.debug("Found unexpected entry");
                            reader.skipValue();
                        }
                        break;
View Full Code Here

Examples of org.mitre.oauth2.model.OAuth2AccessTokenEntity

  }
 
  private OAuth2AccessTokenEntity fetchValidRegistrationToken(OAuth2Authentication auth, ClientDetailsEntity client) {
   
    OAuth2AuthenticationDetails details = (OAuth2AuthenticationDetails) auth.getDetails();
    OAuth2AccessTokenEntity token = tokenService.readAccessToken(details.getTokenValue());
   
    if (config.getRegTokenLifeTime() != null) {
   
      try {
        // Re-issue the token if it has been issued before [currentTime - validity]
        Date validToDate = new Date(System.currentTimeMillis() - config.getRegTokenLifeTime() * 1000);
        if(token.getJwt().getJWTClaimsSet().getIssueTime().before(validToDate)) {
          logger.info("Rotating the registration access token for " + client.getClientId());
          tokenService.revokeAccessToken(token);
          OAuth2AccessTokenEntity newToken = connectTokenService.createRegistrationAccessToken(client);
          tokenService.saveAccessToken(newToken);
          return newToken;
        } else {
          // it's not expired, keep going
          return token;
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.