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


Java UsernamePasswordCredential类代码示例

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


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

示例1: verifyValidateServiceTicketReturnOnlyAllowedAttribute

import org.jasig.cas.authentication.UsernamePasswordCredential; //导入依赖的package包/类
@Test
public void verifyValidateServiceTicketReturnOnlyAllowedAttribute() throws Exception {
    final Service service = getService("eduPersonTestInvalid");
    final UsernamePasswordCredential cred = TestUtils.getCredentialsWithSameUsernameAndPassword();
    final AuthenticationContext ctx = TestUtils.getAuthenticationContext(getAuthenticationSystemSupport(), service);
    final TicketGrantingTicket ticketGrantingTicket = getCentralAuthenticationService().createTicketGrantingTicket(ctx);
    final ServiceTicket serviceTicket = getCentralAuthenticationService().grantServiceTicket(ticketGrantingTicket.getId(),
        service, ctx);

    final Assertion assertion = getCentralAuthenticationService().validateServiceTicket(serviceTicket.getId(),
        service);
    final Authentication auth = assertion.getPrimaryAuthentication();
    final Map<String, Object> attributes = auth.getPrincipal().getAttributes();
    assertEquals(1, attributes.size());
    assertEquals("adopters", attributes.get("groupMembership"));
}
 
开发者ID:yuweijun,项目名称:cas-server-4.2.1,代码行数:17,代码来源:CentralAuthenticationServiceImplTests.java

示例2: SamlAuthenticationMetaDataPopulator

import org.jasig.cas.authentication.UsernamePasswordCredential; //导入依赖的package包/类
/**
 * Instantiates a new SAML authentication meta data populator.
 */
public SamlAuthenticationMetaDataPopulator() {
    this.authenticationMethods.put(
            HttpBasedServiceCredential.class.getName(),
            AUTHN_METHOD_SSL_TLS_CLIENT);
    this.authenticationMethods.put(
            UsernamePasswordCredential.class.getName(),
            AUTHN_METHOD_PASSWORD);

    // Next two classes are in other modules, so avoid using Class#getName() to prevent circular dependency
    this.authenticationMethods.put(
            "org.jasig.cas.adaptors.trusted.authentication.principal.PrincipalBearingCredentials",
            AUTHN_METHOD_UNSPECIFIED);
    this.authenticationMethods.put(
            "org.jasig.cas.adaptors.x509.authentication.principal.X509CertificateCredentials",
            AUTHN_METHOD_X509_PUBLICKEY);
}
 
开发者ID:hsj-xiaokang,项目名称:springboot-shiro-cas-mybatis,代码行数:20,代码来源:SamlAuthenticationMetaDataPopulator.java

示例3: SamlAuthenticationMetaDataPopulator

import org.jasig.cas.authentication.UsernamePasswordCredential; //导入依赖的package包/类
public SamlAuthenticationMetaDataPopulator() {
    this.authenticationMethods.put(
            HttpBasedServiceCredential.class.getName(),
            AUTHN_METHOD_SSL_TLS_CLIENT);
    this.authenticationMethods.put(
            UsernamePasswordCredential.class.getName(),
            AUTHN_METHOD_PASSWORD);

    // Next two classes are in other modules, so avoid using Class#getName() to prevent circular dependency
    this.authenticationMethods.put(
            "org.jasig.cas.adaptors.trusted.authentication.principal.PrincipalBearingCredentials",
            AUTHN_METHOD_UNSPECIFIED);
    this.authenticationMethods.put(
            "org.jasig.cas.adaptors.x509.authentication.principal.X509CertificateCredentials",
            AUTHN_METHOD_X509_PUBLICKEY);
}
 
开发者ID:luotuo,项目名称:cas4.0.x-server-wechat,代码行数:17,代码来源:SamlAuthenticationMetaDataPopulator.java

示例4: verifyFailedAuthenticationWithNoService

