当前位置: 首页>>代码示例>>Java>>正文


Java UsernamePasswordAuthenticationToken类代码示例

本文整理汇总了Java中org.springframework.security.providers.UsernamePasswordAuthenticationToken的典型用法代码示例。如果您正苦于以下问题:Java UsernamePasswordAuthenticationToken类的具体用法?Java UsernamePasswordAuthenticationToken怎么用?Java UsernamePasswordAuthenticationToken使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


UsernamePasswordAuthenticationToken类属于org.springframework.security.providers包,在下文中一共展示了UsernamePasswordAuthenticationToken类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: authenticate

import org.springframework.security.providers.UsernamePasswordAuthenticationToken; //导入依赖的package包/类
@Override
public Authentication authenticate(Authentication authenticationRequest)
		throws AuthenticationException {
	GrantedAuthority[] authorities = new GrantedAuthorityImpl[authenticationRequest.getAuthorities().length + 1];
	authorities[0] = new GrantedAuthorityImpl(AUTHENTICATED_AUTHORITY_NAME);
	int i = 1;
	for(GrantedAuthority originalAuth : authenticationRequest.getAuthorities()){
		authorities[i] = new GrantedAuthorityImpl(originalAuth.getAuthority());
		i += 1;
	}
	
	UsernamePasswordAuthenticationToken authenticationOutcome = new UsernamePasswordAuthenticationToken(authenticationRequest.getPrincipal(), 
			authenticationRequest.getCredentials(), authorities);
	authenticationOutcome.setDetails(authenticationRequest.getDetails());
	return authenticationOutcome;
}
 
开发者ID:Rospaccio,项目名称:pentaho-authentication-ext,代码行数:17,代码来源:ExtensionAuthenticationProvider.java

示例2: testDoFilterNoMapping

import org.springframework.security.providers.UsernamePasswordAuthenticationToken; //导入依赖的package包/类
@Test
public void testDoFilterNoMapping() throws IOException, ServletException
{
	MockHttpServletRequest request = new MockHttpServletRequest();
	MockHttpServletResponse response = new MockHttpServletResponse();
	MockFilterChain chain = new MockFilterChain();

	request.addParameter(LoginTicketGeneratorFilter.GENERATE_TICKET_PARAM_NAME, "1");
	request.addParameter(LoginTicketGeneratorFilter.REQUESTING_APP_PARAM_NAME, "IDoNotExist");
	request.addParameter(LoginTicketGeneratorFilter.REQUESTING_USERNAME_PARAM_NAME, "testUser");

	// Adds an authentication in the SecurityContext, in order to simulate
	// the
	// work of the requestParametersAuthenticationFilter
	SecurityContextHolder.getContext().setAuthentication(new UsernamePasswordAuthenticationToken("test", "test"));

	loginTicketGeneratorFilter.doFilter(request, response, chain);

	assertNotNull(response);
	assertEquals(500, response.getStatus());
}
 
开发者ID:Rospaccio,项目名称:pentaho-authentication-ext,代码行数:22,代码来源:LoginTicketGeneratorFilterTest.java

示例3: testDoFilterNoMapping

import org.springframework.security.providers.UsernamePasswordAuthenticationToken; //导入依赖的package包/类
@Test
public void testDoFilterNoMapping() throws IOException, ServletException
{
	MockHttpServletRequest request = new MockHttpServletRequest();
	MockHttpServletResponse response = new MockHttpServletResponse();
	MockFilterChain chain = new MockFilterChain();

	request.addParameter(LoginTicketGeneratorFilter.GENERATE_TICKET_PARAM_NAME, "1");
	request.addParameter(LoginTicketGeneratorFilter.REQUESTING_APP_PARAM_NAME, "IDoNotExist");
	request.addParameter(LoginTicketGeneratorFilter.REQUESTING_USERNAME_PARAM_NAME, "testUser");

	// Adds an authentication in the SecurityContext, in order to simulate
	// the
	// work of the requestParametersAuthenticationFilter
	SecurityContextHolder.getContext().setAuthentication(new UsernamePasswordAuthenticationToken("test", "test"));

	loginTicketGeneratorFilter.doFilter(request, response, chain);

	assertEquals(500, response.getStatus());
	assertNotNull(response.getErrorMessage());
}
 
