我有自定义身份验证提供程序和自定义身份验证处理程序,用于Spring安全性和自定义用户类,它实现了UserDetails接口。 现在我希望我的应用程序中的所有活动用户列表。 我在web.xml中添加了以下代码
fdescribe('AddItemComponent: ', () => {
let cmp: AddItemComponent;
let fixture: ComponentFixture<AddItemComponent>;
let de: DebugElement;
let el: HTMLElement;
const mockRouter = {
navigate: jasmine.createSpy('navigate')
};
const mockCustomCardService = {
getItemDeliveryDate: () => Observable.empty(),
emitItemChanges: () => Observable.empty(),
};
const mockActivatedRoute = { snapshot: {} };
const mockPageDataService = {};
const mockUserService = {};
beforeEach(() => {
TestBed.configureTestingModule({
declarations: [AddItemComponent],
imports: [FormsModule, ReactiveFormsModule, SharedModule, TranslateModule.forRoot(), RouterTestingModule],
providers: [
SpinningService,
FormBuilder,
TranslateService,
{ provide: Router, useValue: mockRouter },
{ provide: CustomItemService, useValue: mockCustomItemService },
{ provide: PageDataService, useValue: mockPageDataService },
{ provide: UserService, useValue: mockUserService },
{ provide: ActivatedRoute, useValue: mockActivatedRoute }
],
schemas: [NO_ERRORS_SCHEMA]
});
fixture = TestBed.createComponent(AddItemComponent);
cmp = fixture.componentInstance;
fixture.detectChanges();
});
it('Simple test', () => {
expect(true).toBeTruthy();
});
});
在app-context.xml中的代码下面
<listener>
<listener-class>
org.springframework.security.web.session.HttpSessionEventPublisher
</listener-class>
</listener>
在security.xml中的代码下面
<bean id="sessionRegistry"
class="org.springframework.security.core.session.SessionRegistryImpl" />
在我的控制器中我使用了
<session-management>
<concurrency-control
session-registry-alias="sessionRegistry" />
</session-management>
System.out.println的结果为0。
答案 0 :(得分:0)
也许这可能是一个重复的问题:sessionRegistry is empty when I use ConcurrentSessionControlAuthenticationStrategy instead of ConcurrentSessionControlStrategy,但最常见的问题通常是加载弹簧上下文两次。检查您是否没有基于注释的上下文和applicationContext.xml。