本文整理匯總了Java中io.dropwizard.auth.Auth類的典型用法代碼示例。如果您正苦於以下問題:Java Auth類的具體用法?Java Auth怎麽用?Java Auth使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
Auth類屬於io.dropwizard.auth包,在下文中一共展示了Auth類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: heartbeat
import io.dropwizard.auth.Auth; //導入依賴的package包/類
/**
* Agent和Server之間的心跳,可以1分鍾或更長時間一次,傳回Monitor的信息,返回MonitorJob信息
*
* @param monitorId
* @param monitor
* @return
*/
@POST
@Path("/monitor/{monitorId}/heartbeat")
public RestfulReturnResult heartbeat(@Auth OAuthUser user, @PathParam("monitorId") String monitorId, @NotNull @Valid Monitor monitor) {
if (!monitorId.equals(monitor.getMonitorId())) {
log.error("monitor id in path {} and json {} and parameter not match error.", monitorId, monitor.getMonitorId());
return new RestfulReturnResult(new NiPingException(MonitoridNotMatchError), null);
}
monitor.setMonitorId(monitorId);
monitor.setAccountId(user.getAccountId());
log.info("user {} monitorId {} send heartbeat {}", user, monitorId, monitor);
monitorService.heartbeat(monitor);
Optional<MonitorJob> job = Optional.empty();
try {
monitorService.saveMonitor(monitor);
job = taskService.getNextJob(monitorId, monitor.getRunningTaskIds());
if (log.isInfoEnabled() && job.isPresent()) {
log.info("user {} monitorId {} get next job {}", user, monitorId, job.get());
}
} catch (NiPingException e) {
return new RestfulReturnResult(e, job.orElse(null));
}
return new RestfulReturnResult(SUCCESS, job.orElse(null));
}
示例2: result
import io.dropwizard.auth.Auth; //導入依賴的package包/類
@POST
@Path("/monitor/{monitorId}/result")
public RestfulReturnResult result(@Auth OAuthUser user, @PathParam("monitorId") String monitorId, @NotNull @Valid MonitorNiPingResult
monitorNiPingResult) {
if (!monitorId.equals(monitorNiPingResult.getMonitorId())) {
log.error("monitor id in path {} and json {} and parameter not match error.", monitorId, monitorNiPingResult.getMonitorId());
return new RestfulReturnResult(new NiPingException(MonitoridNotMatchError), null);
}
monitorNiPingResult.setAccountId(user.getAccountId());
monitorNiPingResult.setMonitorId(monitorId);
try {
log.info("user {} save monitor NiPing result {}", user, monitorNiPingResult);
taskService.saveMonitorNiPingResult(monitorNiPingResult);
} catch (NiPingException e) {
return new RestfulReturnResult(e, null);
}
return new RestfulReturnResult(SUCCESS, null);
}
示例3: search
import io.dropwizard.auth.Auth; //導入依賴的package包/類
@POST
@Path(SEARCH_ENDPOINT)
@Consumes({MediaType.APPLICATION_JSON})
@Produces({MediaType.APPLICATION_JSON})
@Timed
@UnitOfWork
public Response search(
@NotNull @Auth User user,
@NotNull @Valid SearchRequest searchRequest) {
LOGGER.debug("Received search request");
return performWithAuthorisation(
user,
searchRequest.getQuery().getDataSource(),
() -> Response.ok(hBaseClient.query(searchRequest)).build());
}
示例4: list
import io.dropwizard.auth.Auth; //導入依賴的package包/類
@Override
@GET
@Produces(MediaType.APPLICATION_JSON)
/*@ApiOperation(httpMethod = "GET",
value = "list all users",
response = User.class,
responseContainer = "List",
nickname="list")*/
public List<User> list(@Auth PrincipalUser user, @QueryParam("filter") String filter) throws InternalErrorException {
try {
if(filter == null) {
return userDAO.fetchById(null);
} else {
return userDAO.fetch(filter, User.class);
}
} catch (Exception e) {
log.log(Level.SEVERE, "Error in getting users", e);
throw new BadRequestException(e);
}
}
示例5: delete
import io.dropwizard.auth.Auth; //導入依賴的package包/類
@Override
@DELETE
@Path("/{id}")
/*@ApiOperation(httpMethod = "DELETE",
value = "delete a user",
response = Response.class,
nickname="delete")*/
@Produces(MediaType.APPLICATION_JSON)
public Response delete(@Auth PrincipalUser user, @PathParam("id") String id) throws ResourceNotFoundException, InternalErrorException {
try {
userDAO.deleteById(id);
return Response.ok()
.entity(Entity.json(id))
.build();
} catch (Exception e) {
log.log(Level.SEVERE, "Error in getting users", e);
throw new BadRequestException(e);
}
}
示例6: getByKey
import io.dropwizard.auth.Auth; //導入依賴的package包/類
@GET
@Path("/{group}")
@Produces(MediaType.APPLICATION_JSON)
@PermitAll
@Timed(name = "getByKey")
public Response getByKey(
@Auth AuthPrincipal authPrincipal,
@PathParam("group") String group
) throws AuthenticationException {
final long start = System.currentTimeMillis();
final Optional<Group> maybe = findGroup(group);
if (maybe.isPresent()) {
accessControlSupport.throwUnlessGrantedFor(authPrincipal, maybe.get());
return headers.enrich(Response.ok(maybe.get()), start).build();
}
return headers.enrich(Response.status(404).entity(
Problem.clientProblem(GroupResource.TITLE_NOT_FOUND, "", 404)), start).build();
}
示例7: removeService
import io.dropwizard.auth.Auth; //導入依賴的package包/類
@DELETE
@Path("/{group}/access/services/{service_key}")
@Produces(MediaType.APPLICATION_JSON)
@PermitAll
@Timed(name = "removeService")
public Response removeService(
@Auth AuthPrincipal authPrincipal,
@PathParam("group") String groupKey,
@PathParam("service_key") String serviceKey
) throws AuthenticationException {
final long start = System.currentTimeMillis();
final Optional<Group> maybe = findGroup(groupKey);
if (maybe.isPresent()) {
final Group group = maybe.get();
accessControlSupport.throwUnlessGrantedFor(authPrincipal, group);
final Group updated = groupService.removeServiceAccess(group, serviceKey);
return headers.enrich(Response.ok(updated), start).build();
}
return headers.enrich(Response.status(404).entity(
Problem.clientProblem(TITLE_NOT_FOUND, "", 404)), start).build();
}
示例8: removeMember
import io.dropwizard.auth.Auth; //導入依賴的package包/類
@DELETE
@Path("/{group}/access/members/{member_key}")
@Produces(MediaType.APPLICATION_JSON)
@PermitAll
@Timed(name = "removeMember")
public Response removeMember(
@Auth AuthPrincipal authPrincipal,
@PathParam("group") String groupKey,
@PathParam("member_key") String memberKey
) throws AuthenticationException {
final long start = System.currentTimeMillis();
final Optional<Group> maybe = findGroup(groupKey);
if (maybe.isPresent()) {
final Group group = maybe.get();
accessControlSupport.throwUnlessGrantedFor(authPrincipal, group);
final Group updated = groupService.removeMemberAccess(group, memberKey);
return headers.enrich(Response.ok(updated), start).build();
}
return headers.enrich(Response.status(404).entity(
Problem.clientProblem(TITLE_NOT_FOUND, "", 404)), start).build();
}
示例9: updateFeature
import io.dropwizard.auth.Auth; //導入依賴的package包/類
@POST
@Path("/{group}/{feature_key}")
@PermitAll
@Timed(name = "updateFeature")
public Response updateFeature(
@Auth AuthPrincipal principal,
@PathParam("group") String group,
@PathParam("feature_key") String featureKey,
Feature feature,
@Context HttpHeaders httpHeaders
) throws AuthenticationException {
final long start = System.currentTimeMillis();
grantedGuard(principal, group);
groupValidGuard(group, featureKey, feature);
final Optional<String> maybeSeen = idempotencyChecker.extractKey(httpHeaders);
if (maybeSeen.isPresent() && idempotencyChecker.seen(maybeSeen.get())) {
return alreadyUpdated(feature, start, maybeSeen);
}
return headers.enrich(Response.ok(update(group, feature)), start).build();
}
示例10: getFeatureByKey
import io.dropwizard.auth.Auth; //導入依賴的package包/類
@GET
@Path("/{group}/{feature_key}")
@PermitAll
@Timed(name = "getFeatureByKey")
public Response getFeatureByKey(
@Auth AuthPrincipal principal,
@PathParam("group") String group,
@PathParam("feature_key") String featureKey
) throws AuthenticationException {
final long start = System.currentTimeMillis();
grantedGuard(principal, group);
return headers.enrich(
featureService.loadFeatureByKey(group, featureKey)
.map(Response::ok)
.orElseGet(this::featureNotFound), start).build();
}
示例11: subscribe
import io.dropwizard.auth.Auth; //導入依賴的package包/類
@PermitAll
@GET
/**
* Handle MQTT Subscribe Request in RESTful style
* Granted QoS Levels will send back to client.
* Retain Messages matched the subscriptions will NOT send back to client.
*/
public ResultEntity<List<Subscription>> subscribe(@PathParam("clientId") String clientId, @Auth UserPrincipal user) {
List<Subscription> subscriptions = new ArrayList<>();
// HTTP interface require valid Client Id
if (!this.validator.isClientIdValid(clientId)) {
logger.debug("Protocol violation: Client id {} not valid based on configuration", clientId);
throw new ValidateException(new ErrorEntity(ErrorCode.INVALID));
}
// Read client's subscriptions from storage
Map<String, MqttQoS> map = this.redis.getClientSubscriptions(clientId);
map.forEach((topic, qos) -> subscriptions.add(new Subscription(topic, qos.value())));
return new ResultEntity<>(subscriptions);
}
示例12: tagStubs
import io.dropwizard.auth.Auth; //導入依賴的package包/類
@Path("/tagStubs")
@GET
public Response tagStubs(@Auth Optional<User> user) {
List<Source> sources;
if (user.isPresent()) {
User present = user.get();
if (!articleDao.hasSubscriptions(present.getId())) {
return Response.status(Response.Status.OK)
.type(MediaType.APPLICATION_JSON_TYPE)
.entity(Collections.EMPTY_LIST)
.build();
} else {
sources = articleDao.getSources(userDao.findByEmail(present.getEmail()).getId());
}
} else {
sources = articleDao.getPublicSources();
}
Set<String> tags = sources.stream()
.map(Source::getTags)
.filter(Objects::nonNull)
.flatMap(List::stream)
.collect(Collectors.toSet());
return Response.ok(tags).build();
}
示例13: profileWatches
import io.dropwizard.auth.Auth; //導入依賴的package包/類
@GET
@Path("/watches")
public Collection<Watch> profileWatches(@Auth final User authUser) {
return userRepo.findWatchesOfUser(authUser.getId()).stream()
.map(Watch::new)
.collect(toList());
}
示例14: removeProfileWatch
import io.dropwizard.auth.Auth; //導入依賴的package包/類
@DELETE
@Path("/watches/{deviceId}")
public void removeProfileWatch(
@Auth final User authUser,
@PathParam("deviceId") final long deviceId
) {
userRepo.removeWatch(deviceId, authUser.getId());
}
示例15: claimDevice
import io.dropwizard.auth.Auth; //導入依賴的package包/類
@POST
@Path("{deviceId:\\d+}/claims")
public Claim claimDevice(
@PathParam("deviceId") final long deviceId,
@Auth User user
) {
final Device device = deviceRepo.findById(deviceId);
final Claim newClaim = Claim.startingNow(device, user);
return claimRepo.create(newClaim);
}