Package org.surfnet.oaaas.model

Examples of org.surfnet.oaaas.model.AccessToken


    client = repo.save(client);


    // Create an access token
    AccessToken at = new AccessToken("mytoken", new AuthenticatedPrincipal("username"), client, 0, null);
    at = accessTokenRepository.save(at);
    assertEquals(at, accessTokenRepository.findOne(at.getId()));

    // Create an authorization request
    AuthorizationRequest ar = new AuthorizationRequest("foo", "faa", "boo", null, "boo", "boo");
    ar.setClient(client);
    ar = authorizationRequestRepository.save(ar);
    assertEquals(ar, authorizationRequestRepository.findOne(ar.getId()));

    // Make sure things are saved; the relation between clients and access tokens is unidirectional; therefore a
    // delete would not work with attached entities.
    entityManager.clear();

    final long clientId = client.getId();
    repo.delete(client);
    assertNull(repo.findOne(clientId));

    assertNull(accessTokenRepository.findOne(at.getId()));
    assertNull(authorizationRequestRepository.findOne(ar.getId()));

  }
View Full Code Here


  @Test
  public void testPrincipalDisplayName() {
    AuthorizationRequest authRequest = createAuthRequest(OAuth2Validator.IMPLICIT_GRANT_RESPONSE_TYPE);
    authRequest.getClient().setIncludePrincipal(true);

    AccessToken accessToken = createAccessToken();

    when(authorizationRequestRepository.findByAuthState("auth_state")).thenReturn(authRequest);
    when(request.getAttribute(AbstractAuthenticator.AUTH_STATE)).thenReturn("auth_state");
    when(request.getAttribute(AbstractUserConsentHandler.GRANTED_SCOPES)).thenReturn(accessToken.getScopes().toArray());
    when(accessTokenRepository.save((AccessToken) any())).thenReturn(accessToken);

    URI uri = (URI) tokenResource.authorizeCallback(request).getMetadata().get("Location").get(0);

View Full Code Here

    assertEquals("http://localhost:8080#access_token=ABCDEF&token_type=bearer&expires_in=" + expiresIn + "&scope=read,write&state=important&principal=sammy%20sammy", uri.toString());
    assertTrue(uri.getFragment().endsWith("principal=" + authRequest.getPrincipal().getDisplayName()));
  }

  private AccessToken createAccessToken() {
    AccessToken token = new AccessToken();
    token.setToken("ABCDEF");
    token.setExpires(System.currentTimeMillis() + 1800 * 1000);
    token.setScopes(Arrays.asList("read","write"));
    return token;
  }
View Full Code Here

public class AccessTokenRepositoryTest extends AbstractTestRepository {

  @Test
  public void testPrincipal() {
    AccessTokenRepository repo = getRepository(AccessTokenRepository.class);
    AccessToken token = repo.findByToken("00-11-22-33");
    assertEquals("it-test-enduser",token.getPrincipal().getName());
  }
View Full Code Here

    if (resourceServer == null || !resourceServer.getSecret().equals(credentials.getPassword())) {
      LOG.warn("For access token {}: Resource server not found for credentials {}. Responding with 401 in VerifyResource#verifyToken.", accessToken, credentials);
      return unauthorized();
    }

    AccessToken token = accessTokenRepository.findByToken(accessToken);
    if (token == null || !resourceServer.containsClient(token.getClient())) {
      LOG.warn("Access token {} not found for resource server '{}'. Responding with 404 in VerifyResource#verifyToken for user {}", accessToken, resourceServer.getName(), credentials);
      return Response.status(Status.NOT_FOUND).entity(new VerifyTokenResponse("not_found")).build();
    }
    if (tokenExpired(token)) {
      LOG.warn("Token {} is expired. Responding with 410 in VerifyResource#verifyToken for user {}", accessToken, credentials);
      return Response.status(Status.GONE).entity(new VerifyTokenResponse("token_expired")).build();
    }

    final VerifyTokenResponse verifyTokenResponse = new VerifyTokenResponse(token.getClient().getName(),
            token.getScopes(), token.getPrincipal(), token.getExpires());

    if (LOG.isDebugEnabled()) {
      LOG.debug("Responding with 200 in VerifyResource#verifyToken for access token {} and user {}", accessToken, credentials);
    }
    return Response.ok(mapper.writeValueAsString(verifyTokenResponse)).build();
View Full Code Here

  public Response delete(@Context HttpServletRequest request, @PathParam("accessTokenId") Long id) {
    Response validateScopeResponse = validateScope(request, Collections.singletonList(AbstractResource.SCOPE_WRITE));
    if (validateScopeResponse != null) {
      return validateScopeResponse;
    }
    AccessToken accessToken = getAccessToken(request, id);
    if (accessToken == null) {
      return Response.status(Response.Status.NOT_FOUND).build();
    }
    LOG.debug("About to delete accessToken {}", id);
    accessTokenRepository.delete(id);
View Full Code Here

    accessTokenRepository.delete(id);
    return Response.noContent().build();
  }

  private AccessToken getAccessToken(HttpServletRequest request, Long id) {
    AccessToken accessToken;
    if (isAdminPrincipal(request)) {
      accessToken = accessTokenRepository.findOne(id);
    } else {
      String owner = getUserId(request);
      accessToken = accessTokenRepository.findByIdAndResourceOwnerId(id, owner);
View Full Code Here

      accessToken = CollectionUtils.isEmpty(params) ? null : params.get(0);
    } catch (ValidationResponseException e) {
      ValidationResponse validationResponse = e.v;
      return Response.status(Status.BAD_REQUEST).entity(new ErrorResponse(validationResponse.getValue(), validationResponse.getDescription())).build();
    }
    AccessToken token = accessTokenRepository.findByTokenAndClient(accessToken, client);
    if (token == null) {
      LOG.info("Access token {} not found for client '{}'. Will return OK however.", accessToken, client.getClientId());
      return Response.ok().build();
    }
    accessTokenRepository.delete(token);
View Full Code Here

TOP

Related Classes of org.surfnet.oaaas.model.AccessToken

Copyright © 2018 www.massapicom. 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.