Example usage for javax.script ScriptException ScriptException

List of usage examples for javax.script ScriptException ScriptException

Introduction

In this page you can find the example usage for javax.script ScriptException ScriptException.

Prototype

public ScriptException(Exception e) 

Source Link

Document

Creates a ScriptException wrapping an Exception thrown by an underlying interpreter.

Usage

From source file:org.wso2.carbon.hostobjects.sso.SAMLSSORelyingPartyObject.java

/**
 * @param cx// w ww. j  av a  2s  . c o m
 * @param thisObj
 * @param args-args[0]- Logout response xml as a string
 * @param funObj
 * @return
 * @throws Exception
 */
public static boolean jsFunction_isLogoutResponse(Context cx, Scriptable thisObj, Object[] args,
        Function funObj) throws Exception {
    int argLength = args.length;
    if (argLength != 1 || !(args[0] instanceof String)) {
        throw new ScriptException("Invalid argument. Logout response xml is missing.");
    }
    String decodedString = Util.decode((String) args[0]);
    XMLObject samlObject = Util.unmarshall(decodedString);
    return samlObject instanceof LogoutResponse;

}

From source file:org.wso2.carbon.hostobjects.sso.SAMLSSORelyingPartyObject.java

/**
 * Compressing and Encoding the response
 *
 * @param cx/*from  w  ww.  j  a  va 2s. c  o m*/
 * @param thisObj
 * @param args    -args[0]- string to be encoded.
 * @param funObj
 * @return
 * @throws Exception
 */
public static String jsFunction_encode(Context cx, Scriptable thisObj, Object[] args, Function funObj)
        throws Exception {
    int argLength = args.length;
    if (argLength != 1 || !(args[0] instanceof String)) {
        throw new ScriptException("Invalid argument. String to be encoded is missing.");
    }
    return Util.encode((String) args[0]);

}

From source file:org.wso2.carbon.hostobjects.sso.SAMLSSORelyingPartyObject.java

public static String jsFunction_getSAMLToken(Context cx, Scriptable thisObj, Object[] args, Function funObj)
        throws Exception {
    int argLength = args.length;
    if (argLength != 1 || !(args[0] instanceof String)) {
        throw new ScriptException("Invalid argument. Session Id is missing.");
    }// ww w . java  2  s . c  o m
    SAMLSSORelyingPartyObject relyingPartyObject = (SAMLSSORelyingPartyObject) thisObj;
    SessionInfo sessionInfo = relyingPartyObject.getSessionInfo((String) args[0]);
    if (sessionInfo != null) {
        //            Here the samlToken is encoded. So no need to encode that again
        return sessionInfo.getSamlToken();
    }
    return null;
}

From source file:org.wso2.carbon.hostobjects.sso.SAMLSSORelyingPartyObject.java

/**
 * Decoding and deflating the encoded AuthReq
 *
 * @param cx/*  w w w.j  a  v  a  2 s. c  o  m*/
 * @param thisObj
 * @param args    -args[0]-String to be decoded
 * @param funObj
 * @return
 * @throws Exception
 */
public static String jsFunction_decode(Context cx, Scriptable thisObj, Object[] args, Function funObj)
        throws Exception {
    int argLength = args.length;
    if (argLength != 1 || !(args[0] instanceof String)) {
        throw new ScriptException("Invalid argument. String to be decoded is missing.");
    }
    return Util.decode((String) args[0]);

}

From source file:org.wso2.carbon.hostobjects.sso.SAMLSSORelyingPartyObject.java

/**
 * Get SAML logout request build./*from   w  ww. jav a2  s  . c  o m*/
 *
 * @param cx
 * @param thisObj
 * @param args-args[0]-the user to be logout
 * @param funObj
 * @return
 * @throws Exception
 */
public static String jsFunction_getSAMLLogoutRequest(Context cx, Scriptable thisObj, Object[] args,
        Function funObj) throws Exception {
    int argLength = args.length;
    if (argLength != 2 || !(args[0] instanceof String) && (args[1] instanceof String)) {
        throw new ScriptException("Invalid argument. The user to be logout is missing.");
    }
    SAMLSSORelyingPartyObject relyingPartyObject = (SAMLSSORelyingPartyObject) thisObj;
    String sessionIndexId = relyingPartyObject.getSessionInfo((String) args[1]).getSessionIndex();
    return Util.marshall(new LogoutRequestBuilder().buildLogoutRequest((String) args[0], sessionIndexId,
            SSOConstants.LOGOUT_USER, relyingPartyObject.getSSOProperty(SSOConstants.ISSUER_ID)));

}

From source file:org.wso2.carbon.hostobjects.sso.SAMLSSORelyingPartyObject.java

