Example usage for javax.servlet.http HttpServletRequest getUserPrincipal

List of usage examples for javax.servlet.http HttpServletRequest getUserPrincipal

Introduction

In this page you can find the example usage for javax.servlet.http HttpServletRequest getUserPrincipal.

Prototype

public java.security.Principal getUserPrincipal();

Source Link

Document

Returns a java.security.Principal object containing the name of the current authenticated user.

Usage

From source file:business.security.CustomLoggingInterceptor.java

@Override
public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler,
        ModelAndView model) throws Exception {
    log.trace(String.format("%s\t%s\t%s\t%s\t%s\t%d", new Date(), request.getRemoteAddr(),
            request.getUserPrincipal() == null ? " - " : request.getUserPrincipal().getName(),
            request.getMethod(), request.getRequestURI(), response.getStatus()));
    super.postHandle(request, response, handler, model);
}

From source file:org.jboss.bpm.console.server.TaskMgmtFacade.java

@POST
@Path("{taskId}/release")
@Produces("application/json")
public Response releaseTask(@Context HttpServletRequest request, @PathParam("taskId") long taskId) {
    log.debug("Release task " + taskId);
    getTaskManagement().assignTask(taskId, null, request.getUserPrincipal().getName());
    return Response.ok().build();
}

From source file:org.jboss.bpm.console.server.TaskMgmtFacade.java

@POST
@Path("{taskId}/close")
@Produces("application/json")
public Response closeTask(@Context HttpServletRequest request, @PathParam("taskId") long taskId) {
    log.debug("Close task " + taskId);
    getTaskManagement().completeTask(taskId, null, request.getUserPrincipal().getName());
    return Response.ok().build();
}

From source file:org.nuxeo.ecm.platform.annotations.gwt.server.configuration.WebConfigurationServiceImpl.java

@Override
protected void service(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    currentUser = (NuxeoPrincipal) request.getUserPrincipal();
    super.service(request, response);
}

From source file:org.easit.core.handlers.ConnectedToHandlerInterceptor.java

@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
        throws Exception {

    if (request.getUserPrincipal() != null) {
        String requestURI = request.getRequestURI();
        String webNameUri = request.getSession().getAttribute("webNameUri").toString();
        String shortURI = requestURI.substring(webNameUri.length());

        // Sets uri for every request
        request.setAttribute("uri", shortURI);

        // Load user account settings from session attributes
        EasitAccount acc = (EasitAccount) request.getSession().getAttribute("user");

        // Plugin: log operations (Leave here) + current section in horizontal menu
        if (!requestURI.equals(webNameUri) && !requestURI.equals(webNameUri + "gmail")) {

            ArrayList<String> currentOperation = currentOperation(shortURI);
            String providerId = currentOperation.get(0);
            String operation = currentOperation.get(1);
            String currentSection;

            if (operation.equals(""))
                currentSection = webNameUri + providerId;
            else//from  w w  w.j  av a 2 s. c  o  m
                currentSection = webNameUri + providerId + "/" + operation;

            if (!requestURI.contains(webNameUri + PSMetadata.USER_SETTINGS_PAGE)
                    && !requestURI.contains(webNameUri + PSMetadata.CONNECT_PAGE)
                    && !requestURI.contains(webNameUri + PSMetadata.DISCONNECT_PAGE)
                    && !requestURI.contains(webNameUri + PSMetadata.ABOUT_PAGE)
                    && !requestURI.contains(webNameUri + PSMetadata.CONTACT_PAGE)
                    && !requestURI.contains(PSMetadata.SEARCH)
                    && !requestURI.contains(PSMetadata.NEWS_PLUGIN)) {
                if (pluginManager.isLoaded("logOperations")) {
                    for (Plugin plugin : pluginManager.listPlugins()) {
                        if (plugin.getName().equalsIgnoreCase("logOperations")) {
                            plugin.execute(acc, providerId, operation, operationsRepository);
                            break;
                        }
                    }
                }
            }

            request.setAttribute("currentSection", currentSection);
        }

        // Plugin: favourites(Leave here)
        if (pluginManager.isLoaded("favourites")) {
            List<String> disconnectedProvs = new ArrayList<String>();
            if (!(Boolean.parseBoolean(request.getSession().getAttribute("connectedToTwitter").toString())))
                disconnectedProvs.add(PSMetadata.PROVIDER_TWITTER);
            if (!(Boolean.parseBoolean(request.getSession().getAttribute("connectedToFacebook").toString())))
                disconnectedProvs.add(PSMetadata.PROVIDER_FACEBOOK);

            request.setAttribute("favourites", pluginManager.getPlugin("favourites").execute(acc,
                    disconnectedProvs, operationsRepository));
            request.setAttribute("favouritesLoaded", true);
        } else
            request.setAttribute("favouritesLoaded", false);
    }
    return true;
}

From source file:cn.edu.zjnu.acm.judge.service.SubmissionService.java

public boolean canView(HttpServletRequest request, Submission submission) {
    if (UserDetailService.isAdminLoginned(request)) {
        return true;
    }//from w  w  w  . j  av a  2 s.c om
    // TODO cast to Authentication
    if (UserDetailService.isUser((Authentication) request.getUserPrincipal(), submission.getUser())) {
        return true;
    }
    boolean sourceBrowser = UserDetailService.isSourceBrowser(request);
    if (sourceBrowser) {
        Long contestId = submission.getContest();
        if (contestId == null) {
            return true;
        }
        Contest contest = contestMapper.findOne(contestId);
        return contest == null || contest.isEnded();
    }
    return false;
}

