use of gemma.gsec.authentication.UserDetailsImpl in project Gemma by PavlidisLab.
the class AclCollectionBeforeTest method setup.
@Before
public final void setup() {
one = super.getTestPersistentBasicExpressionExperiment();
two = super.getTestPersistentBasicExpressionExperiment();
securityService.makePublic(one);
securityService.makePublic(two);
ees = new HashSet<>();
ees.add(one);
ees.add(two);
try {
userManager.loadUserByUsername(userName);
} catch (UsernameNotFoundException e) {
userManager.createUser(new UserDetailsImpl("foo", userName, true, null, RandomStringUtils.randomAlphabetic(10) + "@gmail.com", "key", new Date()));
}
}
use of gemma.gsec.authentication.UserDetailsImpl in project Gemma by PavlidisLab.
the class AuditAdviceTest method testSimpleAuditCreateUpdateUser.
@Test
public void testSimpleAuditCreateUpdateUser() {
String USERNAME = RandomStringUtils.randomAlphabetic(BaseSpringContextTest.RANDOM_STRING_LENGTH);
String encodedPassword = passwordEncoder.encodePassword(USERNAME, USERNAME);
UserDetailsImpl u = new UserDetailsImpl(encodedPassword, USERNAME, true, null, null, null, new Date());
userManager.createUser(u);
User user = (User) userService.findByUserName(USERNAME);
List<AuditEvent> events = auditTrailService.getEvents(user);
assertEquals("Should have just one event, a 'create'", 1, events.size());
assertEquals(AuditAction.CREATE, events.get(0).getAction());
assertNotNull(events.get(0).getId());
// change something.
user.setEmail(RandomStringUtils.randomNumeric(10));
userService.update(user);
events = auditTrailService.getEvents(user);
int sizeAfterFirstUpdate = events.size();
assertEquals("Should have a 'create' and an 'update'", 2, sizeAfterFirstUpdate);
// debugging...
if (!events.get(0).getAction().equals(AuditAction.CREATE)) {
log.info("First event wasn't 'C', dumping trail");
for (AuditEvent ae : events) {
log.info(ae);
}
}
assertEquals(AuditAction.CREATE, events.get(0).getAction());
assertEquals(AuditAction.UPDATE, events.get(sizeAfterFirstUpdate - 1).getAction());
// third time.
// change something.
user.setEmail(RandomStringUtils.randomNumeric(10));
userService.update(user);
events = auditTrailService.getEvents(user);
assertEquals(3, user.getAuditTrail().getEvents().size());
assertEquals(AuditAction.UPDATE, events.get(2).getAction());
// cleanup
userManager.deleteUser(USERNAME);
}
use of gemma.gsec.authentication.UserDetailsImpl in project Gemma by PavlidisLab.
the class ManualAuthenticationProcessingTest method before.
@Before
public void before() {
pwd = this.randomName();
username = this.randomName();
try {
userManager.loadUserByUsername(username);
} catch (UsernameNotFoundException e) {
String encodedPassword = passwordEncoder.encodePassword(pwd, username);
UserDetailsImpl u = new UserDetailsImpl(encodedPassword, username, true, null, null, null, new Date());
userManager.createUser(u);
}
}
use of gemma.gsec.authentication.UserDetailsImpl in project Gemma by PavlidisLab.
the class ExecutingTaskTest method testSecurityContextManagement.
@Test
public void testSecurityContextManagement() {
try {
this.userManager.loadUserByUsername("ExecutingTaskTestUser");
} catch (UsernameNotFoundException e) {
this.userManager.createUser(new UserDetailsImpl("foo", "ExecutingTaskTestUser", true, null, "fooUser@chibi.ubc.ca", "key", new Date()));
}
this.runAsUser("ExecutingTaskTestUser");
TaskCommand taskCommand = new TaskCommand();
this.runAsAdmin();
Task<TaskResult, TaskCommand> task = new SuccessTestTask();
task.setTaskCommand(taskCommand);
ExecutingTask<TaskResult> executingTask = new ExecutingTask<>(task, taskCommand);
executingTask.setProgressAppender(progressAppender);
executingTask.setStatusCallback(statusSecurityContextCheckerHandler);
ExecutorService executorService = Executors.newSingleThreadExecutor();
Future<TaskResult> future = executorService.submit(executingTask);
this.tryGetAnswer(future);
assertEquals(taskCommand.getSecurityContext(), securityContextAfterInitialize);
assertNotSame(taskCommand.getSecurityContext(), securityContextAfterFinish);
assertEquals(null, securityContextAfterFail);
}
use of gemma.gsec.authentication.UserDetailsImpl in project Gemma by PavlidisLab.
the class SecurityControllerImpl method getGroupMembers.
@Override
public Collection<UserValueObject> getGroupMembers(String groupName) {
Collection<UserValueObject> result = new HashSet<>();
// happens if user is not in any displayed groups.
if (StringUtils.isBlank(groupName)) {
return result;
}
List<String> usersInGroup = userManager.findUsersInGroup(groupName);
for (String userName : usersInGroup) {
UserDetails details = userManager.loadUserByUsername(userName);
UserValueObject uvo = new UserValueObject();
uvo.setUserName(details.getUsername());
if (details instanceof UserDetailsImpl) {
uvo.setEmail(((UserDetailsImpl) details).getEmail());
}
uvo.setCurrentGroup(groupName);
uvo.setInGroup(true);
uvo.setAllowModification(true);
/*
* You can't remove yourself from a group, or remove users from the USER group.
*/
if (userName.equals(userManager.getCurrentUsername()) || groupName.equals(AuthorityConstants.USER_GROUP_NAME)) {
uvo.setAllowModification(false);
}
result.add(uvo);
}
return result;
}
Aggregations