Derzeit verwende ich Apache Shiro-Authentifizierung in meinem Spring-Boot-Projekt. Ich habe Custom Realm für Cassandra DB geschrieben. Während das Autowiren der Klasse innerhalb des Realmobjekts null zurückgibt, wenn Anmeldedaten gesendet werden. My Application Config (@component Annotation):Autowiring funktioniert nicht in Apache Shiro benutzerdefinierte Realm-Klasse
@Bean(name = "realm")
@DependsOn("lifecycleBeanPostProcessor")
public ApplicationRealm realm() {
ApplicationRealm realm = new ApplicationRealm();
realm.init();
return realm;
}
@Bean
public LifecycleBeanPostProcessor lifecycleBeanPostProcessor() {
return new LifecycleBeanPostProcessor();
}
My Application Realm Klasse:
@Configuration
@ComponentScan("com.scm.auth")
public class ApplicationRealm extends AuthorizingRealm {
@Autowired
IAuthRepository authRepo;
@Override
protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principals) {
Set<String> roles = new HashSet<String>();
try {
roles.add("admin");
} catch (Exception rEx) {
throw new AuthorizationException(rEx);
}
SimpleAuthorizationInfo info = new SimpleAuthorizationInfo(roles);
info.setRoles(roles);
return info;
}
@Override
protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) throws AuthenticationException {
SimpleAuthenticationInfo info = null;
UsernamePasswordToken upToken = (UsernamePasswordToken) token;
User user = authRepo.findByUserName(upToken.getUsername(), true); // my model class
try {
if (user.getCurrentPwd().equals(upToken.getPassword())) {
info = new SimpleAuthenticationInfo(user, user.getCurrentPwd(), getName());
} else {
throw new AuthenticationException("Login name [" + upToken.getUsername() + "] not found!");
}
} catch (Exception idEx) {
throw new AuthenticationException(idEx);
}
return info;
}
Ist jede Anmerkung verpasst?