From source file:edu.nwpu.gemfire.monitor.service.ClusterSelectedRegionsMemberService.java

@Override
public ObjectNode execute(final HttpServletRequest request) throws Exception {
    PulseLogWriter LOGGER = PulseLogWriter.getLogger();
    String userName = request.getUserPrincipal().getName();
    String pulseData = request.getParameter("pulseData");
    JsonNode parameterMap = mapper.readTree(pulseData);
    String selectedRegionFullPath = parameterMap.get("ClusterSelectedRegionsMember").get("regionFullPath")
            .textValue();/*from   w  w w  . ja va  2 s .  c  o m*/
    LOGGER.finest("ClusterSelectedRegionsMemberService selectedRegionFullPath = " + selectedRegionFullPath);

    // get cluster object
    Cluster cluster = Repository.get().getCluster();

    // json object to be sent as response
    ObjectNode responseJSON = mapper.createObjectNode();

    // getting cluster's Regions
    responseJSON.put("clusterName", cluster.getServerName());
    responseJSON.put("userName", userName);
    responseJSON.put("selectedRegionsMembers", getSelectedRegionsMembersJson(cluster, selectedRegionFullPath));
    // Send json response
    return responseJSON;
}

From source file:org.opendaylight.controller.web.DaylightWeb.java

@RequestMapping(value = "save", method = RequestMethod.POST)
@ResponseBody/* ww  w . j  a v a  2  s .  c  om*/
public String save(HttpServletRequest request) {
    String username = request.getUserPrincipal().getName();
    IUserManager userManager = (IUserManager) ServiceHelper.getGlobalInstance(IUserManager.class, this);
    if (userManager == null) {
        return "User Manager is not available";
    }
    UserLevel level = userManager.getUserLevel(username);
    Status status;
    switch (level) {
    case SYSTEMADMIN:
    case NETWORKADMIN:
        IConfigurationService configService = (IConfigurationService) ServiceHelper
                .getGlobalInstance(IConfigurationService.class, this);
        if (configService != null) {
            status = configService.saveConfigurations();
        } else {
            status = new Status(StatusCode.NOSERVICE, "Configuration Service is not available");
        }
        break;
    case NETWORKOPERATOR:
    case CONTAINERUSER:
        IContainerAuthorization containerAuth = (IContainerAuthorization) ServiceHelper
                .getGlobalInstance(IContainerAuthorization.class, this);
        if (containerAuth != null) {
            boolean oneSaved = false;
            Set<Resource> authorizedContainers = containerAuth.getAllResourcesforUser(username);
            if (authorizedContainers.isEmpty()) {
                status = new Status(StatusCode.UNAUTHORIZED, "User is not authorized for any container");
            } else {
                for (Resource container : authorizedContainers) {
                    if (container.getPrivilege() == Privilege.WRITE) {
                        String containerName = (String) container.getResource();
                        IConfigurationContainerService containerConfigService = (IConfigurationContainerService) ServiceHelper
                                .getInstance(IConfigurationContainerService.class, containerName, this);
                        if (containerConfigService != null) {
                            status = containerConfigService.saveConfigurations();
                            if (status.isSuccess()) {
                                oneSaved = true;
                            }
                        }
                    }
                }
                if (oneSaved) {
                    status = new Status(StatusCode.SUCCESS);
                } else {
                    status = new Status(StatusCode.UNAUTHORIZED, "Operation not allowed for current user");
                }
            }
        } else {
            status = new Status(StatusCode.NOSERVICE, "Container Authorization Service is not available");
        }
        break;
    case APPUSER:
    case NOUSER:
    default:
        status = new Status(StatusCode.UNAUTHORIZED, "Operation not allowed for current user");
        break;
    }
    // This function will eventually return a Status
    return status.getDescription();
}

From source file:org.fcrepo.http.commons.session.SessionFactory.java

/**
 * Retrieve a JCR session from an active transaction
 *
 * @param servletRequest the servlet request
 * @param txId the transaction id//from w  w  w  .java  2  s.co m
 * @return a JCR session that is associated with the transaction
 */
protected Session getSessionFromTransaction(final HttpServletRequest servletRequest, final String txId) {

    final Principal userPrincipal = servletRequest.getUserPrincipal();

    String userName = null;
    if (userPrincipal != null) {
        userName = userPrincipal.getName();
    }

    final Transaction transaction = transactionService.getTransaction(txId, userName);
    LOGGER.debug("Returning a session in the transaction {} for user {}", transaction, userName);
    return transaction.getSession();

}

From source file:edu.nwpu.gemfire.monitor.service.ClusterRegionService.java

@Override
public ObjectNode execute(final HttpServletRequest request) throws Exception {

    String userName = request.getUserPrincipal().getName();

    // get cluster object
    Cluster cluster = Repository.get().getCluster();

    // json object to be sent as response
    ObjectNode responseJSON = mapper.createObjectNode();

    // getting cluster's Regions
    responseJSON.put("clusterName", cluster.getServerName());
    responseJSON.put("userName", userName);
    responseJSON.put("region", getRegionJson(cluster));

    // Send json response
    return responseJSON;
}