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.sharmila.hibernatespringsecurity.controller.DefaultController.java

@RequestMapping(value = "/admin", method = RequestMethod.GET)
public String adminProfile(Principal principal, ModelMap map) {
    String name = principal.getName();

    map.addAttribute("username", name);
    return "adminDashboard";
}

From source file:sample.mvc.SessionController.java

@RequestMapping(value = "/sessions/", method = RequestMethod.DELETE, produces = {
        MediaType.APPLICATION_JSON_VALUE, "application/hal+json" })
public HttpStatus removeSession(Principal principal, @RequestHeader("x-auth-token") String sessionIdToDelete) {
    Set<String> usersSessionIds = sessions.findByPrincipalName(principal.getName()).keySet();
    if (usersSessionIds.contains(sessionIdToDelete)) {
        sessions.delete(sessionIdToDelete);
    }//from   ww w. ja v a2s.co  m

    return HttpStatus.NO_CONTENT;
}

From source file:fi.vm.sade.eperusteet.ylops.service.external.impl.KayttajanTietoServiceImpl.java

@Override
public KayttajanTietoDto haeKirjautaunutKayttaja() {
    Principal ap = SecurityUtil.getAuthenticatedPrincipal();
    KayttajanTietoDto kayttaja = hae(ap.getName());
    if (kayttaja == null) { //"fallback" jos integraatio on rikki eik lyd kyttjn tietoja
        kayttaja = new KayttajanTietoDto(ap.getName());
    }/*from w ww  .  java  2  s. c  om*/
    return kayttaja;
}

From source file:com.example.HoneycombFilter.java

public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
        throws IOException, ServletException {

    if (!(request instanceof HttpServletRequest)) {
        chain.doFilter(request, response);
        return;/*from  www . j av  a2 s  .  co  m*/
    }
    HttpServletRequest req = (HttpServletRequest) request;
    long start = System.nanoTime();
    try {
        chain.doFilter(request, response);
    } finally {
        long responseTimeNanos = System.nanoTime() - start;
        Event event = libhoney.newEvent();
        event.addField("method", req.getMethod());
        event.addField("path", req.getRequestURI());
        event.addField("query", req.getQueryString());
        Principal principal = req.getUserPrincipal();
        if (principal != null) {
            event.addField("user", principal.getName());
        }
        event.addField("host", req.getRemoteHost());
        event.addField("responseTimeNanos", responseTimeNanos);
        try {
            event.send();
        } catch (HoneyException e) {
            log.error(e.getMessage(), e);
        }
    }
}

From source file:com.skymobi.monitor.security.SimpleAuthz.java

/**
 * Get the username of the user//from   w  ww .  j a  va 2  s . c o m
 *
 * @return the username of the user
 */
public String getPrincipal() {
    Principal obj = getUserPrincipal();

    if (obj != null) {
        return obj.getName();
    } else {
        return "guest";
    }
}

From source file:gov.nih.nci.cacis.xds.auth.axis.AbstractCacisXdsHandler.java

/**
 * //  w w w.  j  a va2  s.  com
 * @param msgContext Accepts the axis2 message context
 * @return returns the SubjectDN present in the x509 certificate presented by client.
 */
protected String getSubjectDN(MessageContext msgContext) {

    final HttpServletRequest req = (HttpServletRequest) msgContext
            .getProperty(HTTPConstants.MC_HTTP_SERVLETREQUEST);

    final X509Certificate[] certificate = (X509Certificate[]) req
            .getAttribute("javax.servlet.request.X509Certificate");
    if (certificate == null) {
        LOG.debug("javax.servlet.request.X509Certificate NOT AVAILABLE");
    } else {
        final Principal clientDN = certificate[0].getSubjectDN(); // certificate[0] is the end of the chain.
        if (clientDN != null) {
            return clientDN.getName();
        }
    }
    return null;
}

From source file:org.easit.core.controllers.home.HomeController.java

