本文整理汇总了Java中org.jasig.cas.authentication.HandlerResult类的典型用法代码示例。如果您正苦于以下问题:Java HandlerResult类的具体用法?Java HandlerResult怎么用?Java HandlerResult使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
HandlerResult类属于org.jasig.cas.authentication包,在下文中一共展示了HandlerResult类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: authenticateUsernamePasswordInternal
import org.jasig.cas.authentication.HandlerResult; //导入依赖的package包/类
@Override
protected final HandlerResult authenticateUsernamePasswordInternal(final UsernamePasswordCredential credential)
throws GeneralSecurityException, PreventedException {
if (this.kerberosKdcSystemProperty != null) {
logger.debug("Setting kerberos system property {} to {}", SYS_PROP_KERB5_KDC, this.kerberosKdcSystemProperty);
System.setProperty(SYS_PROP_KERB5_KDC, this.kerberosKdcSystemProperty);
}
if (this.kerberosRealmSystemProperty != null) {
logger.debug("Setting kerberos system property {} to {}", SYS_PROP_KRB5_REALM, this.kerberosRealmSystemProperty);
System.setProperty(SYS_PROP_KRB5_REALM, this.kerberosRealmSystemProperty);
}
final String username = credential.getUsername();
final String password = getPasswordEncoder().encode(credential.getPassword());
final LoginContext lc = new LoginContext(
this.realm,
new UsernamePasswordCallbackHandler(username, password));
try {
logger.debug("Attempting authentication for: {}", username);
lc.login();
} finally {
lc.logout();
}
Principal principal = null;
final Set<java.security.Principal> principals = lc.getSubject().getPrincipals();
if (principals != null && !principals.isEmpty()) {
final java.security.Principal secPrincipal = principals.iterator().next();
principal = this.principalFactory.createPrincipal(secPrincipal.getName());
}
return createHandlerResult(credential, principal, null);
}
示例2: doAuthentication
import org.jasig.cas.authentication.HandlerResult; //导入依赖的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
示例3: authenticate
import org.jasig.cas.authentication.HandlerResult; //导入依赖的package包/类
@Override
public HandlerResult authenticate(final Credential credential) throws GeneralSecurityException {
final HttpBasedServiceCredential httpCredential = (HttpBasedServiceCredential) credential;
if (!httpCredential.getService().getProxyPolicy().isAllowedProxyCallbackUrl(httpCredential.getCallbackUrl())) {
logger.warn("Proxy policy for service [{}] cannot authorize the requested callback url [{}].",
httpCredential.getService().getServiceId(), httpCredential.getCallbackUrl());
throw new FailedLoginException(httpCredential.getCallbackUrl() + " cannot be authorized");
}
logger.debug("Attempting to authenticate {}", httpCredential);
final URL callbackUrl = httpCredential.getCallbackUrl();
if (!this.httpClient.isValidEndPoint(callbackUrl)) {
throw new FailedLoginException(callbackUrl.toExternalForm() + " sent an unacceptable response status code");
}
return new DefaultHandlerResult(this, httpCredential, this.principalFactory.createPrincipal(httpCredential.getId()));
}
开发者ID:hsj-xiaokang,项目名称:springboot-shiro-cas-mybatis,代码行数:17,代码来源:HttpBasedServiceCredentialsAuthenticationHandler.java
示例4: doAuthentication
import org.jasig.cas.authentication.HandlerResult; //导入依赖的package包/类
@Override
protected HandlerResult doAuthentication(final Credential credential) throws GeneralSecurityException, PreventedException {
final ClientCredential clientCredentials = (ClientCredential) credential;
logger.debug("clientCredentials {}", clientCredentials);
final Credentials credentials = clientCredentials.getCredentials();
final String clientName = credentials.getClientName();
logger.debug("clientName: {}", clientName);
// get client
final Client<Credentials, UserProfile> client = this.clients.findClient(clientName);
logger.debug("client: {}", client);
// web context
final HttpServletRequest request = WebUtils.getHttpServletRequest();
final HttpServletResponse response = WebUtils.getHttpServletResponse();
final WebContext webContext = new J2EContext(request, response);
// get user profile
final UserProfile userProfile = client.getUserProfile(credentials, webContext);
logger.debug("userProfile: {}", userProfile);
return createResult(clientCredentials, userProfile);
}
示例5: createResult
import org.jasig.cas.authentication.HandlerResult; //导入依赖的package包/类
/**
* Build the handler result.
*
* @param credentials the provided credentials
* @param profile the retrieved user profile
* @return the built handler result
* @throws GeneralSecurityException On authentication failure.
* @throws PreventedException On the indeterminate case when authentication is prevented.
*/
protected HandlerResult createResult(final ClientCredential credentials, final UserProfile profile)
throws GeneralSecurityException, PreventedException {
if (profile != null) {
final String id;
if (typedIdUsed) {
id = profile.getTypedId();
} else {
id = profile.getId();
}
if (StringUtils.isNotBlank(id)) {
credentials.setUserProfile(profile);
credentials.setTypedIdUsed(typedIdUsed);
return new DefaultHandlerResult(
this,
new BasicCredentialMetaData(credentials),
this.principalFactory.createPrincipal(id, profile.getAttributes()));
}
throw new FailedLoginException("No identifier found for this user profile: " + profile);
}
throw new FailedLoginException("Authentication did not produce a user profile for: " + credentials);
}
开发者ID:hsj-xiaokang,项目名称:springboot-shiro-cas-mybatis,代码行数:34,代码来源:AbstractPac4jAuthenticationHandler.java
示例6: authenticateUsernamePasswordInternal
import org.jasig.cas.authentication.HandlerResult; //导入依赖的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:hsj-xiaokang,项目名称:springboot-shiro-cas-mybatis,代码行数:22,代码来源:SearchModeSearchDatabaseAuthenticationHandler.java
示例7: verifyAuthenticate
import org.jasig.cas.authentication.HandlerResult; //导入依赖的package包/类
/**
* Tests the {@link X509CredentialsAuthenticationHandler#authenticate(org.jasig.cas.authentication.Credential)} method.
*/
@Test
public void verifyAuthenticate() {
try {
if (this.handler.supports(this.credential)) {
final HandlerResult result = this.handler.authenticate(this.credential);
if (this.expectedResult instanceof DefaultHandlerResult) {
assertEquals(this.expectedResult, result);
} else {
fail("Authentication succeeded when it should have failed with " + this.expectedResult);
}
}
} catch (final Exception e) {
if (this.expectedResult instanceof Exception) {
assertEquals(this.expectedResult.getClass(), e.getClass());
} else {
fail("Authentication failed when it should have succeeded.");
}
}
}
示例8: authenticate
import org.jasig.cas.authentication.HandlerResult; //导入依赖的package包/类
@Override
public HandlerResult authenticate(final Credential credential) throws GeneralSecurityException {
final OpenIdCredential c = (OpenIdCredential) credential;
final TicketGrantingTicket t = this.ticketRegistry.getTicket(c.getTicketGrantingTicketId(),
TicketGrantingTicket.class);
if (t == null || t.isExpired()) {
throw new FailedLoginException("TGT is null or expired.");
}
final Principal principal = t.getAuthentication().getPrincipal();
if (!principal.getId().equals(c.getUsername())) {
throw new FailedLoginException("Principal ID mismatch");
}
return new DefaultHandlerResult(this, new BasicCredentialMetaData(c), principal);
}
开发者ID:hsj-xiaokang,项目名称:springboot-shiro-cas-mybatis,代码行数:17,代码来源:OpenIdCredentialsAuthenticationHandler.java
示例9: authenticateUsernamePasswordInternal
import org.jasig.cas.authentication.HandlerResult; //导入依赖的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();
}
示例10: doAuthentication
import org.jasig.cas.authentication.HandlerResult; //导入依赖的package包/类
@Override
protected HandlerResult doAuthentication(final Credential credential) throws GeneralSecurityException, PreventedException {
CommonHelper.assertNotNull("profileCreator", this.profileCreator);
final C credentials = convertToPac4jCredentials((I) credential);
logger.debug("credentials: {}", credentials);
try {
final Authenticator authenticator = getAuthenticator(credential);
CommonHelper.assertNotNull("authenticator", authenticator);
authenticator.validate(credentials);
} catch (final CredentialsException e) {
logger.error("Failed to validate credentials", e);
throw new FailedLoginException("Failed to validate credentials: " + e.getMessage());
}
final UserProfile profile = profileCreator.create(credentials);
logger.debug("profile: {}", profile);
return createResult(new ClientCredential(credentials), profile);
}
开发者ID:hsj-xiaokang,项目名称:springboot-shiro-cas-mybatis,代码行数:22,代码来源:AbstractWrapperAuthenticationHandler.java
示例11: verifyAuthenticationSuccessfulWithAPasswordEncoder
import org.jasig.cas.authentication.HandlerResult; //导入依赖的package包/类
@Test
public void verifyAuthenticationSuccessfulWithAPasswordEncoder() throws Exception {
final QueryAndEncodeDatabaseAuthenticationHandler q =
new QueryAndEncodeDatabaseAuthenticationHandler(this.dataSource, buildSql(),
ALG_NAME);
q.setNumberOfIterationsFieldName("numIterations");
q.setStaticSalt(STATIC_SALT);
q.setPasswordEncoder(new PasswordEncoder() {
@Override
public String encode(final String password) {
return password.concat("1");
}
});
q.setPrincipalNameTransformer(new PrefixSuffixPrincipalNameTransformer("user", null));
final HandlerResult r = q.authenticateUsernamePasswordInternal(
TestUtils.getCredentialsWithDifferentUsernameAndPassword("1", "user"));
assertNotNull(r);
assertEquals(r.getPrincipal().getId(), "user1");
}
开发者ID:yuweijun,项目名称:cas-server-4.2.1,代码行数:22,代码来源:QueryAndEncodeDatabaseAuthenticationHandlerTests.java
示例12: authenticateUsernamePasswordInternal
import org.jasig.cas.authentication.HandlerResult; //导入依赖的package包/类
/**
* {@inheritDoc}
*/
@Override
protected final HandlerResult authenticateUsernamePasswordInternal(final UsernamePasswordCredential credential)
throws GeneralSecurityException, PreventedException {
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:hsj-xiaokang,项目名称:springboot-shiro-cas-mybatis,代码行数:21,代码来源:SearchModeSearchDatabaseAuthenticationHandler.java
示例13: authenticate
import org.jasig.cas.authentication.HandlerResult; //导入依赖的package包/类
@Override
public HandlerResult authenticate(final Credential credential) throws GeneralSecurityException {
final HttpBasedServiceCredential httpCredential = (HttpBasedServiceCredential) credential;
if (!httpCredential.getService().getProxyPolicy().isAllowedProxyCallbackUrl(httpCredential.getCallbackUrl())) {
logger.warn("Proxy policy for service [{}] cannot authorize the requested callbackurl [{}]",
httpCredential.getService(), httpCredential.getCallbackUrl());
throw new FailedLoginException(httpCredential.getCallbackUrl() + " cannot be authorized");
}
logger.debug("Attempting to authenticate {}", httpCredential);
final URL callbackUrl = httpCredential.getCallbackUrl();
if (!this.httpClient.isValidEndPoint(callbackUrl)) {
throw new FailedLoginException(callbackUrl.toExternalForm() + " sent an unacceptable response status code");
}
return new DefaultHandlerResult(this, httpCredential, this.principalFactory.createPrincipal(httpCredential.getId()));
}
开发者ID:hsj-xiaokang,项目名称:springboot-shiro-cas-mybatis,代码行数:17,代码来源:HttpBasedServiceCredentialsAuthenticationHandler.java
示例14: authenticate
import org.jasig.cas.authentication.HandlerResult; //导入依赖的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
示例15: authenticateUsernamePasswordInternal
import org.jasig.cas.authentication.HandlerResult; //导入依赖的package包/类
/** {@inheritDoc} */
@Override
protected final HandlerResult authenticateUsernamePasswordInternal(final UsernamePasswordCredential credential)
throws GeneralSecurityException, PreventedException {
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, new SimplePrincipal(username), null);
}
开发者ID:luotuo,项目名称:cas4.0.x-server-wechat,代码行数:19,代码来源:SearchModeSearchDatabaseAuthenticationHandler.java