List of usage examples for org.springframework.security.core Authentication Authentication
Authentication
From source file:se.kth.csc.config.MockAuthConfig.java
@Bean @Autowired// w w w . j a v a2 s. c o m public AuthenticationProvider authenticationProvider( final AuthenticationUserDetailsService<Authentication> authenticationUserDetailsService) { return new AuthenticationProvider() { @Override public Authentication authenticate(final Authentication authentication) throws AuthenticationException { final UserDetails userDetails = authenticationUserDetailsService.loadUserDetails(authentication); return new Authentication() { @Override public Collection<? extends GrantedAuthority> getAuthorities() { return userDetails.getAuthorities(); } @Override public Object getCredentials() { return authentication.getCredentials(); } @Override public Object getDetails() { return authentication.getDetails(); } public UserDetails getUserDetails() { return userDetails; } @Override public Object getPrincipal() { return userDetails; } @Override public boolean isAuthenticated() { return authentication.isAuthenticated(); } @Override public void setAuthenticated(boolean isAuthenticated) throws IllegalArgumentException { authentication.setAuthenticated(isAuthenticated); } @Override public String getName() { return authentication.getName(); } }; } @Override public boolean supports(Class<?> authentication) { return true; } }; }
From source file:com.orange.clara.cloud.servicedbdumper.security.AccessManagerTest.java
private void injectAdmin() { when(accessManager.getSecurityContextHolder()).thenReturn(new SecurityContext() { @Override/* ww w . j ava 2 s . c o m*/ public Authentication getAuthentication() { return new Authentication() { @Override public Collection<? extends GrantedAuthority> getAuthorities() { List<GrantedAuthority> grantedAuthorities = Lists.newArrayList(); grantedAuthorities.add(new SimpleGrantedAuthority(AccessManager.AUTHORIZED_AUTHORITY)); return grantedAuthorities; } @Override public String getName() { return null; } @Override public Object getCredentials() { return null; } @Override public Object getDetails() { return null; } @Override public Object getPrincipal() { return null; } @Override public boolean isAuthenticated() { return false; } @Override public void setAuthenticated(boolean b) throws IllegalArgumentException { } }; } @Override public void setAuthentication(Authentication authentication) { } }); }
From source file:org.cloudfoundry.identity.uaa.audit.event.GroupModifiedEvent.java
protected static Authentication getContextAuthentication() { Authentication a = SecurityContextHolder.getContext().getAuthentication(); if (a == null) { a = new Authentication() { ArrayList<GrantedAuthority> authorities = new ArrayList<GrantedAuthority>(); @Override/*from w ww . j a v a2 s . c o m*/ public Collection<? extends GrantedAuthority> getAuthorities() { return authorities; } @Override public Object getCredentials() { return null; } @Override public Object getDetails() { return null; } @Override public Object getPrincipal() { return "null"; } @Override public boolean isAuthenticated() { return false; } @Override public void setAuthenticated(boolean isAuthenticated) throws IllegalArgumentException { } @Override public String getName() { return "null"; } }; } return a; }
From source file:com.orange.clara.cloud.servicedbdumper.security.AccessManagerTest.java
private void injectUser() { when(accessManager.getSecurityContextHolder()).thenReturn(new SecurityContext() { @Override/* w w w .j ava 2 s . c o m*/ public Authentication getAuthentication() { return new Authentication() { @Override public Collection<? extends GrantedAuthority> getAuthorities() { List<GrantedAuthority> grantedAuthorities = Lists.newArrayList(); grantedAuthorities.add(new SimpleGrantedAuthority("USER")); return grantedAuthorities; } @Override public Object getCredentials() { return null; } @Override public Object getDetails() { return null; } @Override public Object getPrincipal() { return null; } @Override public boolean isAuthenticated() { return false; } @Override public void setAuthenticated(boolean b) throws IllegalArgumentException { } @Override public String getName() { return null; } }; } @Override public void setAuthentication(Authentication authentication) { } }); }
From source file:bjerne.gallery.service.impl.GalleryAuthorizationServiceSSImpl.java
@Override public void loginAdminUser() { Authentication auth = new Authentication() { private static final long serialVersionUID = -7444637463199474476L; @Override/*from w ww . ja v a 2s. c om*/ public String getName() { return "admin"; } @Override public Collection<? extends GrantedAuthority> getAuthorities() { return rootDirs.stream().map(rd -> new SimpleGrantedAuthority(rd.getRole())) .collect(Collectors.toList()); } @Override public Object getCredentials() { return null; } @Override public Object getDetails() { return null; } @Override public Object getPrincipal() { return "admin"; } @Override public boolean isAuthenticated() { return true; } @Override public void setAuthenticated(boolean arg0) throws IllegalArgumentException { } }; SecurityContextHolder.getContext().setAuthentication(auth); }
From source file:org.slc.sli.dashboard.unit.client.LiveAPIClientTest.java
@Ignore @Test/* w w w.j ava2s .c o m*/ public void testGetSchools() { LiveAPIClient liveClient = new LiveAPIClient() { @Override public String getId(String token) { return null; } @Override public List<GenericEntity> getSectionsForTeacher(String teacherId, String token, String schoolId) { return null; } }; SecurityContextHolder.getContext().setAuthentication(new Authentication() { @Override public String getName() { // TODO Auto-generated method stub return null; } @Override public void setAuthenticated(boolean isAuthenticated) throws IllegalArgumentException { // TODO Auto-generated method stub } @Override public boolean isAuthenticated() { // TODO Auto-generated method stub return false; } @Override public Object getPrincipal() { // TODO Auto-generated method stub return null; } @Override public Object getDetails() { // TODO Auto-generated method stub return null; } @Override public Object getCredentials() { // TODO Auto-generated method stub return null; } @Override public Collection<GrantedAuthority> getAuthorities() { // TODO Auto-generated method stub return Collections.emptyList(); } }); String token = "fakeToken"; String[] ids = { "1", "2" }; List<GenericEntity> result = liveClient.getSchools(token, Arrays.asList(ids)); assertEquals(result.size(), 1); }
From source file:org.slc.sli.dashboard.unit.client.SDKAPIClientTest.java
@Test public void testGetSchools() throws URISyntaxException, IOException, MessageProcessingException, SLIClientException { SDKAPIClient client = new SDKAPIClient() { @Override/*from w ww . j a va 2s. c om*/ public String getId(String token) { return null; } @Override public List<GenericEntity> getSectionsForTeacher(String teacherId, String token, Map<String, String> params) { return null; } @Override public List<GenericEntity> getSectionsForNonEducator(String token, Map<String, String> params) { return null; } }; SLIClientFactory factory = mock(SLIClientFactory.class); when(factory.getClientWithSessionToken(anyString())).thenReturn(mockSdk); client.setClientFactory(factory); SecurityContextHolder.getContext().setAuthentication(new Authentication() { @Override public String getName() { return null; } @Override public void setAuthenticated(boolean isAuthenticated) throws IllegalArgumentException { } @Override public boolean isAuthenticated() { return false; } @Override public Object getPrincipal() { return null; } @Override public Object getDetails() { return null; } @Override public Object getCredentials() { return null; } @Override public Collection<GrantedAuthority> getAuthorities() { return Collections.emptyList(); } }); String token = "token"; String key = "schoolId"; String[] idArr = { "Illinois PS145", "Illinois PS200" }; List<String> schoolIds = Arrays.asList(idArr); String filename = getFilename(MOCK_DATA_DIRECTORY + "common/" + MOCK_SCHOOL_FILE); when(mockSdk.read(anyString())).thenReturn(fromFileWithIDList(filename, schoolIds, key)); List<GenericEntity> schoolList = client.getSchools(token, schoolIds); assertNotNull(schoolList); assertEquals(2, schoolList.size()); ListIterator<GenericEntity> li = schoolList.listIterator(); while (li.hasNext()) { assertTrue(schoolIds.contains(li.next().getString(key))); } }
From source file:org.finra.herd.service.helper.DefaultNotificationMessageBuilderTest.java
@SuppressWarnings("serial") @Test/*from w w w .j av a2 s .com*/ public void testBuildBusinessObjectDataStatusChangeMessagesWithXmlPayloadWithUserInContext() throws Exception { Authentication originalAuthentication = SecurityContextHolder.getContext().getAuthentication(); try { SecurityContextHolder.getContext().setAuthentication(new Authentication() { @Override public String getName() { return null; } @Override public void setAuthenticated(boolean isAuthenticated) throws IllegalArgumentException { } @Override public boolean isAuthenticated() { return false; } @Override public Object getPrincipal() { List<GrantedAuthority> authorities = Collections.emptyList(); return new User("testUsername", "", authorities); } @Override public Object getDetails() { return null; } @Override public Object getCredentials() { return null; } @Override public Collection<? extends GrantedAuthority> getAuthorities() { return null; } }); // Test message building using 4 sub-partitions and a non-default user. testBuildBusinessObjectDataStatusChangeMessagesWithXmlPayloadHelper(SUBPARTITION_VALUES, "testUsername"); } finally { // Restore the original authentication. SecurityContextHolder.getContext().setAuthentication(originalAuthentication); } }
From source file:org.finra.herd.service.helper.notification.BusinessObjectDataStatusChangeMessageBuilderTest.java
@SuppressWarnings("serial") @Test//w w w . ja v a 2s . c om public void testBuildBusinessObjectDataStatusChangeMessagesXmlPayloadUserInContext() throws Exception { Authentication originalAuthentication = SecurityContextHolder.getContext().getAuthentication(); try { SecurityContextHolder.getContext().setAuthentication(new Authentication() { @Override public Collection<? extends GrantedAuthority> getAuthorities() { return null; } @Override public Object getCredentials() { return null; } @Override public Object getDetails() { return null; } @Override public String getName() { return null; } @Override public Object getPrincipal() { List<GrantedAuthority> authorities = Collections.emptyList(); return new User("testUsername", "", authorities); } @Override public boolean isAuthenticated() { return false; } @Override public void setAuthenticated(boolean isAuthenticated) throws IllegalArgumentException { } }); // Test message building using 4 sub-partitions and a non-default user. testBuildBusinessObjectDataStatusChangeMessagesWithXmlPayloadHelper(SUBPARTITION_VALUES, "testUsername"); } finally { // Restore the original authentication. SecurityContextHolder.getContext().setAuthentication(originalAuthentication); } }