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.lennonjesus.auth.security.provider.SecurityAuthenticationProvider.java

@Override
public Authentication authenticate(Authentication authentication) throws AuthenticationException {
    String name = authentication.getName();
    String password = authentication.getCredentials().toString();

    if (name.equals("user") && password.equals("user")) {
        List<GrantedAuthority> grantedAuths = new ArrayList<GrantedAuthority>();
        grantedAuths.add(new SimpleGrantedAuthority("ROLE_USER"));
        return new UsernamePasswordAuthenticationToken(name, password, grantedAuths);
    }/*  ww w . j a va 2  s.  c  om*/
    if (name.equals("admin") && password.equals("admin")) {
        List<GrantedAuthority> grantedAuths = new ArrayList<GrantedAuthority>();
        grantedAuths.add(new SimpleGrantedAuthority("ROLE_ADMIN"));
        return new UsernamePasswordAuthenticationToken(name, password, grantedAuths);
    }

    return null;

}

From source file:org.snippr.business.dao.UserDAO.java

@Override
@Transactional(readOnly = true)/*from w w  w.  ja v a 2s.c o m*/
public User getCurrentUser() {
    Authentication auth = SecurityUtil.getAuthentication();
    return getByUsername(auth.getName());
}

From source file:br.com.itw.qopsearch.api.security.ScaAuthenticationProvider.java

@Override
public Authentication authenticate(Authentication authentication) throws AuthenticationException {
    String login = authentication.getName().trim().toLowerCase();
    //        String password = authentication.getCredentials().toString();

    //        byte[] decodedBytes = Base64.decode(password.getBytes());
    //        String decodedPasswd = new String(decodedBytes, Charset.forName("UTF-8"));

    if (EmailValidator.getInstance().isValid(login)) {
        //        if (ValidarEmail.validate(login) && login.split("\\@")[0].equals(decodedPasswd)) {
        List<GrantedAuthority> grantedAuths = new ArrayList<>();
        grantedAuths.add(new SimpleGrantedAuthority("ROLE_USER"));
        Authentication auth = new UsernamePasswordAuthenticationToken(login, null, grantedAuths);
        return auth;
    } else {//from  ww w  .j  av  a2  s.c  o  m
        return null;
    }
}

From source file:am.ik.categolj2.api.user.UserRestController.java

@RequestMapping(value = "me", method = RequestMethod.GET, headers = Categolj2Headers.X_ADMIN)
public UserResource getMe(Authentication authentication) {
    return getUser(authentication.getName());
}

From source file:org.obp.handlers.AuthenticationSuccessful.java

@Override
public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response,
        Authentication authentication) throws IOException, ServletException {
    logService.logUserLoggedIn(authentication.getName());
    super.onAuthenticationSuccess(request, response, authentication);
}

From source file:psiprobe.controllers.apps.ReloadContextController.java

@Override
protected void executeAction(String contextName) throws Exception {
    Context context = getContainerWrapper().getTomcatContainer().findContext(contextName);
    if (context != null) {
        context.reload();//from www .j  a v  a 2  s . co m

        // Logging action
        Authentication auth = SecurityContextHolder.getContext().getAuthentication();
        String name = auth.getName(); // get username logger
        logger.info(getMessageSourceAccessor().getMessage("probe.src.log.reload"), name, contextName);
    }
}

From source file:by.bsuir.finance.controllers.SalaryController.java

@RequestMapping(value = "/view")
public ModelAndView view() {
    ModelAndView model = new ModelAndView("salary/view");
    Authentication auth = SecurityContextHolder.getContext().getAuthentication();
    String name = auth.getName(); //get logged in username
    List<Salary> salarys = salaryService.findByUsername(name);
    model.addObject("salaries", salarys);
    return model;
}

From source file:com.sasav.blackjack.controller.AccountController.java

@RequestMapping(value = "/deposit", method = RequestMethod.POST)
public ModelAndView deposit(AccountTransaction deposit) {
    Authentication auth = SecurityContextHolder.getContext().getAuthentication();
    String login = auth.getName();
    accountMaster.depositUserAccount(login, deposit.getAmount());
    ModelAndView mv = new ModelAndView("redirect:game");
    return mv;/* w  ww .  j a va  2 s.c om*/
}

From source file:com.sasav.blackjack.controller.AccountController.java

@RequestMapping(value = "/deposit", method = RequestMethod.GET)
public ModelAndView depositPage() {
    Authentication auth = SecurityContextHolder.getContext().getAuthentication();
    String login = auth.getName();
    AccountTransaction deposit = accountMaster.createTransactionForUser(login);
    ModelAndView mv = new ModelAndView("deposit");
    mv.addObject("depositAcc", deposit);
    return mv;//from  w  w  w.  j  a  v a  2s.c  om
}

From source file:com.epam.ta.reportportal.auth.permissions.ProjectLeadPermission.java

/**
 * Validates this is {@link ProjectRole#LEAD} or higher authority in the
 * authentication context//from   ww  w.  ja v  a 2 s  .  co  m
 */
@Override
protected boolean checkAllowed(@NotNull Authentication authentication, @NotNull Project project) {
    return project.getUsers().get(authentication.getName()).getProjectRole().compareTo(ProjectRole.LEAD) >= 0;
}