authorizing a security group rule to a specified security group
@param request The request containing all options for authorizing security group rule
485299
public void authorizeSecurityGroupRule(SecurityGroupRuleOperateRequest request) {
        checkNotNull(request, "request should not be null.");
        checkStringNotEmpty(request.getSecurityGroupId(), "securityGroupId should not be empty.");
        if (Strings.isNullOrEmpty(request.getClientToken())) {
            request.setClientToken(this.generateClientToken());
        }
        if (null == request.getRule()) {
            throw new IllegalArgumentException("request rule should not be null");
        }
        InternalRequest internalRequest = this.createRequest(request, HttpMethodName.PUT, SECURITYGROUP_PREFIX,
                request.getSecurityGroupId());
        internalRequest.addParameter("authorizeRule", null);
        internalRequest.addParameter("clientToken", request.getClientToken());
        fillPayload(internalRequest, request);
        invokeHttpClient(internalRequest, AbstractBceResponse.class);
    }
931943
public void setSecurityGroupIds(java.util.Collection<String> securityGroupIds) {
        if (securityGroupIds == null) {
            this.securityGroupIds = null;
            return;
        }

        this.securityGroupIds = new java.util.ArrayList<String>(securityGroupIds);
    }
771295
protected SecurityToken getSecurityTokenFromRequest(final HttpServletRequest request) {
        val cookieValue = wsFederationRequestConfigurationContext.getTicketGrantingTicketCookieGenerator().retrieveCookieValue(request);
        if (StringUtils.isNotBlank(cookieValue)) {
            val tgt = wsFederationRequestConfigurationContext.getTicketRegistry().getTicket(cookieValue, TicketGrantingTicket.class);
            if (tgt != null) {
                val sts = tgt.getDescendantTickets().stream()
                    .filter(t -> t.startsWith(SecurityTokenTicket.PREFIX))
                    .findFirst()
                    .orElse(null);
                if (StringUtils.isNotBlank(sts)) {
                    val stt = wsFederationRequestConfigurationContext.getTicketRegistry().getTicket(sts, SecurityTokenTicket.class);
                    if (stt == null || stt.isExpired()) {
                        LOGGER.warn("Security token ticket [{}] is not found or has expired", sts);
                        return null;
                    }
                    if (stt.getSecurityToken().isExpired()) {
                        LOGGER.warn("Security token linked to ticket [{}] has expired", sts);
                        return null;
                    }
                    return stt.getSecurityToken();
                }
            }
        }
        return null;
    }
70055
@Override
	public boolean checkPermission(Set<SecurityGroup> groups, Permission permission)
	{
		if (groups == null || groups.isEmpty())
			return false;

		for (SecurityGroup group : groups)
		{
			if (checkPermission(group, permission))
				return true;
		}

		return false;
	}
708909
@Override
	public void handleRequest(final Request request) {
		if (isDisabled()) {
			// Protect against client-side tampering of disabled/read-only fields.
			return;
		}

		// Remember which client side tab we were on.
		String[] indicesStr = request.getParameterValues(getId());

		if (indicesStr != null && indicesStr.length > 0) {
			List<Integer> oldIndices = getActiveIndices();
			List<Integer> changes = new ArrayList<>(1);
			int[] indices = new int[indicesStr.length];

			if (Util.empty(indicesStr[0])) {
				// Special case - no tab selected
				if (getType() == TYPE_ACCORDION) {
					indices = null;
				} else {
					int idx = findFirstVisibleTab();
					indices = new int[idx];
				}
			} else {
				// Normal case - one or more tabs selected
				for (int i = 0; i < indices.length; i++) {
					int clientIndex = Integer.parseInt(indicesStr[i]);
					int idx = clientIndexToTabIndex(clientIndex);
					indices[i] = idx;

					if (!oldIndices.contains(idx)) {
						// Check for a server mode tab and set focus
						WTab tab = getTab(idx);
						if (TabMode.SERVER.equals(tab.getMode()) && UIContextHolder.getCurrent().getFocussed() == null) {
							tab.setFocussed();
						}
						changes.add(idx);
					}
				}
			}

			setActiveIndices(indices);

			// Invoke action if tab selection has changed
			final Action action = getActionOnChange();

			if (action != null && !changes.isEmpty()) {
				final ActionEvent event = new ActionEvent(this, changes.toString(), null);

				Runnable later = new Runnable() {
					@Override
					public void run() {
						action.execute(event);
					}
				};

				invokeLater(later);
			}
		}

		String showHeadOnlyStr = request.getParameter(getId() + ".showHeadOnly");

		if (showHeadOnlyStr != null) {
			boolean showHeadOnly = "true".equals(showHeadOnlyStr);
			setShowHeadOnly(showHeadOnly);
		}
	}
