org.wso2.carbon.authenticator.stub.AuthenticationAdminStub Java Examples

The following examples show how to use org.wso2.carbon.authenticator.stub.AuthenticationAdminStub. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Authenticator.java    From micro-integrator with Apache License 2.0 6 votes vote down vote up
private boolean authenticate() throws Exception {
    ConfigurationContext configurationContext;
    configurationContext = ConfigurationContextFactory.createDefaultConfigurationContext();
    Map<String, TransportOutDescription> transportsOut = configurationContext.getAxisConfiguration()
            .getTransportsOut();
    for (TransportOutDescription transportOutDescription : transportsOut.values()) {
        transportOutDescription.getSender().init(configurationContext, transportOutDescription);
    }
    boolean isAuthenticated = false;
    if (StringUtils.isNotEmpty(userName) && StringUtils.isNotEmpty(password)) {
        //if authorized cookie is not available authorize using credentials
        AuthenticationAdminStub authAdmin = new AuthenticationAdminStub(configurationContext, serverUrl);
        isAuthenticated = authAdmin.login(userName, password, "localhost");
        cookie = (String) authAdmin._getServiceClient().getServiceContext()
                .getProperty(HTTPConstants.COOKIE_STRING);
        authAdmin._getServiceClient().cleanupTransport();
    } else if (StringUtils.isNotEmpty(authorizedCookie)) {
        //when authorized cookie is available assign it to local variable
        isAuthenticated = true;
        cookie = authorizedCookie;
    }
    return isAuthenticated;

}
 
Example #2
Source File: Authenticator.java    From carbon-identity with Apache License 2.0 6 votes vote down vote up
private boolean authenticate() throws Exception {
    ConfigurationContext configurationContext;
    configurationContext = ConfigurationContextFactory.createDefaultConfigurationContext();
    Map<String, TransportOutDescription> transportsOut =configurationContext
            .getAxisConfiguration().getTransportsOut();
    for (TransportOutDescription transportOutDescription : transportsOut.values()) {
        transportOutDescription.getSender().init(configurationContext, transportOutDescription);
    }
    AuthenticationAdminStub authAdmin = new AuthenticationAdminStub(configurationContext,
            serverUrl);
    boolean isAuthenticated = authAdmin.login(userName, password, "localhost");
    cookie = (String) authAdmin._getServiceClient().getServiceContext()
            .getProperty(HTTPConstants.COOKIE_STRING);
    authAdmin._getServiceClient().cleanupTransport();
    return isAuthenticated;

}
 
Example #3
Source File: APIGatewayAdminClientTest.java    From carbon-apimgt with Apache License 2.0 6 votes vote down vote up
@Before
public void setup() throws Exception {

    environment = new Environment();
    environment.setName(ENV_NAME);
    environment.setPassword(PASSWORD);
    environment.setUserName(USERNAME);
    environment.setServerURL(SERVER_URL);
    apiGatewayAdminStub = Mockito.mock(APIGatewayAdminStub.class);

    Options options = new Options();
    ServiceContext serviceContext = new ServiceContext();
    OperationContext operationContext = Mockito.mock(OperationContext.class);
    serviceContext.setProperty(HTTPConstants.COOKIE_STRING, "");
    ServiceClient serviceClient = Mockito.mock(ServiceClient.class);
    AuthenticationAdminStub authAdminStub = Mockito.mock(AuthenticationAdminStub.class);
    Mockito.doReturn(true).when(authAdminStub).login(Mockito.anyString(), Mockito.anyString(), Mockito.anyString());
    Mockito.when(authAdminStub._getServiceClient()).thenReturn(serviceClient);
    Mockito.when(serviceClient.getLastOperationContext()).thenReturn(operationContext);
    Mockito.when(operationContext.getServiceContext()).thenReturn(serviceContext);
    Mockito.when(apiGatewayAdminStub._getServiceClient()).thenReturn(serviceClient);
    Mockito.when(serviceClient.getOptions()).thenReturn(options);
    PowerMockito.whenNew(AuthenticationAdminStub.class)
            .withArguments(Mockito.any(ConfigurationContext.class), Mockito.anyString()).thenReturn(authAdminStub);
}
 
Example #4
Source File: AuthenticatorClient.java    From product-es with Apache License 2.0 5 votes vote down vote up
public AuthenticatorClient(String backendUrl) throws AxisFault {

        String serviceName = "AuthenticationAdmin";
        String endPoint = backendUrl + serviceName;
        if (log.isDebugEnabled()) {
            log.debug("EndPoint" + endPoint);
        }
        try {
            authenticationAdminStub = new AuthenticationAdminStub(endPoint);
        } catch (AxisFault axisFault) {
            log.info("authenticationAdminStub initialization fails");
            throw new AxisFault("authenticationAdminStub initialization fails");
        }
    }
 
