private boolean dealWithFacebookPrincipal(Request request, Response response, Principal principal) throws IOException { String userName = principal.getName(); request.getSessionInternal().setNote(Constants.SESS_USERNAME_NOTE, userName); request.getSessionInternal().setNote(Constants.SESS_PASSWORD_NOTE, ""); request.setUserPrincipal(principal); if (saveRestoreRequest) { this.restoreRequest(request, request.getSessionInternal()); } registerWithAuthenticatorBase(request, response, principal, userName); request.getSession().setAttribute("STATE", STATES.FINISH.name()); return true; }
private boolean dealWithOpenIDPrincipal(Request request, Response response, Principal principal) throws IOException { HttpSession httpSession = request.getSession(); String principalName = principal.getName(); request.getSessionInternal().setNote(Constants.SESS_USERNAME_NOTE, principalName); request.getSessionInternal().setNote(Constants.SESS_PASSWORD_NOTE, ""); request.setUserPrincipal(principal); if (saveRestoreRequest) { this.restoreRequest(request, request.getSessionInternal()); } if (trace) log.trace("Logged in as:" + principal); registerWithAuthenticatorBase(request, response, principal, principalName); httpSession.setAttribute("STATE", STATES.FINISH.name()); return true; } }
protected void saveRequest(Request request, String contextId) throws IOException { String uri = request.getDecodedRequestURI(); Session session = request.getSessionInternal(true); if (session != null) { LOG.debug("Save request in session '{}'", session.getIdInternal()); } if (session != null && uri != null) { SavedRequest saved; synchronized (session) { super.saveRequest(request, session); saved = (SavedRequest) session.getNote(Constants.FORM_REQUEST_NOTE); } session.setNote(SESSION_SAVED_REQUEST_PREFIX + uri, saved); StringBuilder sb = new StringBuilder(saved.getRequestURI()); if (saved.getQueryString() != null) { sb.append('?'); sb.append(saved.getQueryString()); } session.setNote(SESSION_SAVED_URI_PREFIX + contextId, sb.toString()); } }
@Override protected FedizPrincipal createPrincipal(HttpServletRequest request, HttpServletResponse response, FedizResponse wfRes) { // Add "Authenticated" role List<String> roles = wfRes.getRoles(); if (roles == null || roles.isEmpty()) { roles = Collections.singletonList("Authenticated"); } else if (getFedizContext().isAddAuthenticatedRole()) { roles = new ArrayList<>(roles); roles.add("Authenticated"); } // proceed creating the JAAS Subject FedizPrincipal principal = new FederationPrincipalImpl(wfRes.getUsername(), roles, wfRes.getClaims(), wfRes.getToken()); Session session = ((Request)request).getSessionInternal(); // Save the authenticated Principal in our session session.setNote(Constants.FORM_PRINCIPAL_NOTE, principal); // Save Federation response in our session session.setNote(FederationAuthenticator.FEDERATION_NOTE, wfRes); // Save Federation response in public session request.getSession(true).setAttribute(FederationAuthenticator.SECURITY_TOKEN, wfRes.getToken()); LOG.debug("UserPrincipal was created successfully for {}", principal); return principal; }
@Override protected FedizPrincipal createPrincipal(HttpServletRequest request, HttpServletResponse response, FedizResponse wfRes) { // Add "Authenticated" role List<String> roles = wfRes.getRoles(); if (roles == null || roles.isEmpty()) { roles = Collections.singletonList("Authenticated"); } else if (getFedizContext().isAddAuthenticatedRole()) { roles = new ArrayList<>(roles); roles.add("Authenticated"); } // proceed creating the JAAS Subject FedizPrincipal principal = new FederationPrincipalImpl(wfRes.getUsername(), roles, wfRes.getClaims(), wfRes.getToken()); Session session = ((Request)request).getSessionInternal(); // Save the authenticated Principal in our session session.setNote(Constants.FORM_PRINCIPAL_NOTE, principal); // Save Federation response in our session session.setNote(FederationAuthenticator.FEDERATION_NOTE, wfRes); // Save Federation response in public session request.getSession(true).setAttribute(FederationAuthenticator.SECURITY_TOKEN, wfRes.getToken()); LOG.debug("UserPrincipal was created successfully for {}", principal); return principal; }
/** * Parses and removes jreplica (if present) from the request URI. */ protected void parseJReplica(CharChunk uriCC) { String jreplica = parseParameterFromRequestURI(uriCC, Globals.JREPLICA_PARAMETER); if (jreplica != null) { Session session = getSessionInternal(false); if (session != null) { session.setNote(Globals.JREPLICA_SESSION_NOTE, jreplica); } // if (!coyoteRequest.requestURI().getByteChunk().isNull()) { removeParameterFromRequestURI(Globals.JREPLICA_PARAMETER); // } } }
protected void saveRequest(Request request, RequestState requestState) throws IOException { String contextId = requestState.getState(); String uri = request.getDecodedRequestURI(); Session session = request.getSessionInternal(true); if (session != null) { LOG.debug("Save request in session '{}'", session.getIdInternal()); } if (session != null && uri != null) { SavedRequest saved; synchronized (session) { super.saveRequest(request, session); saved = (SavedRequest) session.getNote(Constants.FORM_REQUEST_NOTE); } session.setNote(SESSION_SAVED_REQUEST_PREFIX + uri, saved); StringBuilder sb = new StringBuilder(saved.getRequestURI()); if (saved.getQueryString() != null) { sb.append('?'); sb.append(saved.getQueryString()); } session.setNote(SESSION_SAVED_URI_PREFIX + contextId, sb.toString()); //we set Request State as session attribute for later retrieval in SigninHandler request.getSession().setAttribute( FederationConstants.SESSION_SAVED_REQUEST_STATE_PREFIX + requestState.getState(), requestState); } }
@Override protected boolean matchRequest(Request request) { Session session = request.getSessionInternal(false); String uri = request.getDecodedRequestURI(); if (session != null && uri != null) { SavedRequest saved = (SavedRequest) session.getNote(SESSION_SAVED_REQUEST_PREFIX + uri); if (saved != null) { synchronized (session) { session.setNote(Constants.FORM_REQUEST_NOTE, saved); return super.matchRequest(request); } } } return false; }
@Override protected boolean matchRequest(Request request) { Session session = request.getSessionInternal(false); String uri = request.getDecodedRequestURI(); if (session != null && uri != null) { SavedRequest saved = (SavedRequest) session.getNote(SESSION_SAVED_REQUEST_PREFIX + uri); if (saved != null) { synchronized (session) { session.setNote(Constants.FORM_REQUEST_NOTE, saved); return super.matchRequest(request); } } } return false; }
protected boolean restoreRequest(Request request) throws IOException { Session session = request.getSessionInternal(false); String uri = request.getDecodedRequestURI(); if (session != null && uri != null) { SavedRequest saved = (SavedRequest)session.getNote(SESSION_SAVED_REQUEST_PREFIX + uri); if (saved != null) { session.removeNote(SESSION_SAVED_REQUEST_PREFIX + uri); // cleanup session synchronized (session) { session.setNote(Constants.FORM_REQUEST_NOTE, saved); return super.restoreRequest(request, session); } } } return false; }
protected boolean restoreRequest(Request request) throws IOException { Session session = request.getSessionInternal(false); String uri = request.getDecodedRequestURI(); if (session != null && uri != null) { SavedRequest saved = (SavedRequest)session.getNote(SESSION_SAVED_REQUEST_PREFIX + uri); if (saved != null) { session.removeNote(SESSION_SAVED_REQUEST_PREFIX + uri); // cleanup session synchronized (session) { session.setNote(Constants.FORM_REQUEST_NOTE, saved); return super.restoreRequest(request, session); } } } return false; }
@Override protected void register(Request request, HttpServletResponse response, Principal principal, String authType, String username, String password) { super.register(request, response, principal, authType, username, password); LogMessages.LOGGER.debug(Messages.MESSAGES.authenticateUserSession(principal.getName())); userSessionManagement.login(request.getSessionInternal(), principal.getName()); if (!skeletonKeyConfig.isCancelPropagation()) { GenericPrincipal gp = (GenericPrincipal) request.getPrincipal(); if (gp != null) { SkeletonKeyToken token = buildToken(gp); String stringToken = buildTokenString(realmPrivateKey, token); SkeletonKeySession skSession = new SkeletonKeySession(stringToken, resourceMetadata); request.setAttribute(SkeletonKeySession.class.getName(), skSession); ResteasyProviderFactory.pushContext(SkeletonKeySession.class, skSession); request.getSessionInternal(true).setNote(SkeletonKeySession.class.getName(), skSession); } } }
/** * <p>This method populate the request and session with a logout requests to start a global logout from the IdP.</p> * * @param request * @param userPrincipal */ private void prepareLocalGlobalLogoutRequest(Request request, Principal userPrincipal) { try { SAML2Request saml2Request = new SAML2Request(); LogoutRequestType lort = saml2Request.createLogoutRequest(getIdentityURL()); NameIDType nameID = new NameIDType(); nameID.setValue(userPrincipal.getName()); nameID.setFormat(URI.create(JBossSAMLURIConstants.NAMEID_FORMAT_PERSISTENT.get())); lort.setNameID(nameID); lort.setDestination(URI.create(getIdentityURL())); byte[] responseBytes = DocumentUtil.getDocumentAsString(saml2Request.convert(lort)).getBytes("UTF-8"); String samlRequest = RedirectBindingUtil.deflateBase64Encode(responseBytes); Session session = request.getSessionInternal(); session.setNote(SAML_REQUEST_KEY, samlRequest); } catch (Exception e) { throw new RuntimeException("Could not perform IdP Initiated Single Logout.", e); } }
/** * <p>This method populate the request and session with a logout requests to start a global logout from the IdP.</p> * * @param request * @param userPrincipal */ private void prepareLocalGlobalLogoutRequest(Request request, Principal userPrincipal) { try { SAML2Request saml2Request = new SAML2Request(); LogoutRequestType lort = saml2Request.createLogoutRequest(getIdentityURL()); NameIDType nameID = new NameIDType(); nameID.setValue(userPrincipal.getName()); nameID.setFormat(URI.create(JBossSAMLURIConstants.NAMEID_FORMAT_PERSISTENT.get())); lort.setNameID(nameID); lort.setDestination(URI.create(getIdentityURL())); byte[] responseBytes = DocumentUtil.getDocumentAsString(saml2Request.convert(lort)).getBytes("UTF-8"); String samlRequest = RedirectBindingUtil.deflateBase64Encode(responseBytes); Session session = request.getSessionInternal(); session.setNote(SAML_REQUEST_KEY, samlRequest); } catch (Exception e) { throw new RuntimeException("Could not perform IdP Initiated Single Logout.", e); } }
/** * <p>This method populate the request and session with a logout requests to start a global logout from the IdP.</p> * * @param request * @param userPrincipal */ private void prepareLocalGlobalLogoutRequest(Request request, Principal userPrincipal) { try { SAML2Request saml2Request = new SAML2Request(); LogoutRequestType lort = saml2Request.createLogoutRequest(getIdentityURL()); NameIDType nameID = new NameIDType(); nameID.setValue(userPrincipal.getName()); nameID.setFormat(URI.create(JBossSAMLURIConstants.NAMEID_FORMAT_PERSISTENT.get())); lort.setNameID(nameID); lort.setDestination(URI.create(getIdentityURL())); byte[] responseBytes = DocumentUtil.getDocumentAsString(saml2Request.convert(lort)).getBytes("UTF-8"); String samlRequest = RedirectBindingUtil.deflateBase64Encode(responseBytes); Session session = request.getSessionInternal(); session.setNote(SAML_REQUEST_KEY, samlRequest); } catch (Exception e) { throw new RuntimeException("Could not perform IdP Initiated Single Logout.", e); } }
public Principal login(String username, String password, HttpServletRequest servletRequest) { Realm realm = container.getRealm(); if (realm == null) return null; Principal principal = realm.authenticate(username, password); if (principal == null) return null; if (servletRequestMatches(servletRequest)) { request.setAuthType(AUTH_TYPE); request.setUserPrincipal(principal); Session session = getSession(request, true); // Cache the authentication information in our session. if (session != null) { session.setAuthType(AUTH_TYPE); session.setPrincipal(principal); if (username != null) session.setNote(Constants.SESS_USERNAME_NOTE, username); else session.removeNote(Constants.SESS_USERNAME_NOTE); if (password != null) session.setNote(Constants.SESS_PASSWORD_NOTE, password); else session.removeNote(Constants.SESS_PASSWORD_NOTE); } } return principal; }
public Principal login(Object credentials, String charset) throws SecurityServiceException { String[] decoded = decodeBase64Credentials(credentials, charset); HttpGraniteContext context = (HttpGraniteContext)GraniteContext.getCurrentInstance(); HttpServletRequest httpRequest = context.getRequest(); Realm realm = getRealm(httpRequest); Principal principal = realm.authenticate(decoded[0], decoded[1]); if (principal == null) throw SecurityServiceException.newInvalidCredentialsException("Wrong username or password"); Request request = getRequest(httpRequest); request.setAuthType(AUTH_TYPE); request.setUserPrincipal(principal); Session session = request.getSessionInternal(true); session.setAuthType(AUTH_TYPE); session.setPrincipal(principal); session.setNote(Constants.SESS_USERNAME_NOTE, decoded[0]); session.setNote(Constants.SESS_PASSWORD_NOTE, decoded[1]); endLogin(credentials, charset); return principal; }
public Principal login(String username, String password, HttpServletRequest servletRequest) { Realm realm = valve.getContainer().getRealm(); if (realm == null) return null; Principal principal = realm.authenticate(username, password); if (principal == null) return null; if (servletRequestMatches(servletRequest)) { request.setAuthType(AUTH_TYPE); request.setUserPrincipal(principal); Session session = getSession(request, true); // Cache the authentication information in our session. if (session != null) { session.setAuthType(AUTH_TYPE); session.setPrincipal(principal); if (username != null) session.setNote(Constants.SESS_USERNAME_NOTE, username); else session.removeNote(Constants.SESS_USERNAME_NOTE); if (password != null) session.setNote(Constants.SESS_PASSWORD_NOTE, password); else session.removeNote(Constants.SESS_PASSWORD_NOTE); } } return principal; }
public Principal login(Object credentials, String charset) throws SecurityServiceException { String[] decoded = decodeBase64Credentials(credentials, charset); HttpGraniteContext context = (HttpGraniteContext)GraniteContext.getCurrentInstance(); HttpServletRequest httpRequest = context.getRequest(); CoyoteRequest request = getRequest(httpRequest); Realm realm = request.getContext().getRealm(); Principal principal = realm.authenticate(decoded[0], decoded[1]); if (principal == null) throw SecurityServiceException.newInvalidCredentialsException("Wrong username or password"); request.setAuthType(AUTH_TYPE); request.setUserPrincipal(principal); Session session = request.getSessionInternal(); session.setAuthType(AUTH_TYPE); session.setPrincipal(principal); session.setNote(Constants.SESS_USERNAME_NOTE, decoded[0]); session.setNote(Constants.SESS_PASSWORD_NOTE, decoded[1]); endLogin(credentials, charset); return principal; }