当前位置: 首页>>代码示例>>Java>>正文


Java NewCookie类代码示例

本文整理汇总了Java中javax.ws.rs.core.NewCookie的典型用法代码示例。如果您正苦于以下问题:Java NewCookie类的具体用法?Java NewCookie怎么用?Java NewCookie使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


NewCookie类属于javax.ws.rs.core包,在下文中一共展示了NewCookie类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: create

import javax.ws.rs.core.NewCookie; //导入依赖的package包/类
@POST
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public Response create(@NotNull @Valid final AcquisitionRequest request,
    @Context final HttpServletRequest httpRequest) {

    final AcquisitionFlow acquisitionFlow = credentials.acquire(connectorId, apiBase(httpRequest),
        absoluteTo(httpRequest, request.getReturnUrl()));

    final CredentialFlowState flowState = acquisitionFlow.state().get();
    final NewCookie cookie = state.persist(flowState.persistenceKey(), "/", flowState);

    final AcquisitionResponse acquisitionResponse = AcquisitionResponse.Builder.from(acquisitionFlow)
        .state(State.Builder.cookie(cookie.toString())).build();

    return Response.accepted().entity(acquisitionResponse).build();
}
 
开发者ID:syndesisio,项目名称:syndesis,代码行数:18,代码来源:ConnectorCredentialHandler.java

示例2: shouldPersistAsInRfcErrata

import javax.ws.rs.core.NewCookie; //导入依赖的package包/类
@Test
public void shouldPersistAsInRfcErrata() {
    final ClientSideState clientSideState = new ClientSideState(RFC_EDITION, RFC_TIME, RFC_IV_SOURCE,
        SIMPLE_SERIALIZATION, SIMPLE_DESERIALIZATION, ClientSideState.DEFAULT_TIMEOUT);

    final NewCookie cookie = clientSideState.persist("id", "/path", "a state string");

    assertThat(cookie).isNotNull();
    assertThat(cookie.getName()).isEqualTo("id");

    assertThat(cookie.getValue())
        .isEqualTo("pzSOjcNui9-HWS_Qk1Pwpg|MTM0NzI2NTk1NQ|dGlk|tL3lJPf2nUSFMN6dtVXJTw|uea1fgC67RmOxfpNz8gMbnPWfDA");
    assertThat(cookie.getPath()).isEqualTo("/path");
    assertThat(cookie.isHttpOnly()).isFalse();
    assertThat(cookie.isSecure()).isTrue();
}
 
开发者ID:syndesisio,项目名称:syndesis,代码行数:17,代码来源:ClientSideStateTest.java

示例3: shouldRestoreMultipleAndOrderByTimestamp

import javax.ws.rs.core.NewCookie; //导入依赖的package包/类
@Test
public void shouldRestoreMultipleAndOrderByTimestamp() {
    final Iterator<Long> times = Arrays
        .asList(946598400L, 1293753600L, 978220800L, 946598400L, 1293753600L, 978220800L).iterator();
    final ClientSideState clientSideState = new ClientSideState(RFC_EDITION, () -> times.next(),
        ClientSideState.DEFAULT_TIMEOUT);

    final NewCookie cookie1999 = clientSideState.persist("key", "/path", "1");
    final NewCookie cookie2010 = clientSideState.persist("key", "/path", "3");
    final NewCookie cookie2000 = clientSideState.persist("key", "/path", "2");

    final Set<String> restored = clientSideState.restoreFrom(Arrays.asList(cookie1999, cookie2010, cookie2000),
        String.class);

    assertThat(restored).containsExactly("3", "2", "1");
}
 
开发者ID:syndesisio,项目名称:syndesis,代码行数:17,代码来源:ClientSideStateTest.java

示例4: login

import javax.ws.rs.core.NewCookie; //导入依赖的package包/类
/**
 * Logs in the user with email address and password.
 * Returns the user on success.
 *
 * @param email The user's email address.
 * @param password The user's plain text password.
 * @return the user details.
 */
public NewCookie login(final String email, final String password) {
    final SecurityUser candidate = dao.findUserByEmail(userClass, email);
    if (candidate == null) {
        throw new BadRequestException("notfound");
    }

    if (candidate.getPasswordHash() == null) {
        throw new BadRequestException("invalid");
    }

    if (!BCrypt.checkpw(password, candidate.getPasswordHash())) {
        throw new BadRequestException("incorrect");
    }

    return loginAs(candidate);
}
 
开发者ID:minijax,项目名称:minijax,代码行数:25,代码来源:Security.java

示例5: testLogout

import javax.ws.rs.core.NewCookie; //导入依赖的package包/类
@Test
public void testLogout() {
    final User user = new User();

    final UserSession session = new UserSession();
    session.setUser(user);

    final String cookie = session.getId().toString();

    final SecurityDao dao = mock(SecurityDao.class);
    when(dao.read(eq(UserSession.class), eq(session.getId()))).thenReturn(session);
    when(dao.read(eq(User.class), eq(user.getId()))).thenReturn(user);

    final Configuration config = mock(Configuration.class);
    when(config.getProperty(eq(MinijaxProperties.SECURITY_USER_CLASS))).thenReturn(User.class);

    final Security<User> security = new Security<>(dao, config, null, cookie);
    final NewCookie newCookie = security.logout();
    assertNotNull(newCookie);
    assertEquals("", newCookie.getValue());

    verify(dao).purge(eq(session));
}
 
