Search in sources :

Example 1 with UsernamePasswordAuthenticationToken

use of org.springframework.security.authentication.UsernamePasswordAuthenticationToken in project opennms by OpenNMS.

the class RadiusAuthenticationProviderTest method testRetrieveUserChap.

@Test
@Ignore("Need to have a RADIUS server running on localhost")
public void testRetrieveUserChap() throws IOException {
    RadiusAuthenticationProvider provider = new RadiusAuthenticationProvider(m_radiusServer, m_sharedSecret);
    RadiusAuthenticator authTypeClass = new CHAPAuthenticator();
    provider.setAuthTypeClass(authTypeClass);
    provider.setRolesAttribute("Unknown-VSAttribute(5813:1)");
    UsernamePasswordAuthenticationToken token = new UsernamePasswordAuthenticationToken(m_principal, m_credentials);
    provider.retrieveUser(m_username, token);
}
Also used : CHAPAuthenticator(net.jradius.client.auth.CHAPAuthenticator) UsernamePasswordAuthenticationToken(org.springframework.security.authentication.UsernamePasswordAuthenticationToken) RadiusAuthenticator(net.jradius.client.auth.RadiusAuthenticator) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 2 with UsernamePasswordAuthenticationToken

use of org.springframework.security.authentication.UsernamePasswordAuthenticationToken in project opennms by OpenNMS.

the class RadiusAuthenticationProviderTest method testRetrieveUserPap.

@Test
@Ignore("Need to have a RADIUS server running on localhost")
public void testRetrieveUserPap() throws IOException {
    RadiusAuthenticationProvider provider = new RadiusAuthenticationProvider(m_radiusServer, m_sharedSecret);
    RadiusAuthenticator authTypeClass = new PAPAuthenticator();
    provider.setAuthTypeClass(authTypeClass);
    provider.setRolesAttribute("Unknown-VSAttribute(5813:1)");
    UsernamePasswordAuthenticationToken token = new UsernamePasswordAuthenticationToken(m_principal, m_credentials);
    provider.retrieveUser(m_username, token);
}
Also used : UsernamePasswordAuthenticationToken(org.springframework.security.authentication.UsernamePasswordAuthenticationToken) PAPAuthenticator(net.jradius.client.auth.PAPAuthenticator) RadiusAuthenticator(net.jradius.client.auth.RadiusAuthenticator) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 3 with UsernamePasswordAuthenticationToken

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);
}
Also used : UsernamePasswordAuthenticationToken(org.springframework.security.authentication.UsernamePasswordAuthenticationToken) RadiusAuthenticator(net.jradius.client.auth.RadiusAuthenticator)

Example 4 with UsernamePasswordAuthenticationToken

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());
}
Also used : UsernamePasswordAuthenticationToken(org.springframework.security.authentication.UsernamePasswordAuthenticationToken) Test(org.junit.Test) JUnitHttpServer(org.opennms.core.test.http.annotations.JUnitHttpServer)

Example 5 with UsernamePasswordAuthenticationToken

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);
}
Also used : OnmsUser(org.opennms.netmgt.model.OnmsUser) UsernamePasswordAuthenticationToken(org.springframework.security.authentication.UsernamePasswordAuthenticationToken) Test(org.junit.Test)

Aggregations

UsernamePasswordAuthenticationToken (org.springframework.security.authentication.UsernamePasswordAuthenticationToken)802 Authentication (org.springframework.security.core.Authentication)340 Test (org.junit.Test)224 GrantedAuthority (org.springframework.security.core.GrantedAuthority)170 SimpleGrantedAuthority (org.springframework.security.core.authority.SimpleGrantedAuthority)160 Test (org.junit.jupiter.api.Test)157 UserDetails (org.springframework.security.core.userdetails.UserDetails)125 ArrayList (java.util.ArrayList)124 SecurityContext (org.springframework.security.core.context.SecurityContext)115 User (org.springframework.security.core.userdetails.User)103 BadCredentialsException (org.springframework.security.authentication.BadCredentialsException)82 AuthenticationException (org.springframework.security.core.AuthenticationException)58 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)39 OAuth2Authentication (org.springframework.security.oauth2.provider.OAuth2Authentication)36 AuthenticationManager (org.springframework.security.authentication.AuthenticationManager)35 SecurityContextImpl (org.springframework.security.core.context.SecurityContextImpl)33 StandaloneSession (org.pentaho.platform.engine.core.system.StandaloneSession)30 User (ca.corefacility.bioinformatics.irida.model.user.User)26 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)25 WebAuthenticationDetails (org.springframework.security.web.authentication.WebAuthenticationDetails)23