Example usage for org.apache.wicket.util.string StringValue toLong

List of usage examples for org.apache.wicket.util.string StringValue toLong

Introduction

In this page you can find the example usage for org.apache.wicket.util.string StringValue toLong.

Prototype

public final long toLong(final long defaultValue) 

Source Link

Document

Convert to long integer, returning default value if text is inconvertible.

Usage

From source file:org.apache.openmeetings.core.remote.red5.ScopeApplicationAdapter.java

License:Apache License

@Override
public boolean roomConnect(IConnection conn, Object[] params) {
    log.debug("roomConnect : ");

    IServiceCapableConnection service = (IServiceCapableConnection) conn;
    String streamId = conn.getClient().getId();

    log.debug("### Client connected to OpenMeetings, register Client StreamId: " + streamId + " scope "
            + conn.getScope().getName());

    // Set StreamId in Client
    service.invoke("setId", new Object[] { streamId }, this);

    Map<String, Object> map = conn.getConnectParams();
    String swfURL = map.containsKey("swfUrl") ? (String) map.get("swfUrl") : "";
    String tcUrl = map.containsKey("tcUrl") ? (String) map.get("tcUrl") : "";
    Map<String, Object> connParams = getConnParams(params);
    String uid = (String) connParams.get("uid");
    String securityCode = (String) connParams.get(SECURITY_CODE_PARAM);
    if (!Strings.isEmpty(securityCode)) {
        //FIXME TODO add better mechanism, this is for external applications like ffmpeg
        Client parent = sessionManager.getClientByPublicSID(securityCode, null);
        if (parent == null || !parent.getScope().equals(conn.getScope().getName())) {
            return rejectClient();
        }/*from  w  w  w  . ja  va  2s .  co  m*/
    }
    if ("networktest".equals(uid)) {
        return true;
    }

    Client parentClient = null;
    //TODO add similar code for other connections
    if (map.containsKey("screenClient")) {
        String parentSid = (String) map.get("parentSid");
        parentClient = sessionManager.getClientByPublicSID(parentSid, null);
        if (parentClient == null) {
            return rejectClient();
        }
    }
    Client rcm = new Client();
    rcm.setStreamid(conn.getClient().getId());
    StringValue scn = StringValue.valueOf(conn.getScope().getName());
    rcm.setScope(scn.toString());
    long roomId = scn.toLong(Long.MIN_VALUE);
    if (Long.MIN_VALUE != roomId) {
        rcm.setRoomId(roomId);
    } else if (!"hibernate".equals(scn.toString())) {
        return rejectClient();
    }
    rcm.setUserport(conn.getRemotePort());
    rcm.setUserip(conn.getRemoteAddress());
    rcm.setSwfurl(swfURL);
    rcm.setTcUrl(tcUrl);
    rcm.setNativeSsl(Boolean.TRUE.equals(connParams.get(NATIVE_SSL_PARAM)));
    rcm.setPublicSID(uid);
    rcm.setSecurityCode(securityCode);
    rcm = sessionManager.add(rcm, null);
    if (rcm == null) {
        log.warn("Failed to create Client on room connect");
        return false;
    }

    SessionVariablesUtil.initClient(conn.getClient(), rcm.getPublicSID());
    //TODO add similar code for other connections, merge with above block
    if (map.containsKey("screenClient")) {
        //TODO add check for room rights
        String parentSid = parentClient.getPublicSID();
        rcm.setRoomId(Long.valueOf(conn.getScope().getName()));
        rcm.setScreenClient(true);
        SessionVariablesUtil.setIsScreenClient(conn.getClient());

        rcm.setUserId(parentClient.getUserId());
        Long userId = rcm.getUserId();
        SessionVariablesUtil.setUserId(conn.getClient(), userId);

        rcm.setStreamPublishName(parentSid);
        User u = null;
        if (userId != null) {
            long _uid = userId.longValue();
            u = userDao.get(_uid < 0 ? -_uid : _uid);
        }
        if (u != null) {
            rcm.setUsername(u.getLogin());
            rcm.setFirstname(u.getFirstname());
            rcm.setLastname(u.getLastname());
        }
        log.debug("publishName :: " + rcm.getStreamPublishName());
        sessionManager.updateClientByStreamId(streamId, rcm, false, null);
    }

    // Log the User
    conferenceLogDao.add(ConferenceLog.Type.clientConnect, rcm.getUserId(), streamId, null, rcm.getUserip(),
            rcm.getScope());
    return true;
}

From source file:org.apache.openmeetings.web.pages.auth.SignInPage.java

License:Apache License

public SignInPage(PageParameters p) {
    super();//from   w w  w  .java 2 s  .c o  m
    StringValue oauthid = p.get("oauthid");
    if (!oauthid.isEmpty()) { // oauth2 login
        try {
            long serverId = oauthid.toLong(-1);
            OAuthServer server = getBean(OAuth2Dao.class).get(serverId);
            log.debug("OAuthServer=" + server);
            if (server == null) {
                log.warn("OAuth server id=" + serverId + " not found");
                return;
            }

            if (p.get("code").toString() != null) { // got code
                String code = p.get("code").toString();
                log.debug("OAuth response code=" + code);
                AuthInfo authInfo = getToken(code, server);
                if (authInfo == null)
                    return;
                log.debug("OAuthInfo=" + authInfo);
                Map<String, String> authParams = getAuthParams(authInfo.accessToken, code, server);
                if (authParams != null) {
                    loginViaOAuth2(authParams, serverId);
                }
            } else { // redirect to get code
                String redirectUrl = prepareUrlParams(server.getRequestKeyUrl(), server.getClientId(), null,
                        null, getRedirectUri(server, this), null);
                log.debug("redirectUrl=" + redirectUrl);
                throw new RedirectToUrlException(redirectUrl);
            }
        } catch (IOException e) {
            log.error("OAuth2 login error", e);
        } catch (NoSuchAlgorithmException e) {
            log.error("OAuth2 login error", e);
        }
    }
    //will try to login directly using parameters sent by POST
    IRequestParameters pp = RequestCycle.get().getRequest().getPostParameters();
    StringValue login = pp.getParameterValue("login"), password = pp.getParameterValue("password");
    if (!login.isEmpty() && !password.isEmpty()) {
        if (WebSession.get().signIn(login.toString(), password.toString(), Type.user, null)) {
            setResponsePage(Application.get().getHomePage());
        } else {
            log.error("Failed to login using POST parameters passed");
        }
    }

    RegisterDialog r = new RegisterDialog("register");
    ForgetPasswordDialog f = new ForgetPasswordDialog("forget");
    d = new SignInDialog("signin");
    d.setRegisterDialog(r);
    d.setForgetPasswordDialog(f);
    r.setSignInDialog(d);
    f.setSignInDialog(d);
    m = new KickMessageDialog("kick");
    add(d.setVisible(!WebSession.get().isKickedByAdmin()), r.setVisible(allowRegister()), f,
            m.setVisible(WebSession.get().isKickedByAdmin()));
}