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:alfio.controller.api.admin.UsersApiController.java

@RequestMapping(value = "/users/update-password", method = POST)
public ValidationResult updatePassword(@RequestBody PasswordModification passwordModification,
        Principal principal) {
    return userManager
            .validateNewPassword(principal.getName(), passwordModification.oldPassword,
                    passwordModification.newPassword, passwordModification.newPasswordConfirm)
            .ifSuccess(() -> userManager.updatePassword(principal.getName(), passwordModification.newPassword));
}

From source file:com.lixiaocong.controller.BlogController.java

@RolesAllowed("ROLE_USER")
@RequestMapping(method = RequestMethod.POST)
public ModelAndView post(@Valid ArticleForm articleForm, BindingResult result, Principal principal)
        throws ControllerParamException {
    if (result.hasErrors())
        throw new ControllerParamException();

    User user = userService.getByUsername(principal.getName());
    Article article = articleService.create(user.getId(), articleForm.getTitle(), articleForm.getContent());
    return new ModelAndView("redirect:/blog/detail?id=" + article.getId());
}

From source file:org.geosdi.geoplatform.experimental.dropwizard.resources.secure.viewport.GPSecureViewportResource.java

@PUT
@Path(value = GPServiceRSPathConfig.UPDATE_VIEWPORT_PATH)
@Override//ww w.j  a v a2s .  com
public Long updateViewport(@Auth Principal principal, GPViewport viewport) throws Exception {
    logger.debug("\n\n@@@@@@@@@@@@@@Executing secure updateViewport - " + "Principal : {}\n\n",
            principal.getName());
    return super.updateViewport(viewport);
}

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

@RequestMapping(value = "/event/{eventName}/reservations/list", method = RequestMethod.GET)
public PageAndContent<List<TicketReservation>> findAll(@PathVariable("eventName") String eventName,
        @RequestParam(value = "page", required = false) Integer page,
        @RequestParam(value = "search", required = false) String search,
        @RequestParam(value = "status", required = false) List<TicketReservation.TicketReservationStatus> status,
        Principal principal) {
    Event event = eventRepository.findByShortName(eventName);
    eventManager.checkOwnership(event, principal.getName(), event.getOrganizationId());
    Pair<List<TicketReservation>, Integer> res = ticketReservationManager
            .findAllReservationsInEvent(event.getId(), page, search, status);
    return new PageAndContent<>(res.getLeft(), res.getRight());
}

From source file:alfio.controller.api.AdminApiController.java

@RequestMapping(value = "/users", method = GET)
public List<User> getAllUsers(Principal principal) {
    return userManager.findAllUsers(principal.getName());
}

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

@Override
@RequestMapping(value = "/password/change", method = POST)
@ResponseBody/* w ww .  j  av a2 s . c  om*/
@ResponseStatus(OK)
@ApiOperation("Change own password")
public OperationCompletionRS changePassword(@RequestBody @Validated ChangePasswordRQ changePasswordRQ,
        Principal principal) {
    return editUserMessageHandler.changePassword(principal.getName(), changePasswordRQ);
}

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

/**
 * Este metodo inicia el proceso para eliminar completamente los datos en la
 * base de datos de documentos/* w w  w  . jav  a  2  s .c o  m*/
 *
 * @param id
 * @param response
 * @param principal
 * @return
 * @throws JRException
 * @throws IOException
 */
@RequestMapping(value = "/eliminar", method = RequestMethod.GET)
public String eliminar(@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);
    if (!usuario.isAdministrador()) {
        return "usuario/noAutorizado";
    }
    instance.eliminaDocumentosCompleto();
    return "redirect:/depurar";
}

From source file:org.drugis.addis.security.repository.impl.AccountRepositoryImpl.java

@Override
public Account getAccount(Principal principal) {
    try {/*from w ww .  j a  va 2  s .  com*/
        return jdbcTemplate.queryForObject(
                "select id, username, firstName, lastName, email from Account where username = ?", rowMapper,
                principal.getName());

    } catch (EmptyResultDataAccessException e) {
        throw new EmptyResultDataAccessException(
                "getAccount: Unknown account for principal with name:: " + principal.getName(), 1);
    }
}

From source file:org.geosdi.geoplatform.experimental.dropwizard.resources.secure.server.GPSecureServerResource.java

@PUT
@Path(value = GPServiceRSPathConfig.UPDATE_SERVER_PATH)
@Override/*from   ww w .  j  ava2 s. c  om*/
public Long updateServer(@Auth Principal principal, GeoPlatformServer server) throws Exception {
    logger.debug("\n\n@@@@@@@@@@@@@@Executing secure updateServer - " + "Principal : {}\n\n",
            principal.getName());
    return super.updateServer(server);
}

From source file:ch.hortis.mongodb.training.blog.oauth.AdminResource.java

private void checkResourceOwner(String user, Principal principal) {
    if (principal instanceof OAuth2Authentication) {
        OAuth2Authentication authentication = (OAuth2Authentication) principal;
        if (!authentication.isClientOnly() && !user.equals(principal.getName())) {
            throw new AccessDeniedException(
                    String.format("User '%s' cannot obtain tokens for user '%s'", principal.getName(), user));
        }/*  w ww  .j  a  va  2 s . c  om*/
    }
}