Search in sources :

Example 1 with Person

use of org.devgateway.toolkit.persistence.dao.Person in project ocvn by devgateway.

the class UserDashboardRestController method getCurrentAuthenticatedUserDetails.

@RequestMapping(method = { RequestMethod.POST, RequestMethod.GET }, value = "/userDashboards/getCurrentAuthenticatedUserDetails")
@ResponseBody
public ResponseEntity<?> getCurrentAuthenticatedUserDetails(PersistentEntityResourceAssembler persistentEntityResourceAssembler) {
    Person currentAuthenticatedPersonToken = getCurrentAuthenticatedPerson();
    Person currentAuthenticatedPerson;
    if (currentAuthenticatedPersonToken != null) {
        currentAuthenticatedPerson = personRepository.getOne(currentAuthenticatedPersonToken.getId());
    } else {
        return ResponseEntity.ok().build();
    }
    return ResponseEntity.ok(currentAuthenticatedPerson);
}
Also used : Person(org.devgateway.toolkit.persistence.dao.Person) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 2 with Person

use of org.devgateway.toolkit.persistence.dao.Person in project ocvn by devgateway.

the class TestUserDetailsConfiguration method testUserDetailsAdminProcuringEntity.

@Bean("testUserDetailsAdminProcuringEntity")
public UserDetailsService testUserDetailsAdminProcuringEntity() {
    return new UserDetailsService() {

        @Override
        public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
            Person person = new Person();
            person.setUsername(username);
            person.setPassword("idontcare");
            person.setAuthorities(Arrays.asList(new SimpleGrantedAuthority("ROLE_PROCURING_ENTITY"), new SimpleGrantedAuthority("ROLE_ADMIN")));
            return personRepository.save(person);
        }
    };
}
Also used : SimpleGrantedAuthority(org.springframework.security.core.authority.SimpleGrantedAuthority) UserDetailsService(org.springframework.security.core.userdetails.UserDetailsService) Person(org.devgateway.toolkit.persistence.dao.Person) Bean(org.springframework.context.annotation.Bean)

Example 3 with Person

use of org.devgateway.toolkit.persistence.dao.Person in project ocvn by devgateway.

the class BasePage method newAccountMenu.

protected NavbarButton<EditUserPage> newAccountMenu() {
    PageParameters pageParametersForAccountPage = new PageParameters();
    Person person = SecurityUtil.getCurrentAuthenticatedPerson();
    // account menu
    Model<String> account = null;
    if (person != null) {
        account = Model.of(person.getFirstName());
        pageParametersForAccountPage.add(WebConstants.PARAM_ID, person.getId());
    }
    NavbarButton<EditUserPage> accountMenu = new NavbarButton<>(EditUserPage.class, pageParametersForAccountPage, account);
    accountMenu.setIconType(GlyphIconType.user);
    MetaDataRoleAuthorizationStrategy.authorize(accountMenu, Component.RENDER, SecurityConstants.Roles.ROLE_USER);
    return accountMenu;
}
Also used : NavbarButton(de.agilecoders.wicket.core.markup.html.bootstrap.navbar.NavbarButton) PageParameters(org.apache.wicket.request.mapper.parameter.PageParameters) EditUserPage(org.devgateway.toolkit.forms.wicket.page.user.EditUserPage) Person(org.devgateway.toolkit.persistence.dao.Person)

Example 4 with Person

use of org.devgateway.toolkit.persistence.dao.Person in project ocvn by devgateway.

the class EditUserPage method getSaveEditPageButton.

@Override
public SaveEditPageButton getSaveEditPageButton() {
    return new SaveEditPageButton("save", new StringResourceModel("save", EditUserPage.this, null)) {

        private static final long serialVersionUID = 5214537995514151323L;

        @Override
        protected void onSubmit(final AjaxRequestTarget target, final Form<?> form) {
            Person saveable = editForm.getModelObject();
            StandardPasswordEncoder encoder = new StandardPasswordEncoder("");
            // encode the password
            if (saveable.getChangePass()) {
                saveable.setPassword(encoder.encode(password.getField().getModelObject()));
            } else {
                if (saveable.getPassword() == null || saveable.getPassword().compareTo("") == 0) {
                    feedbackPanel.error(new StringResourceModel("nullPassword", this, null).getString());
                    target.add(feedbackPanel);
                    return;
                }
            }
            // it again next time
            if (isChangePassPage()) {
                saveable.setChangePassword(false);
            }
            saveable = jpaRepository.save(saveable);
            ensureDefaultDashboardIsAlsoAssignedDashboard(saveable);
            if (!SecurityUtil.isCurrentUserAdmin()) {
                setResponsePage(Homepage.class);
            } else {
                setResponsePage(listPageClass);
            }
        }
    };
}
Also used : AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) StandardPasswordEncoder(org.springframework.security.crypto.password.StandardPasswordEncoder) Form(org.apache.wicket.markup.html.form.Form) StringResourceModel(org.apache.wicket.model.StringResourceModel) Person(org.devgateway.toolkit.persistence.dao.Person)

Example 5 with Person

use of org.devgateway.toolkit.persistence.dao.Person in project oc-explorer by devgateway.

the class UserDashboardRestController method saveDashboardForCurrentUser.

@RequestMapping(method = { RequestMethod.POST, RequestMethod.GET }, value = "/userDashboards/saveDashboardForCurrentUser")
@PreAuthorize("hasRole('ROLE_PROCURING_ENTITY')")
public ResponseEntity<Void> saveDashboardForCurrentUser(@ModelAttribute @Valid UserDashboard userDashboard) {
    Person person = personRepository.getOne(getCurrentAuthenticatedPerson().getId());
    userDashboard.getUsers().add(person);
    person.getDashboards().add(userDashboard);
    repository.save(userDashboard);
    return ResponseEntity.ok().build();
}
Also used : Person(org.devgateway.toolkit.persistence.dao.Person) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

Person (org.devgateway.toolkit.persistence.dao.Person)19 Authentication (org.springframework.security.core.Authentication)4 SimpleGrantedAuthority (org.springframework.security.core.authority.SimpleGrantedAuthority)4 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)4 AjaxRequestTarget (org.apache.wicket.ajax.AjaxRequestTarget)3 Form (org.apache.wicket.markup.html.form.Form)3 StringResourceModel (org.apache.wicket.model.StringResourceModel)3 NavbarButton (de.agilecoders.wicket.core.markup.html.bootstrap.navbar.NavbarButton)2 EqualPasswordInputValidator (org.apache.wicket.markup.html.form.validation.EqualPasswordInputValidator)2 PageParameters (org.apache.wicket.request.mapper.parameter.PageParameters)2 StringValue (org.apache.wicket.util.string.StringValue)2 EditUserPage (org.devgateway.toolkit.forms.wicket.page.user.EditUserPage)2 Bean (org.springframework.context.annotation.Bean)2 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)2 GrantedAuthority (org.springframework.security.core.GrantedAuthority)2 UserDetailsService (org.springframework.security.core.userdetails.UserDetailsService)2 UsernameNotFoundException (org.springframework.security.core.userdetails.UsernameNotFoundException)2 StandardPasswordEncoder (org.springframework.security.crypto.password.StandardPasswordEncoder)2 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)2