开发者ID:Rospaccio,项目名称:pentaho-transparent-authentication,代码行数:22,代码来源:LoginTicketGeneratorFilterTest.java

示例4: shouldUpdatePluginRolesForAUserPostAuthentication

import org.springframework.security.providers.UsernamePasswordAuthenticationToken; //导入依赖的package包/类
@Test
public void shouldUpdatePluginRolesForAUserPostAuthentication() {
    securityConfig.securityAuthConfigs().add(new SecurityAuthConfig("ldap", "cd.go.ldap"));
    securityConfig.securityAuthConfigs().add(new SecurityAuthConfig("github", "cd.go.github"));

    String pluginId1 = "cd.go.ldap";
    String pluginId2 = "cd.go.github";

    addPluginSupportingPasswordBasedAuthentication(pluginId1);
    addPluginSupportingPasswordBasedAuthentication(pluginId2);
    when(authorizationExtension.authenticateUser(pluginId1, "username", "password", securityConfig.securityAuthConfigs().findByPluginId(pluginId1), securityConfig.getPluginRoles(pluginId1))).thenReturn(
            new AuthenticationResponse(
                    new User("username", "bob", "[email protected]"),
                    Arrays.asList("blackbird", "admins")
            )
    );

    when(authorizationExtension.authenticateUser(pluginId2, "username", "password", securityConfig.securityAuthConfigs().findByPluginId(pluginId2), securityConfig.getPluginRoles(pluginId2))).thenReturn(NULL_AUTH_RESPONSE);

    UserDetails userDetails = provider.retrieveUser("username", new UsernamePasswordAuthenticationToken(null, "password"));

    assertNotNull(userDetails);

    verify(pluginRoleService).updatePluginRoles("cd.go.ldap", "username", CaseInsensitiveString.caseInsensitiveStrings(Arrays.asList("blackbird", "admins")));
}
 
开发者ID:gocd,项目名称:gocd,代码行数:26,代码来源:PluginAuthenticationProviderTest.java

示例5: authenticatedUsersUsernameShouldBeUsedToAssignRoles

import org.springframework.security.providers.UsernamePasswordAuthenticationToken; //导入依赖的package包/类
@Test
public void authenticatedUsersUsernameShouldBeUsedToAssignRoles() throws Exception {
    String pluginId1 = "cd.go.ldap";

    securityConfig.securityAuthConfigs().add(new SecurityAuthConfig("ldap", "cd.go.ldap"));
    addPluginSupportingPasswordBasedAuthentication(pluginId1);
    when(authorizationExtension.authenticateUser(pluginId1, "[email protected]", "password", securityConfig.securityAuthConfigs().findByPluginId(pluginId1), securityConfig.getPluginRoles(pluginId1))).thenReturn(
            new AuthenticationResponse(
                    new User("username", "bob", "[email protected]"),
                    Arrays.asList("blackbird", "admins")
            )
    );

    UserDetails userDetails = provider.retrieveUser("[email protected]", new UsernamePasswordAuthenticationToken(null, "password"));

    assertNotNull(userDetails);

    verify(pluginRoleService).updatePluginRoles("cd.go.ldap", "username", CaseInsensitiveString.caseInsensitiveStrings(Arrays.asList("blackbird", "admins")));
}
 
开发者ID:gocd,项目名称:gocd,代码行数:20,代码来源:PluginAuthenticationProviderTest.java

示例6: reuthenticationUsingAuthorizationPlugins_shouldUseTheLoginNameAvailableInGoUserPrinciple

import org.springframework.security.providers.UsernamePasswordAuthenticationToken; //导入依赖的package包/类
@Test
public void reuthenticationUsingAuthorizationPlugins_shouldUseTheLoginNameAvailableInGoUserPrinciple() throws Exception {
    String pluginId1 = "cd.go.ldap";

    securityConfig.securityAuthConfigs().add(new SecurityAuthConfig("ldap", "cd.go.ldap"));
    addPluginSupportingPasswordBasedAuthentication(pluginId1);
    when(authorizationExtension.authenticateUser(pluginId1, "[email protected]", "password", securityConfig.securityAuthConfigs().findByPluginId(pluginId1), securityConfig.getPluginRoles(pluginId1))).thenReturn(
            new AuthenticationResponse(
                    new User("username", "bob", "[email protected]"),
                    Arrays.asList("blackbird", "admins")
            )
    );
    GoUserPrinciple principal = new GoUserPrinciple("username", "Display", "password", true, true, true, true, new GrantedAuthority[]{}, "[email protected]");

    UserDetails userDetails = provider.retrieveUser("username", new UsernamePasswordAuthenticationToken(principal, "password"));

    assertThat(userDetails, is(instanceOf(GoUserPrinciple.class)));
    GoUserPrinciple goUserPrincipal = (GoUserPrinciple) userDetails;
    assertThat(goUserPrincipal.getUsername(), is("username"));
    assertThat(goUserPrincipal.getLoginName(), is("[email protected]"));

    verify(pluginRoleService).updatePluginRoles("cd.go.ldap", "username", CaseInsensitiveString.caseInsensitiveStrings(Arrays.asList("blackbird", "admins")));
}
 
