本文整理汇总了Java中org.springframework.security.core.annotation.AuthenticationPrincipal类的典型用法代码示例。如果您正苦于以下问题:Java AuthenticationPrincipal类的具体用法?Java AuthenticationPrincipal怎么用?Java AuthenticationPrincipal使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
AuthenticationPrincipal类属于org.springframework.security.core.annotation包,在下文中一共展示了AuthenticationPrincipal类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: fileUpload
import org.springframework.security.core.annotation.AuthenticationPrincipal; //导入依赖的package包/类
@PostMapping(value = "/chunks/{resumableChunkNumber}")
@ResponseStatus(HttpStatus.ACCEPTED)
public String fileUpload(@AuthenticationPrincipal Object claims,
@RequestBody @Valid ResumableInfo resumableInfo,
@PathVariable String resumableChunkNumber) {
if (claims == null || !(claims instanceof Claims)) {
throw new UnauthorizedException();
}
switch (uploadService.addChunk(resumableInfo, Integer.parseInt(resumableChunkNumber), null, null)) {
case FINISHED:
return "Finished";
case UPLOAD:
return "Upload";
default:
return "";
}
}
示例2: deleteOrder
import org.springframework.security.core.annotation.AuthenticationPrincipal; //导入依赖的package包/类
@PreAuthorize("@securityServiceImpl.hasAdminPermissions(#userPrincipal)")
@RequestMapping(value = "/{id}", method = RequestMethod.DELETE)
public ResponseEntity<?> deleteOrder(@AuthenticationPrincipal User userPrincipal,
@PathVariable("id") long id) {
LOGGER.info("Start deleteOrder");
Order order = orderService.getById(id);
if (order == null) {
LOGGER.error("Order with id {} is not found", id);
return new ResponseEntity<>("Order not found", HttpStatus.NOT_FOUND);
}
for (Request request : order.getRequests()) {
LOGGER.info("set order to null of request with id: {}", request.getId());
request.setOrder(null);
}
orderService.delete(id);
return new ResponseEntity<>(id, HttpStatus.NO_CONTENT);
}
示例3: deleteAddress
import org.springframework.security.core.annotation.AuthenticationPrincipal; //导入依赖的package包/类
@PreAuthorize("@securityServiceImpl.hasAdminPermissions(#userPrincipal)")
@RequestMapping(value = "/{id}", method = RequestMethod.DELETE)
public ResponseEntity<?> deleteAddress(@AuthenticationPrincipal User userPrincipal,
@PathVariable("id") long id) {
LOGGER.info("Start deleteAddress");
Address address = addressService.findOne(id);
if (address == null) {
LOGGER.error("Address with id {} is not found", id);
return new ResponseEntity<>("Address not found", HttpStatus.NOT_FOUND);
}
// todo also maybe only set "disabled/deleted" property to true and doesn't show to user instead of deleting
// todo add check for order status and if one of the orders has "In progress" status then don't delete address
for (Order order : address.getOrders()) {
//order.setAddressFrom(null);
// todo
}
addressService.delete(id);
return new ResponseEntity<>(id, HttpStatus.NO_CONTENT);
}
示例4: updateTeamQuota
import org.springframework.security.core.annotation.AuthenticationPrincipal; //导入依赖的package包/类
@PutMapping(path = "/{teamId}/quota")
@ResponseStatus(HttpStatus.OK)
public TeamQuota updateTeamQuota(@AuthenticationPrincipal final Object claims, @PathVariable final String teamId, @RequestBody final TeamQuotaInfo teamQuotaInfo){
//check if team owner
String userId = ((Claims) claims).getSubject();
if (!teamService.isOwner(teamId, userId)) {
log.warn("Access denied for {} : /teams/{}/quota PUT", userId, teamId);
throw new ForbiddenException();
}
TeamQuota teamQuota = teamService.updateTeamQuota(teamId, teamQuotaInfo);
Team team = teamService.getTeamById(teamId);
ZonedDateTime startDate = team.getApplicationDate();
ZonedDateTime endDate = ZonedDateTime.now();
String usage = analyticsService.getUsageStatistics(teamId, startDate, endDate);
return new TeamQuotaInfo(teamQuota, usage);
}
示例5: deleteAddress
import org.springframework.security.core.annotation.AuthenticationPrincipal; //导入依赖的package包/类
@PreAuthorize("@securityServiceImpl.hasPermissions(#userPrincipal, #userId)")
@RequestMapping(value = "/{address_id}", method = RequestMethod.DELETE)
public ResponseEntity<?> deleteAddress(@AuthenticationPrincipal User userPrincipal,
@PathVariable("user_id") long userId,
@PathVariable("address_id") long addressId) {
LOGGER.info("Start deleteAddress addressId: {}", addressId);
Address address = addressService.findOne(addressId);
if (address == null) {
LOGGER.error("Address with id {} is not found", addressId);
return new ResponseEntity<>("Address not found", HttpStatus.NOT_FOUND);
}
// todo add check for order status and if one of the orders has "In progress" status then don't delete address
for (Order order : address.getOrders()) {
order.setAddressFrom(null);
}
addressService.delete(addressId);
return new ResponseEntity<>(addressId, HttpStatus.NO_CONTENT);
}
示例6: updateMarket
import org.springframework.security.core.annotation.AuthenticationPrincipal; //导入依赖的package包/类
/**
* Updates a given Market configuration.
*
* @param user the authenticated user.
* @param botId the id of the Bot to update the Market config for.
* @param marketId id of the Market config to update.
* @param marketConfig the updated Market config.
* @return 200 'Ok' and the updated Market config if successful, some other HTTP status code otherwise.
*/
@PreAuthorize("hasRole('ADMIN')")
@RequestMapping(value = "/{botId}" + MARKETS_RESOURCE_PATH + "/{marketId}", method = RequestMethod.PUT)
public ResponseEntity<?> updateMarket(@AuthenticationPrincipal User user, @PathVariable String botId,
@PathVariable String marketId, @RequestBody MarketConfig marketConfig) {
if (marketConfig.getId() == null || !marketId.equals(marketConfig.getId())) {
return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
}
LOG.info("PUT " + CONFIG_ENDPOINT_BASE_URI + botId + MARKETS_RESOURCE_PATH + "/" + marketId + " - updateMarket() "); //- caller: " + user.getUsername());
LOG.info("Request: " + marketConfig);
final MarketConfig updatedConfig = marketConfigService.updateMarketConfig(botId, marketConfig);
return updatedConfig == null
? new ResponseEntity<>(HttpStatus.NOT_FOUND)
: buildResponseEntity(updatedConfig, HttpStatus.OK);
}
示例7: updateBot
import org.springframework.security.core.annotation.AuthenticationPrincipal; //导入依赖的package包/类
/**
* Updates the Bot config configuration for a given Bot id.
*
* @param user the authenticated user making the request.
* @param botConfig the Bot config to update.
* @return 200 'OK' HTTP status code with updated Bot config if successful, some other HTTP status code otherwise.
*/
@PreAuthorize("hasRole('ADMIN')")
@RequestMapping(value = "/{botId}", method = RequestMethod.PUT)
public ResponseEntity<?> updateBot(@AuthenticationPrincipal User user, @PathVariable String botId, @RequestBody BotConfig botConfig) {
LOG.info("PUT " + CONFIG_ENDPOINT_BASE_URI + botId + " - updateBot()"); // - caller: " + user.getUsername());
LOG.info("Request: " + botConfig);
if (!botId.equals(botConfig.getId())) {
return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
}
final BotConfig updateBotConfig = botConfigService.updateBotConfig(botConfig);
return updateBotConfig == null
? new ResponseEntity<>(HttpStatus.NOT_FOUND)
: buildResponseEntity(updateBotConfig, HttpStatus.OK);
}
示例8: deleteBot
import org.springframework.security.core.annotation.AuthenticationPrincipal; //导入依赖的package包/类
/**
* Deletes a Bot configuration for a given id.
*
* @param user the authenticated user.
* @param botId the id of the Bot configuration to delete.
* @return 204 'No Content' HTTP status code if delete successful, some other HTTP status code otherwise.
*/
@PreAuthorize("hasRole('ADMIN')")
@RequestMapping(value = "/{botId}", method = RequestMethod.DELETE)
public ResponseEntity<?> deleteBot(@AuthenticationPrincipal User user, @PathVariable String botId) {
LOG.info("DELETE " + CONFIG_ENDPOINT_BASE_URI + botId + " - deleteBot()"); // - caller: " + user.getUsername());
final BotConfig deletedConfig = botConfigService.deleteBotConfig(botId);
return deletedConfig == null
? new ResponseEntity<>(HttpStatus.NOT_FOUND)
: new ResponseEntity<>(HttpStatus.NO_CONTENT);
}
示例9: updateStrategy
import org.springframework.security.core.annotation.AuthenticationPrincipal; //导入依赖的package包/类
/**
* Updates a given Strategy configuration.
*
* @param user the authenticated user.
* @param botId the id of the Bot to update the Strategy config for.
* @param strategyId id of the Strategy config to update.
* @param strategyConfig the updated Strategy config.
* @return 200 'Ok' and the updated Strategy config if successful, some other HTTP status code otherwise.
*/
@PreAuthorize("hasRole('ADMIN')")
@RequestMapping(value = "/{botId}" + STRATEGIES_RESOURCE_PATH + "/{strategyId}", method = RequestMethod.PUT)
public ResponseEntity<?> updateStrategy(@AuthenticationPrincipal User user, @PathVariable String botId,
@PathVariable String strategyId, @RequestBody StrategyConfig strategyConfig) {
if (strategyConfig.getId() == null || !strategyId.equals(strategyConfig.getId())) {
return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
}
LOG.info("PUT " + CONFIG_ENDPOINT_BASE_URI + botId + STRATEGIES_RESOURCE_PATH + "/" + strategyId + " - updateStrategy() "); //- caller: " + user.getUsername());
LOG.info("Request: " + strategyConfig);
final StrategyConfig updatedConfig = strategyConfigService.updateStrategyConfig(botId, strategyConfig);
return updatedConfig == null
? new ResponseEntity<>(HttpStatus.NOT_FOUND)
: buildResponseEntity(updatedConfig, HttpStatus.OK);
}
示例10: deleteUpload
import org.springframework.security.core.annotation.AuthenticationPrincipal; //导入依赖的package包/类
@GetMapping(params = {"filename"})
public String deleteUpload(@AuthenticationPrincipal Object claims, @RequestParam("filename") String filename) {
if (claims == null || !(claims instanceof Claims)) {
throw new UnauthorizedException();
}
try {
if (uploadService.deleteUpload("", "", filename)) {
log.info("File {} deleted.", filename);
return "Deleted";
} else {
log.info("File {} not deleted.", filename);
return "Not Deleted";
}
} catch (IOException e) {
log.error("Unable to delete file: {}", e);
throw new BadRequestException();
}
}
示例11: updatePullRequestStatuses
import org.springframework.security.core.annotation.AuthenticationPrincipal; //导入依赖的package包/类
@RequestMapping(value = "/admin/cla/link/migrate", method = RequestMethod.POST)
public String updatePullRequestStatuses(@AuthenticationPrincipal User user, @ModelAttribute UpdatePullRequestStatusesForm updatePullRequestStatusesForm, HttpServletRequest request) throws Exception {
String claName = updatePullRequestStatusesForm.getClaName();
String urlEncodedClaName = URLEncoder.encode(claName, "UTF-8");
UrlBuilder signClaUrlBldr = UrlBuilder.fromRequest(request);
String signClaUrl = signClaUrlBldr.path("/sign/" + urlEncodedClaName).build();
UrlBuilder aboutUrlBldr = UrlBuilder.fromRequest(request);
String aboutUrl = aboutUrlBldr.path("/about").build();
UrlBuilder baseSyncUrlBldr = UrlBuilder.fromRequest(request);
String baseSyncUrl = baseSyncUrlBldr.path("/sync/" + urlEncodedClaName).build();
MigratePullRequestStatusRequest migratePullRequests = MigratePullRequestStatusRequest.builder()
.accessToken(user.getAccessToken())
.commitStatusUrl(signClaUrl)
.repositoryIds(updatePullRequestStatusesForm.getRepositories())
.faqUrl(aboutUrl)
.baseSyncUrl(baseSyncUrl)
.build();
claService.migratePullRequestStatus(updatePullRequestStatusesForm.getClaName(), migratePullRequests);
return "redirect:/admin/cla/link";
}
示例12: getUsageStatistics
import org.springframework.security.core.annotation.AuthenticationPrincipal; //导入依赖的package包/类
@GetMapping("/usage/teams/{id}")
@ResponseStatus(HttpStatus.OK)
public String getUsageStatistics(@AuthenticationPrincipal Object claims,
@PathVariable final String id,
@RequestParam(value = "startDate", required = false) String startDate,
@RequestParam(value = "endDate", required = false) String endDate) {
if (claims == null || !(claims instanceof Claims)) {
log.warn("Access denied for: /analytics/usage/teams GET");
throw new UnauthorizedException();
}
ZonedDateTime start = getZonedDateTime(startDate);
ZonedDateTime end = getZonedDateTime(endDate);
ZonedDateTime now = ZonedDateTime.now();
if (start == null)
start = now.with(firstDayOfMonth());
if (end == null)
end = now.with(lastDayOfMonth());
return analyticsService.getUsageStatistics(id, start, end);
}
示例13: getEnergyStatistics
import org.springframework.security.core.annotation.AuthenticationPrincipal; //导入依赖的package包/类
@GetMapping("/energy")
@ResponseStatus(HttpStatus.OK)
public List<Double> getEnergyStatistics(@AuthenticationPrincipal Object claims,
@RequestParam(value = "startDate", required = false) String startDate,
@RequestParam(value = "endDate", required = false) String endDate) {
//check admin using validator class from common
checkAdmin((Claims) claims);
ZonedDateTime start = getZonedDateTime(startDate);
ZonedDateTime end = getZonedDateTime(endDate);
ZonedDateTime now = ZonedDateTime.now();
if (start == null) {
start = now.with(firstDayOfMonth());
}
if (end == null) {
end = now.with(lastDayOfMonth());
}
return analyticsService.getEnergyStatistics(start, end);
}
示例14: getDatasets
import org.springframework.security.core.annotation.AuthenticationPrincipal; //导入依赖的package包/类
@GetMapping()
@ResponseStatus(HttpStatus.OK)
public List<Data> getDatasets(@AuthenticationPrincipal Object claims) {
if (claims == null || !(claims instanceof Claims)) {
log.warn("Access denied for: /datasets GET");
throw new UnauthorizedException();
}
try {
checkAdmin((Claims) claims);
return dataService.getDatasets().stream().map(DataInfo::new).collect(Collectors.toList());
} catch (ForbiddenException e) {
String contextUserId = ((Claims) claims).getSubject();
return dataService.getDatasets().stream()
.filter(d -> !(d.getVisibility() == DataVisibility.PRIVATE && !d.getContributorId().equals(contextUserId)))
.map(DataInfo::new).collect(Collectors.toList());
}
}
示例15: getDatasetById
import org.springframework.security.core.annotation.AuthenticationPrincipal; //导入依赖的package包/类
@GetMapping(path = "/{id}")
@ResponseStatus(HttpStatus.OK)
public Data getDatasetById(@AuthenticationPrincipal Object claims, @PathVariable Long id) {
if (claims == null || !(claims instanceof Claims)) {
throw new UnauthorizedException();
}
try {
checkAdmin((Claims) claims);
return new DataInfo(dataService.getDataset(id));
} catch (ForbiddenException e) {
String contextUserId = ((Claims) claims).getSubject();
Data data = dataService.getDataset(id);
if (!(data.getVisibility() == DataVisibility.PRIVATE && !data.getContributorId().equals(contextUserId))) {
return new DataInfo(data);
} else {
throw new ForbiddenException();
}
}
}