Search in sources :

Example 1 with NoneBackend

use of com.tremolosecurity.idp.providers.oidc.none.NoneBackend in project OpenUnison by TremoloSecurity.

the class TokenData method createUserSession.

public OidcSessionState createUserSession(HttpServletRequest request, String clientID, UrlHolder holder, OpenIDConnectTrust trust, String dn, ConfigManager cfgMgr, OpenIDConnectAccessToken access, String nonce, String authChain, JSONObject existingClaims, JSONObject actor) throws UnsupportedEncodingException, IOException, ServletException, MalformedURLException {
    String sessionID = UUID.randomUUID().toString();
    String encryptedSessionID = null;
    try {
        encryptedSessionID = this.encryptToken(this.sessionKeyName, new Gson(), sessionID);
    } catch (InvalidKeyException | NoSuchAlgorithmException | NoSuchPaddingException | IllegalBlockSizeException | BadPaddingException e2) {
        throw new ServletException("Could not generate session id", e2);
    }
    HashMap<String, String> extraAttribs = new HashMap<String, String>();
    extraAttribs.put("session_id", encryptedSessionID);
    String accessToken = null;
    try {
        accessToken = this.produceJWT(this.generateClaims(dn, cfgMgr, new URL(request.getRequestURL().toString()), trust, nonce, extraAttribs, request, authChain, existingClaims, actor), cfgMgr).getCompactSerialization();
    } catch (JoseException | LDAPException | ProvisioningException e1) {
        throw new ServletException("Could not generate jwt", e1);
    }
    access.setAccess_token(accessToken);
    access.setExpires_in((int) (trust.getAccessTokenTimeToLive() / 1000));
    try {
        JwtClaims claims = this.generateClaims(dn, cfgMgr, new URL(request.getRequestURL().toString()), trust, nonce, null, request, authChain, existingClaims, actor);
        access.setIdTokenId(claims.getJwtId());
        access.setId_token(this.produceJWT(claims, cfgMgr).getCompactSerialization());
    } catch (Exception e) {
        throw new ServletException("Could not generate JWT", e);
    }
    access.setToken_type("Bearer");
    OidcSessionState oidcSession = null;
    try {
        oidcSession = this.storeSession(access, holder.getApp(), trust.getCodeLastmileKeyName(), clientID, dn, sessionID);
        if (!(this.sessionStore instanceof NoneBackend)) {
            request.getSession().setAttribute(SessionManagerImpl.TREMOLO_EXTERNAL_SESSION, new OidcSessionExpires(oidcSession.getSessionID(), this.sessionStore));
        }
    } catch (Exception e) {
        throw new ServletException("Could not store session", e);
    }
    LogoutUtil.insertFirstLogoutHandler(request, new ClearOidcSessionOnLogout(oidcSession, this));
    return oidcSession;
}
Also used : HashMap(java.util.HashMap) JwtClaims(org.jose4j.jwt.JwtClaims) JoseException(org.jose4j.lang.JoseException) Gson(com.google.gson.Gson) NoSuchPaddingException(javax.crypto.NoSuchPaddingException) IllegalBlockSizeException(javax.crypto.IllegalBlockSizeException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) BadPaddingException(javax.crypto.BadPaddingException) InvalidKeyException(java.security.InvalidKeyException) URL(java.net.URL) ProvisioningException(com.tremolosecurity.provisioning.core.ProvisioningException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) InvalidKeyException(java.security.InvalidKeyException) LDAPException(com.novell.ldap.LDAPException) InvalidAlgorithmParameterException(java.security.InvalidAlgorithmParameterException) IOException(java.io.IOException) ServletException(javax.servlet.ServletException) URISyntaxException(java.net.URISyntaxException) InvalidJwtException(org.jose4j.jwt.consumer.InvalidJwtException) IllegalBlockSizeException(javax.crypto.IllegalBlockSizeException) JoseException(org.jose4j.lang.JoseException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) ParseException(org.json.simple.parser.ParseException) NoSuchPaddingException(javax.crypto.NoSuchPaddingException) MalformedURLException(java.net.MalformedURLException) BadPaddingException(javax.crypto.BadPaddingException) ServletException(javax.servlet.ServletException) OidcSessionExpires(com.tremolosecurity.idp.providers.oidc.session.OidcSessionExpires) LDAPException(com.novell.ldap.LDAPException) ClearOidcSessionOnLogout(com.tremolosecurity.idp.providers.oidc.session.ClearOidcSessionOnLogout) ProvisioningException(com.tremolosecurity.provisioning.core.ProvisioningException) NoneBackend(com.tremolosecurity.idp.providers.oidc.none.NoneBackend) OidcSessionState(com.tremolosecurity.idp.providers.oidc.model.OidcSessionState)

Aggregations

Gson (com.google.gson.Gson)1 LDAPException (com.novell.ldap.LDAPException)1 OidcSessionState (com.tremolosecurity.idp.providers.oidc.model.OidcSessionState)1 NoneBackend (com.tremolosecurity.idp.providers.oidc.none.NoneBackend)1 ClearOidcSessionOnLogout (com.tremolosecurity.idp.providers.oidc.session.ClearOidcSessionOnLogout)1 OidcSessionExpires (com.tremolosecurity.idp.providers.oidc.session.OidcSessionExpires)1 ProvisioningException (com.tremolosecurity.provisioning.core.ProvisioningException)1 IOException (java.io.IOException)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 MalformedURLException (java.net.MalformedURLException)1 URISyntaxException (java.net.URISyntaxException)1 URL (java.net.URL)1 InvalidAlgorithmParameterException (java.security.InvalidAlgorithmParameterException)1 InvalidKeyException (java.security.InvalidKeyException)1 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1 HashMap (java.util.HashMap)1 BadPaddingException (javax.crypto.BadPaddingException)1 IllegalBlockSizeException (javax.crypto.IllegalBlockSizeException)1 NoSuchPaddingException (javax.crypto.NoSuchPaddingException)1 ServletException (javax.servlet.ServletException)1