Search in sources :

Example 1 with PARAMETERS

use of org.wso2.carbon.mediation.commons.rest.api.swagger.SwaggerConstants.PARAMETERS in project carbon-identity-framework by wso2.

the class FileBasedConfigurationBuilder method processIdPConfigElement.

private ExternalIdPConfig processIdPConfigElement(OMElement idpConfigElem) {
    OMAttribute nameAttr = idpConfigElem.getAttribute(new QName("name"));
    // if the name is not given, do not register this config
    if (nameAttr == null) {
        log.warn("Each IDP configuration should have a unique name attribute");
        return null;
    }
    // read the config parameters
    Map<String, String> parameterMap = new HashMap<>();
    for (Iterator paramIterator = idpConfigElem.getChildrenWithLocalName("Parameter"); paramIterator.hasNext(); ) {
        OMElement paramElem = (OMElement) paramIterator.next();
        OMAttribute paramNameAttr = paramElem.getAttribute(new QName("name"));
        if (paramNameAttr == null) {
            log.warn("A Parameter should have a name attribute. Skipping the parameter.");
            continue;
        }
        parameterMap.put(paramNameAttr.getAttributeValue(), paramElem.getText());
    }
    IdentityProvider fedIdp = new IdentityProvider();
    fedIdp.setIdentityProviderName(nameAttr.getAttributeValue());
    ExternalIdPConfig externalIdPConfig = new ExternalIdPConfig(fedIdp);
    externalIdPConfig.setParameterMap(parameterMap);
    return externalIdPConfig;
}
Also used : HashMap(java.util.HashMap) QName(javax.xml.namespace.QName) Iterator(java.util.Iterator) OMElement(org.apache.axiom.om.OMElement) IdentityProvider(org.wso2.carbon.identity.application.common.model.IdentityProvider) ExternalIdPConfig(org.wso2.carbon.identity.application.authentication.framework.config.model.ExternalIdPConfig) OMAttribute(org.apache.axiom.om.OMAttribute)

Example 2 with PARAMETERS

use of org.wso2.carbon.mediation.commons.rest.api.swagger.SwaggerConstants.PARAMETERS in project carbon-identity-framework by wso2.

the class FileBasedConfigurationBuilder method processAuthenticatorConfigElement.

/**
 * Create AuthenticatorBean elements for each authenticator entry
 *
 * @param authenticatorConfigElem OMElement for Authenticator
 * @return AuthenticatorBean object
 */
private AuthenticatorConfig processAuthenticatorConfigElement(OMElement authenticatorConfigElem) {
    // read the name of the authenticator. this is a mandatory attribute.
    OMAttribute nameAttr = authenticatorConfigElem.getAttribute(new QName(FrameworkConstants.Config.ATTR_AUTHENTICATOR_CONFIG_NAME));
    // if the name is not given, do not register this authenticator
    if (nameAttr == null) {
        log.warn("Each Authenticator Configuration should have a unique name attribute. +" + "This Authenticator will not be registered.");
        return null;
    }
    String authenticatorName = nameAttr.getAttributeValue();
    // Check whether the enabled attribute is set. By default it will be true if not configured.
    boolean enabled = true;
    OMAttribute enabledAttr = authenticatorConfigElem.getAttribute(new QName(FrameworkConstants.Config.ATTR_AUTHENTICATOR_ENABLED));
    if (enabledAttr != null) {
        enabled = Boolean.parseBoolean(enabledAttr.getAttributeValue());
    }
    // read the config parameters
    Map<String, String> parameterMap = new HashMap<>();
    for (Iterator paramIterator = authenticatorConfigElem.getChildrenWithLocalName(FrameworkConstants.Config.ELEM_PARAMETER); paramIterator.hasNext(); ) {
        OMElement paramElem = (OMElement) paramIterator.next();
        OMAttribute paramNameAttr = paramElem.getAttribute(new QName(FrameworkConstants.Config.ATTR_PARAMETER_NAME));
        if (paramNameAttr == null) {
            log.warn("An Authenticator Parameter should have a name attribute. Skipping the parameter.");
            continue;
        }
        parameterMap.put(paramNameAttr.getAttributeValue(), paramElem.getText());
    }
    AuthenticatorConfig authenticatorConfig = new AuthenticatorConfig(authenticatorName, enabled, parameterMap);
    authenticatorConfig.setApplicationAuthenticator(FrameworkUtils.getAppAuthenticatorByName(authenticatorName));
    return authenticatorConfig;
}
Also used : AuthenticatorConfig(org.wso2.carbon.identity.application.authentication.framework.config.model.AuthenticatorConfig) HashMap(java.util.HashMap) QName(javax.xml.namespace.QName) Iterator(java.util.Iterator) OMElement(org.apache.axiom.om.OMElement) OMAttribute(org.apache.axiom.om.OMAttribute)

