Search in sources :

Example 1 with GaeUser

use of samples.gae.users.GaeUser in project spring-security by spring-projects.

the class RegistrationController method register.

@RequestMapping(method = RequestMethod.POST)
public String register(@Valid RegistrationForm form, BindingResult result) {
    if (result.hasErrors()) {
        return null;
    }
    Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
    GaeUser currentUser = (GaeUser) authentication.getPrincipal();
    Set<AppRole> roles = EnumSet.of(AppRole.USER);
    if (UserServiceFactory.getUserService().isUserAdmin()) {
        roles.add(AppRole.ADMIN);
    }
    GaeUser user = new GaeUser(currentUser.getUserId(), currentUser.getNickname(), currentUser.getEmail(), form.getForename(), form.getSurname(), roles, true);
    registry.registerUser(user);
    // Update the context with the full authentication
    SecurityContextHolder.getContext().setAuthentication(new GaeUserAuthentication(user, authentication.getDetails()));
    return "redirect:/home.htm";
}
Also used : AppRole(samples.gae.security.AppRole) GaeUserAuthentication(samples.gae.security.GaeUserAuthentication) Authentication(org.springframework.security.core.Authentication) GaeUserAuthentication(samples.gae.security.GaeUserAuthentication) GaeUser(samples.gae.users.GaeUser) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 2 with GaeUser

use of samples.gae.users.GaeUser in project spring-security by spring-projects.

the class GoogleAccountsAuthenticationProvider method authenticate.

public Authentication authenticate(Authentication authentication) throws AuthenticationException {
    User googleUser = (User) authentication.getPrincipal();
    GaeUser user = userRegistry.findUser(googleUser.getUserId());
    if (user == null) {
        // User not in registry. Needs to register
        user = new GaeUser(googleUser.getUserId(), googleUser.getNickname(), googleUser.getEmail());
    }
    if (!user.isEnabled()) {
        throw new DisabledException("Account is disabled");
    }
    return new GaeUserAuthentication(user, authentication.getDetails());
}
Also used : GaeUser(samples.gae.users.GaeUser) User(com.google.appengine.api.users.User) DisabledException(org.springframework.security.authentication.DisabledException) GaeUser(samples.gae.users.GaeUser)

Aggregations

GaeUser (samples.gae.users.GaeUser)2 User (com.google.appengine.api.users.User)1 DisabledException (org.springframework.security.authentication.DisabledException)1 Authentication (org.springframework.security.core.Authentication)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1 AppRole (samples.gae.security.AppRole)1 GaeUserAuthentication (samples.gae.security.GaeUserAuthentication)1