开发者ID:minijax,项目名称:minijax,代码行数:24,代码来源:SecurityTest.java

示例6: fromString

import javax.ws.rs.core.NewCookie; //导入依赖的package包/类
@Override
public NewCookie fromString(final String value) {
    if (value == null || value.isEmpty()) {
        return null;
    }

    final List<HttpCookie> httpCookies = HttpCookie.parse(value);
    final HttpCookie httpCookie = httpCookies.get(0);
    return new NewCookie(
            httpCookie.getName(),
            httpCookie.getValue(),
            httpCookie.getPath(),
            httpCookie.getDomain(),
            httpCookie.getVersion(),
            httpCookie.getComment(),
            (int) httpCookie.getMaxAge(),
            null,
            httpCookie.getSecure(),
            httpCookie.isHttpOnly());
}
 
开发者ID:minijax,项目名称:minijax,代码行数:21,代码来源:MinijaxNewCookieDelegate.java

示例7: createHeaderDelegate

import javax.ws.rs.core.NewCookie; //导入依赖的package包/类
@Override
@SuppressWarnings("unchecked")
public <T> HeaderDelegate<T> createHeaderDelegate(final Class<T> type) {
    if (type == MediaType.class) {
        return (HeaderDelegate<T>) MEDIA_TYPE_DELEGATE;
    }
    if (type == Cookie.class) {
        return (HeaderDelegate<T>) COOKIE_DELEGATE;
    }
    if (type == NewCookie.class) {
        return (HeaderDelegate<T>) NEW_COOKIE_DELEGATE;
    }
    if (type == CacheControl.class) {
        return (HeaderDelegate<T>) CACHE_CONTROL_DELEGATE;
    }
    throw new IllegalArgumentException("Unrecognized header delegate: " + type);
}
 
开发者ID:minijax,项目名称:minijax,代码行数:18,代码来源:MinijaxRuntimeDelegate.java

示例8: authenticate

import javax.ws.rs.core.NewCookie; //导入依赖的package包/类
@POST
@Consumes(APPLICATION_JSON)
@Produces(APPLICATION_JSON)
@ApiOperation(value = "Authenticate a user", notes = "Verify a user credentials")
@ApiResponses(value = {
        @ApiResponse(code = 200, message = "user authenticated"),
        @ApiResponse(code = 401, message = "Wrong user or password")})
public Response authenticate(Credentials credentials) {
    if (UsersDao.authenticate(credentials)) {
        byte[] bearer = UsersDao.getBearer(credentials);
        StringBuilder auth = new StringBuilder().append("Bearer ").append(PasswordStorage.toBase64(bearer));
        return Response.ok()
                .cookie(new NewCookie("Authorization", auth.toString(), null, null,
                        DEFAULT_VERSION, null, DEFAULT_MAX_AGE, null, true, true))
                .entity(new ResponseMessage(true, "user authenticated")).build();
    } else {
        return Response.status(UNAUTHORIZED)
                .entity(new ResponseMessage(false, "Username or password is incorrect")).build();
    }

}
 
开发者ID:javathought,项目名称:devoxx-2017,代码行数:22,代码来源:AuthenticateResource.java

示例9: testGetCookie

import javax.ws.rs.core.NewCookie; //导入依赖的package包/类
@Test
public void testGetCookie() throws Exception {
    NewCookie cookie1 = ParsecHttpUtil.getCookie(new Cookie(
        "cookie1_name",
        "cookie1_value",
        false,
        null,
        "cookie1_path",
        1,
        true,
        true
    ));

    assertEquals("cookie1_name", cookie1.getName());
    assertEquals("cookie1_value", cookie1.getValue());
    assertEquals(null, cookie1.getDomain());
    assertEquals("cookie1_path", cookie1.getPath());
    assertEquals(null, cookie1.getExpiry());
    assertEquals(1, cookie1.getMaxAge());
    assertTrue(cookie1.isSecure());
    assertTrue(cookie1.isHttpOnly());
}
 
开发者ID:yahoo,项目名称:parsec-libraries,代码行数:23,代码来源:ParsecHttpUtilTest.java

示例10: populateResponse

import javax.ws.rs.core.NewCookie; //导入依赖的package包/类
public void populateResponse(ContainerResponseContext responseContext) {
    if (hasResponseContent) {
        responseContext.setEntity(responseContent);
    }
    if (hasResponseContentType) {
        responseContext.getHeaders().putSingle(HttpHeaders.CONTENT_TYPE, responseContentType);
    }
    if (hasResponseStatus) {
        responseContext.setStatus(responseStatus);
    }
    for (Entry<String, String> headers : responseHeaders.entrySet()) {
        responseContext.getHeaders().putSingle(headers.getKey(), headers.getValue());
    }
    for (NewCookie cookie : responseCookies) {
        responseContext.getHeaders().add(HttpHeaders.SET_COOKIE, cookie);
    }
}
 