import org.jasig.cas.authentication.UsernamePasswordCredential; //导入依赖的package包/类
@Test
public void verifyFailedAuthenticationWithNoService() throws Exception {
    final MockHttpServletRequest request = new MockHttpServletRequest();
    final MockRequestContext context = new MockRequestContext();

    final UsernamePasswordCredential c = org.jasig.cas.authentication.TestUtils.getCredentialsWithDifferentUsernameAndPassword();
    
    request.addParameter("username", c.getUsername());
    request.addParameter("password", c.getPassword());
    context.setExternalContext(new ServletExternalContext(
            new MockServletContext(), request, new MockHttpServletResponse()));
    
    putCredentialInRequestScope(context, c);
    context.getRequestScope().put(
        "org.springframework.validation.BindException.credentials",
        new BindException(c, "credentials"));

    final MessageContext messageContext = mock(MessageContext.class);
    assertEquals("authenticationFailure", this.action.submit(context, c, messageContext).getId());
}
 
开发者ID:hsj-xiaokang,项目名称:springboot-shiro-cas-mybatis,代码行数:21,代码来源:AuthenticationViaFormActionTests.java

示例5: authenticateUsernamePasswordInternal

import org.jasig.cas.authentication.UsernamePasswordCredential; //导入依赖的package包/类
@Override
protected final HandlerResult authenticateUsernamePasswordInternal(final UsernamePasswordCredential credential)
        throws GeneralSecurityException, PreventedException {

    try {
        if (this.fileName == null || !this.fileName.exists()) {
            throw new FileNotFoundException("Filename does not exist");
        }

        final String username = credential.getUsername();
        final String passwordOnRecord = getPasswordOnRecord(username);
        if (StringUtils.isBlank(passwordOnRecord)) {
            throw new AccountNotFoundException(username + " not found in backing file.");
        }
        final String password = credential.getPassword();
        if (StringUtils.isNotBlank(password) && this.getPasswordEncoder().encode(password).equals(passwordOnRecord)) {
            return createHandlerResult(credential, this.principalFactory.createPrincipal(username), null);
        }
    } catch (final IOException e) {
        throw new PreventedException("IO error reading backing file", e);
    }
    throw new FailedLoginException();
}
 
开发者ID:yuweijun,项目名称:cas-server-4.2.1,代码行数:24,代码来源:FileAuthenticationHandler.java

示例6: authenticateUsernamePasswordInternal

import org.jasig.cas.authentication.UsernamePasswordCredential; //导入依赖的package包/类
@Override
protected final HandlerResult authenticateUsernamePasswordInternal(final UsernamePasswordCredential credential)
        throws GeneralSecurityException, PreventedException {

    if (StringUtils.isBlank(this.sql) || getJdbcTemplate() == null) {
        throw new GeneralSecurityException("Authentication handler is not configured correctly");
    }

    final String username = credential.getUsername();
    final String encyptedPassword = getPasswordEncoder().encode(credential.getPassword());
    final int count;
    try {
        count = getJdbcTemplate().queryForObject(this.sql, Integer.class, username, encyptedPassword);
    } catch (final DataAccessException e) {
        throw new PreventedException("SQL exception while executing query for " + username, e);
    }
    if (count == 0) {
        throw new FailedLoginException(username + " not found with SQL query.");
    }
    return createHandlerResult(credential, this.principalFactory.createPrincipal(username), null);
}
 
开发者ID:yuweijun,项目名称:cas-server-4.2.1,代码行数:22,代码来源:SearchModeSearchDatabaseAuthenticationHandler.java

示例7: doAuthentication

import org.jasig.cas.authentication.UsernamePasswordCredential; //导入依赖的package包/类
/**
 * {@inheritDoc}
 **/
