use of org.springframework.security.core.GrantedAuthority in project Asqatasun by Asqatasun.
the class HomeControllerTest method setUpMockAuthenticationContext.
private void setUpMockAuthenticationContext() {
// initialise the context with the user identified by the email
// "test1@test.com" seen as authenticated
Collection<GrantedAuthority> gac = new ArrayList<GrantedAuthority>();
TgolUserDetails tud = new TgolUserDetails("test1@test.com", "", true, false, true, true, gac, mockUser);
mockAuthentication = createMock(Authentication.class);
SecurityContextImpl securityContextImpl = new SecurityContextImpl();
securityContextImpl.setAuthentication(mockAuthentication);
SecurityContextHolder.setContext(securityContextImpl);
expect(mockAuthentication.getName()).andReturn("test1@test.com").anyTimes();
expect(mockAuthentication.getPrincipal()).andReturn(tud).anyTimes();
expect(mockAuthentication.getAuthorities()).andReturn(null).anyTimes();
replay(mockAuthentication);
mockAuthenticationDetails = createMock(AuthenticationDetails.class);
expect(mockAuthenticationDetails.getContext()).andReturn("test1@test.com").anyTimes();
replay(mockAuthenticationDetails);
}
use of org.springframework.security.core.GrantedAuthority in project OpenClinica by OpenClinica.
the class OpenClinicaLdapAuthoritiesPopulator method getGrantedAuthorities.
public Collection<GrantedAuthority> getGrantedAuthorities(DirContextOperations userData, String username) {
Collection<GrantedAuthority> auths = new ArrayList<GrantedAuthority>(1);
auths.add(new SimpleGrantedAuthority("ROLE_USER"));
return auths;
}
use of org.springframework.security.core.GrantedAuthority in project Activiti by Activiti.
the class BasicAuthenticationProvider method authenticate.
@Override
public Authentication authenticate(Authentication authentication) throws AuthenticationException {
String name = authentication.getName();
String password = authentication.getCredentials().toString();
boolean authenticated = identityService.checkPassword(name, password);
if (authenticated) {
List<Group> groups = identityService.createGroupQuery().groupMember(name).list();
Collection<GrantedAuthority> grantedAuthorities = new ArrayList<GrantedAuthority>();
for (Group group : groups) {
grantedAuthorities.add(new SimpleGrantedAuthority(group.getId()));
}
identityService.setAuthenticatedUserId(name);
return new UsernamePasswordAuthenticationToken(name, password, grantedAuthorities);
} else {
throw new BadCredentialsException("Authentication failed for this username and password");
}
}
use of org.springframework.security.core.GrantedAuthority in project Activiti by Activiti.
the class IdentityServiceUserDetailsService method loadUserByUsername.
@Override
public UserDetails loadUserByUsername(String userId) throws UsernameNotFoundException {
User user = null;
try {
user = this.identityService.createUserQuery().userId(userId).singleResult();
} catch (ActivitiException ex) {
// don't care
}
if (null == user) {
throw new UsernameNotFoundException(String.format("user (%s) could not be found", userId));
}
// if the results not null then its active...
boolean active = true;
// get the granted authorities
List<GrantedAuthority> grantedAuthorityList = new ArrayList<GrantedAuthority>();
List<Group> groupsForUser = identityService.createGroupQuery().groupMember(user.getId()).list();
for (Group g : groupsForUser) {
grantedAuthorityList.add(new GroupGrantedAuthority(g));
}
return new org.springframework.security.core.userdetails.User(user.getId(), user.getPassword(), active, active, active, active, grantedAuthorityList);
}
use of org.springframework.security.core.GrantedAuthority in project ORCID-Source by ORCID.
the class StatsApiServiceBaseImplTest method init.
@Before
public void init() {
// create our mock data
List<StatisticValuesEntity> statsTimelineValues = new ArrayList<StatisticValuesEntity>();
List<StatisticValuesEntity> statsSummaryValues = new ArrayList<StatisticValuesEntity>();
StatisticValuesEntity a = new StatisticValuesEntity();
a.setId(1l);
a.setStatisticName(StatisticsEnum.KEY_LIVE_IDS.value());
a.setStatisticValue(100l);
StatisticKeyEntity akey = new StatisticKeyEntity();
akey.setGenerationDate(new Date(2000, 1, 1));
akey.setId(200L);
a.setKey(akey);
StatisticValuesEntity b = new StatisticValuesEntity();
b.setId(1l);
b.setStatisticName(StatisticsEnum.KEY_LIVE_IDS.value());
b.setStatisticValue(101l);
StatisticKeyEntity bkey = new StatisticKeyEntity();
bkey.setGenerationDate(new Date(1999, 1, 1));
bkey.setId(201L);
b.setKey(bkey);
StatisticValuesEntity c = new StatisticValuesEntity();
c.setId(1l);
c.setStatisticName(StatisticsEnum.KEY_NUMBER_OF_WORKS.value());
c.setStatisticValue(102l);
c.setKey(akey);
statsTimelineValues.add(a);
statsTimelineValues.add(b);
statsSummaryValues.add(a);
statsSummaryValues.add(c);
// mock the methods used
when(statisticsDao.getLatestKey()).thenReturn(akey);
when(statisticsDao.getStatistic(StatisticsEnum.KEY_LIVE_IDS.value())).thenReturn(statsTimelineValues);
when(statisticsDao.getStatistic(200l)).thenReturn(statsSummaryValues);
// mock the methods used
StatisticKeyEntity key200 = new StatisticKeyEntity();
key200.setId(200L);
key200.setGenerationDate(new Date(2000, 1, 1));
StatisticKeyEntity key201 = new StatisticKeyEntity();
key201.setId(201L);
key201.setGenerationDate(new Date(1999, 1, 1));
when(statisticsDao.getKey(200L)).thenReturn(key200);
when(statisticsDao.getKey(201L)).thenReturn(key201);
TargetProxyHelper.injectIntoProxy(statsManagerReadOnly, "statisticsDaoReadOnly", statisticsDao);
// setup security context
ArrayList<GrantedAuthority> roles = new ArrayList<GrantedAuthority>();
roles.add(new SimpleGrantedAuthority("ROLE_ANONYMOUS"));
Authentication auth = new AnonymousAuthenticationToken("anonymous", "anonymous", roles);
SecurityContextHolder.getContext().setAuthentication(auth);
}
Aggregations