开发者ID:gocd,项目名称:gocd,代码行数:24,代码来源:PluginAuthenticationProviderTest.java

示例7: reuthenticationUsingAuthorizationPlugins_shouldFallbackOnUserNameInAbsenceOfGoUserPrinciple

import org.springframework.security.providers.UsernamePasswordAuthenticationToken; //导入依赖的package包/类
@Test
public void reuthenticationUsingAuthorizationPlugins_shouldFallbackOnUserNameInAbsenceOfGoUserPrinciple() throws Exception {
    String pluginId1 = "cd.go.ldap";

    securityConfig.securityAuthConfigs().add(new SecurityAuthConfig("ldap", "cd.go.ldap"));
    addPluginSupportingPasswordBasedAuthentication(pluginId1);
    when(authorizationExtension.authenticateUser(pluginId1, "username", "password", securityConfig.securityAuthConfigs().findByPluginId(pluginId1), securityConfig.getPluginRoles(pluginId1))).thenReturn(
            new AuthenticationResponse(
                    new User("username", "bob", "[email protected]"),
                    Arrays.asList("blackbird", "admins")
            )
    );

    UserDetails userDetails = provider.retrieveUser("username", new UsernamePasswordAuthenticationToken(null, "password"));

    assertNotNull(userDetails);

    verify(pluginRoleService).updatePluginRoles("cd.go.ldap", "username", CaseInsensitiveString.caseInsensitiveStrings(Arrays.asList("blackbird", "admins")));
}
 
开发者ID:gocd,项目名称:gocd,代码行数:20,代码来源:PluginAuthenticationProviderTest.java

示例8: SecurityAuthConfig

import org.springframework.security.providers.UsernamePasswordAuthenticationToken; //导入依赖的package包/类
@Test
public void reuthenticationUsingAuthorizationPlugins_shouldFallbackOnUserNameInAbsenceOfLoginNameInGoUserPrinciple() throws Exception {
    String pluginId1 = "cd.go.ldap";

    securityConfig.securityAuthConfigs().add(new SecurityAuthConfig("ldap", "cd.go.ldap"));
    addPluginSupportingPasswordBasedAuthentication(pluginId1);
    when(authorizationExtension.authenticateUser(pluginId1, "username", "password", securityConfig.securityAuthConfigs().findByPluginId(pluginId1), securityConfig.getPluginRoles(pluginId1))).thenReturn(
            new AuthenticationResponse(
                    new User("username", "bob", "[email protected]"),
                    Arrays.asList("blackbird", "admins")
            )
    );
    GoUserPrinciple principal = new GoUserPrinciple("username", "Display", "password", true, true, true, true, new GrantedAuthority[]{}, null);

    UserDetails userDetails = provider.retrieveUser("username", new UsernamePasswordAuthenticationToken(principal, "password"));

    assertNotNull(userDetails);

    verify(pluginRoleService).updatePluginRoles("cd.go.ldap", "username", CaseInsensitiveString.caseInsensitiveStrings(Arrays.asList("blackbird", "admins")));
}
 
开发者ID:gocd,项目名称:gocd,代码行数:21,代码来源:PluginAuthenticationProviderTest.java

示例9: shouldConvey_itsBasicProcessingFilter

