• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java UsernamePasswordAuthenticationToken类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: login

import org.springframework.security.providers.UsernamePasswordAuthenticationToken; //导入依赖的package包/类
public void login() throws SpringSecurityException {
    final ApplicationContext appCtx = Application.instance().getApplicationContext();

    // Attempt login
    UsernamePasswordAuthenticationToken request = new UsernamePasswordAuthenticationToken(getUsername(),
            getPassword());

    Authentication result = null;

    try {
        result = authenticationManager.authenticate(request);
    } catch( SpringSecurityException e ) {
        logger.warn( "authentication failed", e);

        // Fire application event to advise of failed login
        appCtx.publishEvent( new AuthenticationFailedEvent(request, e));
        
        // And rethrow the exception to prevent the dialog from closing
        throw e;
    }

    // Handle success or failure of the authentication attempt
    if( logger.isDebugEnabled()) {
        logger.debug("successful login - update context holder and fire event");
    }

    // Commit the successful Authentication object to the secure
    // ContextHolder
    SecurityContextHolder.getContext().setAuthentication(result);

    // Fire application event to advise of new login
    appCtx.publishEvent(new LoginEvent(result));
}
 
开发者ID:shevek,项目名称:spring-rich-client,代码行数:34,代码来源:SessionDetails.java


示例17: shouldCreateLicenseEnforcementProviderWithUserServicePassedIn

import org.springframework.security.providers.UsernamePasswordAuthenticationToken; //导入依赖的package包/类
@Test
public void shouldCreateLicenseEnforcementProviderWithUserServicePassedIn() throws Exception {
    GoAuthenticationProvider licenseEnforcementProvider = (GoAuthenticationProvider) factory.getObject();
    AuthenticationProvider underlyingProvider = mock(AuthenticationProvider.class);
    licenseEnforcementProvider.setProvider(underlyingProvider);
    UsernamePasswordAuthenticationToken auth = new UsernamePasswordAuthenticationToken("foo", "bar");
    UsernamePasswordAuthenticationToken resultantAuthorization = new UsernamePasswordAuthenticationToken(
            new org.springframework.security.userdetails.User("foo-user", "pass", true, true, true, true, new GrantedAuthority[]{GoAuthority.ROLE_USER.asAuthority()}), "bar");
    when(underlyingProvider.authenticate(auth)).thenReturn(resultantAuthorization);
    licenseEnforcementProvider.authenticate(auth);
    verify(userService).addUserIfDoesNotExist(UserHelper.getUser(resultantAuthorization));
}
 
开发者ID:gocd,项目名称:gocd,代码行数:13,代码来源:GoAuthenticationProviderFactoryTest.java


示例18: authenticate_shouldSupportAuthenticationForPreAuthenticatedAuthenticationTokenOnly

import org.springframework.security.providers.UsernamePasswordAuthenticationToken; //导入依赖的package包/类
@Test
public void authenticate_shouldSupportAuthenticationForPreAuthenticatedAuthenticationTokenOnly()  {
    Authentication authenticate = authenticationProvider.authenticate(new UsernamePasswordAuthenticationToken("p", "c"));

    assertNull(authenticate);

    verifyZeroInteractions(authorizationExtension);
}
 
开发者ID:gocd,项目名称:gocd,代码行数:9,代码来源:PreAuthenticatedAuthenticationProviderTest.java


示例19: setUp

import org.springframework.security.providers.UsernamePasswordAuthenticationToken; //导入依赖的package包/类
@Before
public void setUp() throws Exception {
    userService = mock(UserService.class);
    underlyingProvider = mock(AuthenticationProvider.class);
    enforcementProvider = new GoAuthenticationProvider(userService, underlyingProvider);
    auth = new UsernamePasswordAuthenticationToken(new User("user", "pass", true, true, true, true, new GrantedAuthority[]{}), "credentials");
    resultantAuthorization = new UsernamePasswordAuthenticationToken(new User("user-authenticated", "pass", true, true, true, true,
            new GrantedAuthority[]{GoAuthority.ROLE_GROUP_SUPERVISOR.asAuthority()}), "credentials");
    when(underlyingProvider.authenticate(auth)).thenReturn(resultantAuthorization);
}
 
开发者ID:gocd,项目名称:gocd,代码行数:11,代码来源:GoAuthenticationProviderTest.java


示例20: shouldAnswerSupportsBasedOnPluginAvailability

import org.springframework.security.providers.UsernamePasswordAuthenticationToken; //导入依赖的package包/类
@Test
public void shouldAnswerSupportsBasedOnPluginAvailability() {
    addPluginSupportingPasswordBasedAuthentication("plugin-id-1");
    assertThat(provider.supports(UsernamePasswordAuthenticationToken.class), is(true));

    AuthorizationMetadataStore.instance().clear();
    assertThat(provider.supports(UsernamePasswordAuthenticationToken.class), is(false));
}
 
开发者ID:gocd,项目名称:gocd,代码行数:9,代码来源:PluginAuthenticationProviderTest.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java EllipseVertexShapeTransformer类代码示例发布时间:2022-05-22
下一篇:
Java ListTestSuiteBuilder类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap