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.WidgetController.java

@Override
@RequestMapping(value = "/{widgetId}", method = RequestMethod.GET)
@ResponseStatus(HttpStatus.OK)/*from   w  w w . j av  a 2 s  .  co  m*/
@ResponseBody
@ApiOperation("Get widget by ID")
public WidgetResource getWidget(@PathVariable String projectName, @PathVariable String widgetId,
        Principal principal) {
    return getHandler.getWidget(widgetId, principal.getName(), EntityUtils.normalizeProjectName(projectName));
}

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

@Override
@RequestMapping(value = "/shared", method = RequestMethod.GET)
@ResponseStatus(OK)/* ww w  . j  ava  2 s  .c  o m*/
@ResponseBody
@ApiOperation("Get names of shared dashboards from specified project")
public Map<String, SharedEntity> getSharedDashboardsNames(@PathVariable String projectName,
        Principal principal) {
    return getHandler.getSharedDashboardsNames(principal.getName(),
            EntityUtils.normalizeProjectName(projectName));
}

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

@Override
@RequestMapping(value = "/{dashboardId}", method = RequestMethod.GET)
@ResponseStatus(OK)/*from  ww w  . j  a  va2  s. co m*/
@ResponseBody
@ApiOperation("Get specified dashboard by ID for specified project")
public DashboardResource getDashboard(@PathVariable String projectName, @PathVariable String dashboardId,
        Principal principal) {
    return getHandler.getDashboard(dashboardId, principal.getName(),
            EntityUtils.normalizeProjectName(projectName));
}

From source file:ch.cyberduck.core.ssl.CertificateStoreX509KeyManagerTest.java

@Test
public void testChooseClientAliasStartcom() throws Exception {
    final AtomicBoolean choose = new AtomicBoolean();
    final X509KeyManager m = new CertificateStoreX509KeyManager(new DisabledCertificateStore() {
        @Override//from   w ww. ja  v a2  s.com
        public X509Certificate choose(String[] keyTypes, Principal[] issuers, String hostname, String prompt)
                throws ConnectionCanceledException {
            assertEquals(
                    "The server requires a certificate to validate your identity. Select the certificate to authenticate yourself to test.cyberduck.ch.",
                    prompt);
            for (Principal issuer : issuers) {
                assertEquals("CN=StartCom Class 2 Primary Intermediate Client CA", issuer.getName());
            }
            choose.set(true);
            throw new ConnectionCanceledException();
        }
    }).init();
    assertNull(m.chooseClientAlias(new String[] { "RSA", "DSA" },
            new Principal[] { new X500Principal("CN=StartCom Class 2 Primary Intermediate Client CA") },
            new Socket("test.cyberduck.ch", 443)));
    assertTrue(choose.get());
}

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

/**
 * Este metodo da entrada el usuario a la pantalla de depuracion
 *
 * @param model//from  w w w .ja v  a  2s .  c  om
 * @param principal
 * @return regresa jsp de depuracion si no es admin arroja a pagina de
 * prohibido
 */
@RequestMapping
public String lista(Model model, Principal principal) {
    String username = principal.getName();
    Usuario usuario = usuarioDao.obtinePorUsername(username);
    if (!usuario.isAdministrador()) {
        return "usuario/noAutorizado";
    }
    return "repurar/lista";
}

From source file:org.mitre.openid.connect.web.ApprovedSiteAPI.java

/**
 * Get a list of all of this user's approved sites
 * @param m/*from   w  ww  .  j a  v a  2  s  .c  o  m*/
 * @return
 */
@RequestMapping(method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
public String getAllApprovedSites(ModelMap m, Principal p) {

    Collection<ApprovedSite> all = approvedSiteService.getByUserId(p.getName());

    m.put(JsonEntityView.ENTITY, all);

    return JsonApprovedSiteView.VIEWNAME;
}

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

@PreAuthorize(SecurityExpressionConstants.IS_USER)
@RequestMapping(value = "/api/user/solutions", method = RequestMethod.GET)
@JsonView(SolutionDto.SolutionDTOView.class)
public List<SolutionDto> showUserSolutions(
        @RequestParam(value = "page", defaultValue = "1") final Integer pageNumber, final Model model,
        final Principal principal) {
    final User user = this.userService.getUserByUsername(principal.getName());
    final List<Solution> solutions = new ArrayList<>();
    final Contest contest = this.contestService.getRunningContest();
    if (contest != null) {
        solutions.addAll(this.solutionService.getPage(user, pageNumber, SolutionListController.PAGE_SIZE,
                contest.getStartTime(), this.contestService.getContestEndTimeForUser(contest, user)));
    } else {/*  ww  w. ja  v a2s.  co  m*/
        solutions.addAll(this.solutionService.getPageOutsideOfContest(user, pageNumber,
                SolutionListController.PAGE_SIZE));
    }

    return solutions.stream().map(solution -> new SolutionDto(solution)).map(dto -> {
        if (contest != null) {
            dto.setScore(null);
        }
        return dto;
    }).collect(Collectors.toList());
}

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

@RequestMapping
public String lista(Model model, Principal principal) {
    String username = principal.getName();
    Usuario usuario = usuarioDao.obtinePorUsername(username);
    model.addAttribute("oficios", instance.lista("Oficio", usuario.getIniciales()));
    List lista = instance.lista("Oficio", usuario.getIniciales());
    log.error("lista{}", lista);
    return "oficio/lista";
}

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

@PreAuthorize("hasRole(user)")
@RequestMapping(value = VideoSvcApi.VIDEO_SVC_PATH + "/{id}/like", method = RequestMethod.POST)
public void likeVideo(@PathVariable("id") long id, HttpServletResponse response, Principal user) {
    String userName = user.getName();
    Video v = videoRepository.findById(id);
    if (v == null) {
        response.setStatus(404);//from  w  ww . j av a  2  s.c  o  m
        return;
    }
    Set<Like> likes = likeRepository.findByVideo_id(id);
    Unlike unlike = unlikeRepository.findByVideo_idAndUser(id, userName);
    if (unlike != null)
        unlikeRepository.delete(unlike);
    if (likes.size() == 0) {
        addNewLike(v, userName);
        response.setStatus(200);
    } else {
        for (Like like : likes) {
            if (like.getUser().equals(userName)) {
                response.setStatus(400);
            }
        }
        if (response.getStatus() != 400) {
            addNewLike(v, userName);
            response.setStatus(200);
        }
    }
}

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

@PreAuthorize("hasRole(user)")
@RequestMapping(value = VideoSvcApi.VIDEO_SVC_PATH + "/{id}/unlike", method = RequestMethod.POST)
public void unlikeVideo(@PathVariable("id") long id, HttpServletResponse response, Principal user) {
    String userName = user.getName();
    Video v = videoRepository.findById(id);
    if (v == null) {
        response.setStatus(404);//w w w.java  2  s  . com
        return;
    }
    Set<Unlike> unlikeSet = unlikeRepository.findByVideo_id(id);
    Like like = likeRepository.findByVideo_idAndUser(id, userName);
    if (like != null)
        likeRepository.delete(like);
    if (unlikeSet.size() == 0) {
        addNewUnLike(v, userName);
        response.setStatus(200);
    } else {
        for (Unlike unlike : unlikeSet) {
            if (unlike.getUser().equals(userName)) {
                response.setStatus(404);
            }
        }
        if (response.getStatus() != 404) {
            addNewUnLike(v, userName);
            response.setStatus(200);
        }
    }
}