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:cz.lbenda.coursing.server.security.SecurityServiceImpl.java
@Override public void login(String username, String password) { UsernamePasswordAuthenticationToken token = new UsernamePasswordAuthenticationToken(username, password); Authentication authentication = authenticationProvider.authenticate(token); SecurityContextHolder.getContext().setAuthentication(authentication); for (SecurityListener l : listeners) { l.onLogin();// w w w . j a v a 2s. com } }
From source file:org.parancoe.plugins.securityevolution.AuthenticationManagerTest.java
public void testAuthenticateWithUserLocked() { authentication = new UsernamePasswordAuthenticationToken("locked", "locked"); try {/*w w w . j a va 2 s . com*/ authenticationManager.authenticate(authentication); fail("User locked is locked!"); } catch (AuthenticationException e) { assertTrue(e instanceof LockedException); } }
From source file:cz.sohlich.workstack.security.StatelessLoginFilter.java
@Override public Authentication attemptAuthentication(HttpServletRequest request, HttpServletResponse response) throws AuthenticationException, IOException, ServletException { final User user = new ObjectMapper().readValue(request.getInputStream(), User.class); final UsernamePasswordAuthenticationToken loginToken = new UsernamePasswordAuthenticationToken( user.getUsername(), user.getPassword()); return getAuthenticationManager().authenticate(loginToken); }
From source file:org.saiku.web.rest.resources.QueryResourceTest.java
@Before public void setUp() throws Exception { Authentication auth = new UsernamePasswordAuthenticationToken("testuser", null); SecurityContextHolder.getContext().setAuthentication(auth); ss.login(null, "testuser", null); }
From source file:cz.swi2.mendeluis.service.facade.UserFacade.java
@Override public void doLogin(String username) { try {/* w w w . ja v a 2 s .c om*/ Authentication token = new UsernamePasswordAuthenticationToken(username, null); SecurityContextHolder.getContext().setAuthentication(token); } catch (Exception e) { SecurityContextHolder.getContext().setAuthentication(null); } }
From source file:com.github.cmis4j.ws.CmisUsernameTokenValidator.java
@Override protected void verifyPlaintextPassword(UsernameToken usernameToken, RequestData data) throws WSSecurityException { String username = String.valueOf(usernameToken.getName()); String password = String.valueOf(usernameToken.getPassword()); Authentication authentication = new UsernamePasswordAuthenticationToken(username, password); authentication = authenticationManager.authenticate(authentication); if (!authentication.isAuthenticated()) { throw new WSSecurityException(WSSecurityException.FAILED_AUTHENTICATION); }//www .j a v a 2 s .c o m SecurityContextHolder.getContext().setAuthentication(authentication); }
From source file:hsa.awp.admingui.AbstractSecurityTest.java
protected void login(String name, String password) { Authentication auth = new UsernamePasswordAuthenticationToken(name, password); SecurityContextHolder.getContext().setAuthentication(am.authenticate(auth)); System.out.println(auth);//from ww w .j av a2 s. c o m }
From source file:org.cloudfoundry.identity.uaa.authentication.manager.ScopeAuthenticationManagerTest.java
public void testPasswordAuthenticate() throws Exception { UsernamePasswordAuthenticationToken userAuth = new UsernamePasswordAuthenticationToken("username", "password"); OAuth2Authentication auth = new OAuth2Authentication(request, userAuth); Authentication authentication = authenticationManager.authenticate(auth); //false since we don't authenticate the user yet assertFalse(authentication.isAuthenticated()); }
From source file:org.jasig.schedassist.web.register.delegate.DelegateRegistrationHelperTest.java
@Test public void testCurrentDelegateIsIneligibleDefault() { MockCalendarAccount ownerAccount = new MockCalendarAccount(); MockScheduleOwner owner = new MockScheduleOwner(ownerAccount, 1L); IDelegateCalendarAccount delegate = mock(IDelegateCalendarAccount.class); when(delegate.isEligible()).thenReturn(true); DelegateCalendarAccountUserDetailsImpl details = new DelegateCalendarAccountUserDetailsImpl(delegate, owner);//from w w w. j a va 2s. c o m SecurityContext context = new SecurityContextImpl(); context.setAuthentication(new UsernamePasswordAuthenticationToken(details, "")); SecurityContextHolder.setContext(context); DelegateRegistrationHelper helper = new DelegateRegistrationHelper(); Assert.assertFalse(helper.currentDelegateIsIneligible()); }
From source file:org.vader.common.cxf.SpringSecurityUsernameTokenValidator.java
@Override protected void verifyPlaintextPassword(UsernameToken usernameToken, RequestData data) throws WSSecurityException { SecurityContextHolder.clearContext(); final String login = usernameToken.getName(); final String password = usernameToken.getPassword(); if (StringUtils.isBlank(login) || StringUtils.isBlank(password)) { throw new WSSecurityException( String.format("Auth failed for login=[%s], password=[%s]", login, password)); }// w ww.j a va 2 s .com try { final Authentication authentication = authenticationManager .authenticate(new UsernamePasswordAuthenticationToken(login, password)); SecurityContextHolder.getContext().setAuthentication(authentication); } catch (AuthenticationException e) { throw new WSSecurityException( String.format("Auth failed for login=[%s], password=[%s]", login, password), e); } }