import org.springframework.security.providers.UsernamePasswordAuthenticationToken; //导入依赖的package包/类
@Test
public void shouldConvey_itsBasicProcessingFilter() throws IOException, ServletException {
    BasicAuthenticationFilter filter = new BasicAuthenticationFilter(localizer);
    final Boolean[] hadBasicMarkOnInsideAuthenticationManager = new Boolean[]{false};

    filter.setAuthenticationManager(new AuthenticationManager() {
        public Authentication authenticate(Authentication authentication) throws AuthenticationException {
            hadBasicMarkOnInsideAuthenticationManager[0] = BasicAuthenticationFilter.isProcessingBasicAuth();
            return new UsernamePasswordAuthenticationToken("school-principal", "u can be principal if you know this!");
        }
    });
    assertThat(BasicAuthenticationFilter.isProcessingBasicAuth(), is(false));
    MockHttpServletRequest httpRequest = new MockHttpServletRequest();
    httpRequest.addHeader("Authorization", "Basic " + Base64.getEncoder().encodeToString("loser:boozer".getBytes()));
    filter.doFilterHttp(httpRequest, new MockHttpServletResponse(), new FilterChain() {
        public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse) throws IOException, ServletException {

        }
    });
    assertThat(BasicAuthenticationFilter.isProcessingBasicAuth(), is(false));

    assertThat(hadBasicMarkOnInsideAuthenticationManager[0], is(true));
}
 
开发者ID:gocd,项目名称:gocd,代码行数:24,代码来源:BasicAuthenticationFilterTest.java

示例10: testAuthenticateTempUser

import org.springframework.security.providers.UsernamePasswordAuthenticationToken; //导入依赖的package包/类
@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);

	Authentication authentication = new UsernamePasswordAuthenticationToken("tempuser", "mike");
	Authentication authenticated = m_provider.authenticate(authentication);
	assertNotNull("authenticated Authentication object not null", authenticated);
	GrantedAuthority[] authorities = authenticated.getAuthorities();
	assertNotNull("GrantedAuthorities should not be null", authorities);
	assertEquals("GrantedAuthorities size", 1, authorities.length);
	assertEquals("GrantedAuthorities zero role", "ROLE_USER", authorities[0].getAuthority());
}
 
开发者ID:vishwaabhinav,项目名称:OpenNMS,代码行数:17,代码来源:AuthenticationIntegrationTest.java

示例11: getAuthenticationInfo

import org.springframework.security.providers.UsernamePasswordAuthenticationToken; //导入依赖的package包/类
private void getAuthenticationInfo() {
	if (m_uri == null || m_uri.getScheme() == null) {
		throw new RuntimeException("no URI specified!");
	}
	if (m_uri.getScheme().equals("rmi")) {
		// RMI doesn't have authentication
		return;
	}
	
	if (m_username == null) {
		GroovyGui gui = createGui();
        gui.createAndShowGui();
        AuthenticationBean auth = gui.getAuthenticationBean();
        m_username = auth.getUsername();
        m_password = auth.getPassword();
	}
	
	if (m_username != null) {
		SecurityContextHolder.setStrategyName(SecurityContextHolder.MODE_GLOBAL);
		SecurityContextHolder.getContext().setAuthentication(new UsernamePasswordAuthenticationToken(m_username, m_password));
	}
}
 
开发者ID:vishwaabhinav,项目名称:OpenNMS,代码行数:23,代码来源:Main.java

示例12: testBackendWithBasicAuthInDifferentThread

import org.springframework.security.providers.UsernamePasswordAuthenticationToken; //导入依赖的package包/类
@Test
@JUnitHttpServer(port=9162, basicAuth=true, [email protected](context="/", path="src/test/resources/simple-test-webapp"))
public void testBackendWithBasicAuthInDifferentThread() throws Exception {
	SecurityContextHolder.getContext().setAuthentication(new UsernamePasswordAuthenticationToken("testuser", "testpassword"));
	assertNotNull(m_authBackEnd);
	
	final AtomicInteger first = new AtomicInteger(-1);
	final AtomicInteger second = new AtomicInteger(-1);
	
	Thread t = new Thread() {
		public void run() {
			first.set(m_authBackEnd.getCount());
			second.set(m_authBackEnd.getCount());
		}
	};
	t.start();
	t.join();
	assertEquals("first get should be 0", 0, first.get());
	assertEquals("second should be 1", 1, second.get());
}
 
开发者ID:vishwaabhinav,项目名称:OpenNMS,代码行数:21,代码来源:SimpleBackEndTest.java

