Java Code Examples for org.wso2.carbon.utils.CarbonUtils#isRunningOnLocalTransportMode()

The following examples show how to use org.wso2.carbon.utils.CarbonUtils#isRunningOnLocalTransportMode() . 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: BasicAuthUIAuthenticator.java    From attic-stratos with Apache License 2.0 6 votes vote down vote up
@Override
public boolean canHandle(HttpServletRequest request) {

    String userName = request.getParameter(AbstractCarbonUIAuthenticator.USERNAME);
    String password = request.getParameter(AbstractCarbonUIAuthenticator.PASSWORD);

    if (CarbonUtils.isRunningOnLocalTransportMode()) {
        return false;
    }

    if (userName != null && password != null) {
        return true;
    }

    // This is to login with Remember Me.
    Cookie[] cookies = request.getCookies();
    if (cookies != null) {
        for (Cookie cookie : cookies) {
            if (cookie.getName().equals(CarbonConstants.REMEMBER_ME_COOKE_NAME)) {
                return true;
            }
        }
    }

    return false;
}
 
Example 2
Source File: SAML2SSOAuthenticationClient.java    From carbon-identity with Apache License 2.0 5 votes vote down vote up
public void logout(HttpSession session) throws AuthenticationException {
    try {
        if (!CarbonUtils.isRunningOnLocalTransportMode()) {
            stub.logout();
        }
        session.removeAttribute(ServerConstants.ADMIN_SERVICE_AUTH_TOKEN);
    } catch (java.lang.Exception e) {
        String msg = "Error occurred while logging out";
        log.error(msg, e);
        throw new AuthenticationException(msg, e);
    }
}
 
Example 3
Source File: OIDCAuthenticationClient.java    From carbon-apimgt with Apache License 2.0 5 votes vote down vote up
public void logout(HttpSession session) throws AuthenticationException {
    try {
        if(!CarbonUtils.isRunningOnLocalTransportMode()){
            stub.logout();
        }
        session.removeAttribute(ServerConstants.ADMIN_SERVICE_AUTH_TOKEN);
        session.invalidate();
    } catch (java.lang.Exception e) {
        String msg = "Error occurred while logging out";
        log.error(msg, e);
        throw new AuthenticationException(msg, e);
    }
}
 
Example 4
Source File: DefaultCarbonAuthenticator.java    From attic-stratos with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
public boolean canHandle(HttpServletRequest request) {
    // try to authenticate any request that comes
    // least priority authenticator
    String userName = request.getParameter(AbstractCarbonUIAuthenticator.USERNAME);
    String password = request.getParameter(AbstractCarbonUIAuthenticator.PASSWORD);

    if (!CarbonUtils.isRunningOnLocalTransportMode()) {
        return false;
    }

    if (userName != null && password != null) {
        return true;
    }

    // This is to login with Remember Me.
    Cookie[] cookies = request.getCookies();
    if (cookies != null) {
        for (Cookie cookie : cookies) {
            if (cookie.getName().equals(CarbonConstants.REMEMBER_ME_COOKE_NAME)) {
                return true;
            }
        }
    }

    return false;
}
 
Example 5
Source File: AbstractCarbonUIAuthenticator.java    From attic-stratos with Apache License 2.0 4 votes vote down vote up
/**
   * 
   * @param request
   * @param userName
   * @throws Exception
   */
  public void onSuccessAdminLogin(HttpServletRequest request, String userName) throws Exception {

HttpSession session = request.getSession();

  	String tenantDomain = MultitenantUtils.getTenantDomain(userName);
      if (tenantDomain != null && tenantDomain.trim().length() > 0) {
          session.setAttribute(MultitenantConstants.TENANT_DOMAIN, tenantDomain);
          // we will make it an attribute on request as well
          if (request.getAttribute(MultitenantConstants.TENANT_DOMAIN) == null) {
              request.setAttribute(MultitenantConstants.TENANT_DOMAIN, tenantDomain);
          }
      } else {
          audit.info("User with null domain tried to login.");
          return;
      }
      
if (session.getAttribute(CarbonConstants.LOGGED_USER) != null) {
	userName = (String) session
			.getAttribute(CarbonConstants.LOGGED_USER);
}
request.setAttribute(AbstractCarbonUIAuthenticator.USERNAME, userName);

      String serverURL = getBackendUrl(request);
      if (serverURL == null) {
          throw new AuthenticationException("Server not initialized properly.");
      }

      String cookie = (String) session.getAttribute(ServerConstants.ADMIN_SERVICE_COOKIE);

      // For local transport, cookie might be null.
      if ((serverURL == null || cookie == null) && (!CarbonUtils.isRunningOnLocalTransportMode())) {
          throw new Exception("Cannot proceed logging in. The server URL and/or Cookie is null");
      }

      if (tenantDomain != null
              && MultitenantConstants.SUPER_TENANT_DOMAIN_NAME.equals(tenantDomain.trim())) {
          request.getSession().setAttribute(MultitenantConstants.IS_SUPER_TENANT, "true");
      } else if (tenantDomain != null && tenantDomain.trim().length() > 0) {
          session.setAttribute(MultitenantConstants.TENANT_DOMAIN, tenantDomain);
          // we will make it an attribute on request as well
          if (request.getAttribute(MultitenantConstants.TENANT_DOMAIN) == null) {
              request.setAttribute(MultitenantConstants.TENANT_DOMAIN, tenantDomain);
          }
      } else {
          audit.info("User with null domain tried to login.");
          return;
      }

      String tenantAwareUserName = MultitenantUtils.getTenantAwareUsername(userName);

      setUserInformation(cookie, serverURL, session);
     
session.setAttribute(CarbonConstants.LOGGED_USER, tenantAwareUserName);
      session.getServletContext().setAttribute(CarbonConstants.LOGGED_USER, tenantAwareUserName);
      session.setAttribute("authenticated", Boolean.parseBoolean("true"));

      UIAuthenticationExtender[] uiAuthenticationExtenders = CarbonUIServiceComponent
              .getUIAuthenticationExtenders();
      for (UIAuthenticationExtender uiAuthenticationExtender : uiAuthenticationExtenders) {
          uiAuthenticationExtender.onSuccessAdminLogin(request, tenantAwareUserName,
                  tenantDomain, serverURL);
      }
  }