开发者ID:pac4j,项目名称:jax-rs-pac4j,代码行数:18,代码来源:JaxRsContext.java

示例11: getQuote

import javax.ws.rs.core.NewCookie; //导入依赖的package包/类
/**
 * Retrieve a stock for a given symbol.
 * http://localhost:9090/stockquote/IBM
 *
 * @param symbol Stock symbol will be taken from the path parameter.
 * @return Response
 */
@GET
@Path("/{symbol}")
@Produces({"application/json", "text/xml"})
@ApiOperation(
        value = "Return stock quote corresponding to the symbol",
        notes = "Returns HTTP 404 if the symbol is not found")
@ApiResponses(value = {
        @ApiResponse(code = 200, message = "Valid stock item found"),
        @ApiResponse(code = 404, message = "Stock item not found")})
public Response getQuote(@ApiParam(value = "Symbol", required = true)
                         @PathParam("symbol") String symbol) throws SymbolNotFoundException {
    Stock stock = stockQuotes.get(symbol);
    if (stock == null) {
        throw new SymbolNotFoundException("Symbol " + symbol + " not found");
    }
    return Response.ok().entity(stock).cookie(new NewCookie("symbol", symbol)).build();
}
 
开发者ID:wso2,项目名称:product-ei,代码行数:25,代码来源:StockQuoteService.java

示例12: createCustomer

import javax.ws.rs.core.NewCookie; //导入依赖的package包/类
@POST
@Produces("text/html")
public Response createCustomer(@FormParam("firstname") String first,
                               @FormParam("lastname") String last)
{
   Customer customer = new Customer();
   customer.setId(idCounter.incrementAndGet());
   customer.setFirstName(first);
   customer.setLastName(last);
   customerDB.put(customer.getId(), customer);
   System.out.println("Created customer " + customer.getId());
   String output = "Created customer <a href=\"customers/" + customer.getId() + "\">" + customer.getId() + "</a>";
   String lastVisit = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.LONG).format(new Date());
   URI location = URI.create("/customers/" + customer.getId());
   return Response.created(location)
           .entity(output)
           .cookie(new NewCookie("last-visit", lastVisit))
           .build();

}
 
开发者ID:resteasy,项目名称:resteasy-examples,代码行数:21,代码来源:CustomerResource.java

示例13: getCustomer

import javax.ws.rs.core.NewCookie; //导入依赖的package包/类
@GET
@Path("{id}")
@Produces("text/plain")
public Response getCustomer(@PathParam("id") int id,
                            @HeaderParam("User-Agent") String userAgent,
                            @CookieParam("last-visit") String date)
{
   final Customer customer = customerDB.get(id);
   if (customer == null)
   {
      throw new WebApplicationException(Response.Status.NOT_FOUND);
   }
   String output = "User-Agent: " + userAgent + "\r\n";
   output += "Last visit: " + date + "\r\n\r\n";
   output += "Customer: " + customer.getFirstName() + " " + customer.getLastName();
   String lastVisit = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.LONG).format(new Date());
   return Response.ok(output)
           .cookie(new NewCookie("last-visit", lastVisit))
           .build();
}
 
开发者ID:resteasy,项目名称:resteasy-examples,代码行数:21,代码来源:CustomerResource.java

示例14: authenticateUser

import javax.ws.rs.core.NewCookie; //导入依赖的package包/类
@POST
@Path("/login")
   @Produces("application/json")
   @Consumes("application/json")
   public Response authenticateUser(Credentials credentials) {
       boolean authenticated = authenticator.authenticate(credentials);
       if(authenticated) {
       	Session session = issueToken(credentials.getUsername());
       	NewCookie cookie = new NewCookie("sessionid", session.getToken(), "/", null, 1, null, -1, null, false, false);
       	Profile profile = getProfile(credentials.getUsername());
       	session.setProfile(profile);
       	return Response.ok(session).cookie(cookie).build();            	
       } else {
       	return Response.status(Response.Status.UNAUTHORIZED).build();            	
       }    
   }
 
开发者ID:denkbar,项目名称:step,代码行数:17,代码来源:AccessServices.java

示例15: setCookies

import javax.ws.rs.core.NewCookie; //导入依赖的package包/类
public void setCookies(
    Response.ResponseBuilder builder, String token, boolean secure, boolean isAnonymous) {
  builder.header(
      "Set-Cookie",
      new NewCookie(
              "token-access-key",
              token,
              accessCookiePath,
              null,
              null,
              ticketLifeTimeSeconds,
              secure)
          + ";HttpOnly");
  builder.header(
      "Set-Cookie",
      new NewCookie("session-access-key", token, "/", null, null, -1, secure) + ";HttpOnly");
  if (!isAnonymous) {
    builder.cookie(
        new NewCookie("logged_in", "true", "/", null, null, ticketLifeTimeSeconds, secure));
  }
}
 
开发者ID:codenvy,项目名称:codenvy,代码行数:22,代码来源:SsoCookieBuilder.java


注:本文中的javax.ws.rs.core.NewCookie类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。