List of usage examples for org.springframework.security.core.context SecurityContextImpl SecurityContextImpl
public SecurityContextImpl()
From source file:com.apress.prospringintegration.security.SecurityMain.java
@SuppressWarnings("unchecked") public static SecurityContext createContext(String username, String password, String... roles) { SecurityContextImpl ctxImpl = new SecurityContextImpl(); UsernamePasswordAuthenticationToken authToken; if (roles != null && roles.length > 0) { GrantedAuthority[] authorities = new GrantedAuthority[roles.length]; for (int i = 0; i < roles.length; i++) { authorities[i] = new GrantedAuthorityImpl(roles[i]); }//from w ww. j a v a 2 s .com authToken = new UsernamePasswordAuthenticationToken(username, password, CollectionUtils.arrayToList(authorities)); } else { authToken = new UsernamePasswordAuthenticationToken(username, password); } ctxImpl.setAuthentication(authToken); return ctxImpl; }
From source file:org.ff4j.security.test.FlipSecurityTests.java
@Before public void setUp() throws Exception { securityCtx = SecurityContextHolder.getContext(); // Init SpringSecurity Context SecurityContext context = new SecurityContextImpl(); List<GrantedAuthority> listOfRoles = new ArrayList<GrantedAuthority>(); listOfRoles.add(new SimpleGrantedAuthority("ROLE_USER")); User u1 = new User("user1", "user1", true, true, true, true, listOfRoles); UsernamePasswordAuthenticationToken token = new UsernamePasswordAuthenticationToken(u1.getUsername(), u1.getPassword(), u1.getAuthorities()); token.setDetails(u1);/* w w w. j a va 2s.c o m*/ context.setAuthentication(token); SecurityContextHolder.setContext(context); // <-- ff4j = new FF4j("test-ff4j-security-spring.xml"); ff4j.setAuthorizationsManager(new SpringSecurityAuthorisationManager()); }
From source file:com.utest.domain.service.BaseDomainServiceIntegrationTest.java
protected void loginUser(final User user) throws Exception { final List<GrantedAuthority> grantedAuthorities = new ArrayList<GrantedAuthority>(); final AuthenticatedUserInfo authUser = new AuthenticatedUserInfo(user.getId(), user.getFullName()); final Authentication auth = new UsernamePasswordAuthenticationToken(authUser, null, grantedAuthorities); final SecurityContext ctx = new SecurityContextImpl(); ctx.setAuthentication(auth);//from w w w .j av a 2s .com SecurityContextHolder.setContext(ctx); }
From source file:be.dnsbelgium.rate.spring.security.LeakyBucketVoterTest.java
@Before public void setup() { SecurityContext context = new SecurityContextImpl(); context.setAuthentication(new TestingAuthenticationToken(USERNAME, null)); SecurityContextHolder.setContext(context); keyFactory = new UsernameLeakyBucketKeyFactory(); }
From source file:jedai.business.JedaiSecurityContextHolderStrategy.java
public SecurityContext getContext() { IConnection connection = Red5.getConnectionLocal(); if (connection != null) { synchronized (connection) { SecurityContext securityContext = (SecurityContext) connection.getAttribute(CONTEXT_ATTRIBUTE); if (securityContext == null) { securityContext = new SecurityContextImpl(); connection.setAttribute(CONTEXT_ATTRIBUTE, securityContext); }// www. jav a 2 s . c o m return securityContext; } } else { if (contextHolder.get() == null) { contextHolder.set(new SecurityContextImpl()); } return (SecurityContext) contextHolder.get(); } }
From source file:org.jasig.schedassist.web.register.delegate.DelegateRegistrationHelperTest.java
@Test public void testCurrentDelegateIsIneligibleDefault() { MockCalendarAccount ownerAccount = new MockCalendarAccount(); MockScheduleOwner owner = new MockScheduleOwner(ownerAccount, 1L); IDelegateCalendarAccount delegate = mock(IDelegateCalendarAccount.class); when(delegate.isEligible()).thenReturn(true); DelegateCalendarAccountUserDetailsImpl details = new DelegateCalendarAccountUserDetailsImpl(delegate, owner);/* w w w . j av a 2s. com*/ SecurityContext context = new SecurityContextImpl(); context.setAuthentication(new UsernamePasswordAuthenticationToken(details, "")); SecurityContextHolder.setContext(context); DelegateRegistrationHelper helper = new DelegateRegistrationHelper(); Assert.assertFalse(helper.currentDelegateIsIneligible()); }
From source file:org.parancoe.plugins.security.ParancoeSecurityContextHolderStrategy.java
@Override public SecurityContext createEmptyContext() { return new SecurityContextImpl(); }
From source file:org.ngrinder.security.NGrinderAuthenticationProviderTest.java
@Test public void testAdditionalAuthenticationChecks() { UserDetails user = userDetailService.loadUserByUsername(getTestUser().getUserId()); //remove authentication temporally Authentication oriAuth = SecurityContextHolder.getContext().getAuthentication(); SecurityContextImpl context = new SecurityContextImpl(); SecurityContextHolder.setContext(context); UsernamePasswordAuthenticationToken token = new UsernamePasswordAuthenticationToken("admin", null); try {/*from w w w.j ava 2 s.c o m*/ provider.additionalAuthenticationChecks(user, token); assertTrue(false); } catch (BadCredentialsException e) { assertTrue(true); } token = new UsernamePasswordAuthenticationToken("TEST_USER", "123"); provider.additionalAuthenticationChecks(user, token); context.setAuthentication(oriAuth); }
From source file:com.mtt.myapp.AbstractSystemTransactionalTest.java
@Before public void beforeSetSecurity() { UsernamePasswordAuthenticationToken token = new UsernamePasswordAuthenticationToken("admin", null); SecurityContextImpl context = new SecurityContextImpl(); context.setAuthentication(token);//w w w. ja va2s . c o m SecurityContextHolder.setContext(context); }
From source file:org.openmrs.contrib.metadatarepository.service.impl.UserSecurityAdviceTest.java
@Before public void setUp() throws Exception { // store initial security context for later restoration initialSecurityContext = SecurityContextHolder.getContext(); SecurityContext context = new SecurityContextImpl(); User user = new User("user"); user.setId(1L);// ww w .j a v a 2s. c o m user.setPassword("password"); user.addRole(new Role(Constants.USER_ROLE)); UsernamePasswordAuthenticationToken token = new UsernamePasswordAuthenticationToken(user.getUsername(), user.getPassword(), user.getAuthorities()); token.setDetails(user); context.setAuthentication(token); SecurityContextHolder.setContext(context); }