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:de.fau.amos4.web.PrintDataController.java

@RequestMapping("/employee/download/zip")
public void EmployeeDownloadZip(Principal principal, HttpServletResponse response,
        @RequestParam(value = "id", required = true) long employeeId) throws IOException,
        NoSuchMessageException, COSVisitorException, ZipException, CloneNotSupportedException {
    final String currentUser = principal.getName();
    Client currentClient = clientService.getClientByEmail(currentUser);

    int fontSize = 12;
    float height = 1;
    height = height * fontSize * 1.05f;//www .java  2s.  co m

    //Prepare textfile contents
    Employee employee = employeeRepository.findOne(employeeId);
    Locale locale = LocaleContextHolder.getLocale();
    response.setContentType("application/zip");
    response.setHeader("Content-Disposition", "attachment;filename=employee.zip");

    ZipGenerator zipGenerator = new ZipGenerator();

    zipGenerator.generate(response.getOutputStream(), locale, height, employee, fontSize,
            currentClient.getZipPassword());
}

From source file:com.jd.survey.web.settings.QuestionColumnLabelController.java

@Secured({ "ROLE_ADMIN", "ROLE_SURVEY_ADMIN" })
@RequestMapping(value = "/{id}", params = "form", produces = "text/html")
public String updateForm(@PathVariable("id") Long questionId, Principal principal,
        HttpServletRequest httpServletRequest, Model uiModel) {
    log.info("updateForm(): questionId=" + questionId);
    try {//  ww  w.ja v  a 2  s. c  o m
        String login = principal.getName();
        User user = userService.user_findByLogin(login);
        Question question = surveySettingsService.question_findById(questionId);
        //Check if the user is authorized
        if (!securityService.userIsAuthorizedToManageSurvey(question.getPage().getSurveyDefinition().getId(),
                user)
                && !securityService.userBelongsToDepartment(
                        question.getPage().getSurveyDefinition().getDepartment().getId(), user)) {
            log.warn("Unauthorized access to url path " + httpServletRequest.getPathInfo()
                    + " attempted by user login:" + principal.getName() + "from IP:"
                    + httpServletRequest.getLocalAddr());
            return "accessDenied";
        }

        SortedSet<QuestionColumnLabel> ColumnLabels = question.getColumnLabels();
        log.info("initial set size" + ColumnLabels.size());
        for (int i = 1; i <= EMPTY_OPTIONS_COUNT; i++) {

            log.info("adding to set" + i);
            ColumnLabels
                    .add(new QuestionColumnLabel(question, (short) (question.getColumnLabels().size() + i)));
        }
        question.setColumnLabels(ColumnLabels);
        uiModel.addAttribute("question", question);
        return "settings/questionCols/update";
    } catch (Exception e) {
        log.error(e.getMessage(), e);
        throw (new RuntimeException(e));
    }
}

From source file:com.zanshang.controllers.web.SettingController.java

@RequestMapping(value = "/name", method = RequestMethod.POST)
@Secured("ROLE_USER")
@ResponseBody/*from  ww w .  j a  v a2s .c  om*/
public Object saveDisplayName(@RequestParam("name") String displayName, Principal principal) {
    Setting setting = settingService.get(new ObjectId(principal.getName()));
    setting.setDisplayName(displayName);
    settingService.save(setting);
    return Ajax.ok();
}

From source file:com.zanshang.controllers.web.SettingController.java

@RequestMapping(value = "/avatar", method = RequestMethod.POST)
@ResponseBody//w  ww  .  ja  v  a 2 s .  com
@Secured("ROLE_USER")
public Object settingsAvatar(@RequestParam("image") String avatar, Principal principal) {
    Setting setting = settingService.get(new ObjectId(principal.getName()));
    setting.setAvatar(avatar);
    settingService.save(setting);
    return Ajax.ok();
}

From source file:FacultyAdvisement.SignupBean.java

