Example usage for org.springframework.security.core Authentication getName

List of usage examples for org.springframework.security.core Authentication getName

Introduction

In this page you can find the example usage for org.springframework.security.core Authentication getName.

Prototype

public String getName();

Source Link

Document

Returns the name of this principal.

Usage

From source file:com.rockagen.gnext.service.spring.security.extension.ExAuthenticationHandler.java

/**
 * Authentication success handler/*from   w  w w  . j  a v  a2s  . c o  m*/
 *
 * @param request        request
 * @param response       response
 * @param authentication {@link org.springframework.security.core.Authentication}
 */
public void successHandler(HttpServletRequest request, HttpServletResponse response,
        Authentication authentication) {

    String uid = authentication.getName();
    successRegister(uid, request);
    // Response Token
    String token = exTokenAuthentication.newToken(uid);
    if (CommUtil.isNotBlank(token)) {
        response.setHeader(tokenName, token);
        response.setStatus(HttpServletResponse.SC_OK);
    } else {
        response.setStatus(HttpServletResponse.SC_FORBIDDEN);
    }
}

From source file:cherry.sqlman.tool.load.SqlLoadControllerImpl.java

private void initializeForm(SqlLoadForm form, Integer ref, Authentication auth) {
    if (ref != null) {
        SqlMetadataForm mdForm = metadataService.findById(ref, auth.getName());
        if (mdForm != null) {
            SqlLoadForm f = loadService.findById(ref);
            if (f != null) {
                form.setDatabaseName(f.getDatabaseName());
                form.setSql(f.getSql());
                form.setLockVersion(f.getLockVersion());
                return;
            }/*from w  ww  . j  a  v  a 2 s .  c o  m*/
        }
    }
    form.setDatabaseName(dataSourceDef.getDefaultName());
}

From source file:com.gs.config.MyAuthenticationProvider.java

@Override
public Authentication authenticate(Authentication authentication) throws AuthenticationException {
    UserDetails userDetails = this.customJDBCDaoImpl.loadUserByUsername(authentication.getName());
    //Obtengo los intentos de inicio de sesin hechos por un usuario
    int intentos = usuarioConIntentoFallido.getIntentosUsuario(authentication.getName());
    if (intentos < intentosPosibles && !listUsersLockoutIntentFail.findUserBlockout(authentication.getName())) {
        if (userDetails.isEnabled()) {
            if (userDetails != null && shaPasswordEncoder.isPasswordValid(userDetails.getPassword(),
                    authentication.getCredentials().toString(), null)) {
                usuarioConIntentoFallido.removeUsuario(userDetails.getUsername());
                //Verifico si el usuario ya tiene una sesin abierta, si es as la cierro y le creo su nueva instancia
                verifUserInSession(userDetails.getUsername());
                return new UsernamePasswordAuthenticationToken(userDetails, null, userDetails.getAuthorities());
            }/*from  ww w  .  ja  v a  2  s  . co  m*/
            throw new BadCredentialsException("Bad credentials");
        } else {
            throw new DisabledException("User disabled");
        }
    } else {
        throw new IntentLimitExceeded("limite de intentos excedidos");
    }
}

From source file:com.bigbang.iowservices.beans.LoginController.java

/**
 *
 * Redirects the login request directly to spring security check. Leave this
 * method as it is to properly support spring security.
 *
 * @return//from w  w w  .  j a  va  2  s  . c o  m
 * @throws ServletException
 * @throws IOException
 */
public String doLogin() throws ServletException, IOException {
    ExternalContext context = FacesContext.getCurrentInstance().getExternalContext();

    RequestDispatcher dispatcher = ((ServletRequest) context.getRequest())
            .getRequestDispatcher("/j_spring_security_check");

    dispatcher.forward((ServletRequest) context.getRequest(), (ServletResponse) context.getResponse());

    FacesContext.getCurrentInstance().responseComplete();
    Authentication auth = SecurityContextHolder.getContext().getAuthentication();
    if (auth != null) {
        user = userFacade.getUserInfo(auth.getName());
    }

    System.out.println("user+++ " + user.getUserInformation().getFirstName());
    return "protected";
}

From source file:com.alehuo.wepas2016projekti.controller.ProfileController.java

/**
 * Kuvan selaus/*from  www. j a  va  2s .c  om*/
 * @param a Autentikointi
 * @param uuid Kuvan UUID
 * @param m Malli
 * @param l Lokalisaatio
 * @return
 * @throws UnsupportedEncodingException
 */
@RequestMapping("/photo/{uuid}")
public String viewPhoto(Authentication a, @PathVariable String uuid, Model m, Locale l)
        throws UnsupportedEncodingException {

    UserAccount loggedInUser = userService.getUserByUsername(a.getName());
    m.addAttribute("user", loggedInUser);
    m.addAttribute("image", imageService.findOneImageByUuid(uuid));

    LOG.log(Level.INFO, "Kayttaja ''{0}'' selasi kuvaa ''{1}''.", new Object[] { a.getName(), uuid });
    return "image";
}

From source file:com.realdolmen.rdfleet.webmvc.controllers.rd.OrderCarController.java

@RequestMapping(value = "/submitOrder", method = RequestMethod.POST)
public String submitOrder(@ModelAttribute("employeeCar") EmployeeCar employeeCar,
        @ModelAttribute("order") Order order, SessionStatus status) {
    if (!canOrderNewCar() || order == null)
        return "redirect:/index";
    Authentication auth = SecurityContextHolder.getContext().getAuthentication();
    employeeService.createEmployeeCarAndDelegateOrderForEmployee(auth.getName(), order);
    status.setComplete();/*from ww w.ja  v  a2 s.c  om*/
    return "redirect:/index";
}

From source file:cn.edu.zjnu.acm.judge.controller.MailController.java

@GetMapping("/mail")
@SuppressWarnings("AssignmentToMethodParameter")
public String mail(Model model, @RequestParam(value = "size", defaultValue = "20") int size,
        @RequestParam(value = "start", defaultValue = "1") long start, Authentication authentication) {
    if (start <= 0) {
        start = 1;/*from  w ww .  ja va 2s .  c  om*/
    }
    String currentUserId = authentication != null ? authentication.getName() : null;

    List<Mail> mails = mailMapper.findAllByTo(currentUserId, start - 1, size);

    model.addAttribute("userId", currentUserId);
    model.addAttribute("mails", mails);
    model.addAttribute("size", size);
    model.addAttribute("start", start);
    return "mails/list";
}

From source file:com.packt.blog.dao.Impl.UserDaoImpl.java

@Override
public void addComment(int postId, Comment comment) {
    Post post = (Post) sessionFactory.getCurrentSession().get(Post.class, postId);
    System.out.println("Object founds" + post.getTitle() + " " + comment.getId());
    comment.setId(0);/*ww w . j  a v a2  s .co m*/
    Authentication auth = SecurityContextHolder.getContext().getAuthentication();
    String username = auth.getName();

    comment.setCommenter(username);
    post.addComment(comment);
    sessionFactory.getCurrentSession().update(post);
    //  sessionFactory.getCurrentSession().persist(comment);
}

From source file:org.unidle.service.UserServiceImpl.java

@Override
@Transactional(readOnly = true)/*from   ww  w.j  av  a 2s . c  o  m*/
public User currentUser() {

    final Authentication authentication = SecurityContextHolder.getContext().getAuthentication();

    if (authentication == null) {
        return null;
    }

    final String uuid = authentication.getName();

    return userRepository.findOne(UUID.fromString(uuid));
}