933934
@Override
  public boolean isSecure(HttpServletRequest request) {
    String proto = request.getHeader(X_FORWARED_PROTO);
    if( proto != null ) return proto.equalsIgnoreCase(HTTPS_PROTOCOL);
    return super.isSecure(request);
  }
596355
public String authenticateBASIC(final HttpServletRequest request) {
        LOG.debug("authenticateBASIC");
        boolean valid = false;
        String userID = null;
        String password = null;
        try {
            final String authHeader = request.getHeader("Authorization");
            if (authHeader != null) {
                final StringTokenizer st = new StringTokenizer(authHeader);
                if (st.hasMoreTokens()) {
                    final String basic = st.nextToken();
                    if (basic.equalsIgnoreCase("Basic")) {
                        final String credentials = st.nextToken();
                        final String userPass = new String(Base64.decodeBase64(credentials.getBytes()));
                        final int p = userPass.indexOf(":");
                        if (p != -1) {
                            userID = userPass.substring(0, p);
                            password = userPass.substring(p + 1);

                            // Validate the User.
                            valid = validateUser(userID, password);
                        }
                    }
                }
            }
        } catch (final Exception e) {
            LOG.debug("An error occured while processing Basic authentication", e);
        }
        if (valid) {
            // For now assume userID as userName
            return userID;
        }
        return null;
    }
249344
public ListInstanceGroupsResponse listInstanceGroups(ListInstanceGroupsRequest request) {
        checkNotNull(request, "request should not be null.");
        checkStringNotEmpty(request.getClusterId(), "The parameter clusterId should not be null or empty string.");

        InternalRequest internalRequest = this.createRequest(
                request, HttpMethodName.GET, CLUSTER, request.getClusterId(), INSTANCE_GROUP);

        return this.invokeHttpClient(internalRequest, ListInstanceGroupsResponse.class);
    }
1044735
protected static void requestAuthenticated(final Request request) {
        if (null == request) {
            return;
        }

        if (!WonderPush.isInitialized()) {
            WonderPush.safeDefer(new Runnable() {
                @Override
                public void run() {
                    requestAuthenticated(request);
                }
            }, 100);
            return;
        }

        String accessToken = WonderPushConfiguration.getAccessTokenForUserId(request.getUserId());

        if (accessToken == null) {
            // User is not authenticated, request a token
            fetchAnonymousAccessTokenAndRunRequest(request);
            return;
        }

        // Add the access token to the params
        RequestParams params = request.getParams();
        if (null == params) {
            params = new RequestParams();
            request.setParams(params);
        }

        params.remove("accessToken");
        params.put("accessToken", accessToken);

        // Wrap the request handler with our own
        ResponseHandler wrapperHandler = new ResponseHandler() {
            @Override
            public void onSuccess(int status, Response response) {
                WonderPush.logDebug("Request successful: (" + status + ") " + response + " (for " + request + ")");
                if (request.getHandler() != null) {
                    request.getHandler().onSuccess(status, response);
                }
            }

            @Override
            public void onFailure(Throwable e, Response errorResponse) {
                WonderPush.logError("Request failed: " + errorResponse, e);
                if (errorResponse != null && ERROR_INVALID_ACCESS_TOKEN == errorResponse.getErrorCode()) {
                    // null out the access token
                    WonderPushConfiguration.invalidateCredentials();

                    // retry later now
                    WonderPush.safeDefer(new Runnable() {
                        @Override
                        public void run() {
                            requestAuthenticated(request);
                        }
                    }, RETRY_INTERVAL_BAD_AUTH);
                } else {
                    if (request.getHandler() != null) {
                        request.getHandler().onFailure(e, errorResponse);
                    }
                }
            }

            @Override
            public void onSuccess(Response response) {
                WonderPush.logDebug("Request successful: " + response + " (for " + request + ")");
                if (request.getHandler() != null) {
                    request.getHandler().onSuccess(response);
                }
            }
        };
        Request wrapperRequest = (Request) request.clone();
        wrapperRequest.setHandler(wrapperHandler);

        // Perform request
        request(wrapperRequest);
    }
