List of usage examples for java.security Principal getName
public String getName();
From source file:org.mitreid.multiparty.service.InMemoryResourceService.java
@Override public Collection<Resource> getAllForUser(Principal p) { if (p == null) { return Collections.emptySet(); } else {//from w w w . j a v a 2 s . c o m Collection<Resource> res = resources.get(p.getName()); if (res == null) { return Collections.emptySet(); } else { return res; } } }
From source file:alfio.controller.api.admin.UsersApiController.java
@RequestMapping(value = "/users/current", method = GET) public UserModification loadCurrentUser(Principal principal) { User user = userManager.findUserByUsername(principal.getName()); Optional<Organization> userOrganization = userManager.findUserOrganizations(user.getUsername()).stream() .findFirst();//from w ww. j a v a2s . co m return new UserModification(user.getId(), userOrganization.map(Organization::getId).orElse(-1), userManager.getUserRole(user).name(), user.getUsername(), user.getFirstName(), user.getLastName(), user.getEmailAddress()); }
From source file:com.rest.it.TestData.java
@Test public void changePassword() { userEntity = userRepository.findByUsername("test@gmail.com"); if (userEntity == null) { userEntity = new UserEntity(); userEntity.setFirstName("tester"); userEntity.setLastName("tester"); userEntity.setPassword(standardPasswordEncoder.encode("password1")); userEntity.setEnabled(true);/*from w w w. j av a 2s .c o m*/ userEntity.setUsername("test@gmail.com"); userRepository.save(userEntity);// needed to be able to save authority } Principal userMock = Mockito.mock(Principal.class); when(userMock.getName()).thenReturn("test@gmail.com"); userRest.userRepository = userRepository; UserPasswordRequestDto userPasswordDto = new UserPasswordRequestDto(); userPasswordDto.setCurrentPassword("password1"); userPasswordDto.setNewPassword("password2"); userRest.changePassword(userPasswordDto, userMock); UserEntity user = userRepository.findByUsername("test@gmail.com"); boolean isPasswordChanged = false; if (standardPasswordEncoder.matches("password2", user.getPassword())) { isPasswordChanged = true; } assertEquals(isPasswordChanged, true); }
From source file:org.dawnsci.marketplace.controllers.ExtendedRestApiController.java
@PreAuthorize("hasRole('UPLOAD')") @RequestMapping(value = "/upload", method = RequestMethod.POST) public ResponseEntity<String> postSolution(Principal principal, @RequestBody String solution) throws Exception { Account account = accountRepository.findOne(principal.getName()); Node node = MarketplaceSerializer.deSerializeSolution(solution); Object result = marketplaceDAO.saveOrUpdateSolution(node, account); if (result instanceof Node) { return new ResponseEntity<String>(MarketplaceSerializer.serialize((Node) result), HttpStatus.OK); } else {/* w ww . jav a 2s. com*/ if (result instanceof Exception) { ((Exception) result).printStackTrace(); String message = ((Exception) result).getMessage(); return new ResponseEntity<String>(message, HttpStatus.INTERNAL_SERVER_ERROR); } else return new ResponseEntity<String>(result.toString(), HttpStatus.FORBIDDEN); } }
From source file:com.lixiaocong.controller.BlogController.java
@RolesAllowed("ROLE_USER") @RequestMapping(value = "/comment/{id}", method = RequestMethod.POST) public ModelAndView comment(@PathVariable long id, @Valid CommentForm comment, BindingResult result, Principal principal) throws ControllerParamException { if (result.hasErrors()) throw new ControllerParamException(); User user = userService.getByUsername(principal.getName()); commentService.create(id, user.getId(), comment.getContent()); return new ModelAndView("redirect:/blog/detail?id=" + id); }
From source file:org.starfishrespect.myconsumption.server.business.controllers.UserController.java
@RequestMapping(value = "/{name}/sensor/{sensorId}", method = RequestMethod.DELETE) public SimpleResponseDTO removeSensor(Principal principal, @PathVariable String name, @PathVariable String sensorId) throws DaoException { // Check if this user can access this resource if (!(principal.getName().equals(name))) return new SimpleResponseDTO(false, "you are not allowed to modify this user"); User user = mUserRepository.getUser(name); if (user == null) throw new NotFoundException(); if (!user.getSensors().remove(sensorId)) throw new NotFoundException(); mUserRepository.updateUser(user);//from ww w . j a v a 2s . c om mSensorRepository.decrementUsageCount(sensorId); return new SimpleResponseDTO(true, "sensor unassociated from the user"); }
From source file:com.epam.ta.reportportal.ws.controller.impl.UserFilterController.java
@Override @RequestMapping(value = "/filters", method = RequestMethod.GET) @ResponseBody/*from w w w.j a v a2 s .co m*/ @ResponseStatus(HttpStatus.OK) @ApiOperation("Get list of specified user filters") public List<UserFilterResource> getUserFilters(@PathVariable String projectName, @RequestParam(value = "ids", required = true) String[] ids, Principal principal) { return getFilterHandler.getFilters(EntityUtils.normalizeProjectName(projectName), ids, principal.getName()); }
From source file:org.geosdi.geoplatform.experimental.dropwizard.resources.secure.organization.GPSecureOrganizationResource.java
@Path(value = GPServiceRSPathConfig.DELETE_ORGANIZATION_PATH) @DELETE//from ww w. ja va2 s .c o m @Override public Boolean deleteOrganization(@Auth Principal principal, @PathParam(value = "organizationID") Long organizationID) throws Exception { logger.debug("\n\n@@@@@@@@@@@@@@Executing secure deleteOrganization - " + "Principal : {}\n\n", principal.getName()); return super.deleteOrganization(organizationID); }
From source file:org.dawnsci.marketplace.controllers.SolutionController.java
/** * Deletes the solution from the database. The logged in user must be the * owner or an 403 error will be returned. *//*from ww w . j ava 2 s . c o m*/ @PreAuthorize("hasRole('UPLOAD')") @RequestMapping(value = "/delete-solution/{identifier}", method = RequestMethod.GET) public String deleteSolution(ModelMap map, Principal principal, @PathVariable int identifier) { Account account = accountRepository.findOne(principal.getName()); marketplaceDAO.deleteSolution(account, Long.valueOf(identifier)); return "redirect:/"; }
From source file:org.starfishrespect.myconsumption.server.business.controllers.UserController.java
@RequestMapping(value = "/{name}/sensor/{sensorId}", method = RequestMethod.POST) public SimpleResponseDTO addSensor(Principal principal, @PathVariable String name, @PathVariable String sensorId) throws DaoException { // Check if this user can access this resource if (!(principal.getName().equals(name))) return new SimpleResponseDTO(false, "you are not allowed to modify this user"); User user = mUserRepository.getUser(name); if (user == null) throw new NotFoundException(); if (!mSensorRepository.sensorExists(sensorId)) throw new NotFoundException(); if (user.getSensors().contains(sensorId)) return new SimpleResponseDTO(false, "you already have this sensor"); user.getSensors().add(sensorId);/* w ww . j a v a2 s . co m*/ mUserRepository.updateUser(user); mSensorRepository.incrementUsageCount(sensorId); return new SimpleResponseDTO(true, "sensor associated to the user"); }