Files
SCM-Manager/scm-webapp/src/main/java/sonia/scm/security/AnonymousRealm.java

45 lines
1.3 KiB
Java
Raw Normal View History

package sonia.scm.security;
import com.google.common.annotations.VisibleForTesting;
import com.google.inject.Inject;
import org.apache.shiro.authc.AuthenticationInfo;
import org.apache.shiro.authc.AuthenticationToken;
import org.apache.shiro.authc.credential.AllowAllCredentialsMatcher;
import org.apache.shiro.realm.AuthenticatingRealm;
import sonia.scm.SCMContext;
import sonia.scm.plugin.Extension;
import javax.inject.Singleton;
2019-10-17 09:26:36 +02:00
import static com.google.common.base.Preconditions.checkArgument;
@Singleton
@Extension
public class AnonymousRealm extends AuthenticatingRealm {
/**
* realm name
*/
@VisibleForTesting
static final String REALM = "AnonymousRealm";
/**
* dao realm helper
*/
private final DAORealmHelper helper;
@Inject
public AnonymousRealm(DAORealmHelperFactory helperFactory) {
this.helper = helperFactory.create(REALM);
setAuthenticationTokenClass(AnonymousToken.class);
setCredentialsMatcher(new AllowAllCredentialsMatcher());
}
@Override
2019-10-17 09:26:36 +02:00
protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken authenticationToken) {
checkArgument(authenticationToken instanceof AnonymousToken, "%s is required", AnonymousToken.class);
return helper.authenticationInfoBuilder(SCMContext.USER_ANONYMOUS).build();
}
}