本文整理汇总了Java中org.wso2.carbon.identity.sso.agent.SSOAgentConstants类的典型用法代码示例。如果您正苦于以下问题:Java SSOAgentConstants类的具体用法?Java SSOAgentConstants怎么用?Java SSOAgentConstants使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
SSOAgentConstants类属于org.wso2.carbon.identity.sso.agent包,在下文中一共展示了SSOAgentConstants类的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: processResponse
import org.wso2.carbon.identity.sso.agent.SSOAgentConstants; //导入依赖的package包/类
public void processResponse(HttpServletRequest request, HttpServletResponse response)
throws SSOAgentException {
String saml2SSOResponse = request.getParameter(SSOAgentConstants.SAML2SSO.HTTP_POST_PARAM_SAML2_RESP);
if (saml2SSOResponse != null) {
String decodedResponse = new String(Base64.decode(saml2SSOResponse), Charset.forName("UTF-8"));
XMLObject samlObject = SSOAgentUtils.unmarshall(decodedResponse);
if (samlObject instanceof LogoutResponse) {
//This is a SAML response for a single logout request from the SP
doSLO(request);
} else {
processSSOResponse(request);
}
String relayState = request.getParameter(RelayState.DEFAULT_ELEMENT_LOCAL_NAME);
if (relayState != null && !relayState.isEmpty() && !"null".equalsIgnoreCase(relayState)) { //additional
// checks for incompetent IdPs
ssoAgentConfig.getSAML2().setRelayState(relayState);
}
} else {
throw new SSOAgentException("Invalid SAML2 Response. SAML2 Response can not be null.");
}
}
示例2: invalidateSession
import org.wso2.carbon.identity.sso.agent.SSOAgentConstants; //导入依赖的package包/类
public static void invalidateSession(HttpSession session) {
LoggedInSessionBean sessionBean = (LoggedInSessionBean) session.getAttribute(
SSOAgentConstants.SESSION_BEAN_NAME);
if (sessionBean != null && sessionBean.getSAML2SSO() != null) {
String sessionIndex = sessionBean.getSAML2SSO().getSessionIndex();
if (sessionIndex != null) {
Set<HttpSession> sessions = ssoSessionsMap.get(sessionIndex);
if (sessions != null) {
sessions.remove(session);
}
}
}
}
示例3: invalidateAllSessions
import org.wso2.carbon.identity.sso.agent.SSOAgentConstants; //导入依赖的package包/类
public static Set<HttpSession> invalidateAllSessions(HttpSession session) {
LoggedInSessionBean sessionBean = (LoggedInSessionBean) session.getAttribute(
SSOAgentConstants.SESSION_BEAN_NAME);
Set<HttpSession> sessions = new HashSet<HttpSession>();
if (sessionBean != null && sessionBean.getSAML2SSO() != null) {
String sessionIndex = sessionBean.getSAML2SSO().getSessionIndex();
if (sessionIndex != null) {
sessions = ssoSessionsMap.remove(sessionIndex);
}
}
if (sessions == null) {
sessions = new HashSet<HttpSession>();
}
return sessions;
}
示例4: addAuthenticatedSession
import org.wso2.carbon.identity.sso.agent.SSOAgentConstants; //导入依赖的package包/类
public static void addAuthenticatedSession(HttpSession session) {
String sessionIndex = ((LoggedInSessionBean) session.getAttribute(
SSOAgentConstants.SESSION_BEAN_NAME)).getSAML2SSO().getSessionIndex();
if (ssoSessionsMap.get(sessionIndex) != null) {
ssoSessionsMap.get(sessionIndex).add(session);
} else {
Set<HttpSession> sessions = new HashSet<HttpSession>();
sessions.add(session);
ssoSessionsMap.put(sessionIndex, sessions);
}
}
示例5: sessionCreated
import org.wso2.carbon.identity.sso.agent.SSOAgentConstants; //导入依赖的package包/类
@Override
public void sessionCreated(HttpSessionEvent httpSessionEvent) {
if (httpSessionEvent.getSession().getAttribute(SSOAgentConstants.SESSION_BEAN_NAME) == null) {
// This log is not accurate, since we depend on request.getSession() to create new session
// if there is no existing session. After that only we set the Session-Bean.
// Thus in this listener the session always does not contain a Session-Bean Attribute.
LOGGER.log(Level.WARNING, "HTTP Session created without LoggedInSessionBean");
}
}
示例6: getAccessToken
import org.wso2.carbon.identity.sso.agent.SSOAgentConstants; //导入依赖的package包/类
public void getAccessToken(HttpServletRequest request, HttpServletResponse response)
throws SSOAgentException {
String samlAssertionString = ((LoggedInSessionBean) request.getSession(false).
getAttribute(SSOAgentConstants.SESSION_BEAN_NAME)).getSAML2SSO().
getAssertionString();
String clientLogin = ssoAgentConfig.getOAuth2().getClientId() + ":" +
ssoAgentConfig.getOAuth2().getClientSecret();
String queryParam = "grant_type=" + SSOAgentConstants.OAuth2.SAML2_BEARER_GRANT_TYPE + "&assertion=" +
URLEncoder.encode(Base64.encodeBytes(
samlAssertionString.getBytes(Charset.forName("UTF-8"))).replaceAll("\n", ""));
String additionalQueryParam = ssoAgentConfig.getRequestQueryParameters();
if (additionalQueryParam != null) {
queryParam = queryParam + additionalQueryParam;
}
String accessTokenResponse = executePost(queryParam,
Base64.encodeBytes(clientLogin.getBytes(Charset.forName("UTF-8")))
.replace("\n", ""));
Gson gson = new Gson();
LoggedInSessionBean.AccessTokenResponseBean accessTokenResp =
gson.fromJson(accessTokenResponse, LoggedInSessionBean.AccessTokenResponseBean.class);
((LoggedInSessionBean) request.getSession(false).getAttribute(
SSOAgentConstants.SESSION_BEAN_NAME)).getSAML2SSO()
.setAccessTokenResponseBean(accessTokenResp);
}
示例7: invalidateSession
import org.wso2.carbon.identity.sso.agent.SSOAgentConstants; //导入依赖的package包/类
public static void invalidateSession(HttpSession session) {
LoggedInSessionBean sessionBean = (LoggedInSessionBean) session.getAttribute(
SSOAgentConstants.SESSION_BEAN_NAME);
if (sessionBean != null && sessionBean.getSAML2SSO() != null) {
String sessionIndex = sessionBean.getSAML2SSO().getSessionIndex();
if (sessionIndex != null) {
Set<HttpSession> sessions = ssoSessionsMap.get(sessionIndex);
sessions.remove(session);
}
}
}
示例8: sessionDestroyed
import org.wso2.carbon.identity.sso.agent.SSOAgentConstants; //导入依赖的package包/类
@Override
public void sessionDestroyed(HttpSessionEvent httpSessionEvent) {
// No need to invalidate session here, as it is going to be invalidated soon
SSOAgentSessionManager.invalidateSession(httpSessionEvent.getSession());
httpSessionEvent.getSession().removeAttribute(SSOAgentConstants.SESSION_BEAN_NAME);
}
示例9: buildRedirectRequest
import org.wso2.carbon.identity.sso.agent.SSOAgentConstants; //导入依赖的package包/类
/**
* Returns the redirection URL with the appended SAML2
* Request message
*
* @param request SAML 2 request
* @return redirectionUrl
*/
public String buildRedirectRequest(HttpServletRequest request, boolean isLogout) throws SSOAgentException {
RequestAbstractType requestMessage = null;
if (!isLogout) {
requestMessage = buildAuthnRequest(request);
} else {
HttpSession httpSession = request.getSession(false);
if (httpSession == null) {
throw new InvalidSessionException("Session is expired or user already logged out.");
}
LoggedInSessionBean sessionBean = (LoggedInSessionBean) httpSession.getAttribute(SSOAgentConstants
.SESSION_BEAN_NAME);
if (sessionBean != null) {
requestMessage = buildLogoutRequest(sessionBean.getSAML2SSO().getSubjectId(),
sessionBean.getSAML2SSO().getSessionIndex());
} else {
throw new SSOAgentException("SLO Request can not be built. SSO Session is NULL");
}
}
String idpUrl = null;
String encodedRequestMessage = encodeRequestMessage(
requestMessage, SAMLConstants.SAML2_REDIRECT_BINDING_URI);
StringBuilder httpQueryString = new StringBuilder(
SSOAgentConstants.SAML2SSO.HTTP_POST_PARAM_SAML2_AUTH_REQ +
"=" + encodedRequestMessage);
String relayState = request.getParameter(RelayState.DEFAULT_ELEMENT_LOCAL_NAME);
if (StringUtils.isNotEmpty(relayState)) {
relayState = ssoAgentConfig.getSAML2().getRelayState();
}
if (relayState != null) {
try {
httpQueryString.append("&" + RelayState.DEFAULT_ELEMENT_LOCAL_NAME + "=" +
URLEncoder.encode(relayState, "UTF-8").trim());
} catch (UnsupportedEncodingException e) {
throw new SSOAgentException("Error occurred while URLEncoding " +
RelayState.DEFAULT_ELEMENT_LOCAL_NAME, e);
}
}
if (ssoAgentConfig.getSAML2().isRequestSigned()) {
SSOAgentUtils.addDeflateSignatureToHTTPQueryString(httpQueryString,
new X509CredentialImpl(ssoAgentConfig.getSAML2().getSSOAgentX509Credential()));
}
if (ssoAgentConfig.getQueryParams() != null && !ssoAgentConfig.getQueryParams().isEmpty()) {
StringBuilder builder = new StringBuilder();
for (Map.Entry<String, String[]> entry : ssoAgentConfig.getQueryParams().entrySet()) {
if (entry.getKey() != null && entry.getValue() != null && entry.getValue().length > 0) {
for (String param : entry.getValue()) {
builder.append("&").append(entry.getKey()).append("=").append(param);
}
}
}
httpQueryString.append(builder);
}
if (ssoAgentConfig.getSAML2().getIdPURL().indexOf("?") > -1) {
idpUrl = ssoAgentConfig.getSAML2().getIdPURL().concat("&").concat(httpQueryString.toString());
} else {
idpUrl = ssoAgentConfig.getSAML2().getIdPURL().concat("?").concat(httpQueryString.toString());
}
return idpUrl;
}
示例10: doFilter
import org.wso2.carbon.identity.sso.agent.SSOAgentConstants; //导入依赖的package包/类
@Override
public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse,
FilterChain filterChain) throws IOException, ServletException {
String httpBinding = servletRequest.getParameter(
SSOAgentConstants.SSOAgentConfig.SAML2.HTTP_BINDING);
if (httpBinding != null && !httpBinding.isEmpty()) {
if ("HTTP-POST".equals(httpBinding)) {
httpBinding = "urn:oasis:names:tc:SAML:2.0:bindings:HTTP-POST";
} else if ("HTTP-Redirect".equals(httpBinding)) {
httpBinding = "urn:oasis:names:tc:SAML:2.0:bindings:HTTP-Redirect";
} else {
LOGGER.log(Level.INFO, "Unknown SAML2 HTTP Binding. Defaulting to HTTP-POST");
httpBinding = "urn:oasis:names:tc:SAML:2.0:bindings:HTTP-POST";
}
} else {
LOGGER.log(Level.INFO, "SAML2 HTTP Binding not found in request. Defaulting to HTTP-POST");
httpBinding = "urn:oasis:names:tc:SAML:2.0:bindings:HTTP-POST";
}
SSOAgentConfig config = (SSOAgentConfig) filterConfig.getServletContext().
getAttribute(SSOAgentConstants.CONFIG_BEAN_NAME);
config.getSAML2().setHttpBinding(httpBinding);
config.getOpenId().setClaimedId(servletRequest.getParameter(
SSOAgentConstants.SSOAgentConfig.OpenID.CLAIMED_ID));
config.getOpenId().setMode(servletRequest.getParameter(
SSOAgentConstants.OpenID.OPENID_MODE));
if (StringUtils.isNotEmpty(servletRequest.getParameter(USERNAME)) &&
StringUtils.isNotEmpty(servletRequest.getParameter(PASSWORD))) {
String authorization = servletRequest.getParameter(USERNAME) + ":" + servletRequest.getParameter(PASSWORD);
// Base64 encoded username:password value
authorization = Base64.encode(authorization.getBytes(CHARACTER_ENCODING));
String htmlPayload = "<html>\n" +
"<body>\n" +
"<p>You are now redirected back to " + properties.getProperty("SAML2.IdPURL") + " \n" +
"If the redirection fails, please click the post button.</p>\n" +
"<form method='post' action='" + properties.getProperty("SAML2.IdPURL") + "'>\n" +
"<input type='hidden' name='sectoken' value='" + authorization + "'/>\n" +
"<p>\n" +
"<!--$saml_params-->\n" +
"<button type='submit'>POST</button>\n" +
"</p>\n" +
"</form>\n" +
"<script type='text/javascript'>\n" +
"document.forms[0].submit();\n" +
"</script>\n" +
"</body>\n" +
"</html>";
config.getSAML2().setPostBindingRequestHTMLPayload(htmlPayload);
} else {
// Reset previously sent HTML payload
config.getSAML2().setPostBindingRequestHTMLPayload(null);
}
servletRequest.setAttribute(SSOAgentConstants.CONFIG_BEAN_NAME, config);
super.doFilter(servletRequest, servletResponse, filterChain);
}
示例11: sessionCreated
import org.wso2.carbon.identity.sso.agent.SSOAgentConstants; //导入依赖的package包/类
@Override
public void sessionCreated(HttpSessionEvent httpSessionEvent) {
if (httpSessionEvent.getSession().getAttribute(SSOAgentConstants.SESSION_BEAN_NAME) == null) {
LOGGER.log(Level.WARNING, "HTTP Session created without LoggedInSessionBean");
}
}
示例12: buildRedirectRequest
import org.wso2.carbon.identity.sso.agent.SSOAgentConstants; //导入依赖的package包/类
/**
* Returns the redirection URL with the appended SAML2
* Request message
*
* @param request SAML 2 request
* @return redirectionUrl
*/
public String buildRedirectRequest(HttpServletRequest request, boolean isLogout) throws SSOAgentException {
RequestAbstractType requestMessage = null;
if (!isLogout) {
requestMessage = buildAuthnRequest(request);
} else {
LoggedInSessionBean sessionBean = (LoggedInSessionBean) request.getSession(false).
getAttribute(SSOAgentConstants.SESSION_BEAN_NAME);
if (sessionBean != null) {
requestMessage = buildLogoutRequest(sessionBean.getSAML2SSO().getSubjectId(),
sessionBean.getSAML2SSO().getSessionIndex());
} else {
throw new SSOAgentException("SLO Request can not be built. SSO Session is NULL");
}
}
String idpUrl = null;
String encodedRequestMessage = encodeRequestMessage(
requestMessage, SAMLConstants.SAML2_REDIRECT_BINDING_URI);
StringBuilder httpQueryString = new StringBuilder(
SSOAgentConstants.SAML2SSO.HTTP_POST_PARAM_SAML2_AUTH_REQ +
"=" + encodedRequestMessage);
String relayState = ssoAgentConfig.getSAML2().getRelayState();
if (relayState != null) {
try {
httpQueryString.append("&" + RelayState.DEFAULT_ELEMENT_LOCAL_NAME + "=" +
URLEncoder.encode(relayState, "UTF-8").trim());
} catch (UnsupportedEncodingException e) {
throw new SSOAgentException("Error occurred while URLEncoding " +
RelayState.DEFAULT_ELEMENT_LOCAL_NAME, e);
}
}
if (ssoAgentConfig.getSAML2().isRequestSigned()) {
SSOAgentUtils.addDeflateSignatureToHTTPQueryString(httpQueryString,
new X509CredentialImpl(ssoAgentConfig.getSAML2().getSSOAgentX509Credential()));
}
if (ssoAgentConfig.getQueryParams() != null && !ssoAgentConfig.getQueryParams().isEmpty()) {
StringBuilder builder = new StringBuilder();
for (Map.Entry<String, String[]> entry : ssoAgentConfig.getQueryParams().entrySet()) {
if (entry.getKey() != null && entry.getValue() != null && entry.getValue().length > 0) {
for (String param : entry.getValue()) {
builder.append("&").append(entry.getKey()).append("=").append(param);
}
}
}
httpQueryString.append(builder);
}
if (ssoAgentConfig.getSAML2().getIdPURL().indexOf("?") > -1) {
idpUrl = ssoAgentConfig.getSAML2().getIdPURL().concat("&").concat(httpQueryString.toString());
} else {
idpUrl = ssoAgentConfig.getSAML2().getIdPURL().concat("?").concat(httpQueryString.toString());
}
return idpUrl;
}