@Override
protected final HandlerResult doAuthentication(final Credential credential)
        throws GeneralSecurityException, PreventedException {
    final UsernamePasswordCredential userPass = (UsernamePasswordCredential) credential;
    if (userPass.getUsername() == null) {
        throw new AccountNotFoundException("Username is null.");
    }
    
    final String transformedUsername= this.principalNameTransformer.transform(userPass.getUsername());
    if (transformedUsername == null) {
        throw new AccountNotFoundException("Transformed username is null.");
    }
    userPass.setUsername(transformedUsername);
    return authenticateUsernamePasswordInternal(userPass);
}
 
开发者ID:hsj-xiaokang,项目名称:springboot-shiro-cas-mybatis,代码行数:19,代码来源:AbstractUsernamePasswordAuthenticationHandler.java

示例8: authenticate

import org.jasig.cas.authentication.UsernamePasswordCredential; //导入依赖的package包/类
@Override
public HandlerResult authenticate(final Credential credential)
        throws GeneralSecurityException, PreventedException {

    final UsernamePasswordCredential usernamePasswordCredential = (UsernamePasswordCredential) credential;
    final String username = usernamePasswordCredential.getUsername();
    final String password = usernamePasswordCredential.getPassword();

    final Exception exception = this.usernameErrorMap.get(username);
    if (exception instanceof GeneralSecurityException) {
        throw (GeneralSecurityException) exception;
    } else if (exception instanceof PreventedException) {
        throw (PreventedException) exception;
    } else if (exception instanceof RuntimeException) {
        throw (RuntimeException) exception;
    } else if (exception != null) {
        logger.debug("Cannot throw checked exception {} since it is not declared by method signature.", exception);
    }

    if (StringUtils.hasText(username) && StringUtils.hasText(password) && username.equals(password)) {
        logger.debug("User [{}] was successfully authenticated.", username);
        return new DefaultHandlerResult(this, new BasicCredentialMetaData(credential));
    }
    logger.debug("User [{}] failed authentication", username);
    throw new FailedLoginException();
}
 
开发者ID:hsj-xiaokang,项目名称:springboot-shiro-cas-mybatis,代码行数:27,代码来源:SimpleTestUsernamePasswordAuthenticationHandler.java

示例9: testValidateServiceTicketReturnAllAttributes

import org.jasig.cas.authentication.UsernamePasswordCredential; //导入依赖的package包/类
@Test
public void testValidateServiceTicketReturnAllAttributes() throws Exception {
    final Service service = TestUtils.getService("eduPersonTest");
    final UsernamePasswordCredential cred =  TestUtils.getCredentialsWithSameUsernameAndPassword();
    final String ticketGrantingTicket = getCentralAuthenticationService().createTicketGrantingTicket(cred);
    final String serviceTicket = getCentralAuthenticationService().grantServiceTicket(ticketGrantingTicket,
            service);

    final Assertion assertion = getCentralAuthenticationService().validateServiceTicket(serviceTicket,
            service);
    final Authentication auth = assertion.getPrimaryAuthentication();
    assertEquals(3, auth.getPrincipal().getAttributes().size());
}
 
开发者ID:luotuo,项目名称:cas4.0.x-server-wechat,代码行数:14,代码来源:CentralAuthenticationServiceImplTests.java

示例10: authenticateUsernamePasswordInternal

import org.jasig.cas.authentication.UsernamePasswordCredential; //导入依赖的package包/类
@Override
protected final HandlerResult authenticateUsernamePasswordInternal(final UsernamePasswordCredential credential)
        throws GeneralSecurityException, PreventedException {

    final String username = credential.getUsername();
    if (this.users.contains(username)) {
        throw new FailedLoginException();
    }

    return createHandlerResult(credential, this.principalFactory.createPrincipal(username), null);
}
 
开发者ID:yuweijun,项目名称:cas-server-4.2.1,代码行数:12,代码来源:RejectUsersAuthenticationHandler.java

示例11: verifyFailsNullPassword

import org.jasig.cas.authentication.UsernamePasswordCredential; //导入依赖的package包/类
@Test(expected = FailedLoginException.class)
public void verifyFailsNullPassword() throws Exception {
    final UsernamePasswordCredential c = new UsernamePasswordCredential();

    c.setUsername("scott");
    c.setPassword(null);

    this.authenticationHandler.authenticate(c);
}
 
