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:com.epam.ta.reportportal.ws.controller.impl.LaunchController.java

@Override
@PostMapping//from w w w .ja va 2 s  . c  o m
@ResponseBody
@ResponseStatus(CREATED)
@ApiOperation("Starts launch for specified project")
public EntryCreatedRS startLaunch(
        @ApiParam(value = "Name of project launch starts under", required = true) @PathVariable String projectName,
        @ApiParam(value = "Start launch request body", required = true) @RequestBody @Validated StartLaunchRQ startLaunchRQ,
        Principal principal) {
    return createLaunchMessageHandler.startLaunch(principal.getName(), normalizeProjectName(projectName),
            startLaunchRQ);
}

From source file:com.jd.survey.web.settings.VelocityTemplateController.java

@Secured({ "ROLE_ADMIN" })
@RequestMapping(params = "create", produces = "text/html")
public String createForm(Principal principal, Model uiModel) {
    log.info("createForm(): handles param form");
    try {// ww  w . j  a  v  a 2 s .  c  om
        User user = userService.user_findByLogin(principal.getName());
        populateEditForm(uiModel, new VelocityTemplate(), user);
        return "admin/templates/create";
    } catch (Exception e) {
        log.error(e.getMessage(), e);
        throw (new RuntimeException(e));
    }
}

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

@Override
@GetMapping("/{launchId}")
@ResponseBody//from  ww w.j  av  a 2 s . c  o m
@ResponseStatus(OK)
@ApiOperation("Get specified launch")
public LaunchResource getLaunch(@PathVariable String projectName, @PathVariable String launchId,
        Principal principal) {
    return getLaunchMessageHandler.getLaunch(launchId, principal.getName(), normalizeProjectName(projectName));
}

From source file:alfio.controller.api.admin.ResourceController.java

private void checkAccess(int organizationId, Principal principal) {
    Validate.isTrue(userManager.isOwnerOfOrganization(userManager.findUserByUsername(principal.getName()),
            organizationId));// w  ww .j a v  a 2  s . c o  m
}

From source file:org.dawnsci.marketplace.controllers.SolutionController.java

/**
 * Store changes/*from  ww  w  .j a  v  a  2  s.c  o m*/
 */
@PreAuthorize("hasRole('UPLOAD')")
@RequestMapping(value = "/edit-solution", method = RequestMethod.POST)
public String postSolution(ModelMap map, Principal principal, @ModelAttribute NodeProxy content) {
    addCommonItems(map, principal);
    // try to store the node
    Account account = accountRepository.findOne(principal.getName());
    Node node = content.getNode();
    Object result = marketplaceDAO.saveOrUpdateSolution(node, account);
    if (result instanceof Node) {
        node = (Node) result;
        content.setNode(node);
        Long id = node.getId();
        if (content.getScreenshotfile() != null && !content.getScreenshotfile().isEmpty()) {
            fileService.saveSolutionFile(id, content.getScreenshotfile());
            node.setScreenshot(content.getScreenshotfile().getOriginalFilename());
            Object o = marketplaceDAO.saveOrUpdateSolution(node, account);
            if (o instanceof Node)
                node = (Node) o;
        }
        if (content.getImagefile() != null && !content.getImagefile().isEmpty()) {
            fileService.saveSolutionFile(id, content.getImagefile());
            node.setImage(content.getImagefile().getOriginalFilename());
            Object o = marketplaceDAO.saveOrUpdateSolution(node, account);
            if (o instanceof Node)
                node = (Node) o;
        }
        if (content.getRepositoryfile() != null && !content.getRepositoryfile().isEmpty()) {
            // if a p2-repository is uploaded for the solution, the URL to the update
            // site will be overwritten with a new value pointing to this server.
            fileService.uploadRepository(id, content.getRepositoryfile());
            node.setUpdateurl("/files/" + id + "/");
            Object o = marketplaceDAO.saveOrUpdateSolution(node, account);
        }
    }
    return "redirect:/content/" + content.getNode().getId();
}

From source file:mx.gob.cfe.documentos.web.DocumentoController.java

