Package com.adito.security

Examples of com.adito.security.User


   
    @Test
    public void checkResourceAccessRights() throws Exception {
        Realm realm = getDefaultRealm();
        Policy policy = createPolicy(realm);
        User user = createAccount();
        getPolicyService().grantPolicyToPrincipal(policy, user);
       
        AccessRights accessRights = createAssignAccessRights(getResourceType().getPermissionClass());
        PropertyList selectedPolicies = PropertyList.createFromArray(new int[] {policy.getResourceId()});
        PolicyDatabaseFactory.getInstance().attachResourceToPolicyList(accessRights, selectedPolicies, getSessionInfo());
View Full Code Here


     */
    public ActionForward onExecute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)
                    throws Exception {
      PolicyUtil.checkPermission(PolicyConstants.ACCOUNTS_AND_GROUPS_RESOURCE_TYPE, PolicyConstants.PERM_DELETE, request);

        User currentUser = isSetupMode() ? null : LogonControllerFactory.getInstance().getUser(request);

        String[] accounts = request.getParameterValues("username");
        boolean found = false;
        for (int i = 0; i < accounts.length; i++) {
            if (currentUser != null && accounts[i].equals(currentUser.getPrincipalName())) {
                found = true;
            }
        }
        if (!found) {
            UserDatabase udb = UserDatabaseManager.getInstance().getUserDatabase(currentUser.getRealm());
            for (int i = 0; accounts != null && i < accounts.length; i++) {
                User user = udb.getAccount(accounts[i]);
                if(udb.supportsAccountCreation()) {
                  try {
                        udb.deleteAccount(user);
                        CoreServlet.getServlet().fireCoreEvent(new CoreEvent(this, CoreEventConstants.USER_REMOVED, null, null, CoreEvent.STATE_SUCCESSFUL)
                            .addAttribute(CoreAttributeConstants.EVENT_ATTR_PRINCIPAL_ID, user.getPrincipalName())
                            .addAttribute(CoreAttributeConstants.EVENT_ATTR_FULL_NAME, user.getFullname()));
                  } catch (Exception e) {
                      CoreServlet.getServlet().fireCoreEvent(new CoreEvent(this, CoreEventConstants.USER_REMOVED, null, null, e)
                            .addAttribute(CoreAttributeConstants.EVENT_ATTR_PRINCIPAL_ID, user.getPrincipalName())
                            .addAttribute(CoreAttributeConstants.EVENT_ATTR_FULL_NAME, user.getFullname()));
                    throw e;
                  }
                }
            }
        } else {
View Full Code Here

    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
        boolean supportCompression = false;
        boolean compressionEnabled = true;
        if (request instanceof HttpServletRequest && !Boolean.FALSE.equals(request.getAttribute(Constants.REQ_ATTR_COMPRESS))) {
            try {
                User user = LogonControllerFactory.getInstance().getUser((HttpServletRequest) request);
                compressionEnabled = CoreUtil.getUsersProfilePropertyBoolean(((HttpServletRequest) request).getSession(), "webServer.compression", user);
            } catch (Exception ex) {
            }
            if (compressionEnabled) {
                Enumeration e = ((HttpServletRequest) request).getHeaders("Accept-Encoding");
View Full Code Here

        try {
            checkValid(resource, new Permission[] { PolicyConstants.PERM_PERSONAL_CREATE_EDIT_AND_DELETE }, mapping, (AbstractResourceForm) form, request);
        } catch (NoPermissionException e) {
            checkValid(resource, new Permission[] { getEditResourcePermission(), getCreateResourcePermission(), getAssignPermission() }, mapping, (AbstractResourceForm) form, request);
        }
        User ownerUser = null;
        if (resource instanceof OwnedResource) {
            String owner = ((OwnedResource) resource).getOwnerUsername();
            if (owner != null && !owner.equals("")) {
                ownerUser = UserDatabaseManager.getInstance().getUserDatabase(session.getUser().getRealm()).getAccount(owner);
            }
View Full Code Here

        AuthenticationModule module = scheme.currentAuthenticationModule();
        if (module == null) {
            throw new Exception("No current authentication module");
        }
        RequestParameterMap params = new RequestParameterMap(new ServletRequestAdapter(request));
        User currentUser = scheme.getUser();
        LogonStateAndCache logonStateMachine = (LogonStateAndCache) request.getSession().getAttribute(
                        LogonStateAndCache.LOGON_STATE_MACHINE);

        if (logonStateMachine == null) {
            logonStateMachine = new LogonStateAndCache(LogonStateAndCache.STATE_STARTED, request.getSession());
View Full Code Here

     */
    public ActionForward confirmRemove(ActionMapping mapping, ActionForm form, HttpServletRequest request,
                    HttpServletResponse response) throws Exception {
        try {
            int selectedResource = Integer.parseInt(request.getParameter("selectedResource"));
            User user = LogonControllerFactory.getInstance().getUser(request);
            T resource = getResourceById(selectedResource);
            PolicyDatabaseFactory.getInstance().isPersonalPermitted(resource, permissions, user);
            PolicyUtil.checkPermission(getResourceType(), PolicyConstants.PERM_PERSONAL_CREATE_EDIT_AND_DELETE,
                request);
        } catch (NoPermissionException e) {
View Full Code Here

     *      javax.servlet.http.HttpServletResponse)
     */
    public ActionForward onExecute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)
                    throws Exception {
        // Get the property profile selected
        User user = getSessionInfo(request).getUser();
        ProfileSelectionForm profileSelectionForm = (ProfileSelectionForm) form;
        PropertyProfile profile = ProfilesFactory.getInstance().getPropertyProfile(
                        profileSelectionForm.getSelectedPropertyProfile());
        if (profile == null) {
            profile = ProfilesFactory.getInstance().getPropertyProfile(user.getPrincipalName(), "Default",
                            user.getRealm().getResourceId());
            if (profile == null) {
                throw new Exception("No default profile.");
            }
        }

        // Make the selected profile the one in use for this session
        if (log.isInfoEnabled())
          log.info("Switching user " + user.getPrincipalName() + " to profile " + profile.getResourceName());
        request.getSession().setAttribute(Constants.SELECTED_PROFILE, profile);
        String originalRequest = (String) request.getSession().getAttribute(Constants.ORIGINAL_REQUEST);

        // Optionally set the users default property profile
        if (profileSelectionForm.getMakeDefault()) {
            Property.setProperty(new UserAttributeKey(user, User.USER_STARTUP_PROFILE), String.valueOf(profile.getResourceId()), getSessionInfo(request));
        }

        // Reset the navigation and timeouts, they may be different in this new
        // profile
        CoreUtil.resetMainNavigation(request.getSession());
        LogonControllerFactory.getInstance().resetSessionTimeout(user, profile, request.getSession());

        // The new profile may have 'Automatically launch VPN client' enabled so
        // launch the VPN client
        if (!DefaultAgentManager.getInstance().hasActiveAgent(LogonControllerFactory.getInstance().getSessionInfo(request))
                        && Property.getPropertyBoolean(new ProfilePropertyKey(profile.getResourceId(), user.getPrincipalName(),
                                        "client.autoStart", user.getRealm().getResourceId()))) {
            request.getSession().removeAttribute(Constants.ORIGINAL_REQUEST);
            request.getSession().setAttribute(Constants.REQ_ATTR_LAUNCH_AGENT_REFERER, originalRequest);
            return mapping.findForward("launchAgent");
        }

View Full Code Here

        if (LogonControllerFactory.getInstance().hasClientLoggedOn(request, response) != LogonController.LOGGED_ON) {
            throw new Exception("You must be logged on to select a property.");
        }
        List propertyProfiles = null;
        int selectedPropertyProfile = 0;
        User user = LogonControllerFactory.getInstance().getUser(request);
        if (user != null) {
            propertyProfiles = (List)request.getSession().getAttribute(Constants.PROFILES);
            String selectedProfile = Property.getProperty(new UserAttributeKey(user, User.USER_STARTUP_PROFILE));
            if(selectedProfile.equals(ProfilesListDataSource.SELECT_ON_LOGIN)) {
              selectedPropertyProfile = 0;
View Full Code Here

     */
    public ActionForward favorite(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)
                    throws Exception {
        AbstractResourcesForm f = (AbstractResourcesForm) form;
        ActionMessages msgs = new ActionMessages();
        User user = LogonControllerFactory.getInstance().getUser(request);
        SystemDatabase sdb = SystemDatabaseFactory.getInstance();
        if (getSessionInfo(request).getNavigationContext() != SessionInfo.USER_CONSOLE_CONTEXT) {
            throw new Exception("Favorites may only be set in the user console.");
        }       
        Resource resource = getResourceById(f.getSelectedResource());
        if(ResourceUtil.filterResourceIdsForGlobalFavorites(PolicyDatabaseFactory.getInstance().getGrantedResourcesOfType(getSessionInfo(request).getUser(),
            resource.getResourceType()), resource.getResourceType()).contains(new Integer(resource.getResourceId()))) {
            throw new Exception("Cannot set a user favorite for items that have a policy favorite.");
        }
        if (sdb.getFavorite(getResourceType().getResourceTypeId(), user, f.getSelectedResource()) != null) {
            msgs.add(Globals.ERROR_KEY, new BundleActionMessage("navigation", "addToFavorites.error.alreadyFavorite", resource
                .getResourceName()));
            saveErrors(request, msgs);
            return mapping.findForward("refresh");
        }
        sdb.addFavorite(getResourceType().getResourceTypeId(), f.getSelectedResource(), user.getPrincipalName());
        msgs.add(Globals.MESSAGES_KEY, new BundleActionMessage("navigation", "addToFavorites.message.favoriteAdded", resource
            .getResourceName()));
        saveMessages(request, msgs);
        return mapping.findForward("refresh");
    }
View Full Code Here

     */
    public ActionForward removeFavorite(ActionMapping mapping, ActionForm form, HttpServletRequest request,
                    HttpServletResponse response) throws Exception {
        AbstractResourcesForm f = (AbstractResourcesForm) form;
        ActionMessages msgs = new ActionMessages();
        User user = LogonControllerFactory.getInstance().getUser(request);
        SystemDatabase sdb = SystemDatabaseFactory.getInstance();
        if (getSessionInfo(request).getNavigationContext() != SessionInfo.USER_CONSOLE_CONTEXT) {
            throw new Exception("Favorites may only be set in the user console.");
        }       
        Resource resource = getResourceById(f.getSelectedResource());
        if(ResourceUtil.filterResourceIdsForGlobalFavorites(PolicyDatabaseFactory.getInstance().getGrantedResourcesOfType(getSessionInfo(request).getUser(),
            resource.getResourceType()), resource.getResourceType()).contains(new Integer(resource.getResourceId()))) {
            throw new Exception("Cannot remove a user favorite from items that have a policy favorite.");
        }       
        if (sdb.getFavorite(getResourceType().getResourceTypeId(), user, f.getSelectedResource()) == null) {
            msgs.add(Globals.ERROR_KEY, new BundleActionMessage("navigation", "removeFromFavorites.error.notFavorite", resource
                .getResourceName()));
            saveErrors(request, msgs);
            return mapping.findForward("refresh");
        }
        sdb.removeFavorite(getResourceType().getResourceTypeId(), f.getSelectedResource(), user.getPrincipalName());
        msgs.add(Globals.MESSAGES_KEY, new BundleActionMessage("navigation", "removeFromFavorites.message.favoriteAdded", resource
            .getResourceName()));
        saveMessages(request, msgs);
        return mapping.findForward("refresh");
    }
View Full Code Here

TOP

Related Classes of com.adito.security.User

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.