public ResponseToken process(RequestToken request) throws TrustException { MessageContext context = MessageContext.getCurrentMessageContext(); SAMLPassiveTokenIssuer issuer = null; WSHandlerResult handlerResults = null; WSSecurityEngineResult engineResult = null; WSUsernameTokenPrincipal principal = null; Vector<WSSecurityEngineResult> wsResults = null; ResponseToken reponseToken = null; Vector<WSHandlerResult> handlerResultsVector = null; OMElement rstr = null; try { if (request.getAttributes() == null || request.getAttributes().trim().length() == 0) { throw new TrustException("attributesMissing"); } principal = new WSUsernameTokenPrincipal(request.getUserName(), false); engineResult = new WSSecurityEngineResult(WSConstants.UT, principal, null, null, null); wsResults = new Vector<WSSecurityEngineResult>(); wsResults.add(engineResult); handlerResults = new WSHandlerResult("", wsResults); handlerResultsVector = new Vector<WSHandlerResult>(); handlerResultsVector.add(handlerResults); MessageContext.getCurrentMessageContext() .setProperty(WSHandlerConstants.RECV_RESULTS, handlerResultsVector); MessageContext.getCurrentMessageContext() .setProperty( RahasConstants.PASSIVE_STS_RST, getRST(request.getRealm(), request.getAttributes(), request.getDialect())); rahasData = new RahasData(context); issuer = new SAMLPassiveTokenIssuer(); issuer.setAudienceRestrictionCondition(request.getRealm()); issuer.setConfig( getSAMLTokenIssuerConfig( MessageContext.getCurrentMessageContext().getAxisService(), true)); rstr = issuer.issuePassiveRSTR(rahasData); reponseToken = new ResponseToken(); reponseToken.setResults(rstr.toStringWithConsume()); } catch (Exception e) { throw new TrustException("errorWhileProcessingAttributeRequest", e); } return reponseToken; }
/** * Method to obtain a list of paths having resources of the given media type. * * @param registry the registry instance to run query on. * @param mediaType the media type. * @return an array of resource paths. * @throws RegistryException if the operation failed. */ public static String[] getResultPaths(Registry registry, String mediaType) throws RegistryException { String[] result; String[] paginatedResult; try { Map<String, String> parameter = new HashMap<String, String>(); parameter.put("1", mediaType); parameter.put( "query", "SELECT DISTINCT REG_PATH_ID, REG_NAME FROM REG_RESOURCE WHERE REG_MEDIA_TYPE=?"); result = (String[]) registry.executeQuery(null, parameter).getContent(); if (result == null || result.length == 0) { return new String[0]; } result = removeMountPaths(result, registry); MessageContext messageContext = MessageContext.getCurrentMessageContext(); if (PaginationUtils.isPaginationAnnotationFound("getPaginatedGovernanceArtifacts") && ((messageContext != null && PaginationUtils.isPaginationHeadersExist(messageContext)) || PaginationContext.getInstance() != null)) { int rowCount = result.length; PaginationContext paginationContext; try { if (messageContext != null) { PaginationUtils.setRowCount(messageContext, Integer.toString(rowCount)); paginationContext = PaginationUtils.initPaginationContext(messageContext); } else { paginationContext = PaginationContext.getInstance(); } int start = paginationContext.getStart(); int count = paginationContext.getCount(); int startIndex; if (start == 1) { startIndex = 0; } else { startIndex = start; } if (rowCount < start + count) { paginatedResult = new String[rowCount - startIndex]; System.arraycopy(result, startIndex, paginatedResult, 0, (rowCount - startIndex)); } else { paginatedResult = new String[count]; System.arraycopy(result, startIndex, paginatedResult, 0, count); } return paginatedResult; } finally { PaginationContext.destroy(); } } } catch (RegistryException e) { String msg = "Error in getting the result for media type: " + mediaType + "."; log.error(msg, e); throw new RegistryException(msg, e); } return result; }
public static String getCurrentContextUsername() { MessageContext ctx = MessageContext.getCurrentMessageContext(); if (ctx != null) { return getUsername(ctx); } else { return null; } }
public boolean unregister(String domain, String subDomain, String hostName) throws CartridgeAgentException { MessageContext messageContext = MessageContext.getCurrentMessageContext(); ConfigurationContext configurationContext = messageContext.getConfigurationContext(); ClusteringClient clusteringClient = (ClusteringClient) configurationContext.getProperty(CartridgeAgentConstants.CLUSTERING_CLIENT); clusteringClient.removeClusterDomain(domain, subDomain, hostName, configurationContext); return true; }
public boolean register(Registrant registrant) throws CartridgeAgentException { MessageContext messageContext = MessageContext.getCurrentMessageContext(); ConfigurationContext configurationContext = messageContext.getConfigurationContext(); ClusteringClient clusteringClient = (ClusteringClient) configurationContext.getProperty(CartridgeAgentConstants.CLUSTERING_CLIENT); if (registrant.getRemoteHost() == null || registrant.getRemoteHost().isEmpty()) { String remoteAddr = (String) messageContext.getProperty("REMOTE_ADDR"); registrant.setRemoteHost(remoteAddr); } log.info("Trying to add new registrant " + registrant + "..."); clusteringClient.joinGroup(registrant, configurationContext); // Main.getHealthChecker().start(registrant); DataHolder.getHealthChecker().start(registrant); return true; }
public APIKeyValidationInfoDTO getAPIKeyData( String context, String apiVersion, String apiKey, String requiredAuthenticationLevel, String clientDomain, String matchingResource, String httpVerb) throws APISecurityException { CarbonUtils.setBasicAccessSecurityHeaders( username, password, true, keyValidationServiceStub._getServiceClient()); if (cookie != null) { keyValidationServiceStub ._getServiceClient() .getOptions() .setProperty(HTTPConstants.COOKIE_STRING, cookie); } try { List headerList = (List) keyValidationServiceStub ._getServiceClient() .getOptions() .getProperty(org.apache.axis2.transport.http.HTTPConstants.HTTP_HEADERS); Map headers = (Map) MessageContext.getCurrentMessageContext() .getProperty(org.apache.axis2.context.MessageContext.TRANSPORT_HEADERS); if (headers != null) { headerList.add( new Header(APIConstants.ACTIVITY_ID, (String) headers.get(APIConstants.ACTIVITY_ID))); } keyValidationServiceStub ._getServiceClient() .getOptions() .setProperty(org.apache.axis2.transport.http.HTTPConstants.HTTP_HEADERS, headerList); /**/ org.wso2.carbon.apimgt.impl.dto.xsd.APIKeyValidationInfoDTO dto = keyValidationServiceStub.validateKey( context, apiVersion, apiKey, requiredAuthenticationLevel, clientDomain, matchingResource, httpVerb); ServiceContext serviceContext = keyValidationServiceStub ._getServiceClient() .getLastOperationContext() .getServiceContext(); cookie = (String) serviceContext.getProperty(HTTPConstants.COOKIE_STRING); return toDTO(dto); } catch (Exception e) { throw new APISecurityException( APISecurityConstants.API_AUTH_GENERAL_ERROR, "Error while accessing backend services for API key validation", e); } }
@Override public Handler.InvocationResponse invoke(MessageContext messageContext) throws AxisFault { SystemStatisticsUtil systemStatisticsUtil; SystemStatistics systemStatistics; try { int tenantID = PublisherUtil.getTenantId(messageContext); Map<Integer, EventConfigNStreamDef> tenantSpecificEventConfig = TenantEventConfigData.getTenantSpecificEventingConfigData(); EventConfigNStreamDef eventingConfigData = tenantSpecificEventConfig.get(tenantID); // Check service stats enable -- if true -- go if (eventingConfigData != null && eventingConfigData.isServiceStatsEnable()) { systemStatisticsUtil = StatisticsServiceComponent.getSystemStatisticsUtil(); systemStatistics = systemStatisticsUtil.getSystemStatistics(messageContext); AxisOperation axisOperation = messageContext.getAxisOperation(); AxisService axisService = messageContext.getAxisService(); if (axisService == null || SystemFilter.isFilteredOutService(axisService.getAxisServiceGroup()) || axisService.isClientSide()) { return Handler.InvocationResponse.CONTINUE; } MessageContext inMessageContext = MessageContext.getCurrentMessageContext(); // If already set in the activity handlers get it or create new publish data /* PublishData publishData = (PublishData) messageContext.getProperty( BAMDataPublisherConstants.PUBLISH_DATA); EventData eventData; if (publishData != null) { eventData = publishData.getEventData(); } else { publishData = new PublishData(); eventData = new EventData(); Date date = new Date(); Timestamp timestamp = new Timestamp(date.getTime()); eventData.setTimestamp(timestamp); if (axisOperation != null) { eventData.setOperationName(axisOperation.getName().getLocalPart()); } else { eventData.setOperationName(null); } if (axisService != null) { eventData.setServiceName(messageContext.getAxisService().getName()); } else { eventData.setServiceName(null); } //This is a hack for setting message id when sending request to a non-existing operation. if (eventingConfigData.isMsgDumpingEnable() && axisService != null && axisOperation == null) { eventData.setOutMessageId(new ActivityOutHandler().getUniqueId()); } } */ PublishData publishData = new PublishData(); EventData eventData = new EventData(); /* Date date = new Date(); Timestamp timestamp = new Timestamp(date.getTime()); eventData.setTimestamp(timestamp);*/ if (axisOperation != null) { eventData.setOperationName(axisOperation.getName().getLocalPart()); } else { eventData.setOperationName(null); } if (axisService != null) { eventData.setServiceName(messageContext.getAxisService().getName()); } else { eventData.setServiceName(null); } // This is a hack for setting message id when sending request to a non-existing operation. /* if (eventingConfigData.isMsgDumpingEnable() && axisService != null && axisOperation == null) { eventData.setOutMessageId(new ActivityOutHandler().getUniqueId()); }*/ // Skip resetting same info if already set by activity in/out handlers /* if (!eventingConfigData.isMsgDumpingEnable()) { Timestamp timestamp = null; if (inMessageContext != null) { timestamp = new Timestamp(Long.parseLong(inMessageContext.getProperty( StatisticsConstants.REQUEST_RECEIVED_TIME).toString())); Object requestProperty = inMessageContext.getProperty( HTTPConstants.MC_HTTP_SERVLETREQUEST); ServiceAgentUtil.extractInfoFromHttpHeaders(eventData, requestProperty); } else { Date date = new Date(); timestamp = new Timestamp(date.getTime()); } eventData.setTimestamp(timestamp); }*/ Timestamp timestamp = null; if (inMessageContext != null) { timestamp = new Timestamp( Long.parseLong( inMessageContext .getProperty(StatisticsConstants.REQUEST_RECEIVED_TIME) .toString())); Object requestProperty = inMessageContext.getProperty(HTTPConstants.MC_HTTP_SERVLETREQUEST); ServiceAgentUtil.extractInfoFromHttpHeaders(eventData, requestProperty); } else { Date date = new Date(); timestamp = new Timestamp(date.getTime()); } eventData.setTimestamp(timestamp); eventData.setSystemStatistics(systemStatistics); publishData.setEventData(eventData); // Skip if bam server info already set at activity handlers if (!eventingConfigData.isMsgDumpingEnable()) { BAMServerInfo bamServerInfo = ServiceAgentUtil.addBAMServerInfo(eventingConfigData); publishData.setBamServerInfo(bamServerInfo); } Event event = ServiceAgentUtil.makeEventList(publishData, eventingConfigData); EventPublisher publisher = new EventPublisher(); publisher.publish(event, eventingConfigData); } } catch (Throwable ignore) { log.error( "Error at SystemStatisticsOutHandler. " + "But continuing message processing for message id: " + messageContext.getMessageID(), ignore); } return Handler.InvocationResponse.CONTINUE; }