508283
public SetRequestAuthResponse setRequestAuth(SetRequestAuthRequest request) {
        checkNotNull(request, "The parameter request should NOT be null.");
        InternalRequest internalRequest = 
                createRequest(request, HttpMethodName.PUT, DOMAIN, request.getDomain(), "config");
        internalRequest.addParameter("requestAuth", "");
        this.attachRequestToBody(request, internalRequest);
        return invokeHttpClient(internalRequest, SetRequestAuthResponse.class);
    }
779963
def authorize_ip_permission(
        self, group_name, ip_protocol, from_port, to_port, cidr_ip):
        
        d = self.authorize_security_group(
            group_name,
            ip_protocol=ip_protocol, from_port=from_port, to_port=to_port,
            cidr_ip=cidr_ip)
        return d
438316
private function _convertAuthorize($request) {
        
        $parameters = array();
        $parameters['Action'] = 'Authorize';
        if ($request->isSetSellerId()) {
            $parameters['SellerId'] =  $request->getSellerId();
        }
        if ($request->isSetAmazonOrderReferenceId()) {
            $parameters['AmazonOrderReferenceId'] =  $request->getAmazonOrderReferenceId();
        }
        if ($request->isSetAuthorizationReferenceId()) {
            $parameters['AuthorizationReferenceId'] =  $request->getAuthorizationReferenceId();
        }
        if ($request->isSetAuthorizationAmount()) {
            $authorizationAmount = $request->getAuthorizationAmount();
            if ($authorizationAmount->isSetAmount()) {
                $parameters['AuthorizationAmount' . '.' . 'Amount'] =  $authorizationAmount->getAmount();
            }
            if ($authorizationAmount->isSetCurrencyCode()) {
                $parameters['AuthorizationAmount' . '.' . 'CurrencyCode'] =  $authorizationAmount->getCurrencyCode();
            }
        }
        if ($request->isSetSellerAuthorizationNote()) {
            $parameters['SellerAuthorizationNote'] =  $request->getSellerAuthorizationNote();
        }
        if ($request->isSetOrderItemCategories()) {
            $orderItemCategories = $request->getOrderItemCategories();
            foreach  ($orderItemCategories->getOrderItemCategory() as $orderItemCategoryIndex => $orderItemCategory) {
                $parameters['OrderItemCategories' . '.' . 'OrderItemCategory' . '.'  . ($orderItemCategoryIndex + 1)] =  $orderItemCategory;
            }
        }
        if ($request->isSetTransactionTimeout()) {
            $parameters['TransactionTimeout'] =  $request->getTransactionTimeout();
        }
        if ($request->isSetCaptureNow()) {
            $parameters['CaptureNow'] =  $request->getCaptureNow() ? "true" : "false";
        }
        if ($request->isSetSoftDescriptor()) {
            $parameters['SoftDescriptor'] =  $request->getSoftDescriptor();
        }

        return $parameters;
    }
