use of org.apache.shiro.subject.support.DefaultSubjectContext in project shiro by apache.
the class AbstractRememberMeManagerTest method testGetRememberedPrincipalsWithEmptySerializedBytes.
/**
* Tests the {@link AbstractRememberMeManager#getRememberedPrincipals(SubjectContext)} method
* implementation when the internal
* {@link AbstractRememberMeManager#getRememberedSerializedIdentity(SubjectContext)} method
* returns null or empty bytes.
*/
@Test
public void testGetRememberedPrincipalsWithEmptySerializedBytes() {
AbstractRememberMeManager rmm = new DummyRememberMeManager();
// Since the dummy's getRememberedSerializedIdentity implementation returns an empty byte
// array, we should be ok:
PrincipalCollection principals = rmm.getRememberedPrincipals(new DefaultSubjectContext());
assertNull(principals);
// try with a null return value too:
rmm = new DummyRememberMeManager() {
@Override
protected byte[] getRememberedSerializedIdentity(SubjectContext subjectContext) {
return null;
}
};
principals = rmm.getRememberedPrincipals(new DefaultSubjectContext());
assertNull(principals);
}
use of org.apache.shiro.subject.support.DefaultSubjectContext in project vertx-auth by vert-x3.
the class ShiroAuthProviderImpl method authenticate.
@Override
public void authenticate(JsonObject authInfo, Handler<AsyncResult<User>> resultHandler) {
vertx.executeBlocking(fut -> {
// before doing any shiro operations set the context
SecurityUtils.setSecurityManager(securityManager);
// proceed
SubjectContext subjectContext = new DefaultSubjectContext();
Subject subject = securityManager.createSubject(subjectContext);
String username = authInfo.getString("username");
String password = authInfo.getString("password");
AuthenticationToken token = new UsernamePasswordToken(username, password);
try {
subject.login(token);
fut.complete(new ShiroUser(vertx, securityManager, subject, rolePrefix));
} catch (AuthenticationException e) {
fut.fail(e);
}
}, resultHandler);
}
use of org.apache.shiro.subject.support.DefaultSubjectContext in project vertx-auth by vert-x3.
the class ShiroUser method setAuthProvider.
@Override
public void setAuthProvider(AuthProvider authProvider) {
if (authProvider instanceof ShiroAuthProviderImpl) {
ShiroAuthProviderImpl shiroAuthProvider = (ShiroAuthProviderImpl) authProvider;
this.vertx = shiroAuthProvider.getVertx();
this.securityManager = shiroAuthProvider.getSecurityManager();
// before doing any shiro operations set the context
SecurityUtils.setSecurityManager(securityManager);
// generate the subject back from the provider
SubjectContext subjectContext = new DefaultSubjectContext();
PrincipalCollection coll = new SimplePrincipalCollection(username, shiroAuthProvider.getRealmName());
subjectContext.setPrincipals(coll);
subject = securityManager.createSubject(subjectContext);
} else {
throw new IllegalArgumentException("Not a ShiroAuthProviderImpl");
}
}
Aggregations