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:sample.contact.ClientApplication.java

public static void main(String[] args) {
    String username = System.getProperty("username", "");
    String password = System.getProperty("password", "");
    String nrOfCallsString = System.getProperty("nrOfCalls", "");

    if ("".equals(username) || "".equals(password)) {
        System.out.println(/* w  ww  . java  2s  .  c  om*/
                "You need to specify the user ID to use, the password to use, and optionally a number of calls "
                        + "using the username, password, and nrOfCalls system properties respectively. eg for user rod, "
                        + "use: -Dusername=rod -Dpassword=koala' for a single call per service and "
                        + "use: -Dusername=rod -Dpassword=koala -DnrOfCalls=10 for ten calls per service.");
        System.exit(-1);
    } else {
        int nrOfCalls = 1;

        if (!"".equals(nrOfCallsString)) {
            nrOfCalls = Integer.parseInt(nrOfCallsString);
        }

        ListableBeanFactory beanFactory = new FileSystemXmlApplicationContext("clientContext.xml");
        ClientApplication client = new ClientApplication(beanFactory);

        client.invokeContactService(new UsernamePasswordAuthenticationToken(username, password), nrOfCalls);
        System.exit(0);
    }
}

From source file:fi.helsinki.opintoni.security.TestSecurityContext.java

public static SecurityContext studentSecurityContext() {
    SecurityContext securityContext = SecurityContextHolder.createEmptyContext();
    securityContext.setAuthentication(new UsernamePasswordAuthenticationToken("opiskelija", "password"));
    return securityContext;
}

From source file:fi.helsinki.opintoni.security.TestSecurityContext.java

public static SecurityContext teacherSecurityContext() {
    SecurityContext securityContext = SecurityContextHolder.createEmptyContext();
    securityContext.setAuthentication(new UsernamePasswordAuthenticationToken("opettaja", "password"));
    return securityContext;
}

From source file:uk.ac.ebi.emma.controller.GeneManagementDetailControllerTest.java

@BeforeClass
public static void setUpClass() {
    SecurityContextHolder.getContext().setAuthentication(new UsernamePasswordAuthenticationToken("test", ""));
}

From source file:fr.mael.microrss.BaseTest.java

protected void login(Integer id) {
    User user = userService.get(id);/*ww  w. j  ava2 s  .  c  o  m*/
    SecurityContextHolder.getContext()
            .setAuthentication(new UsernamePasswordAuthenticationToken(user, "admin"));
}

From source file:fi.helsinki.opintoni.security.TestSecurityContext.java

public static SecurityContext hybridUserSecurityContext() {
    SecurityContext securityContext = SecurityContextHolder.createEmptyContext();
    securityContext.setAuthentication(new UsernamePasswordAuthenticationToken("hybriduser", "password"));
    return securityContext;
}

From source file:com.swordcode.webcore.security.server.SecurityService.java

@Async
public void signIn(String username, String password, FutureCallback<Authentication> callback) {
    try {/*w  w w. j  ava  2s  .c  om*/
        Authentication request = new UsernamePasswordAuthenticationToken(username, password);
        Authentication result = _config.getAuthenticationManager().authenticate(request);
        callback.onSuccess(result);
    } catch (Throwable t) {
        callback.onFailure(t);
    }
}

From source file:com.qpark.eip.core.spring.security.EipUserDetailsService.java

/**
 * @param userDetailService/*w ww .jav  a 2s  . co m*/
 * @param userName
 * @return
 */
public static boolean setSecurityContextHolderAuthentication(final EipUserProvider userDetailService,
        final String userName) {
    boolean doLogin = SecurityContextHolder.getContext().getAuthentication() == null;
    if (doLogin) {
        User user = userDetailService.getUser(userName);
        SecurityContextHolder.getContext()
                .setAuthentication(new UsernamePasswordAuthenticationToken(user, user.getPassword()));
    }
    return doLogin;
}

From source file:de.thm.arsnova.entities.TestUser.java

public TestUser(String username) {
    super(new UsernamePasswordAuthenticationToken(username, "secret"));
}

From source file:org.cloudfoundry.identity.app.web.TreeControllerTests.java

@Test
@Ignore//from  w ww  .j av  a  2 s .  com
public void testItems() throws Exception {
    ExtendedModelMap model = new ExtendedModelMap();
    treeController.apps(model, new UsernamePasswordAuthenticationToken("dave", "foo"));
    MapWrapper wrapper = new MapWrapper(model.get("items"));
    System.err.println(wrapper);
    assertEquals("spring", wrapper.get("[0].staging.model"));
}