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:org.jasig.cas.adaptors.trusted.web.flow.PrincipalFromRequestUserPrincipalNonInteractiveCredentialsAction.java

protected Credentials constructCredentialsFromRequest(final RequestContext context) {
    final HttpServletRequest request = WebUtils.getHttpServletRequest(context);
    final Principal principal = request.getUserPrincipal();

    if (principal != null) {
        if (logger.isDebugEnabled()) {
            logger.debug("UserPrincipal [" + principal.getName() + "] found in HttpServletRequest");
        }/*  w ww  .ja va 2 s .  c  o  m*/
        return new PrincipalBearingCredentials(new SimplePrincipal(principal.getName()));
    }

    if (logger.isDebugEnabled()) {
        logger.debug("UserPrincipal not found in HttpServletRequest.");
    }

    return null;
}

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

@Override
@RequestMapping(value = "/{projectName}/launch/jenkins", method = RequestMethod.GET)
@ResponseBody/*ww  w . j av a2s.com*/
@ResponseStatus(HttpStatus.OK)
@ApiIgnore
@PreAuthorize(ASSIGNED_TO_PROJECT)
public LaunchResource getLaunchByName(@PathVariable String projectName,
        @SortFor(Launch.class) Pageable pageable, @FilterFor(Launch.class) Filter filter, Principal principal) {
    return getLaunchMessageHandler.getLaunchByName(normalizeProjectName(projectName), pageable, filter,
            principal.getName());
}

From source file:business.controllers.LabController.java

@RequestMapping(value = "/admin/labs", method = RequestMethod.GET)
public List<Lab> getAll(Principal principal) {
    log.info("GET /admin/labs (for user: " + principal.getName() + ")");
    return labService.findAll();
}

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

@Override
@RequestMapping(value = "/names/all", method = RequestMethod.GET)
@ResponseStatus(HttpStatus.OK)/* w  w  w .  j av a 2 s .com*/
@ResponseBody
@ApiOperation("Load all widget names which belong to a user")
public List<String> getWidgetNames(@PathVariable String projectName, Principal principal) {
    return getHandler.getWidgetNames(EntityUtils.normalizeProjectName(projectName), principal.getName());
}

From source file:com.kdubb.socialshowcaseboot.HomeController.java

@RequestMapping("/")
public String home(Principal currentUser, Model model) {
    model.addAttribute("connectionsToProviders", getConnectionRepository().findAllConnections());
    model.addAttribute(accountRepository.findAccountByUsername(currentUser.getName()));
    return "home";
}

From source file:eu.tripledframework.demo.presentation.HelloController.java

@RequestMapping(value = "/hello", method = RequestMethod.GET)
public HelloResponse sayHiAuthenticated(Principal principal) throws ExecutionException, InterruptedException {
    LOGGER.debug("Saying hi to authenticated user {}", principal);

    return new HelloResponse("Hello authenticated user " + principal.getName());
}

From source file:ddf.security.sts.claimsHandler.AttributeMapLoader.java

/**
 * Obtains the user name from the principal.
 *
 * @param principal Describing the current user that should be used for retrieving claims.
 * @return the user name if the principal has one, null if no name is specified or if principal
 * is null./*from www .  j av  a  2s. c  om*/
 */
public static String getUser(Principal principal) {
    String user = null;
    if (principal instanceof KerberosPrincipal) {
        KerberosPrincipal kp = (KerberosPrincipal) principal;
        StringTokenizer st = new StringTokenizer(kp.getName(), "@");
        st = new StringTokenizer(st.nextToken(), "/");
        user = st.nextToken();
    } else if (principal instanceof X500Principal) {
        X500Principal x500p = (X500Principal) principal;
        StringTokenizer st = new StringTokenizer(x500p.getName(), ",");
        while (st.hasMoreElements()) {
            // token is in the format:
            // syntaxAndUniqueId
            // cn
            // ou
            // o
            // loc
            // state
            // country
            String[] strArr = st.nextToken().split("=");
            if (strArr.length > 1 && strArr[0].equalsIgnoreCase("cn")) {
                user = strArr[1];
                break;
            }
        }
    } else if (principal != null) {
        user = principal.getName();
    }

    return user;
}

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

/**
 * (non-Javadoc)//  ww w .  j a  va  2s.co m
 * 
 * @see com.epam.ta.reportportal.ws.controller.IFileStorageController#getMyPhoto
 *      (java.security.Principal, javax.servlet.http.HttpServletResponse)
 */
@RequestMapping(value = "/data/photo", method = RequestMethod.GET)
@Override
@ApiOperation("Get photo of current user")
public void getMyPhoto(Principal principal, HttpServletResponse response) {
    toResponse(response, userRepository.findUserPhoto(principal.getName()));
}

From source file:it.greenvulcano.gvesb.iam.jaas.GVBackingEngine.java

@Override
public List<RolePrincipal> listRoles(Principal principal) {
    try {//from  w  w w  . ja  v a  2 s.  c o m
        return userManager.getUser(principal.getName()).getRoles().stream().map(Role::getName)
                .map(RolePrincipal::new).collect(Collectors.toList());
    } catch (UserNotFoundException constraintViolationException) {
        throwException(constraintViolationException);
    }

    return null;
}

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

@Override
@RequestMapping(value = "/{filterId}", method = RequestMethod.GET)
@ResponseBody//from w  w  w. j a  va2  s.  co m
@ResponseStatus(HttpStatus.OK)
@ApiOperation("Get specified user filter by id")
public UserFilterResource getFilter(@PathVariable String projectName, @PathVariable String filterId,
        Principal principal) {
    return getFilterHandler.getFilter(principal.getName(), filterId,
            EntityUtils.normalizeProjectName(projectName));
}