Search in sources :

Example 1 with CurrentUser

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;
}
Also used : CurrentUser(com.nixmash.blog.jpa.model.CurrentUser) ModelAttribute(org.springframework.web.bind.annotation.ModelAttribute)

Example 2 with CurrentUser

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()));
}
Also used : CurrentUser(com.nixmash.blog.jpa.model.CurrentUser) UsernamePasswordAuthenticationToken(org.springframework.security.authentication.UsernamePasswordAuthenticationToken)

Example 3 with CurrentUser

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");
}
Also used : RequestBuilder(org.springframework.test.web.servlet.RequestBuilder) CurrentUser(com.nixmash.blog.jpa.model.CurrentUser) Test(org.junit.Test)

Example 4 with CurrentUser

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;
}
Also used : CurrentUser(com.nixmash.blog.jpa.model.CurrentUser) Authentication(org.springframework.security.core.Authentication)

Aggregations

CurrentUser (com.nixmash.blog.jpa.model.CurrentUser)4 Test (org.junit.Test)1 UsernamePasswordAuthenticationToken (org.springframework.security.authentication.UsernamePasswordAuthenticationToken)1 Authentication (org.springframework.security.core.Authentication)1 RequestBuilder (org.springframework.test.web.servlet.RequestBuilder)1 ModelAttribute (org.springframework.web.bind.annotation.ModelAttribute)1