595633
public boolean actionModifyAce(HttpServletRequest request) {

        String file = getParamResource();

        // get request parameters
        String name = getParamName();
        String type = getParamType();
        String inherit = request.getParameter(PARAM_INHERIT);
        String overWriteInherited = request.getParameter(PARAM_OVERWRITEINHERITED);
        String responsible = request.getParameter(PARAM_RESPONSIBLE);

        // get the new permissions
        Set<String> permissionKeys = CmsPermissionSet.getPermissionKeys();
        int allowValue = 0;
        int denyValue = 0;
        String key, param;
        int value, paramInt;

        Iterator<String> i = permissionKeys.iterator();
        // loop through all possible permissions
        while (i.hasNext()) {
            key = i.next();
            value = CmsPermissionSet.getPermissionValue(key);
            // set the right allowed and denied permissions from request parameters
            try {
                param = request.getParameter(value + PERMISSION_ALLOW);
                paramInt = Integer.parseInt(param);
                allowValue |= paramInt;
            } catch (Exception e) {
                // can usually be ignored
                if (LOG.isInfoEnabled()) {
                    LOG.info(e.getLocalizedMessage());
                }
            }
            try {
                param = request.getParameter(value + PERMISSION_DENY);
                paramInt = Integer.parseInt(param);
                denyValue |= paramInt;
            } catch (Exception e) {
                // can usually be ignored
                if (LOG.isInfoEnabled()) {
                    LOG.info(e.getLocalizedMessage());
                }
            }
        }

        // get the current Ace to get the current ace flags
        try {
            List<CmsAccessControlEntry> allEntries = getCms().getAccessControlEntries(file, false);
            int flags = 0;
            for (int k = 0; k < allEntries.size(); k++) {
                CmsAccessControlEntry curEntry = allEntries.get(k);
                String curType = getEntryType(curEntry.getFlags(), false);
                I_CmsPrincipal p;
                try {
                    p = CmsPrincipal.readPrincipalIncludingHistory(getCms(), curEntry.getPrincipal());
                } catch (CmsException e) {
                    p = null;
                }
                if (((p != null) && p.getName().equals(name) && curType.equals(type))) {
                    flags = curEntry.getFlags();
                    break;
                } else if (p == null) {
                    // check if it is the case of a role
                    CmsRole role = CmsRole.valueOfId(curEntry.getPrincipal());
                    if ((role != null) && name.equals(role.getRoleName())) {
                        flags = curEntry.getFlags();
                        break;
                    } else if ((curEntry.getPrincipal().equals(CmsAccessControlEntry.PRINCIPAL_ALL_OTHERS_ID)
                        && name.equals(CmsAccessControlEntry.PRINCIPAL_ALL_OTHERS_NAME))
                        || (curEntry.getPrincipal().equals(CmsAccessControlEntry.PRINCIPAL_OVERWRITE_ALL_ID)
                            && name.equals(CmsAccessControlEntry.PRINCIPAL_OVERWRITE_ALL_NAME))) {
                        flags = curEntry.getFlags();
                        break;
                    }
                }
            }

            // modify the ace flags to determine inheritance of the current ace
            if (Boolean.valueOf(inherit).booleanValue()) {
                flags |= CmsAccessControlEntry.ACCESS_FLAGS_INHERIT;
            } else {
                flags &= ~CmsAccessControlEntry.ACCESS_FLAGS_INHERIT;
            }

            // modify the ace flags to determine overwriting of inherited ace
            if (Boolean.valueOf(overWriteInherited).booleanValue()) {
                flags |= CmsAccessControlEntry.ACCESS_FLAGS_OVERWRITE;
            } else {
                flags &= ~CmsAccessControlEntry.ACCESS_FLAGS_OVERWRITE;
            }

            if (Boolean.valueOf(responsible).booleanValue()) {
                flags |= CmsAccessControlEntry.ACCESS_FLAGS_RESPONSIBLE;
            } else {
                flags &= ~CmsAccessControlEntry.ACCESS_FLAGS_RESPONSIBLE;
            }

            // lock resource if autolock is enabled
            checkLock(getParamResource());
            // try to change the access entry
            if (name.equals(CmsAccessControlEntry.PRINCIPAL_ALL_OTHERS_ID.toString())) {
                getCms().chacc(
                    file,
                    type,
                    CmsAccessControlEntry.PRINCIPAL_ALL_OTHERS_NAME,
                    allowValue,
                    denyValue,
                    flags);
            } else if (name.equals(CmsAccessControlEntry.PRINCIPAL_OVERWRITE_ALL_ID.toString())) {
                getCms().chacc(
                    file,
                    type,
                    CmsAccessControlEntry.PRINCIPAL_OVERWRITE_ALL_NAME,
                    allowValue,
                    denyValue,
                    flags);
            } else {
                getCms().chacc(file, type, name, allowValue, denyValue, flags);
            }
            return true;
        } catch (CmsException e) {
            m_errorMessages.add(key(Messages.ERR_CHACC_MODIFY_ENTRY_0));
            if (LOG.isErrorEnabled()) {
                LOG.error(e.getLocalizedMessage(), e);
            }
            return false;
        }
    }