@RequestMapping(value = "/download/{id}", method = RequestMethod.GET)
public String getDownloadPage(@PathVariable Long id, HttpServletResponse response, Principal principal)
        throws JRException, IOException {
    log.debug("Received request to show download page");
    String username = principal.getName();
    Usuario usuario = usuarioDao.obtinePorUsername(username);

    List<Documento> documentos = instance.listaReporte(usuario.getIniciales());
    generaReporte("PDF", documentos, response);

    return "redirect:/documento/reporte";
}

From source file:org.geosdi.geoplatform.experimental.dropwizard.resources.secure.account.GPSecureAccountResource.java

@GET
@Path(value = GPServiceRSPathConfig.GET_ALL_ACCOUNTS_PATH)
@Timed//from ww w . j av a2s  . com
@Override
public ShortAccountDTOContainer getAllAccounts(@Auth Principal principal) {
    logger.debug("\n\n@@@@@@@@@@@@@@@@@Executing secure getAllAccounts " + "- Principal : {}\n\n",
            principal.getName());
    return super.getAllAccounts();
}

From source file:org.magnum.mobilecloud.video.VideoServiceCtrl.java

@RequestMapping(value = VideoSvcApi.VIDEO_SVC_PATH + "/{id}/like", method = RequestMethod.POST)
@ResponseStatus(HttpStatus.OK)/*w ww.java2s .c o m*/
public @ResponseBody void likeVideo(@PathVariable("id") long id, HttpServletResponse response, Principal user)
        throws IOException {

    if (!videos.exists(id)) {
        response.sendError(404);
        return;
    }
    String username = user.getName();
    Video v = videos.findOne(id);
    Set<String> likesUsernames = v.getLikesUsernames();
    List<String> happyUsers = v.getLikedVideo();
    // Checks if the user has already liked the video.
    if (likesUsernames.contains(username)) {
        response.sendError(400);
        return;
    } else {
        long likes = v.getLikes();
        v.setLikes(++likes);
        v.getLikesUsernames().add(username);
    }
    if (!happyUsers.contains(username)) {
        happyUsers.add(username);
        v.setLikedVideo(happyUsers);
    }
    videos.save(v);
}

From source file:org.magnum.mobilecloud.video.VideoServiceCtrl.java

@RequestMapping(value = VideoSvcApi.VIDEO_SVC_PATH + "/{id}/unlike", method = RequestMethod.POST)
@ResponseStatus(HttpStatus.OK)//  ww w.  ja va  2  s . c om
public @ResponseBody void unlikeVideo(@PathVariable("id") long id, HttpServletResponse response, Principal user)
        throws IOException {

    if (!videos.exists(id)) {
        response.sendError(404);
        return;
    }
    String username = user.getName();
    Video v = videos.findOne(id);
    Set<String> unlikesUsernames = v.getUnlikesUsernames();
    List<String> happyUsers = v.getLikedVideo();
    // Checks if the user has already liked the video.
    if (unlikesUsernames.contains(username)) {
        response.sendError(400);
        return;
    } else {
        long likes = v.getLikes();
        v.setLikes(--likes);
        v.getUnlikesUsernames().add(username);
    }
    if (happyUsers.contains(username)) {
        happyUsers.remove(username);
        v.setLikedVideo(happyUsers);
    }
    videos.save(v);
}

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

@RequestMapping(value = "/password", method = RequestMethod.POST)
@Secured("ROLE_USER")
@ResponseBody/*from  w ww  . j  a v  a2 s.  c om*/
public Object savePassword(@RequestParam("oldPassword") String oldPassword,
        @RequestParam("password") String rawPassword, Principal principal, Locale locale) {
    EPPassword password = mongoTemplate.findById(new ObjectId(principal.getName()), EPPassword.class);
    String originPassword = password.getPassword();
    if (encoder.matches(oldPassword, originPassword)) {
        password.setPassword(encoder.encode(rawPassword));
        mongoTemplate.save(password);
        return Ajax.ok();
    } else {
        return Ajax.failure(messageSource.getMessage("setting.password.notmatch", null, locale));
    }
}