本文整理汇总了Java中org.apache.shiro.authc.credential.CredentialsMatcher类的典型用法代码示例。如果您正苦于以下问题:Java CredentialsMatcher类的具体用法?Java CredentialsMatcher怎么用?Java CredentialsMatcher使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
CredentialsMatcher类属于org.apache.shiro.authc.credential包,在下文中一共展示了CredentialsMatcher类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: assertCredentialsMatch
import org.apache.shiro.authc.credential.CredentialsMatcher; //导入依赖的package包/类
@Override
protected void assertCredentialsMatch(AuthenticationToken token, AuthenticationInfo info) throws AuthenticationException {
CredentialsMatcher cm = getCredentialsMatcher();
if (cm != null) {
if (!cm.doCredentialsMatch(token, info)) {
//not successful - throw an exception to indicate this:
String msg = "Submitted credentials for token [" + token + "] did not match the expected credentials.";
throw new IncorrectCredentialsException(msg);
}else {
//记录登陆日志
/* ShiroUser shiroUser = (ShiroUser)(info.getPrincipals().getPrimaryPrincipal());
Log log = LogBuilder.OP_LOG.buildCommonLog("登陆", shiroUser.getClientIp(), shiroUser.getLoginName());
logService.log(log);*/
}
} else {
throw new AuthenticationException("A CredentialsMatcher must be configured in order to verify " +
"credentials during authentication. If you do not wish for credentials to be examined, you " +
"can configure an " + AllowAllCredentialsMatcher.class.getName() + " instance.");
}
}
示例2: jdbcRealm
import org.apache.shiro.authc.credential.CredentialsMatcher; //导入依赖的package包/类
@Bean(name = "mainRealm")
@ConditionalOnMissingBean(name = "mainRealm")
@ConditionalOnProperty(prefix = "shiro.realm.jdbc", name = "enabled", havingValue = "true")
@DependsOn(value = {"dataSource", "lifecycleBeanPostProcessor", "credentialsMatcher"})
public Realm jdbcRealm(DataSource dataSource, CredentialsMatcher credentialsMatcher) {
JdbcRealm realm = new JdbcRealm();
if (shiroJdbcRealmProperties.getAuthenticationQuery() != null) {
realm.setAuthenticationQuery(shiroJdbcRealmProperties.getAuthenticationQuery());
}
if (shiroJdbcRealmProperties.getUserRolesQuery() != null) {
realm.setUserRolesQuery(shiroJdbcRealmProperties.getUserRolesQuery());
}
if (shiroJdbcRealmProperties.getPermissionsQuery() != null) {
realm.setPermissionsQuery(shiroJdbcRealmProperties.getPermissionsQuery());
}
if (shiroJdbcRealmProperties.getSalt() != null) {
realm.setSaltStyle(shiroJdbcRealmProperties.getSalt());
}
realm.setPermissionsLookupEnabled(shiroJdbcRealmProperties.isPermissionsLookupEnabled());
realm.setDataSource(dataSource);
realm.setCredentialsMatcher(credentialsMatcher);
return realm;
}
示例3: AuthenticatingRealm
import org.apache.shiro.authc.credential.CredentialsMatcher; //导入依赖的package包/类
public AuthenticatingRealm(CacheManager cacheManager, CredentialsMatcher matcher) {
authenticationTokenClass = UsernamePasswordToken.class;
//retain backwards compatibility for Shiro 1.1 and earlier. Setting to true by default will probably cause
//unexpected results for existing applications:
this.authenticationCachingEnabled = false;
int instanceNumber = INSTANCE_COUNT.getAndIncrement();
this.authenticationCacheName = getClass().getName() + DEFAULT_AUTHORIZATION_CACHE_SUFFIX;
if (instanceNumber > 0) {
this.authenticationCacheName = this.authenticationCacheName + "." + instanceNumber;
}
if (cacheManager != null) {
setCacheManager(cacheManager);
}
if (matcher != null) {
setCredentialsMatcher(matcher);
}
}
示例4: AuthorizingRealm
import org.apache.shiro.authc.credential.CredentialsMatcher; //导入依赖的package包/类
public AuthorizingRealm(CacheManager cacheManager, CredentialsMatcher matcher) {
super();
if (cacheManager != null) setCacheManager(cacheManager);
if (matcher != null) setCredentialsMatcher(matcher);
this.authorizationCachingEnabled = true;
this.permissionResolver = new WildcardPermissionResolver();
int instanceNumber = INSTANCE_COUNT.getAndIncrement();
this.authorizationCacheName = getClass().getName() + DEFAULT_AUTHORIZATION_CACHE_SUFFIX;
if (instanceNumber > 0) {
this.authorizationCacheName = this.authorizationCacheName + "." + instanceNumber;
}
}
示例5: assertCredentialsMatch
import org.apache.shiro.authc.credential.CredentialsMatcher; //导入依赖的package包/类
/**
* Asserts that the submitted {@code AuthenticationToken}'s credentials match the stored account
* {@code AuthenticationInfo}'s credentials, and if not, throws an {@link AuthenticationException}.
*
* @param token the submitted authentication token
* @param info the AuthenticationInfo corresponding to the given {@code token}
* @throws AuthenticationException if the token's credentials do not match the stored account credentials.
*/
protected void assertCredentialsMatch(AuthenticationToken token, AuthenticationInfo info) throws AuthenticationException {
CredentialsMatcher cm = getCredentialsMatcher();
if (cm != null) {
if (!cm.doCredentialsMatch(token, info)) {
//not successful - throw an exception to indicate this:
String msg = "Submitted credentials for token [" + token + "] did not match the expected credentials.";
throw new IncorrectCredentialsException(msg);
}
} else {
throw new AuthenticationException("A CredentialsMatcher must be configured in order to verify " +
"credentials during authentication. If you do not wish for credentials to be examined, you " +
"can configure an " + AllowAllCredentialsMatcher.class.getName() + " instance.");
}
}
示例6: isValidCredentials
import org.apache.shiro.authc.credential.CredentialsMatcher; //导入依赖的package包/类
/**
* Checks to see if the credentials in token match the credentials stored on user
*
* @param token the username/password token containing the credentials to verify
* @param user object containing the stored credentials
* @return true if credentials match, false otherwise
*/
private boolean isValidCredentials(final UsernamePasswordToken token, final CUser user) {
boolean credentialsValid = false;
AuthenticationInfo info = createAuthenticationInfo(user);
CredentialsMatcher matcher = getCredentialsMatcher();
if (matcher != null) {
if (matcher.doCredentialsMatch(token, info)) {
credentialsValid = true;
}
}
return credentialsValid;
}
示例7: provideCredentialsMatcher
import org.apache.shiro.authc.credential.CredentialsMatcher; //导入依赖的package包/类
/**
* When annotations activated, you'll need to hash passwords in your configured Realm (i.e.: shiro.ini file)
* @return credentialsMatcher singleton implementation for this application
*/
//@Provides
//@Singleton
public CredentialsMatcher provideCredentialsMatcher(){
HashedCredentialsMatcher matcher = new HashedCredentialsMatcher();
matcher.setHashAlgorithmName(CREDENTIALS_MATCHER_ALGORITHM_NAME);
return matcher;
}
示例8: provideCredentialsMatcher
import org.apache.shiro.authc.credential.CredentialsMatcher; //导入依赖的package包/类
/**
* When annotations activated, you'll need to hash passwords in your configured Realm (i.e.: shiro.ini file)
* @return credentialsMatcher singleton implementation for this application
*/
//@Provides
//@Singleton
public CredentialsMatcher provideCredentialsMatcher(){
logger.entry();
HashedCredentialsMatcher matcher = new HashedCredentialsMatcher();
matcher.setHashAlgorithmName(CREDENTIALS_MATCHER_ALGORITHM_NAME);
logger.exit(matcher);
return matcher;
}
示例9: whenPasswordIsGeneratedTheCredentialsShouldMatch
import org.apache.shiro.authc.credential.CredentialsMatcher; //导入依赖的package包/类
/**
* This test verifies that the AbstractHash and Salt are functioning
* correctly.
*/
@Test
public void whenPasswordIsGeneratedTheCredentialsShouldMatch() {
final CredentialsMatcher matcher = new SecurityModule(null).matcher();
final String salt = "abc";
final String plainPassword = "password";
final String hashedPassword = new UserFactory().hashPassword(plainPassword, salt);
final AuthenticationInfo info = new SimpleAccount("admin", hashedPassword, SaltTool.getFullSalt(salt), "testrealm");
final AuthenticationToken token = new UsernamePasswordToken("admin", plainPassword);
assertThat(matcher.doCredentialsMatch(token, info), is(true));
}
示例10: setupShiro
import org.apache.shiro.authc.credential.CredentialsMatcher; //导入依赖的package包/类
protected static void setupShiro() {
IniSecurityManagerFactory factory = new IniSecurityManagerFactory(); // ("classpath:shiro.ini");
DefaultSecurityManager dsm = (DefaultSecurityManager) factory.getInstance();
passwordService = (DefaultPasswordService) factory.getBeans().get("passwordService");
passwordMatcher = (CredentialsMatcher) factory.getBeans().get("passwordMatcher");
setSecurityManager(dsm);
}
示例11: setAuthzCredentialsMatcher
import org.apache.shiro.authc.credential.CredentialsMatcher; //导入依赖的package包/类
public void setAuthzCredentialsMatcher(CredentialsMatcher authzCredentialsMatcher) {
this.authzCredentialsMatcher = authzCredentialsMatcher;
}
示例12: setResourcesCredentialsMatcher
import org.apache.shiro.authc.credential.CredentialsMatcher; //导入依赖的package包/类
public void setResourcesCredentialsMatcher(CredentialsMatcher resourcesCredentialsMatcher) {
this.resourcesCredentialsMatcher = resourcesCredentialsMatcher;
}
示例13: ShiroDbRealm
import org.apache.shiro.authc.credential.CredentialsMatcher; //导入依赖的package包/类
public ShiroDbRealm(CacheManager cacheManager, CredentialsMatcher matcher) {
super(cacheManager, matcher);
}
示例14: SimpleAuthorizingRealm
import org.apache.shiro.authc.credential.CredentialsMatcher; //导入依赖的package包/类
public SimpleAuthorizingRealm(CacheManager cacheManager, CredentialsMatcher matcher) {
super(cacheManager, matcher);
setAuthenticationTokenClass(SimpleShiroToken.class); // 非常非常重要,与SecurityUtils.getSubject().login是对应关系!!!
}
示例15: credentialsMatcher
import org.apache.shiro.authc.credential.CredentialsMatcher; //导入依赖的package包/类
@Bean(name="credentialsMatcher")
public CredentialsMatcher credentialsMatcher(){
return new PasswordMatcher();
}