示例13: testGetUsernameNoPrincipalObject

import org.springframework.security.providers.UsernamePasswordAuthenticationToken; //导入依赖的package包/类
@Test
public void testGetUsernameNoPrincipalObject() {
    Authentication auth = new UsernamePasswordAuthenticationToken(null, null, new GrantedAuthority[0]);
    SecurityContextHolder.getContext().setAuthentication(auth);
    
    ThrowableAnticipator ta = new ThrowableAnticipator();
    ta.anticipate(new IllegalStateException("No principal object found when calling getPrinticpal on our Authentication object"));
    
    try {
        m_service.getUsername();
    } catch (Throwable t) {
        ta.throwableReceived(t);
    }
    
    ta.verifyAnticipated();
}
 
开发者ID:vishwaabhinav,项目名称:OpenNMS,代码行数:17,代码来源:DefaultSurveillanceServiceTest.java

示例14: testDoFilter

import org.springframework.security.providers.UsernamePasswordAuthenticationToken; //导入依赖的package包/类
@Test
public void testDoFilter() throws IOException, ServletException
{
	MockHttpServletRequest request = new MockHttpServletRequest();
	MockHttpServletResponse response = new MockHttpServletResponse();
	MockFilterChain chain = new MockFilterChain();

	request.addParameter(LoginTicketGeneratorFilter.GENERATE_TICKET_PARAM_NAME, "1");
	request.addParameter(LoginTicketGeneratorFilter.REQUESTING_APP_PARAM_NAME, "test");
	request.addParameter(LoginTicketGeneratorFilter.REQUESTING_USERNAME_PARAM_NAME, "testUser");

	// Adds an authentication in the SecurityContext, in order to simulate
	// the
	// work of the requestParametersAuthenticationFilter
	SecurityContextHolder.getContext().setAuthentication(new UsernamePasswordAuthenticationToken("test", "test"));

	loginTicketGeneratorFilter.doFilter(request, response, chain);

	assertNotNull(response);
	assertEquals(200, response.getStatus());
	String content = response.getContentAsString();
	assertNotNull(content);

	ObjectMapper mapper = new ObjectMapper();
	JsonNode node = mapper.readTree(content);
	assertNotNull(node.get("ticketId"));
	JsonNode valueNode = node.findPath("ticketId");
	assertNotNull(valueNode);

	UUID uuid = new UUID(valueNode.asText());
	assertNotNull(uuid);
}
 
开发者ID:Rospaccio,项目名称:pentaho-authentication-ext,代码行数:33,代码来源:LoginTicketGeneratorFilterTest.java

示例15: testDoFilter

import org.springframework.security.providers.UsernamePasswordAuthenticationToken; //导入依赖的package包/类
@Test
public void testDoFilter() throws IOException, ServletException
{
	MockHttpServletRequest request = new MockHttpServletRequest();
	MockHttpServletResponse response = new MockHttpServletResponse();
	MockFilterChain chain = new MockFilterChain();

	request.addParameter(LoginTicketGeneratorFilter.GENERATE_TICKET_PARAM_NAME, "1");
	request.addParameter(LoginTicketGeneratorFilter.REQUESTING_APP_PARAM_NAME, "test");
	request.addParameter(LoginTicketGeneratorFilter.REQUESTING_USERNAME_PARAM_NAME, "testUser");

	// Adds an authentication in the SecurityContext, in order to simulate
	// the
	// work of the requestParametersAuthenticationFilter
	SecurityContextHolder.getContext().setAuthentication(new UsernamePasswordAuthenticationToken("test", "test"));

	loginTicketGeneratorFilter.doFilter(request, response, chain);

	assertEquals(200, response.getStatus());
	String content = response.getContentAsString();
	assertNotNull(content);

	ObjectMapper mapper = new ObjectMapper();
	JsonNode node = mapper.readTree(content);
	assertNotNull(node.get("ticketId"));
	JsonNode valueNode = node.findPath("ticketId");
	assertNotNull(valueNode);

	UUID uuid = new UUID(valueNode.asText());
	assertNotNull(uuid);
}
 
开发者ID:Rospaccio,项目名称:pentaho-transparent-authentication,代码行数:32,代码来源:LoginTicketGeneratorFilterTest.java


注:本文中的org.springframework.security.providers.UsernamePasswordAuthenticationToken类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。