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

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

Introduction

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

Prototype

Object getCredentials();

Source Link

Document

The credentials that prove the principal is correct.

Usage

From source file:com.companyname.extension.PlatAuthentication.java

public static Authentication getPlatAuthentication(Authentication authentication) {

    if (authentication == null) {
        return null;
    }/*from  w w w.j a v  a 2 s. c o  m*/

    PlatAuthentication auth = new PlatAuthentication(authentication.getPrincipal(),
            authentication.getCredentials(), authentication.getAuthorities());

    BeanUtils.copyProperties(authentication, auth, new String[] { "authenticated" });

    return auth;
}

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());
    }//w w w.j av a2s. co m
    throw new BadCredentialsException("Bad Credentials");
}

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

@Override
public Authentication authenticate(Authentication a) throws AuthenticationException {
    String email = a.getName();/*w w  w  .  ja v  a  2 s.  c  o  m*/
    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);
        }
        throw new AuthenticationException("Password for '" + email + "' not correct.") {
        };
    }

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

From source file:ar.com.zauber.commons.social.facebook.security.FacebookAuthenticationProvider.java

/** @see AuthenticationProvider#authenticate(Authentication) */
public final Authentication authenticate(final Authentication authentication) throws AuthenticationException {
    Validate.notNull(authentication);/*  ww  w . j ava 2  s . co  m*/

    Long fbUID = (Long) authentication.getCredentials();
    UserDetails userDetails = this.userDetailsService.loadUserByFacebookUID(fbUID);
    return new FacebookAuthenticationToken(fbUID, userDetails, userDetails.getAuthorities());
}

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  ww w.j  a  v a  2 s. com*/
        return null;
    }
}

From source file:nz.net.orcon.kanban.security.NullAuthenticationProvider.java

@Override
public Authentication authenticate(Authentication authIn) throws AuthenticationException {

    String username = authIn.getName();
    String password = authIn.getCredentials().toString();
    try {//from www.j  a v  a2s  .c o  m
        List<GrantedAuthority> grantedAuths = this.securityTool.getRoles(username);
        Authentication auth = new UsernamePasswordAuthenticationToken(username, password, grantedAuths);
        logger.info("Authenticated User: " + username);
        return auth;
    } catch (Exception e) {
        logger.error("Authentication Exception: " + username, e);
    }
    return null;
}

From source file:com.muk.security.AuthEventListener.java

@Override
public void onApplicationEvent(AuthorizedEvent event) {
    final Exchange exchange = (Exchange) event.getSource();

    if (!RestConstants.Rest.anonymousToken.equals(event.getAuthentication().getName())
            && exchange.getIn().getHeader(HttpHeaders.AUTHORIZATION, String.class) != null) {
        final Authentication currentAuthentication = event.getAuthentication();
        final String currentTokenRepresentation = (String) currentAuthentication.getCredentials();
        final String incomingTokenRepresentation = StringUtils
                .substringAfter(exchange.getIn().getHeader(HttpHeaders.AUTHORIZATION, String.class), "Bearer ");

        if (!currentTokenRepresentation.equals(incomingTokenRepresentation)) {
            exchange.getOut().getHeaders().put(RestConstants.Headers.refreshToken, currentTokenRepresentation);
        }//from   w  w  w  . java 2s  .  com
    }
}

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);
    }//from ww  w . ja v a 2s .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:com.trenako.web.security.SpringSignupServiceTests.java

@Test
public void shouldAuthenticateAccounts() {
    SecurityContext mockContext = mock(SecurityContext.class);

    Account account = buildAccount();/*from  w  w  w.  ja v a 2 s.  c o m*/
    AccountDetails accountDetails = new AccountDetails(account);

    // inject the mock security context
    service.setSecurityContext(mockContext);
    service.authenticate(account);

    ArgumentCaptor<Authentication> arg = ArgumentCaptor.forClass(Authentication.class);
    verify(mockContext, times(1)).setAuthentication(arg.capture());
    Authentication auth = arg.getValue();
    assertEquals("pa$$word", auth.getCredentials());
    assertEquals(accountDetails, auth.getPrincipal());
    assertEquals(account.getRoles().toString(), auth.getAuthorities().toString());
}

From source file:oobbit.security.JpaAuthenticationProvider.java

@Override
public Authentication authenticate(Authentication a) throws AuthenticationException {
    String username = a.getPrincipal().toString();
    String password = a.getCredentials().toString();

    try {/*from w ww  .j  ava 2  s .c o  m*/
        User user = users.attemptLogin(username, password);
        return new UsernamePasswordAuthenticationToken(user.getUsername(), password,
                accessLevelToGrantedAuthority.accessLevelToSimpleGrantedAuthorityList(user.getAccessLevel()));
    } catch (SQLException ex) {
        Logger.getLogger(JpaAuthenticationProvider.class.getName()).log(Level.SEVERE,
                "SQLException was thrown while authenticating a user in JpaAuthenticationProvider.", ex);
    } catch (FailedLoginException ex) {
        Logger.getLogger(JpaAuthenticationProvider.class.getName()).log(Level.SEVERE,
                "FailedLoginException was thrown while tyring to authenticate a user.", ex);
    }

    throw new AuthenticationException("Unable to authenticate user " + username) {
    };
}