Example 3 with PARAMETERS

use of org.wso2.carbon.mediation.commons.rest.api.swagger.SwaggerConstants.PARAMETERS in project carbon-identity-framework by wso2.

the class FrameworkUtils method getCommonAuthReqWithParams.

/**
 * Builds the wrapper, wrapping incoming request and information take from cache entry.
 *
 * @param request    Original request coming to authentication framework
 * @param cacheEntry Cache entry from the cache, which is added from calling servlets
 * @return
 */
public static HttpServletRequest getCommonAuthReqWithParams(HttpServletRequest request, AuthenticationRequestCacheEntry cacheEntry) {
    // add this functionality as a constructor
    Map<String, String[]> modifiableParameters = new TreeMap<String, String[]>();
    if (cacheEntry != null) {
        AuthenticationRequest authenticationRequest = cacheEntry.getAuthenticationRequest();
        if (!authenticationRequest.getRequestQueryParams().isEmpty()) {
            modifiableParameters.putAll(authenticationRequest.getRequestQueryParams());
        }
        // Adding field variables to wrapper
        if (authenticationRequest.getType() != null) {
            modifiableParameters.put(FrameworkConstants.RequestParams.TYPE, new String[] { authenticationRequest.getType() });
        }
        if (authenticationRequest.getCommonAuthCallerPath() != null) {
            modifiableParameters.put(FrameworkConstants.RequestParams.CALLER_PATH, new String[] { authenticationRequest.getCommonAuthCallerPath() });
        }
        if (authenticationRequest.getRelyingParty() != null) {
            modifiableParameters.put(FrameworkConstants.RequestParams.ISSUER, new String[] { authenticationRequest.getRelyingParty() });
        }
        if (authenticationRequest.getTenantDomain() != null && !IdentityTenantUtil.isTenantQualifiedUrlsEnabled()) {
            modifiableParameters.put(FrameworkConstants.RequestParams.TENANT_DOMAIN, new String[] { authenticationRequest.getTenantDomain() });
        }
        modifiableParameters.put(FrameworkConstants.RequestParams.FORCE_AUTHENTICATE, new String[] { String.valueOf(authenticationRequest.getForceAuth()) });
        modifiableParameters.put(FrameworkConstants.RequestParams.PASSIVE_AUTHENTICATION, new String[] { String.valueOf(authenticationRequest.getPassiveAuth()) });
        if (log.isDebugEnabled()) {
            StringBuilder queryStringBuilder = new StringBuilder("");
            for (Map.Entry<String, String[]> entry : modifiableParameters.entrySet()) {
                StringBuilder paramValueBuilder = new StringBuilder("");
                String[] paramValueArr = entry.getValue();
                if (paramValueArr != null) {
                    for (String paramValue : paramValueArr) {
                        paramValueBuilder.append("{").append(paramValue).append("}");
                    }
                }
                queryStringBuilder.append("\n").append(entry.getKey() + "=" + paramValueBuilder.toString());
            }
            log.debug("\nInbound Request parameters: " + queryStringBuilder.toString());
        }
        return new AuthenticationFrameworkWrapper(request, modifiableParameters, authenticationRequest.getRequestHeaders());
    }
    return request;
}
Also used : TreeMap(java.util.TreeMap) AuthenticationRequest(org.wso2.carbon.identity.application.authentication.framework.model.AuthenticationRequest) Map(java.util.Map) TreeMap(java.util.TreeMap) HashMap(java.util.HashMap) AuthenticationFrameworkWrapper(org.wso2.carbon.identity.application.authentication.framework.model.AuthenticationFrameworkWrapper)

