List of usage examples for org.springframework.security.authentication UsernamePasswordAuthenticationToken UsernamePasswordAuthenticationToken
public UsernamePasswordAuthenticationToken(Object principal, Object credentials)
UsernamePasswordAuthenticationToken
, as the #isAuthenticated() will return false
. From source file:org.jasig.schedassist.web.register.delegate.DelegateRegistrationHelperTest.java
@Test public void testCurrentDelegateIsIneligibleTrue() { MockCalendarAccount ownerAccount = new MockCalendarAccount(); MockScheduleOwner owner = new MockScheduleOwner(ownerAccount, 1L); IDelegateCalendarAccount delegate = mock(IDelegateCalendarAccount.class); when(delegate.isEligible()).thenReturn(false); DelegateCalendarAccountUserDetailsImpl details = new DelegateCalendarAccountUserDetailsImpl(delegate, owner);/*w ww . java 2 s . co m*/ SecurityContext context = new SecurityContextImpl(); context.setAuthentication(new UsernamePasswordAuthenticationToken(details, "")); SecurityContextHolder.setContext(context); DelegateRegistrationHelper helper = new DelegateRegistrationHelper(); Assert.assertTrue(helper.currentDelegateIsIneligible()); }
From source file:it.infn.mw.iam.test.repository.IamTokenRepositoryTests.java
private OAuth2Authentication oauth2Authentication(ClientDetailsEntity client, String username) { String[] scopes = {};//from w w w .ja va 2 s . c o m Authentication userAuth = null; if (username != null) { scopes = SCOPES; userAuth = new UsernamePasswordAuthenticationToken(username, ""); } MockOAuth2Request req = new MockOAuth2Request(client.getClientId(), scopes); OAuth2Authentication auth = new OAuth2Authentication(req, userAuth); return auth; }
From source file:org.xaloon.wicket.security.spring.SpringSecurityFacade.java
public AuthenticationToken authenticate(String username, String password) { UsernamePasswordAuthenticationToken authenticationRequestToken = new UsernamePasswordAuthenticationToken( username, password);/*from w w w . j av a 2 s. co m*/ return authenticateInternal(authenticationRequestToken); }
From source file:com.tasktop.c2c.server.common.service.tests.http.MultiUserClientHttpRequestFactoryTest.java
@Test public void testAuthCredentialsChanged() throws URISyntaxException, IOException { SecurityContextHolder.getContext().setAuthentication(new UsernamePasswordAuthenticationToken("foo", "123")); URI uri = new URI("http://localhost/test"); ClientHttpRequest request = requestFactory.createRequest(uri, HttpMethod.GET); HttpClient client = getHttpClient(request); assertNotNull(client);// ww w . j a v a 2s. c o m client.getState().addCookie(new Cookie("test.com", "sessionid", "123")); assertEquals(1, client.getState().getCookies().length); SecurityContextHolder.getContext() .setAuthentication(new UsernamePasswordAuthenticationToken("foo", "1234")); ClientHttpRequest request2 = requestFactory.createRequest(uri, HttpMethod.GET); HttpClient client2 = getHttpClient(request); assertSame(client, client2); assertEquals(0, client.getState().getCookies().length); }
From source file:com.gcrm.security.AuthenticationFilter.java
@Override public Authentication attemptAuthentication(HttpServletRequest request, HttpServletResponse response) throws AuthenticationException { if (!request.getMethod().equals("POST")) { throw new AuthenticationServiceException("Authentication method not supported: " + request.getMethod()); }//from w ww. j av a 2s . com String username = obtainUsername(request); String password = obtainPassword(request); // Validates username and password username = username.trim(); String localValue = obtainLanguage(request); String[] locals = localValue.split("_"); Locale locale = new Locale(locals[0], locals[1]); request.getSession().setAttribute("WW_TRANS_I18N_LOCALE", locale); request.getSession().setAttribute("locale", localValue); Locale.setDefault(locale); User user = UserUtil.getUser(username); Md5PasswordEncoder encoder = new Md5PasswordEncoder(); password = encoder.encodePassword(password, AuthenticationFilter.SALT); if (user == null || !user.getPassword().equals(password)) { ResourceBundle rb = CommonUtil.getResourceBundle(); String errorMessage = rb.getString("error.login.denied"); throw new AuthenticationServiceException(errorMessage); } UsernamePasswordAuthenticationToken authRequest = new UsernamePasswordAuthenticationToken(username, password); setDetails(request, authRequest); // return authRequest; return this.getAuthenticationManager().authenticate(authRequest); }
From source file:org.apigw.appmanagement.revision.ApplicationManagementRevisionListenerTest.java
private SecurityContext createSecurityContext(final String username, String... roles) { final List<SimpleGrantedAuthority> authorities = new ArrayList<>(); for (String role : roles) { authorities.add(new SimpleGrantedAuthority(role)); }/*www . j a v a2 s .co m*/ return new SecurityContext() { @Override public Authentication getAuthentication() { return new UsernamePasswordAuthenticationToken(new User(username, "", authorities), null); } @Override public void setAuthentication(Authentication authentication) { } }; }
From source file:org.unidle.service.UserServiceImplTest.java
@Test public void testCurrentUser() throws Exception { SecurityContextHolder.getContext()//from ww w . ja v a2s. c om .setAuthentication(new UsernamePasswordAuthenticationToken(user.getUuid(), null)); final User result = subject.currentUser(); assertThat(result).isEqualTo(user); }
From source file:com.trenako.web.security.SpringSecurityContextTests.java
private Authentication usernamePasswordAuthToken() { Account user = new Account.Builder("mail@mail.com").displayName("bob").password("pa$$word").build(); AccountDetails principal = new AccountDetails(user); return new UsernamePasswordAuthenticationToken(principal, null); }
From source file:business.SelectionControllerTests.java
protected UserAuthenticationToken getPalga() { User user = userService.findByUsername("test+palga@dntp.thehyve.nl"); Authentication authentication = new UsernamePasswordAuthenticationToken(user, "palga"); // because of password tests return (UserAuthenticationToken) authenticationProvider.authenticate(authentication); }
From source file:business.ProcessControllerTests.java
protected UserAuthenticationToken getPalga() { User user = userService.findByUsername("test+palga@dntp.thehyve.nl"); user.setPassword(passwordService.getEncoder().encode("palga")); // because of password tests userService.save(user);/*from w w w .ja v a2 s.c o m*/ Authentication authentication = new UsernamePasswordAuthenticationToken(user, "palga"); return (UserAuthenticationToken) authenticationProvider.authenticate(authentication); }