335767
def AuthorizeGroup(self, group, subject):
    """"""

    # Add the subject to the dict if is isn't present, so it will get checked in
    # CheckPermissions
    self.authorized_users.setdefault(subject, set())
    self.group_access_manager.AuthorizeGroup(group, subject)
824988
public void bindInstanceToSecurityGroup(BindSecurityGroupRequest request) {
        checkNotNull(request, "request should not be null.");
        checkStringNotEmpty(request.getInstanceId(), "request instanceId should not be empty.");
        checkStringNotEmpty(request.getSecurityGroupId(), "request securityGroupId should not be empty.");
        InternalRequest internalRequest = this.createRequest(
                request, HttpMethodName.PUT, INSTANCE_PREFIX, request.getInstanceId());
        internalRequest.addParameter(InstanceAction.bind.name(), null);
        fillPayload(internalRequest, request);
        this.invokeHttpClient(internalRequest, AbstractBceResponse.class);
    }
1338197
@Override
    protected int authenticated(final Request request, final Response response)
    {
        try
        {
            final CookieSetting credentialsCookie = this.getCredentialsCookie(request, response);
            credentialsCookie.setValue(this.formatCredentials(request.getChallengeResponse()));
            credentialsCookie.setMaxAge(this.getMaxCookieAge());
        }
        catch(final GeneralSecurityException e)
        {
            this.log.error("Could not format credentials cookie", e);
        }
        
        // log.info("calling super.authenticated");
        // return super.authenticated(request, response);
        
        // Modified copy of Authenticator.authenticated
        if(this.log.isDebugEnabled())
        {
            this.log.debug("The authentication succeeded for the identifer \"{}\" using the {} scheme.", request
                    .getChallengeResponse().getIdentifier(), request.getChallengeResponse().getScheme());
        }
        
        // Update the client info accordingly
        if(request.getClientInfo() != null)
        {
            request.getClientInfo().setAuthenticated(true);
        }
        
        // Clear previous challenge requests
        response.getChallengeRequests().clear();
        
        // Add the roles for the authenticated subject
        if(this.getEnroler() != null)
        {
            this.getEnroler().enrole(request.getClientInfo());
        }
        
        // Return STOP here works for login but not for subsequent requests that expect a response
        // return STOP;
        return Filter.CONTINUE;
    }
78931
@SuppressWarnings("PMD.AvoidLiteralsInIfCondition")
    public Token getAuthorizationToken(final ContainerRequest request) {
        String authorizationString = request.getHeaderString("Authorization");
        if (authorizationString != null && !"".equals(authorizationString)) {
            authorizationString = authorizationString.trim();
            final String[] components = authorizationString.split("\\s");
            if (components.length != 2) {
                throw new NotAuthorizedException(authenticationType);
            }
            final String scheme = components[0];
            if (!authenticationType.equalsIgnoreCase(scheme)) {
                throw new NotAuthorizedException(authenticationType);
            }
            final String tokenString = components[1];
            return Token.fromString(tokenString);
        }
        return null;
    }