Example #5
Source File: AuthenticatorClient.java    From micro-integrator with Apache License 2.0 5 votes vote down vote up
public AuthenticatorClient(String backendUrl) throws Exception {
    String serviceName = "AuthenticationAdmin";
    String endPoint = backendUrl + serviceName;
    if (log.isDebugEnabled()) {
        log.debug("EndPoint" + endPoint);
    }
    try {
        authenticationAdminStub = new AuthenticationAdminStub(endPoint);
    } catch (Exception axisFault) {
        log.info("authenticationAdminStub initialization fails");
        throw new Exception("authenticationAdminStub initialization fails");
    }
}
 
Example #6
Source File: AuthenticationAdminClient.java    From carbon-commons with Apache License 2.0 5 votes vote down vote up
public AuthenticationAdminClient(String backendServerURL,
                                 ConfigurationContext configCtx,
                                 Locale locale) throws AxisFault {
    String serviceURL = backendServerURL + "AuthenticationAdmin";
    bundle = ResourceBundle.getBundle(BUNDLE, locale);
    this.backendServerURL = backendServerURL;
    stub = new AuthenticationAdminStub(configCtx, serviceURL);
}
 
Example #7
Source File: APIAuthenticationServiceClient.java    From carbon-apimgt with Apache License 2.0 5 votes vote down vote up
public APIAuthenticationServiceClient(String backendServerURL, String username, String password)
        throws Exception {
    try {
        AuthenticationAdminStub authenticationAdminStub = new AuthenticationAdminStub(null, backendServerURL + "AuthenticationAdmin");
        ServiceClient authAdminServiceClient = authenticationAdminStub._getServiceClient();
        authAdminServiceClient.getOptions().setManageSession(true);
        authenticationAdminStub.login(username, password, new URL(backendServerURL).getHost());
        ServiceContext serviceContext = authenticationAdminStub.
                _getServiceClient().getLastOperationContext().getServiceContext();
        String authenticatedCookie = (String) serviceContext.getProperty(HTTPConstants.COOKIE_STRING);

        if (log.isDebugEnabled()) {
            log.debug("Authentication Successful with AuthenticationAdmin. " +
                      "Authenticated Cookie ID : " + authenticatedCookie);
        }

        stub = new APIAuthenticationServiceStub(
                null, backendServerURL + "APIAuthenticationService");
        ServiceClient client = stub._getServiceClient();
        Options options = client.getOptions();
        options.setManageSession(true);
        options.setProperty(HTTPConstants.COOKIE_STRING,
                            authenticatedCookie);
    } catch (Exception e) {
        String errorMsg = "Error when instantiating APIAuthenticationServiceClient.";
        log.error(errorMsg, e);
        throw e;
    }
}
 
Example #8
Source File: GlobalThrottleEngineClientWrapper.java    From carbon-apimgt with Apache License 2.0 5 votes vote down vote up
public GlobalThrottleEngineClientWrapper(AuthenticationAdminStub authenticationAdminStub,
        EventProcessorAdminServiceStub eventProcessorAdminServiceStub,
        ThrottleProperties.PolicyDeployer policyDeployer) {
    this.authenticationAdminStub = authenticationAdminStub;
    this.eventProcessorAdminServiceStub = eventProcessorAdminServiceStub;
    this.policyDeployer = policyDeployer;
}
 
Example #9
Source File: RegistryCacheInvalidationClientTest.java    From carbon-apimgt with Apache License 2.0 5 votes vote down vote up
@Before
public void setup() throws APIManagementException, RemoteException {
    PowerMockito.mockStatic(ServiceReferenceHolder.class);
    PowerMockito.mockStatic(ConfigurationContextFactory.class);
    ServiceReferenceHolder serviceReferenceHolder = Mockito.mock(ServiceReferenceHolder.class);
    APIManagerConfigurationService amConfigService = Mockito.mock(APIManagerConfigurationService.class);
    amConfig = Mockito.mock(APIManagerConfiguration.class);
    configFactory = Mockito.mock(ConfigurationContextFactory.class);
    configurationContext = Mockito.mock(ConfigurationContext.class);
    serviceClient = Mockito.mock(ServiceClient.class);
    authStub = Mockito.mock(AuthenticationAdminStub.class);
    cacheStub = Mockito.mock(RegistryCacheInvalidationServiceStub.class);
    OperationContext opContext = Mockito.mock(OperationContext.class);
    ServiceContext serviceContext = Mockito.mock(ServiceContext.class);

    Environment environment = new Environment();
    environment.setServerURL(SERVER_URL);
    environment.setUserName(USERNAME);
    environment.setPassword(PASSWORD);
    validEnvironments = new HashMap<String, Environment>();
    validEnvironments.put(ENV_NAME, environment);

    Mockito.when(opContext.getServiceContext()).thenReturn(serviceContext);
    Mockito.when(serviceContext.getProperty(Mockito.anyString())).thenReturn("cookie");
    Mockito.when(authStub._getServiceClient()).thenReturn(serviceClient);
    Mockito.when(cacheStub._getServiceClient()).thenReturn(serviceClient);
    Mockito.when(serviceClient.getLastOperationContext()).thenReturn(opContext);
    Mockito.when(serviceClient.getOptions()).thenReturn(new Options());
    Mockito.when(serviceReferenceHolder.getAPIManagerConfigurationService()).thenReturn(amConfigService);
    Mockito.when(amConfigService.getAPIManagerConfiguration()).thenReturn(amConfig);
    Mockito.when(configFactory.createConfigurationContextFromFileSystem(null, null))
            .thenReturn(configurationContext);
    PowerMockito.when(ServiceReferenceHolder.getInstance()).thenReturn(serviceReferenceHolder);
}
 
