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:business.controllers.UserController.java

@RequestMapping(value = "/admin/users/scientific_council", method = RequestMethod.GET)
public List<ProfileRepresentation> getScientificCouncilMembers(Principal principal) {
    log.info("GET /admin/users/scientific_council (for user: " + principal.getName() + ")");
    List<ProfileRepresentation> users = new ArrayList<ProfileRepresentation>();
    for (User user : userService.findScientificCouncilMembers()) {
        users.add(new ProfileRepresentation(user));
    }/*from w  w  w. j a va2s .co m*/
    return users;
}

From source file:business.controllers.LabController.java

@RequestMapping(value = "/admin/labs", method = RequestMethod.POST)
public Lab create(Principal principal, @RequestBody Lab body) {
    log.info("POST /admin/labs (for user: " + principal.getName() + ")");
    Lab lab = new Lab();
    if (body.getNumber() == null || body.getNumber().intValue() <= 0) {
        throw new InvalidLabNumber();
    }//w  w w  . j  a v  a2s . c  om
    lab.setNumber(body.getNumber());
    transferLabData(body, lab);
    return labService.save(lab);
}

From source file:com.example.ClientDetailsController.java

@DeleteMapping("/clients/{clientId}")
public String delete(Principal user, @PathVariable String clientId) {
    clients.removeClientDetails(clientId);
    template.update("DELETE from user_client_details where username=? and client_id=?", user.getName(),
            clientId);/*from   w ww  .j a  v  a 2  s. c  o m*/
    return "redirect:/clients";
}

From source file:info.magnolia.cms.security.auth.PrincipalCollectionImpl.java

/**
 * Gets principal associated to the specified name from the collection.
 * @param name//  w w w .j a  va2  s.  c  o m
 * @return principal object associated to the specified name.
 */
@Override
public Principal get(String name) {
    //TODO: change internal collection to a map and store names as keys to avoid loops !!!!
    Iterator<Principal> principalIterator = this.collection.iterator();
    while (principalIterator.hasNext()) {
        Principal principal = principalIterator.next();
        if (StringUtils.equalsIgnoreCase(name, principal.getName())) {
            return principal;
        }
    }
    return null;
}

From source file:org.geosdi.geoplatform.experimental.dropwizard.resources.secure.acl.GPSecureACLResource.java

@POST
@Path(value = GPServiceRSPathConfig.SAVE_ROLE_PATH)
@Override//from w w  w.ja  va2  s .  c om
public Boolean saveRole(@Auth Principal principal, WSSaveRoleRequest saveRoleReq) throws Exception {
    logger.debug("\n\n@@@@@@@@@@@@@@@Executing secure saveRole" + " - Principal : {}\n\n", principal.getName());
    return super.saveRole(saveRoleReq);
}

From source file:org.ng200.openolympus.controller.auth.AuthenticationInformationController.java

@JsonView(UnprivilegedView.class)
@RequestMapping(value = "/api/security/userStatus", method = RequestMethod.GET)
public UserStatus getUsers(Principal principal) {
    if (principal == null) {
        return new UserStatus(false, null, Lists.from());
    }/*from ww w  .j  a v a  2s. com*/
    final User user = this.userService.getUserByUsername(principal.getName());
    return new UserStatus(true, user,
            user.getRoles().stream().map(role -> role.getRoleName()).collect(Collectors.toList()));
}

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

@RequestMapping(value = "/event/{eventName}/{reservationId}/audit", method = RequestMethod.GET)
public Result<List<Audit>> getAudit(@PathVariable("eventName") String eventName,
        @PathVariable("reservationId") String reservationId, Principal principal) {
    return adminReservationManager.getAudit(eventName, reservationId, principal.getName());
}

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

@RequestMapping(value = "/sponsor-scan", method = RequestMethod.POST)
public ResponseEntity<TicketAndCheckInResult> scanBadge(@RequestBody SponsorScanRequest request,
        Principal principal) {
    return ResponseEntity.ok(attendeeManager.registerSponsorScan(request.eventName, request.ticketIdentifier,
            principal.getName()));
}

From source file:be.fedict.hsm.model.SignatureServiceBean.java

@Override
public byte[] sign(String digestMethodAlgorithm, byte[] digestValue, String keyAlias)
        throws NoSuchAlgorithmException {
    LOG.debug("digest method algorithm: " + digestMethodAlgorithm);
    LOG.debug("key alias: " + keyAlias);
    Principal callerPrincipal = this.sessionContext.getCallerPrincipal();
    LOG.debug("caller principal: " + callerPrincipal.getName());
    LOG.debug(/*w ww  .  j  ava  2s.c o  m*/
            "caller in role application: " + this.sessionContext.isCallerInRole(ApplicationRoles.APPLICATION));
    long appId = Long.parseLong(callerPrincipal.getName());
    ApplicationKeyEntity applicationKeyEntity = this.entityManager.find(ApplicationKeyEntity.class,
            new ApplicationKeyId(appId, keyAlias));
    if (null == applicationKeyEntity) {
        throw new NoSuchAlgorithmException("unknown key alias: " + keyAlias);
    }
    String keyStoreAlias = applicationKeyEntity.getKeyStoreKeyAlias();
    long keyStoreId = applicationKeyEntity.getKeyStore().getId();
    String digestAlgo = digestMethodToDigestAlgo.get(digestMethodAlgorithm);
    if (null == digestAlgo) {
        throw new IllegalArgumentException("unsupported digest method algo: " + digestMethodAlgorithm);
    }
    byte[] signatureValue;
    try {
        signatureValue = this.keyStoreSingletonBean.sign(keyStoreId, keyStoreAlias, digestAlgo, digestValue);
    } catch (Exception e) {
        LOG.error("signature error: " + e.getMessage());
        return null;
    }

    AuditEntity auditEntity = new AuditEntity(applicationKeyEntity.getApplication().getName(), keyAlias,
            applicationKeyEntity.getKeyStore().getName(), keyStoreAlias,
            new String(Hex.encodeHex(digestValue)));
    this.entityManager.persist(auditEntity);

    return signatureValue;
}

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

@RequestMapping(value = "/configuration/organizations/{organizationId}/load", method = GET)
public Map<ConfigurationKeys.SettingCategory, List<Configuration>> loadOrganizationConfiguration(
        @PathVariable("organizationId") int organizationId, Principal principal) {
    return configurationManager.loadOrganizationConfig(organizationId, principal.getName());
}