/**
 * Extract the name of authenticated user from SAML response.
 *
 * @param cx/*  w  w  w. java 2 s  .  co  m*/
 * @param thisObj
 * @param args
 * @param funObj
 * @return
 * @throws Exception
 */
public static String jsFunction_getSAMLResponseNameId(Context cx, Scriptable thisObj, Object[] args,
        Function funObj) throws Exception {
    int argLength = args.length;
    if (argLength != 1 || !(args[0] instanceof String)) {
        throw new ScriptException("Invalid argument. The SAML response is missing.");
    }
    String decodedString = Util.decode((String) args[0]);
    XMLObject samlObject = Util.unmarshall(decodedString);
    String username = null;

    if (samlObject instanceof Response) {
        Response samlResponse = (Response) samlObject;
        List<Assertion> assertions = samlResponse.getAssertions();

        // extract the username
        if (assertions != null && assertions.size() > 0) {
            Subject subject = assertions.get(0).getSubject();
            if (subject != null) {
                if (subject.getNameID() != null) {
                    username = subject.getNameID().getValue();
                }
            }
        }
    }
    if (username == null) {
        throw new Exception("Failed to get subject assertion from SAML response.");
    }
    return username;
}

From source file:org.wso2.carbon.hostobjects.sso.SAMLSSORelyingPartyObject.java

/**
 * Set SSO Configuration key,values/* ww  w  .  j av  a 2 s  .c o m*/
 *
 * @param cx
 * @param thisObj
 * @param args
 * @param funObj
 * @throws ScriptException
 */
public static void jsFunction_setProperty(Context cx, Scriptable thisObj, Object[] args, Function funObj)
        throws ScriptException {
    int argLength = args.length;
    if (argLength != 2 || !(args[0] instanceof String) || !(args[1] instanceof String)) {
        throw new ScriptException("Invalid arguments when setting sso configuration values.");
    }
    SAMLSSORelyingPartyObject relyingPartyObject = (SAMLSSORelyingPartyObject) thisObj;
    relyingPartyObject.setSSOProperty((String) args[0], (String) args[1]);

}

From source file:org.wso2.carbon.hostobjects.sso.SAMLSSORelyingPartyObject.java

/**
 * Check if the browser session is valid. If user is log out from any sso service provider,
 * user session is invalidated./*ww w  .j  av  a2 s.  c  o m*/
 *
 * @param cx
 * @param thisObj
 * @param args
 * @param funObj
 * @return
 * @throws ScriptException
 */
public static boolean jsFunction_isSessionAuthenticated(Context cx, Scriptable thisObj, Object[] args,
        Function funObj) throws ScriptException {
    int argLength = args.length;
    if (argLength != 1 || !(args[0] instanceof String)) {
        throw new ScriptException("Invalid argument. Session id is missing.");
    }
    SAMLSSORelyingPartyObject relyingPartyObject = (SAMLSSORelyingPartyObject) thisObj;
    return relyingPartyObject.isSessionIdExists((String) args[0]);

}

From source file:org.wso2.carbon.hostobjects.sso.SAMLSSORelyingPartyObject.java

public static String jsFunction_getIdentitySessionId(Context cx, Scriptable thisObj, Object[] args,
        Function funObj) throws ScriptException {
    String identitySession = null;
    int argLength = args.length;
    if (argLength != 1 || !(args[0] instanceof String)) {
        throw new ScriptException("Invalid argument. Session id is missing.");
    }//w w  w  .java  2  s  . c  o m
    SAMLSSORelyingPartyObject relyingPartyObject = (SAMLSSORelyingPartyObject) thisObj;
    SessionInfo sessionInfo = relyingPartyObject.getSessionInfo((String) args[0]);
    if (sessionInfo != null) {
        identitySession = sessionInfo.getSessionId();
    }
    return identitySession;
}

From source file:org.wso2.carbon.hostobjects.sso.SAMLSSORelyingPartyObject.java

public static String jsFunction_getLoggedInUser(Context cx, Scriptable thisObj, Object[] args, Function funObj)
        throws ScriptException {
    int argLength = args.length;
    if (argLength != 1 || !(args[0] instanceof String)) {
        throw new ScriptException("Invalid argument. Session id is missing.");
    }/*from   ww  w .  ja  v a  2s .  co m*/
    SAMLSSORelyingPartyObject relyingPartyObject = (SAMLSSORelyingPartyObject) thisObj;
    SessionInfo sessionInfo = relyingPartyObject.getSessionInfo((String) args[0]);
    String loggedInUser = null;
    if (sessionInfo != null && sessionInfo.getLoggedInUser() != null) {
        loggedInUser = sessionInfo.getLoggedInUser();
    }
    return loggedInUser;

}