Example 4 with PARAMETERS

use of org.wso2.carbon.mediation.commons.rest.api.swagger.SwaggerConstants.PARAMETERS in project carbon-identity-framework by wso2.

the class PrimitiveConditionValidator method validate.

/**
 * Validate parameters in a {@link PrimitiveCondition} with the given Search bean
 *
 * @param primitiveCondition
 * @return A db qualified {@link PrimitiveCondition}.
 * @throws PrimitiveConditionValidationException
 */
public PrimitiveCondition validate(PrimitiveCondition primitiveCondition) throws PrimitiveConditionValidationException {
    if (searchBean == null) {
        throw new NullPointerException("Invalid search bean: null in the PrimitiveCondition validate.");
    }
    String property = primitiveCondition.getProperty();
    ConditionType.PrimitiveOperator operator = primitiveCondition.getOperator();
    Object value = primitiveCondition.getValue();
    if (property == null || operator == null || value == null) {
        throw new PrimitiveConditionValidationException("Invalid primitive condition parameters found in: property = " + property + (operator == null ? ", condition = null" : "") + (value == null ? ", value = null" : "") + ".");
    }
    try {
        Field field = this.searchBean.getClass().getDeclaredField(property);
        if (!field.getType().getName().equals(value.getClass().getName())) {
            throw new PrimitiveConditionValidationException("Value for the property: " + property + " is expected to be: " + field.getType().getName() + " but found: " + value.getClass().getName());
        }
    } catch (NoSuchFieldException e) {
        throw new PrimitiveConditionValidationException("Property: " + property + " is not found in the allowed search properties present in the bean " + "class: " + ResourceSearchBean.class.getName());
    }
    // If parameter validation are a success then build a database qualified primitive condition.
    PrimitiveCondition dbQualifiedPrimitiveCondition;
    dbQualifiedPrimitiveCondition = this.searchBean.mapPrimitiveCondition(primitiveCondition);
    dbQualifiedPrimitiveCondition.setProperty(this.searchBean.getDBQualifiedFieldName(dbQualifiedPrimitiveCondition.getProperty()));
    return dbQualifiedPrimitiveCondition;
}
Also used : Field(java.lang.reflect.Field) ResourceSearchBean(org.wso2.carbon.identity.configuration.mgt.core.model.ResourceSearchBean) ConditionType(org.wso2.carbon.identity.configuration.mgt.core.search.constant.ConditionType) PrimitiveConditionValidationException(org.wso2.carbon.identity.configuration.mgt.core.search.exception.PrimitiveConditionValidationException)

Example 5 with PARAMETERS

use of org.wso2.carbon.mediation.commons.rest.api.swagger.SwaggerConstants.PARAMETERS in project carbon-identity-framework by wso2.

the class EntitlementServiceComponent method startThriftEntitlementService.

