Esempio n. 1
0
  public String getAdminToken() {

    String adminToken =
        curAdminToken != null && curAdminToken.isValid() ? curAdminToken.getToken() : null;

    if (adminToken == null) {
      final ServiceClientResponse<AuthenticateResponse> serviceResponse =
          client.post(authUrl + "/tokens", requestBody, MediaType.APPLICATION_XML_TYPE);

      switch (HttpStatusCode.fromInt(serviceResponse.getStatusCode())) {
        case OK:
          final AuthenticateResponse authenticateResponse =
              marshaller.unmarshall(serviceResponse.getData(), AuthenticateResponse.class);

          Token token = authenticateResponse.getToken();
          curAdminToken = new AdminToken(token.getId(), token.getExpires().toGregorianCalendar());
          adminToken = curAdminToken.getToken();
          break;

        default:
          LOG.error(
              "Unable to get admin token.  Verify admin credentials. "
                  + serviceResponse.getStatusCode());
          curAdminToken = null;
          break;
      }
    }

    return adminToken;
  }
    @Before
    public void standUp() throws DatatypeConfigurationException {
      dataTypeFactory = DatatypeFactory.newInstance();
      when(request.getRequestURI()).thenReturn("/start/104772/resource");
      when(request.getHeader(anyString())).thenReturn("tokenId");

      Calendar expires = getCalendarWithOffset(1000);

      authResponse = new AuthenticateResponse();
      UserForAuthenticateResponse userForAuthenticateResponse = new UserForAuthenticateResponse();
      userForAuthenticateResponse.setId("104772");
      userForAuthenticateResponse.setName("user2");

      userForAuthenticateResponse.setRoles(defaultRoleList());

      Token token = new Token();
      token.setId("tokenId");
      TenantForAuthenticateResponse tenant = new TenantForAuthenticateResponse();
      tenant.setId("104772");
      tenant.setName("tenantName");
      token.setTenant(tenant);
      token.setExpires(dataTypeFactory.newXMLGregorianCalendar((GregorianCalendar) expires));

      authResponse.setToken(token);
      authResponse.setUser(userForAuthenticateResponse);
    }
  private static AuthenticateResponse getServiceResponse() {
    AuthenticateResponse rsp = new AuthenticateResponse();

    Token token = new Token();
    token.setId("tokenid");
    GregorianCalendar cal = new GregorianCalendar(2013, 11, 12);
    token.setExpires(new XMLGregorianCalendarImpl(cal));
    TenantForAuthenticateResponse tenantForAuthenticateResponse =
        new TenantForAuthenticateResponse();
    tenantForAuthenticateResponse.setId("tenantId");
    tenantForAuthenticateResponse.setName("tenantName");
    token.setTenant(tenantForAuthenticateResponse);
    rsp.setToken(token);

    ServiceCatalog catalog = new ServiceCatalog();
    List<ServiceForCatalog> serviceCatalogList = new ArrayList<>();
    ServiceForCatalog serviceForCatalog = new ServiceForCatalog();
    serviceForCatalog.setName("catName");
    serviceForCatalog.setType("type");
    serviceCatalogList.add(serviceForCatalog);
    catalog.getService().addAll(serviceCatalogList);

    rsp.setServiceCatalog(catalog);

    UserForAuthenticateResponse user = new UserForAuthenticateResponse();
    user.setId("userId");
    user.setName("userName");
    RoleList roles = new RoleList();

    Role role = new Role();
    role.setDescription("role description");
    role.setId("roleId");
    role.setName("roleName");
    role.setServiceId("serviceId");
    role.setTenantId("roleTenantId");
    roles.getRole().add(role);

    user.setRoles(roles);

    rsp.setUser(user);

    return rsp;
  }