Example #10
Source File: TierCacheInvalidationClientTest.java    From carbon-apimgt with Apache License 2.0 5 votes vote down vote up
@Before
public void setup() throws APIManagementException, RemoteException {
    PowerMockito.mockStatic(ServiceReferenceHolder.class);
    PowerMockito.mockStatic(ConfigurationContextFactory.class);
    ServiceReferenceHolder serviceReferenceHolder = Mockito.mock(ServiceReferenceHolder.class);
    APIManagerConfigurationService amConfigService = Mockito.mock(APIManagerConfigurationService.class);
    amConfig = Mockito.mock(APIManagerConfiguration.class);
    configFactory = Mockito.mock(ConfigurationContextFactory.class);
    configurationContext = Mockito.mock(ConfigurationContext.class);
    serviceClient = Mockito.mock(ServiceClient.class);
    authStub = Mockito.mock(AuthenticationAdminStub.class);
    cacheStub = Mockito.mock(TierCacheServiceStub.class);
    OperationContext opContext = Mockito.mock(OperationContext.class);
    ServiceContext serviceContext = Mockito.mock(ServiceContext.class);

    Mockito.when(opContext.getServiceContext()).thenReturn(serviceContext);
    Mockito.when(serviceContext.getProperty(Mockito.anyString())).thenReturn("cookie");
    Mockito.when(authStub._getServiceClient()).thenReturn(serviceClient);
    Mockito.when(cacheStub._getServiceClient()).thenReturn(serviceClient);
    Mockito.when(serviceClient.getLastOperationContext()).thenReturn(opContext);
    Mockito.when(serviceClient.getOptions()).thenReturn(new Options());
    Mockito.when(serviceReferenceHolder.getAPIManagerConfigurationService()).thenReturn(amConfigService);
    Mockito.when(amConfigService.getAPIManagerConfiguration()).thenReturn(amConfig);
    Mockito.when(configFactory.createConfigurationContextFromFileSystem(null, null))
            .thenReturn(configurationContext);
    PowerMockito.when(ServiceReferenceHolder.getInstance()).thenReturn(serviceReferenceHolder);
}
 
Example #11
Source File: SamplesInvoker.java    From product-ei with Apache License 2.0 5 votes vote down vote up
private static void iniAuthenticationAdminStub() throws Exception {

        authenticationAdminStub = new AuthenticationAdminStub(AUTHENTICATION_SERVICE_URL);

        ServiceClient client = authenticationAdminStub._getServiceClient();
        Options options = client.getOptions();
        options.setManageSession(true);
    }
 
Example #12
Source File: AuthenticatorClient.java    From product-ei with Apache License 2.0 5 votes vote down vote up
public AuthenticatorClient(String backendUrl) throws Exception {
    String serviceName = "AuthenticationAdmin";
    String endPoint = backendUrl + serviceName;
    if (log.isDebugEnabled()) {
        log.debug("EndPoint" + endPoint);
    }
    try {
        authenticationAdminStub = new AuthenticationAdminStub(endPoint);
    } catch (Exception axisFault) {
        log.info("authenticationAdminStub initialization fails");
        throw new Exception("authenticationAdminStub initialization fails");
    }
}
 
Example #13
Source File: GlobalThrottleEngineClient.java    From carbon-apimgt with Apache License 2.0 4 votes vote down vote up
protected AuthenticationAdminStub getAuthenticationAdminStub() throws AxisFault {
    return new AuthenticationAdminStub(policyDeployerConfiguration.getServiceUrl() +
            "AuthenticationAdmin");
}
 
Example #14
Source File: RegistryCacheInvalidationClient.java    From carbon-apimgt with Apache License 2.0 4 votes vote down vote up
protected AuthenticationAdminStub getAuthenticationAdminStub(String serverURL) throws AxisFault {
    return new AuthenticationAdminStub(null, serverURL + "AuthenticationAdmin");
}
 