private void startThriftEntitlementService() throws Exception {
    try {
        // read identity.xml
        IdentityUtil.populateProperties();
        // if thrift based EntitlementService is enabled.
        String thriftEnabled = IdentityUtil.getProperty(ThriftConfigConstants.PARAM_ENABLE_THRIFT_SERVICE);
        if (thriftEnabled != null && Boolean.parseBoolean(thriftEnabled)) {
            TSSLTransportFactory.TSSLTransportParameters transportParam = new TSSLTransportFactory.TSSLTransportParameters();
            // read the keystore and password used for ssl communication from config
            String keystorePath = IdentityUtil.getProperty(ThriftConfigConstants.PARAM_KEYSTORE_LOCATION);
            String keystorePassword = IdentityUtil.getProperty(ThriftConfigConstants.PARAM_KEYSTORE_PASSWORD);
            // set it in parameters
            transportParam.setKeyStore(keystorePath, keystorePassword);
            // int receivePort = 10395;
            int receivePort = readThriftReceivePort();
            // int clientTimeOut = 10000;
            int clientTimeOut = Integer.parseInt(IdentityUtil.getProperty(ThriftConfigConstants.PARAM_CLIENT_TIMEOUT));
            // String ifAddress = "localhost";
            TServerSocket serverTransport = TSSLTransportFactory.getServerSocket(receivePort, clientTimeOut, getHostAddress(readThriftHostName()), transportParam);
            EntitlementService.Processor processor = new EntitlementService.Processor(new ThriftEntitlementServiceImpl());
            // TODO: have to decide on the protocol.
            TServer server = new TThreadPoolServer(new TThreadPoolServer.Args(serverTransport).processor(processor));
            // TServer server = new TThreadPoolServer(new TThreadPoolServer.Args())
            /*
                TServer server = new TThreadPoolServer(processor, serverTransport,
                                                   new TCompactProtocol.Factory());*/
            Runnable serverThread = new ServerRunnable(server);
            executor.submit(serverThread);
            if (log.isDebugEnabled()) {
                log.debug("Started thrift entitlement service at port:" + receivePort);
            }
        }
    } catch (TTransportException e) {
        String transportErrorMsg = "Error in initializing thrift transport";
        log.error(transportErrorMsg, e);
        throw new Exception(transportErrorMsg);
    } catch (UnknownHostException e) {
        String hostErrorMsg = "Error in obtaining host name";
        log.error(hostErrorMsg, e);
        throw new Exception(hostErrorMsg);
    }
}
Also used : EntitlementService(org.wso2.carbon.identity.entitlement.thrift.EntitlementService) UnknownHostException(java.net.UnknownHostException) TServer(org.apache.thrift.server.TServer) TTransportException(org.apache.thrift.transport.TTransportException) TSSLTransportFactory(org.apache.thrift.transport.TSSLTransportFactory) ThriftEntitlementServiceImpl(org.wso2.carbon.identity.entitlement.thrift.ThriftEntitlementServiceImpl) TTransportException(org.apache.thrift.transport.TTransportException) RegistryException(org.wso2.carbon.registry.core.exceptions.RegistryException) SocketException(java.net.SocketException) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException) TServerSocket(org.apache.thrift.transport.TServerSocket) TThreadPoolServer(org.apache.thrift.server.TThreadPoolServer)

Aggregations

HashMap (java.util.HashMap)69 ArrayList (java.util.ArrayList)55 Map (java.util.Map)35 Test (org.testng.annotations.Test)30 IOException (java.io.IOException)27 APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)27 OMElement (org.apache.axiom.om.OMElement)24 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)24 List (java.util.List)23 SQLException (java.sql.SQLException)19 QName (javax.xml.namespace.QName)18 Matchers.anyString (org.mockito.Matchers.anyString)17 GoogleOAuthParameters (com.google.gdata.client.authn.oauth.GoogleOAuthParameters)15 PreparedStatement (java.sql.PreparedStatement)15 Connection (java.sql.Connection)14 AuthenticatedUser (org.wso2.carbon.identity.application.authentication.framework.model.AuthenticatedUser)14 PowerMockIdentityBaseTest (org.wso2.carbon.identity.testutil.powermock.PowerMockIdentityBaseTest)13 IdentityOAuth2Exception (org.wso2.carbon.identity.oauth2.IdentityOAuth2Exception)11 File (java.io.File)10 Produces (javax.ws.rs.Produces)10