Example usage for java.security Principal getName

List of usage examples for java.security Principal getName

Introduction

In this page you can find the example usage for java.security Principal getName.

Prototype

public String getName();

Source Link

Document

Returns the name of this principal.

Usage

From source file:sample.U2fController.java

@RequestMapping(value = "/u2f/register", method = RequestMethod.POST)
public String register(Principal principal, @RequestParam("tokenResponse") String response) {
    String username = principal.getName();
    RegisterResponse registerResponse = RegisterResponse.fromJson(response);
    RegisterRequestData registerRequestData = requestStorage
            .deleteRegistration(registerResponse.getRequestId());
    DeviceRegistration registration = u2f.finishRegistration(registerRequestData, registerResponse);
    devices.saveRegistrationForUsername(registration, username);
    return "redirect:/u2f/authenticate";
}

From source file:alfio.controller.AdminController.java

@RequestMapping("")
public String adminHome(Model model, @Value("${alfio.version}") String version, Principal principal) {
    model.addAttribute("alfioVersion", version);
    model.addAttribute("username", principal.getName());
    return "/admin/index";
}

From source file:com.zanshang.controllers.web.SettingCompanyController.java

@RequestMapping(value = "/name", method = RequestMethod.POST)
@Secured("ROLE_USER")
@ResponseBody/*from   w ww  .  j  a  v  a 2 s. c o  m*/
public Object modifyContactName(@RequestParam("name") String name, Principal principal, Locale locale) {
    ObjectId uid = new ObjectId(principal.getName());
    Company company = companyService.get(uid);
    company.setCompanyName(name);
    companyService.save(company);
    return Ajax.ok();
}

From source file:com.mycompany.rent.controllers.ListingController.java

@RequestMapping(value = "/create", method = RequestMethod.POST)
@ResponseBody//  www  .  ja  v a 2  s  . co m
public ForRent createForRent(@RequestBody ForRent forRent, Principal principal, Map model) {

    String name = principal.getName();

    User u = userDao.getByUsername(name);

    forRent.setUser_id(u.getId());

    forRentDao.create(forRent);

    return forRent;
}

From source file:org.ng200.openolympus.controller.solution.SolutionListController.java

@PreAuthorize(SecurityExpressionConstants.IS_USER)
@RequestMapping(value = "/api/user/solutionsCount", method = RequestMethod.GET)
public long getSolutionCountForUser(final Principal principal) {
    final User user = this.userService.getUserByUsername(principal.getName());

    // TODO: replace with SQL
    if (this.contestService.getRunningContest() == null) {
        return this.solutionService.countUserSolutions(user);
    }// w  w w. ja  v a2  s.c  o m
    return this.contestService.getRunningContest().getTasks().stream()
            .map(task -> this.solutionService.countUserSolutionsForTask(user, task)).reduce((x, y) -> x + y)
            .orElse(0l);
}

From source file:com.epam.ta.reportportal.ws.controller.impl.FavoriteResourceController.java

@Override
@RequestMapping(method = RequestMethod.POST)
@ResponseStatus(value = HttpStatus.OK)/* w  w  w  .ja v  a 2s. com*/
@ResponseBody
@ApiOperation("Add resource to favorites")
public DashboardResource addFavoriteResource(
        @RequestBody @Validated AddFavoriteResourceRQ addFavoriteResourceRQ, Principal principal,
        @PathVariable String projectName) {
    return favoritesHandler.add(addFavoriteResourceRQ, principal.getName(),
            EntityUtils.normalizeProjectName(projectName));
}

From source file:com.zanshang.controllers.web.SettingCompanyController.java

@RequestMapping(value = "/code", method = RequestMethod.POST)
@Secured("ROLE_USER")
@ResponseBody/*from  w w w.  ja  v  a2  s. co m*/
public Object modifyCompanyCode(@RequestParam("code") String code, Principal principal, Locale locale) {
    ObjectId uid = new ObjectId(principal.getName());
    if (publisherService.isVerified(uid)) {
        return Ajax.failure(messageSource.getMessage("setting.publisher.verified", null, locale));
    } else {
        Company company = companyService.get(uid);
        company.setCompanyCode(code);
        companyService.save(company);
        return Ajax.ok();
    }
}

From source file:com.zanshang.controllers.web.SettingCompanyController.java

@RequestMapping(value = "/license", method = RequestMethod.POST)
@Secured("ROLE_USER")
@ResponseBody/*from  w w  w  .  jav a  2 s  .  c  o m*/
public Object modifyLicense(@RequestParam("license") String license, Principal principal, Locale locale) {
    ObjectId uid = new ObjectId(principal.getName());
    if (publisherService.isVerified(uid)) {
        return Ajax.failure(messageSource.getMessage("setting.publisher.verified", null, locale));
    } else {
        Company company = companyService.get(uid);
        company.setLicense(license);
        companyService.save(company);
        return Ajax.ok();
    }
}

From source file:com.epam.ta.reportportal.ws.controller.impl.FileStorageController.java

@Override
@RequestMapping(value = "/data/photo", method = RequestMethod.POST)
@ResponseBody/*  w  w  w.  ja  va2s .c  o  m*/
@ApiOperation("Upload user's photo")
public OperationCompletionRS uploadPhoto(@RequestParam("file") MultipartFile file, Principal principal) {
    return editUserHandler.uploadPhoto(principal.getName(), file);
}

From source file:com.epam.ta.reportportal.ws.controller.impl.FileStorageController.java

@Override
@RequestMapping(value = "/data/photo", method = RequestMethod.DELETE)
@ResponseBody//  w w w .  j  a va2 s  .  c  o  m
@ApiOperation("Delete user's photo")
public OperationCompletionRS deletePhoto(Principal principal) {
    return editUserHandler.deletePhoto(principal.getName());
}