Example #15
Source File: RegistryCacheInvalidationClientWrapper.java    From carbon-apimgt with Apache License 2.0 4 votes vote down vote up
public RegistryCacheInvalidationClientWrapper(AuthenticationAdminStub authStub, RegistryCacheInvalidationServiceStub cacheStub)
        throws APIManagementException {
    this.authStub = authStub;
    this.cacheStub = cacheStub;
}
 
Example #16
Source File: RegistryCacheInvalidationClientWrapper.java    From carbon-apimgt with Apache License 2.0 4 votes vote down vote up
@Override
protected AuthenticationAdminStub getAuthenticationAdminStub(String serverURL) throws AxisFault {
    return authStub;
}
 
Example #17
Source File: TierCacheInvalidationClientWrapper.java    From carbon-apimgt with Apache License 2.0 4 votes vote down vote up
public TierCacheInvalidationClientWrapper(AuthenticationAdminStub authStub, TierCacheServiceStub cacheStub)
        throws APIManagementException {
    this.authStub = authStub;
    this.cacheStub = cacheStub;
}
 
Example #18
Source File: TierCacheInvalidationClientWrapper.java    From carbon-apimgt with Apache License 2.0 4 votes vote down vote up
@Override
protected AuthenticationAdminStub getAuthenticationAdminStub(String serverURL) throws AxisFault {
    return authStub;
}
 
Example #19
Source File: TierCacheInvalidationClient.java    From carbon-apimgt with Apache License 2.0 4 votes vote down vote up
protected AuthenticationAdminStub getAuthenticationAdminStub(String serverURL) throws AxisFault {
    return new AuthenticationAdminStub(null, serverURL + "AuthenticationAdmin");
}
 
Example #20
Source File: GlobalThrottleEngineClientWrapper.java    From carbon-apimgt with Apache License 2.0 4 votes vote down vote up
@Override
protected AuthenticationAdminStub getAuthenticationAdminStub() {
    return authenticationAdminStub;
}
 
Example #21
Source File: LoginManager.java    From product-ei with Apache License 2.0 4 votes vote down vote up
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    String userName = null, userPassword = null;
    ServletContext servletContext = this.getServletContext();
    String backendServerURL = servletContext.getInitParameter(HumanTaskSampleConstants.BACKEND_SERVER_URL);

    // set the required system properties
    System.setProperty("javax.net.ssl.trustStore", servletContext
            .getInitParameter(HumanTaskSampleConstants.CLIENT_TRUST_STORE_PATH).trim());
    System.setProperty("javax.net.ssl.trustStorePassword", servletContext
            .getInitParameter(HumanTaskSampleConstants.CLIENT_TRUST_STORE_PASSWORD).trim());
    System.setProperty("javax.net.ssl.trustStoreType", servletContext
            .getInitParameter(HumanTaskSampleConstants.CLIENT_TRUST_STORE_TYPE).trim());
    try {
        AuthenticationAdminStub authenticationAdminStub = new AuthenticationAdminStub(backendServerURL +
                                                                                      HumanTaskSampleConstants
                                                                                              .SERVICE_URL +
                                                                                      HumanTaskSampleConstants
                                                                                              .AUTHENTICATION_ADMIN_SERVICE_URL);
        // handles logout
        String logout = req.getParameter("logout");
        if (logout != null) {
            authenticationAdminStub.logout();
            req.getRequestDispatcher("/Login.jsp").forward(req, resp);
            return;
        }
        if (req.getParameter("userName") != null) {
            userName = req.getParameter("userName").trim();
        }
        if (req.getParameter("userPassword") != null) {
            userPassword = req.getParameter("userPassword").trim();
        }
        // login to server with given user name and password
        if (authenticationAdminStub.login(userName, userPassword, HumanTaskSampleConstants.HOSTNAME)) {
            ServiceContext serviceContext = authenticationAdminStub._getServiceClient().getLastOperationContext()
                    .getServiceContext();
            String sessionCookie = (String) serviceContext.getProperty(HTTPConstants.COOKIE_STRING);
            HttpSession session = req.getSession();
            session.setAttribute(HumanTaskSampleConstants.USERNAME, userName);
            session.setAttribute(HumanTaskSampleConstants.SESSION_COOKIE, sessionCookie);
            req.getRequestDispatcher("/Home.jsp?queryType=assignedToMe&pageNumber=0").forward(req, resp);

        } else {
            log.warn(userName + " login failed.");
            req.setAttribute("message", "Please enter a valid user name and a password.");
            req.getRequestDispatcher("/Login.jsp").forward(req, resp);
        }

    } catch (Exception e) {
        log.error("Failed to retrieve the user session ", e);
        req.setAttribute(HumanTaskSampleConstants.MESSAGE, e);
        req.getRequestDispatcher("/Login.jsp").forward(req, resp);
    }

}