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.isalnikov.config.SampleAuthenticationManager.java

@Override
public Authentication authenticate(Authentication auth) throws AuthenticationException {
    if (auth.getName().equals(auth.getCredentials())) {

        UserAuthorizationToken token = (UserAuthorizationToken) auth;

        return new UserAuthorizationToken(token.getName(), token.getPassword(), token.getTerminalId(),
                token.getAuthorities());
    }//from w ww. j  av  a  2s.co  m
    throw new BadCredentialsException("Bad Credentials");
}

From source file:org.elasticstore.server.service.impl.ElasticSearchAuthenticationManager.java

@Override
public Authentication authenticate(Authentication authentication) throws AuthenticationException {
    final String username = authentication.getName();
    return new UsernamePasswordAuthenticationToken(authentication.getPrincipal(),
            authentication.getCredentials());
}

From source file:scratch.cucumber.example.security.servlet.UserAuthenticationFactory.java

@Override
public void add(HttpServletResponse response, Authentication authentication) {
    httpServletRequestBinder.add(response, authentication.getName());
}

From source file:exanpe.t5.lib.demo.security.SameUserPasswordAP.java

public Authentication authenticate(Authentication authentication) throws AuthenticationException {
    String username = authentication.getName();
    GrantedAuthorityImpl ga = new GrantedAuthorityImpl("ROLE_" + username);
    List<GrantedAuthority> l = new ArrayList<GrantedAuthority>();
    l.add(ga);//from   www . j  av  a2 s  .  c om

    return new UsernamePasswordAuthenticationToken(new User(username, username, true, true, true, true, l),
            username, l);
}

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

@RequestMapping(value = "/username", method = RequestMethod.GET)
public @ResponseBody String getUserName() {
    Authentication auth = SecurityContextHolder.getContext().getAuthentication();
    String name = auth.getName(); //get logged in username
    return name;/*from   w  w w . j  av a 2  s .c  om*/
}

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

@Override
protected void executeAction(String contextName) throws Exception {
    getContainerWrapper().getTomcatContainer().start(contextName);

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

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

@Override
protected void executeAction(String contextName) throws Exception {
    getContainerWrapper().getTomcatContainer().stop(contextName);

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

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

@RequestMapping(value = "userinfo")
public ModelAndView getUserInfo() {
    ModelAndView model = new ModelAndView("userinfo");
    Authentication auth = SecurityContextHolder.getContext().getAuthentication();
    String name = auth.getName(); //get logged in username
    mdoel.addObject("userinfo", infoService.getCurrentUserInfo(name));
    return userinfo;
}

From source file:com.tlantic.integration.authentication.service.security.UserAuthProviderService.java

@Override
public Authentication authenticate(Authentication a) throws AuthenticationException {
    String email = a.getName();
    String password = a.getCredentials().toString();
    User user = authConfigService.getUser(email);
    if (null != user) {
        if (passwordEncoder.matches(password, user.getPassword())) {
            List<GrantedAuthority> roleAuthority = authConfigService.getRights(user);
            return signInUser(user, roleAuthority);
        }/*from   w  w w. ja  v  a2  s . c o  m*/
        throw new AuthenticationException("Password for '" + email + "' not correct.") {
        };
    }

    throw new AuthenticationException("Could not find user with name '" + email + "'") {
    };
}

From source file:com.vaadinspring.components.CustomAuthenticationProvider.java

@Override
public Authentication authenticate(Authentication authentication) throws AuthenticationException {
    String name = authentication.getName();
    String password = authentication.getCredentials().toString();
    Users user = userPresenter.getUser(name);
    if (user.getLogin() != null && password.equals(user.getPassword())) {
        List<GrantedAuthority> grantedAuths = new ArrayList<GrantedAuthority>(1);
        grantedAuths.add(new SimpleGrantedAuthority(user.getRole().getRole_name()));
        Authentication auth = new UsernamePasswordAuthenticationToken(name, password, grantedAuths);
        SecurityContextHolder.getContext().setAuthentication(auth);
        return auth;
    } else {/*from  w ww.  j ava  2  s. c om*/
        return null;
    }
}