@RequestMapping("/")
public ModelAndView home(HttpServletRequest request, HttpServletResponse response, Principal currentUser,
        Model model) {/*from  w ww . j  a  v a  2s.co  m*/
    EasitAccount res = accountRepository.findAccountByUsername(currentUser.getName());
    ModelAndView modelAndView = new ModelAndView("home");
    modelAndView.addObject("connectionsToProviders", getConnectionRepository().findAllConnections());
    modelAndView.addObject("newsLoaded", true);

    // News plugin
    if (pluginManager.isLoaded("news"))
        modelAndView.addObject("newsLoaded", true);
    else
        modelAndView.addObject("newsLoaded", false);

    // cosmSensors plugin
    if (pluginManager.isLoaded("cosmSensors")) {
        modelAndView.addObject("cosmSensorsLoaded", true);
        pluginManager.getPlugin("cosmSensors").execute(res, modelAndView);
    } else
        modelAndView.addObject("cosmSensorsLoaded", false);

    modelAndView.addObject("home", true);
    return modelAndView;
}

From source file:org.ng200.openolympus.controller.user.SolutionStatusController.java

@RequestMapping(value = "/solution", method = RequestMethod.GET)
public String viewSolutionStatus(final HttpServletRequest request, final Model model,
        @RequestParam(value = "id") final Solution solution, final Principal principal) {
    if (principal == null || (!solution.getUser().getUsername().equals(principal.getName())
            && !request.isUserInRole(Role.SUPERUSER))) {
        throw new InsufficientAuthenticationException(
                "You attempted to view a solution that doesn't belong to you!");
    }//w ww . jav a  2  s  .  c  o  m

    this.assertSuperuserOrTaskAllowed(principal, solution.getTask());
    model.addAttribute("solution", solution);
    final List<Verdict> verdicts = this.solutionService.getVerdicts(solution);
    model.addAttribute("completeScore",
            verdicts.stream().map((x) -> x.getScore()).reduce((x, y) -> x.add(y)).orElse(BigDecimal.ZERO));
    model.addAttribute("completeMaximumScore", verdicts.stream().map((x) -> x.getMaximumScore())
            .reduce((x, y) -> x.add(y)).orElse(BigDecimal.ZERO));
    model.addAttribute("verdicts", verdicts.stream().sorted((l, r) -> Long.compare(l.getId(), r.getId()))
            .collect(Collectors.toList()));
    model.addAttribute("verdictMessageStrings", new HashMap<SolutionResult.Result, String>() {
        /**
         *
         */
        private static final long serialVersionUID = 8526897014680785208L;

        {
            this.put(SolutionResult.Result.OK, "solution.result.ok");
            this.put(SolutionResult.Result.TIME_LIMIT, "solution.result.timeLimit");
            this.put(SolutionResult.Result.MEMORY_LIMIT, "solution.result.memoryLimit");
            this.put(SolutionResult.Result.OUTPUT_LIMIT, "solution.result.outputLimit");
            this.put(SolutionResult.Result.RUNTIME_ERROR, "solution.result.runtimeError");
            this.put(SolutionResult.Result.INTERNAL_ERROR, "solution.result.internalError");
            this.put(SolutionResult.Result.SECURITY_VIOLATION, "solution.result.securityViolation");
            this.put(SolutionResult.Result.COMPILE_ERROR, "solution.result.compileError");
            this.put(SolutionResult.Result.PRESENTATION_ERROR, "solution.result.presentationError");
            this.put(SolutionResult.Result.WRONG_ANSWER, "solution.result.wrongAnswer");

        }
    });

    return "tasks/solution";
}

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

@Override
@RequestMapping(value = "/{widgetId}", method = RequestMethod.PUT)
@ResponseStatus(HttpStatus.OK)/*from w  ww. java  2 s  .  c o m*/
@ResponseBody
@ApiOperation("Update specified widget")
public OperationCompletionRS updateWidget(@PathVariable String projectName, @PathVariable String widgetId,
        @RequestBody @Validated WidgetRQ updateRQ, Principal principal) {
    return updateHandler.updateWidget(widgetId, updateRQ, principal.getName(),
            EntityUtils.normalizeProjectName(projectName));
}

From source file:net.lightbody.bmp.proxy.jetty.http.JDBCUserRealm.java

public void logout(Principal user) {
    remove(user.getName());
}