Java源码示例:org.wso2.carbon.ui.CarbonUIAuthenticator

示例1
@Override
public void start(BundleContext bc) throws Exception {
    IWAUIAuthenticator authenticator = new IWAUIAuthenticator();
    Hashtable<String, String> props = new Hashtable<String, String>();
    props.put(CarbonConstants.AUTHENTICATOR_TYPE, authenticator.getAuthenticatorName());
    bc.registerService(CarbonUIAuthenticator.class.getName(), authenticator, props);
    if (log.isDebugEnabled()) {
        log.debug("Integrated Windows Authenticator enabled in the system");
    }
}
 
示例2
@Activate
protected void activate(ComponentContext ctxt) {
    if (Util.isAuthenticatorEnabled()) {
        // initialize the OIDC Config params during the start-up
        boolean initSuccess = Util.initOIDCConfigParams();
        if (initSuccess) {
            HttpServlet loginServlet = new HttpServlet() {

                @Override
                protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
                }
            };
            Filter loginPageFilter = new LoginPageFilter();
            Dictionary loginPageFilterProps = new Hashtable(2);
            Dictionary redirectionParams = new Hashtable(3);
            redirectionParams.put("url-pattern", Util.getLoginPage());
            redirectionParams.put("associated-filter", loginPageFilter);
            redirectionParams.put("servlet-attributes", loginPageFilterProps);
            ctxt.getBundleContext().registerService(Servlet.class.getName(), loginServlet, redirectionParams);
            // register the UI authenticator
            OIDCUIAuthenticator authenticator = new OIDCUIAuthenticator();
            Hashtable<String, String> props = new Hashtable<String, String>();
            props.put(CarbonConstants.AUTHENTICATOR_TYPE, authenticator.getAuthenticatorName());
            ctxt.getBundleContext().registerService(CarbonUIAuthenticator.class.getName(), authenticator, props);
            if (log.isDebugEnabled()) {
                log.debug("OIDC Authenticator FE Bundle activated successfully.");
            }
        } else {
            log.warn("Initialization failed for OIDC Authenticator. Starting with the default authenticator");
        }
    } else {
        if (log.isDebugEnabled()) {
            log.debug("OIDC Authenticator is disabled");
        }
    }
}
 
示例3
public static void init(BundleContext bc) throws Exception {
    try {
        authTracker = new ServiceTracker(bc, CarbonUIAuthenticator.class.getName(), null);
        authTracker.open();
    } catch (Exception e) {
        log.error(e.getMessage(), e);
        throw e;
    }
}
 
示例4
public static CarbonUIAuthenticator getCarbonAuthenticator(HttpServletRequest request) {

        HttpSession session = request.getSession();
        CarbonUIAuthenticator authenticator;

        if ((authenticator = (CarbonUIAuthenticator) session
                .getAttribute(CarbonSecuredHttpContext.CARBON_AUTHNETICATOR)) != null) {
            return authenticator;
        }

        if (authenticators == null || authenticators.length == 0 || authenticators[0] == null) {
            synchronized (lock) {
                if (authenticators == null || authenticators.length == 0
                        || authenticators[0] == null) {
                    Object[] objects = authTracker.getServices();
                    // cast each object - cannot cast object array
                    authenticators = new CarbonUIAuthenticator[objects.length];
                    int i = 0;
                    for (Object obj : objects) {
                        authenticators[i] = (CarbonUIAuthenticator) obj;
                        i++;
                    }
                    Arrays.sort(authenticators, new AuthenticatorComparator());
                }
            }
        }

        for (CarbonUIAuthenticator auth : authenticators) {
            if (!auth.isDisabled() && auth.canHandle(request)) {
                session.setAttribute(CarbonSecuredHttpContext.CARBON_AUTHNETICATOR, auth);
                return auth;
            }
        }

        return null;
    }
 
示例5
public void handleLogout(String sessionIndex) {

        HttpSession session = (HttpSession) sessionMap.get(sessionIndex);

        if (session == null) {
            //send cluster message
            sendSessionInvalidationClusterMessage(sessionIndex);
            return;
        }

        CarbonSSOSessionManager ssoSessionManager = SAML2SSOAuthFEDataHolder.getInstance()
                .getCarbonSSOSessionManager();

        // mark this session as invalid.
        ssoSessionManager.makeSessionInvalid(sessionIndex);

        String username = (String) session.getAttribute(CarbonSecuredHttpContext.LOGGED_USER);
        log.info("Invalidating session for user " + username);

        // invalidating backend session
        try {
            CarbonUIAuthenticator authenticator =
                    (CarbonUIAuthenticator) session.getAttribute(CarbonSecuredHttpContext.CARBON_AUTHNETICATOR);
            if (authenticator != null) {
                authenticator.unauthenticate(session);
                log.debug("Backend session invalidated");
            }
        } catch (Exception e) {
            log.error(e.getMessage());
        }

        // clearing front end session
        session.setAttribute("authenticated", false);
        session.removeAttribute(CarbonSecuredHttpContext.LOGGED_USER);
        session.getServletContext().removeAttribute(CarbonSecuredHttpContext.LOGGED_USER);

        removeSession(sessionIndex);

        try {
            session.invalidate();
        } catch (Exception ignored) {
            log.error(ignored.getMessage());
        }

        if (log.isDebugEnabled()) {
            log.debug("Cleared authenticated session " + session.getId());
        }

    }
 
示例6
protected void activate(ComponentContext ctxt) {
    try {
        if (Util.isAuthenticatorEnabled()) {
            // initialize the SSO Config params during the start-up
            boolean initSuccess = Util.initSSOConfigParams();

            if (initSuccess) {
                HttpServlet loginServlet = new HttpServlet() {
                    @Override
                    protected void doPost(HttpServletRequest req, HttpServletResponse resp)
                            throws ServletException, IOException {
                        throw new UnsupportedOperationException();

                    }
                };

                Filter loginPageFilter = new LoginPageFilter();
                Dictionary loginPageFilterProps = new Hashtable(2);
                Dictionary redirectorParams = new Hashtable(3);

                redirectorParams.put("url-pattern", Util.getLoginPage());

                redirectorParams.put("associated-filter", loginPageFilter);
                redirectorParams.put("servlet-attributes", loginPageFilterProps);
                ctxt.getBundleContext().registerService(Servlet.class.getName(),
                        loginServlet, redirectorParams);
                // register the UI authenticator
                SAML2SSOUIAuthenticator authenticator = new SAML2SSOUIAuthenticator();
                Hashtable<String, String> props = new Hashtable<String, String>();
                props.put(CarbonConstants.AUTHENTICATOR_TYPE, authenticator.getAuthenticatorName());
                ctxt.getBundleContext().registerService(CarbonUIAuthenticator.class.getName(),
                        authenticator, props);
                if (log.isDebugEnabled()) {
                    log.debug("SAML2 SSO Authenticator BE Bundle activated successfully.");
                }
            } else {
                log.warn("Initialization failed for SSO Authenticator. Starting with the default authenticator");
            }
        } else {
            if (log.isDebugEnabled()) {
                log.debug("SAML2 SSO Authenticator is disabled");
            }
        }
    } catch (Throwable e) {
        log.error("Saml Authentication Failed");
    }
}
 
示例7
public int compare(CarbonUIAuthenticator o1, CarbonUIAuthenticator o2) {
    return o2.getPriority()-o1.getPriority();
}