public <E> RestxError<E> on(Class<E> errorCode) { ErrorCode code = errorCode.getAnnotation(ErrorCode.class); HttpStatus errorStatus = code != null ? code.status() : HttpStatus.BAD_REQUEST; String error = code != null ? code.code() : errorCode.getSimpleName(); String description = code != null ? code.description() : errorCode.getName(); return new RestxError<>(uuidGenerator.doGenerate(), errorStatus, error, description); } }
public <E> RestxError<E> on(Class<E> errorCode) { ErrorCode code = errorCode.getAnnotation(ErrorCode.class); HttpStatus errorStatus = code != null ? code.status() : HttpStatus.BAD_REQUEST; String error = code != null ? code.code() : errorCode.getSimpleName(); String description = code != null ? code.description() : errorCode.getName(); return new RestxError<>(uuidGenerator.doGenerate(), errorStatus, error, description); } }
/** * Returns an ID to identify this machine. * * Instead of making a guess based on MAC address and other related stuff, we only rely on a stored UUID to make * it faster. It means that when storage is disabled, the machine id will be different at each run, preventing to * consolidate information at machine level. * * @return the machine id, which may be different at each call. */ private synchronized String getMachineId() { if (!storageEnabled) { return uuidGenerator.doGenerate(); } File machineIdFile = new File(storageStatsDir, "machineId"); if (machineIdFile.exists()) { try { return Files.asCharSource(machineIdFile, Charsets.UTF_8).read(); } catch (Exception e) { // ignored. we'll generate a new one } } String machineId = uuidGenerator.doGenerate(); try { Files.asCharSink(machineIdFile, Charsets.UTF_8).write(machineId); } catch (Exception e) { // we were not able to store the machine id file, it means we'll generate a new one each time } return machineId; }
public HttpTestClient authenticatedAs(String principal) { Factory factory = Factory.newInstance(); RestxSessionCookieDescriptor restxSessionCookieDescriptor = factory.getComponent(RestxSessionCookieDescriptor.class); Signer signer = factory.queryByClass(Signer.class).findOneAsComponent().get(); ImmutableMap.Builder<String, String> cookiesBuilder = ImmutableMap.<String, String>builder().putAll(cookies); String uuid = factory.getComponent(UUIDGenerator.class).doGenerate(); String expires = DateTime.now().plusHours(1).toString(); String sessionContent = String.format( "{\"_expires\":\"%s\",\"principal\":\"%s\",\"sessionKey\":\"%s\"}", expires, principal, uuid); cookiesBuilder.put(restxSessionCookieDescriptor.getCookieName(), sessionContent); cookiesBuilder.put(restxSessionCookieDescriptor.getCookieSignatureName(), signer.sign(sessionContent)); return new HttpTestClient(baseUrl, principal, cookiesBuilder.build()); }
public HttpTestClient authenticatedAs(String principal) { Factory factory = Factory.newInstance(); RestxSessionCookieDescriptor restxSessionCookieDescriptor = factory.getComponent(RestxSessionCookieDescriptor.class); Signer signer = factory.queryByClass(Signer.class).findOneAsComponent().get(); ImmutableMap.Builder<String, String> cookiesBuilder = ImmutableMap.<String, String>builder().putAll(cookies); String uuid = factory.getComponent(UUIDGenerator.class).doGenerate(); String expires = DateTime.now().plusHours(1).toString(); String sessionContent = String.format( "{\"_expires\":\"%s\",\"principal\":\"%s\",\"sessionKey\":\"%s\"}", expires, principal, uuid); cookiesBuilder.put(restxSessionCookieDescriptor.getCookieName(), sessionContent); cookiesBuilder.put(restxSessionCookieDescriptor.getCookieSignatureName(), signer.sign(sessionContent)); return new HttpTestClient(baseUrl, principal, cookiesBuilder.build()); }
.setKey(uuidGenerator.doGenerate()) .setName(spec) .setStatus(status)
.setKey(uuidGenerator.doGenerate()) .setName(spec) .setStatus(status)
@PermitAll @POST("/sessions") public Session authenticate(Map session) { RestxSession.current().clearPrincipal(); RestxSession.current().define(String.class, Session.SESSION_DEF_KEY, null); Map<String, ?> principal = getPrincipal(session); if (principal == null) { throw new WebException(HttpStatus.UNAUTHORIZED); } String name = (String) principal.get("name"); String passwordHash = (String) principal.get("passwordHash"); Optional<? extends RestxPrincipal> principalOptional = authenticator.authenticate( name, passwordHash, ImmutableMap.copyOf(principal)); if (principalOptional.isPresent()) { String sessionKey = uuidGenerator.doGenerate(); RestxSession.current().authenticateAs(principalOptional.get()); RestxSession.current().define(String.class, Session.SESSION_DEF_KEY, sessionKey); return new Session(sessionKey, principalOptional.get()); } else { throw new WebException(HttpStatus.UNAUTHORIZED); } }
@PermitAll @POST("/sessions") public Session authenticate(Map session) { RestxSession.current().clearPrincipal(); RestxSession.current().define(String.class, Session.SESSION_DEF_KEY, null); Map<String, ?> principal = getPrincipal(session); if (principal == null) { throw new WebException(HttpStatus.UNAUTHORIZED); } String name = (String) principal.get("name"); String passwordHash = (String) principal.get("passwordHash"); Optional<? extends RestxPrincipal> principalOptional = authenticator.authenticate( name, passwordHash, ImmutableMap.copyOf(principal)); if (principalOptional.isPresent()) { String sessionKey = uuidGenerator.doGenerate(); RestxSession.current().authenticateAs(principalOptional.get()); RestxSession.current().define(String.class, Session.SESSION_DEF_KEY, sessionKey); return new Session(sessionKey, principalOptional.get()); } else { throw new WebException(HttpStatus.UNAUTHORIZED); } }
public TestRequest submitTestRequest(TestRequest testRequest) { if (testRequest.getTest().startsWith("specs")) { final String requestKey = uuidGenerator.doGenerate(); logger.info("queuing test request {}", testRequest); testRequest.setKey(requestKey);
public TestRequest submitTestRequest(TestRequest testRequest) { if (testRequest.getTest().startsWith("specs")) { final String requestKey = uuidGenerator.doGenerate(); logger.info("queuing test request {}", testRequest); testRequest.setKey(requestKey);
List<String> list = Lists.newArrayList(uuidGenerator.doGenerate(), String.valueOf(new Random().nextLong()), descriptor.appName, descriptor.artifactId); Collections.shuffle(list);