use of org.springframework.security.authentication.UsernamePasswordAuthenticationToken in project opennms by OpenNMS.
the class RadiusAuthenticationProviderTest method doTestRetrieveUserMultipleTimes.
public void doTestRetrieveUserMultipleTimes(RadiusAuthenticator authenticator) {
RadiusAuthenticationProvider provider = new RadiusAuthenticationProvider(m_radiusServer, m_sharedSecret);
RadiusAuthenticator authTypeClass = authenticator;
provider.setAuthTypeClass(authTypeClass);
provider.setRolesAttribute("Unknown-VSAttribute(5813:1)");
UsernamePasswordAuthenticationToken token = new UsernamePasswordAuthenticationToken(m_principal, m_credentials);
provider.retrieveUser(m_username, token);
provider.retrieveUser(m_username, token);
provider.retrieveUser(m_username, token);
provider.retrieveUser(m_username, token);
provider.retrieveUser(m_username, token);
provider.retrieveUser(m_username, token);
}
use of org.springframework.security.authentication.UsernamePasswordAuthenticationToken in project opennms by OpenNMS.
the class SimpleBackEndTest method testBackendWithBasicAuth.
@Test
@JUnitHttpServer(port = 9162, basicAuth = true, webapps = @Webapp(context = "/", path = "src/test/resources/simple-test-webapp"))
public void testBackendWithBasicAuth() throws Exception {
SecurityContextHolder.getContext().setAuthentication(new UsernamePasswordAuthenticationToken("testuser", "testpassword"));
assertNotNull(m_authBackEnd);
assertEquals("first get should be 0", 0, m_authBackEnd.getCount());
assertEquals("second should be 1", 1, m_authBackEnd.getCount());
}
use of org.springframework.security.authentication.UsernamePasswordAuthenticationToken in project opennms by OpenNMS.
the class AuthenticationIT method testAuthenticateTempUser.
@Test
public void testAuthenticateTempUser() throws Exception {
OnmsUser user = new OnmsUser("tempuser");
user.setFullName("Temporary User");
user.setPassword("18126E7BD3F84B3F3E4DF094DEF5B7DE");
user.setDutySchedule(Arrays.asList("MoTuWeThFrSaSu800-2300"));
m_userManager.save(user);
org.springframework.security.core.Authentication authentication = new UsernamePasswordAuthenticationToken("tempuser", "mike");
org.springframework.security.core.Authentication authenticated = m_provider.authenticate(authentication);
assertNotNull("authenticated Authentication object not null", authenticated);
Collection<? extends GrantedAuthority> authorities = authenticated.getAuthorities();
assertNotNull("GrantedAuthorities should not be null", authorities);
assertEquals("GrantedAuthorities size", 1, authorities.size());
assertContainsAuthority(Authentication.ROLE_USER, authorities);
}
use of org.springframework.security.authentication.UsernamePasswordAuthenticationToken in project SI2016_TIM6 by SoftverInzenjeringETFSA.
the class TokenAuthenticationService method getAuthentication.
public static Authentication getAuthentication(HttpServletRequest request) {
ServletContext servletContext = request.getServletContext();
WebApplicationContext webApplicationContext = WebApplicationContextUtils.getWebApplicationContext(servletContext);
studentRepository = webApplicationContext.getBean(StudentRepository.class);
String token = request.getHeader(HEADER_STRING);
if (token != null) {
// parse the token.
String user = Jwts.parser().setSigningKey(SECRET).parseClaimsJws(token.replace(TOKEN_PREFIX, "")).getBody().getSubject();
Student student = studentRepository.findStudentByUsername(user);
Collection<GrantedAuthority> authorities = new ArrayList<>();
if (student != null) {
authorities.add(new SimpleGrantedAuthority("ROLE_STUDENT"));
}
return user != null ? new UsernamePasswordAuthenticationToken(user, null, authorities) : null;
}
return null;
}
use of org.springframework.security.authentication.UsernamePasswordAuthenticationToken in project Asqatasun by Asqatasun.
the class LoginController method doGuestAutoLogin.
private void doGuestAutoLogin(HttpServletRequest request, String guestUser) {
try {
// Must be called from request filtered by Spring Security, otherwise SecurityContextHolder is not updated
UsernamePasswordAuthenticationToken token = new UsernamePasswordAuthenticationToken(guestUser, guestPassword);
token.setDetails(new WebAuthenticationDetails(request));
Authentication guest = authenticationManager.authenticate(token);
Logger.getLogger(this.getClass()).debug("Logging in with [{}]" + guest.getPrincipal());
SecurityContextHolder.getContext().setAuthentication(guest);
} catch (Exception e) {
SecurityContextHolder.getContext().setAuthentication(null);
Logger.getLogger(this.getClass()).debug("Failure in autoLogin", e);
}
}
Aggregations