@PostConstruct
public void init() {
    FacesContext fc = FacesContext.getCurrentInstance();
    Principal p = fc.getExternalContext().getUserPrincipal();
    username = p.getName();
    student = new Student();
    this.appointment = appointmentBean.getAppointment();
    desiredCoureses = new ArrayList<>();

    try {/*from ww w .j  av  a 2 s  .  c o  m*/
        desiredCoureses = DesiredCourseRepository.readDesiredCourses(ds, Long.toString(appointment.aID));
    } catch (SQLException ex) {
        Logger.getLogger(SignupBean.class.getName()).log(Level.SEVERE, null, ex);
    }

    try {
        student = StudentRepository.read(ds, username);
    } catch (SQLException ex) {
        Logger.getLogger(UserBean.class.getName()).log(Level.SEVERE, null, ex);
    }
    try {
        completedCourses = CourseRepository.readCompletedCourses(ds, student.getId());
    } catch (SQLException ex) {
        Logger.getLogger(UserBean.class.getName()).log(Level.SEVERE, null, ex);
    }
    try {
        //TODO: Filter Completed Courses out of Available Courses
        availableCourses = CourseRepository.readAllCourses(ds);
    } catch (SQLException ex) {
        Logger.getLogger(UserBean.class.getName()).log(Level.SEVERE, null, ex);
    }

}

From source file:com.jd.survey.web.settings.RegularExpressionController.java

@Secured({ "ROLE_ADMIN" })
@RequestMapping(value = "/{id}", params = "form", produces = "text/html")
public String updateForm(@PathVariable("id") Long id, Principal principal, Model uiModel) {
    log.info("updateForm(): id=" + id);
    try {//from   w ww  .  ja  v a 2  s .c o  m
        User user = userService.user_findByLogin(principal.getName());
        populateEditForm(uiModel, surveySettingsService.regularExpression_findById(id), user);
        return "admin/masks/update";
    } catch (Exception e) {
        log.error(e.getMessage(), e);
        throw (new RuntimeException(e));
    }
}

From source file:org.openinfinity.core.security.principal.Identity.java

/**
 * Returns collections of GrantedAuthorities for the user.
 *///  w  ww. ja va  2  s.c om
public Collection<GrantedAuthority> getAuthorities() {
    Collection<GrantedAuthority> grantedAuthorities = new ArrayList<GrantedAuthority>();
    for (Principal principal : getAllPrincipalsForIdentity()) {
        if (principal != null) {
            GrantedAuthority grantedAuthority = new SimpleGrantedAuthority(principal.getName());
            grantedAuthorities.add(grantedAuthority);
        }
    }
    return grantedAuthorities;
}

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

@GET
@Path(value = GPServiceRSPathConfig.GET_ROLE_PERMISSION_PATH)
@Override/*  w ww .  j a  v a  2s .c  o  m*/
public GuiComponentsPermissionMapData getRolePermission(@Auth Principal principal,
        @QueryParam(value = "role") String role, @QueryParam(value = "organization") String organization)
        throws Exception {
    logger.debug("\n\n@@@@@@@@@@@@@@@Executing secure getRolePermission" + " - Principal : {}\n\n",
            principal.getName());
    return super.getRolePermission(role, organization);
}

From source file:org.geosdi.geoplatform.experimental.dropwizard.resources.secure.folder.GPSecureFolderResource.java

@DELETE
@Path(value = GPServiceRSPathConfig.DELETE_FOLDER_PATH)
@Override//  w  w  w .  java2s.  c  om
public Boolean deleteFolder(@Auth Principal principal, @QueryParam(value = "folderID") Long folderID)
        throws Exception {
    logger.debug("\n\n@@@@@@@@@@@@@@@@@Executing secure deleteFolder - " + "Principal : {}\n\n",
            principal.getName());
    return super.deleteFolder(folderID);
}

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

@RequestMapping(method = RequestMethod.POST)
public String changePersonInfo(Model model, @Valid final UserInfoDto userInfoDto,
        final BindingResult bindingResult, final Principal principal) {
    if (bindingResult.hasErrors()) {
        model.addAttribute("postUrl", "/user");
        model.addAttribute("changePasswordLink", "/user/changePassword");
        return "user/personalInfo";
    }//from  www  .ja  v a  2  s  .  c  om
    super.copyDtoIntoDatabase(userInfoDto, bindingResult, userRepository.findByUsername(principal.getName()));
    return "redirect:/";
}