Example usage for org.springframework.security.authentication UsernamePasswordAuthenticationToken UsernamePasswordAuthenticationToken

List of usage examples for org.springframework.security.authentication UsernamePasswordAuthenticationToken UsernamePasswordAuthenticationToken

Introduction

In this page you can find the example usage for org.springframework.security.authentication UsernamePasswordAuthenticationToken UsernamePasswordAuthenticationToken.

Prototype

public UsernamePasswordAuthenticationToken(Object principal, Object credentials) 

Source Link

Document

This constructor can be safely used by any code that wishes to create a UsernamePasswordAuthenticationToken, as the #isAuthenticated() will return false.

Usage

From source file:org.cloudfoundry.identity.uaa.oauth.ClientInfoEndpointTests.java

@Test
public void testClientinfo() {
    Mockito.when(clientDetailsService.loadClientByClientId("foo")).thenReturn(foo);
    ClientDetails client = endpoint.clientinfo(new UsernamePasswordAuthenticationToken("foo", "<NONE>"));
    assertEquals("foo", client.getClientId());
    assertNull(client.getClientSecret());
    assertTrue(client.getAdditionalInformation().isEmpty());
}

From source file:org.cloudfoundry.identity.api.web.ApiControllerTests.java

@Test
public void testWithUser() throws Exception {
    controller.setInfo(new ClassPathResource("info.tmpl"));
    HashMap<String, Object> model = new HashMap<String, Object>();
    View view = controller.info(model, new UsernamePasswordAuthenticationToken("marissa", "<NONE>"));
    MockHttpServletResponse response = new MockHttpServletResponse();
    view.render(model, new MockHttpServletRequest(), response);
    String content = response.getContentAsString();
    assertTrue("Wrong content: " + content, content.contains("\n  \"user\": \"marissa\""));
}

From source file:org.parancoe.plugins.securityevolution.AuthenticationManagerTest.java

/**
 * Test method for/* w w  w  .j  a v a  2  s.com*/
 * {@link org.springframework.security.authentication.AuthenticationManager#authenticate(org.springframework.security.core.Authentication)}.
 */
public void testAuthenticate() {
    authentication = new UsernamePasswordAuthenticationToken("parancoe", "parancoe");
    Authentication result = authenticationManager.authenticate(authentication);
    assertTrue(result.isAuthenticated());
}

From source file:com.khs.sherpa.spring.SpringAuthentication.java

public String[] authenticate(String username, String password, HttpServletRequest request,
        HttpServletResponse response) {//  w  w  w  .j av a2  s.  co  m
    UsernamePasswordAuthenticationToken token = new UsernamePasswordAuthenticationToken(username, password);

    Authentication authentication = null;

    try {
        authentication = authenticationManager.authenticate(token);
    } catch (AuthenticationException e) {
        throw new SherpaInvalidUsernamePassword("username and/or password is incorrect");
    }

    if (authentication.isAuthenticated() == false) {
        throw new SherpaInvalidUsernamePassword("username and/or password is incorrect");
    }

    List<String> roles = new ArrayList<String>();
    for (GrantedAuthority auth : authentication.getAuthorities()) {
        roles.add(auth.getAuthority());
    }

    SecurityContextImpl context = new SecurityContextImpl();
    context.setAuthentication(authentication);

    SecurityContextHolder.setContext(context);

    request.getSession().setAttribute("SPRING_SECURITY_CONTEXT_KEY", context);

    return roles.toArray(new String[roles.size()]);

}

From source file:com.seyren.api.bean.UsermanagementBean.java

@Override
public Response authenticateUser(User user) {
    UsernamePasswordAuthenticationToken authenticationToken = new UsernamePasswordAuthenticationToken(
            user.getUsername(), user.getPassword());
    Authentication authentication = this.authManager.authenticate(authenticationToken);
    SecurityContextHolder.getContext().setAuthentication(authentication);
    UserDetails details = this.userDetailsService.loadUserByUsername(user.getUsername());
    return Response.ok(new com.seyren.core.domain.Token(Token.createToken(details))).build();
}

From source file:org.exoplatform.acceptance.security.CrowdAuthenticationProviderMockTest.java

@Test
public void testAuthenticateAdministrator() throws Exception {
    crowdAuthenticationProviderMock.authenticate(new UsernamePasswordAuthenticationToken("admin", "admin"));
}

From source file:fr.xebia.audit.AuditAspectTest.java

@Before
public void before() {

    MockHttpServletRequest request = new MockHttpServletRequest();
    request.setRemoteAddr("10.0.0.1");
    WebAuthenticationDetails details = new WebAuthenticationDetails(request);
    UsernamePasswordAuthenticationToken authentication = new UsernamePasswordAuthenticationToken("ze-principal",
            "ze-credentials");
    authentication.setDetails(details);/*from   ww  w .  j  a va  2 s  . c  o m*/
    SecurityContextHolder.getContext().setAuthentication(authentication);

}

From source file:exanpe.t5.lib.demo.pages.comp.AuthorizeAnnotationTest.java

private void authenticate(String role) {
    Authentication request = new UsernamePasswordAuthenticationToken(role, role);
    Authentication result = authenticationManager.authenticate(request);
    SecurityContextHolder.getContext().setAuthentication(result);
}

From source file:com.acc.storefront.security.impl.DefaultAutoLoginStrategy.java

@Override
public void login(final String username, final String password, final HttpServletRequest request,
        final HttpServletResponse response) {
    final UsernamePasswordAuthenticationToken token = new UsernamePasswordAuthenticationToken(username,
            password);/*ww  w.ja  v  a 2s . c  o m*/
    token.setDetails(new WebAuthenticationDetails(request));
    try {
        final Authentication authentication = getAuthenticationManager().authenticate(token);
        SecurityContextHolder.getContext().setAuthentication(authentication);
        getCustomerFacade().loginSuccess();
        getGuidCookieStrategy().setCookie(request, response);
        getRememberMeServices().loginSuccess(request, response, token);
    } catch (final Exception e) {
        SecurityContextHolder.getContext().setAuthentication(null);
        LOG.error("Failure during autoLogin", e);
    }
}

From source file:com.tasktop.c2c.server.profile.tests.service.WebDavServiceClientTest.java

@Before
public void setup() {
    client.setRestTemplate(restTemplate);

    SecurityContextHolder.getContext()//w  w  w .j  a  va 2s .  co m
            .setAuthentication(new UsernamePasswordAuthenticationToken("jdoe", "Welcome1"));
    client.setBaseUrl("http://localhost:8081/s/test/maven/");
}