开发者ID:yuweijun,项目名称:cas-server-4.2.1,代码行数:10,代码来源:FileAuthenticationHandlerTests.java

示例12: verifyEncodeDecodeTGTWithLinkedHashMap

import org.jasig.cas.authentication.UsernamePasswordCredential; //导入依赖的package包/类
@Test
public void verifyEncodeDecodeTGTWithLinkedHashMap() throws Exception {
    final Credential userPassCredential = new UsernamePasswordCredential(USERNAME, PASSWORD);
    final TicketGrantingTicket expectedTGT =
            new MockTicketGrantingTicket(TGT_ID, userPassCredential, new LinkedHashMap<String, Object>(this.principalAttributes));
    expectedTGT.grantServiceTicket(ST_ID, null, null, false, true);
    assertEquals(expectedTGT, transcoder.decode(transcoder.encode(expectedTGT)));
}
 
开发者ID:yuweijun,项目名称:cas-server-4.2.1,代码行数:9,代码来源:KryoTranscoderTests.java

示例13: newBuilder

import org.jasig.cas.authentication.UsernamePasswordCredential; //导入依赖的package包/类
private AuthenticationBuilder newBuilder(final Credential credential) {
    final CredentialMetaData meta = new BasicCredentialMetaData(new UsernamePasswordCredential());
    final AuthenticationHandler handler = new SimpleTestUsernamePasswordAuthenticationHandler();
    final AuthenticationBuilder builder = new DefaultAuthenticationBuilder(TestUtils.getPrincipal())
            .addCredential(meta)
            .addSuccess("test", new DefaultHandlerResult(handler, meta));

    if (this.p.supports(credential)) {
        this.p.populateAttributes(builder, credential);
    }
    return builder;
}
 
开发者ID:hsj-xiaokang,项目名称:springboot-shiro-cas-mybatis,代码行数:13,代码来源:RememberMeAuthenticationMetaDataPopulatorTests.java

示例14: populateAttributes

import org.jasig.cas.authentication.UsernamePasswordCredential; //导入依赖的package包/类
@Override
public void populateAttributes(final AuthenticationBuilder builder, final Credential credential) {
    if (credential instanceof UsernamePasswordCredential) {
        final UsernamePasswordCredential c = (UsernamePasswordCredential) credential;
        final Authentication authentication = builder.build();
        this.credentialCache.put(authentication.getPrincipal().getId(), c.getPassword());
    }
}
 
开发者ID:luotuo,项目名称:cas4.0.x-server-wechat,代码行数:9,代码来源:CacheCredentialsMetaDataPopulator.java

示例15: verifyValidateServiceTicketReturnAllAttributes

import org.jasig.cas.authentication.UsernamePasswordCredential; //导入依赖的package包/类
@Test
public void verifyValidateServiceTicketReturnAllAttributes() throws Exception {
    final Service service = getService("eduPersonTest");
    final UsernamePasswordCredential cred = TestUtils.getCredentialsWithSameUsernameAndPassword();
    final AuthenticationContext ctx = TestUtils.getAuthenticationContext(getAuthenticationSystemSupport(), service);
    final TicketGrantingTicket ticketGrantingTicket = getCentralAuthenticationService().createTicketGrantingTicket(ctx);
    final ServiceTicket serviceTicket = getCentralAuthenticationService().grantServiceTicket(ticketGrantingTicket.getId(),
        service, ctx);

    final Assertion assertion = getCentralAuthenticationService().validateServiceTicket(serviceTicket.getId(),
        service);
    final Authentication auth = assertion.getPrimaryAuthentication();
    assertEquals(3, auth.getPrincipal().getAttributes().size());
}
 
开发者ID:yuweijun,项目名称:cas-server-4.2.1,代码行数:15,代码来源:CentralAuthenticationServiceImplTests.java


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