use of com.nixmash.blog.jpa.model.CurrentUser in project nixmash-blog by mintster.
the class GlobalController method displayGoogleAnalytics.
@ModelAttribute("displayGoogleAnalytics")
public Boolean displayGoogleAnalytics(Authentication authentication) {
CurrentUser currentUser = this.getCurrentUser(authentication);
Boolean displayAnalytics = siteOptions.getAddGoogleAnalytics();
if (currentUser != null) {
boolean isDisplayUser = !(currentUser.isAdmin() || currentUser.isPostUser());
return displayAnalytics && isDisplayUser;
} else
return displayAnalytics;
}
use of com.nixmash.blog.jpa.model.CurrentUser in project nixmash-blog by mintster.
the class SignInUtils method authorizeUser.
public static void authorizeUser(User user) {
CurrentUser currentUser = new CurrentUser(user);
SecurityContextHolder.getContext().setAuthentication(new UsernamePasswordAuthenticationToken(currentUser, user.getPassword(), user.getAuthorities()));
}
use of com.nixmash.blog.jpa.model.CurrentUser in project nixmash-blog by mintster.
the class SecurityTests method gmailDomainPassesFilter_IsNotYetApproved.
@Test(expected = DisabledException.class)
public void gmailDomainPassesFilter_IsNotYetApproved() throws Exception {
RequestBuilder request = post("/register").param("username", "user1215155").param("firstName", "Bob").param("lastName", "Crachet").param("email", "bob@gmail.com").param("password", "password").param("repeatedPassword", "password").with(csrf());
mvc.perform(request).andExpect(status().is3xxRedirection());
// user is disabled. Where it throws DisabledException
CurrentUser currentUser1215155 = currentUserDetailsService.loadUserByUsername("user1215155");
}
use of com.nixmash.blog.jpa.model.CurrentUser in project nixmash-blog by mintster.
the class UsernameAuditorAware method getCurrentAuditor.
@Override
public String getCurrentAuditor() {
logger.debug("Getting the username of authenticated user.");
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
if (authentication == null) {
// in testing mode, return admin
return TESTGUY_USERNAME;
}
if (authentication.getPrincipal().equals("anonymousUser")) {
logger.debug("Current user is anonymous.");
return ANONYMOUS_USERNAME;
}
String username = ((CurrentUser) authentication.getPrincipal()).getUsername();
logger.debug("Returning username: {}", username);
return username;
}
Aggregations