use of com.sun.identity.plugin.session.SessionProvider in project OpenAM by OpenRock.
the class FSServiceUtils method getLocale.
/**
* Retrieves locale of a http request.
* @param request <code>HttpServletRequest</code> object
* @return locale of the request; or <code>null</code> if locale cannot
* be retrieved.
*/
public static String getLocale(HttpServletRequest request) {
if (request == null) {
FSUtils.debug.error("FSServiceUtil.getLocale: Request param is " + "null, returning null");
return null;
}
try {
SessionProvider sessionProvider = SessionManager.getProvider();
Object ISSSOToken = sessionProvider.getSession(request);
String[] returnStr = sessionProvider.getProperty(ISSSOToken, "Locale");
if ((returnStr != null) && (returnStr.length > 0)) {
if (FSUtils.debug.messageEnabled()) {
FSUtils.debug.message("FSServiceUtil.getLocale returning locale from token " + returnStr[0]);
}
return returnStr[0];
}
} catch (SessionException ssoe) {
FSUtils.debug.error("FSServiceUtil::getLocale():SessionException:", ssoe);
} catch (UnsupportedOperationException ex) {
FSUtils.debug.error("FSServiceUtil::getLocale():Exception:", ex);
}
Locale locale = request.getLocale();
if (locale != null) {
String returnStr = locale.toString();
if (FSUtils.debug.messageEnabled()) {
FSUtils.debug.message("FSServiceUtil.getLocale returning :locale from request:" + returnStr);
}
return returnStr;
}
if (FSUtils.debug.messageEnabled()) {
FSUtils.debug.message("FSServiceUtil.getLocale Not able to get " + "locale from request either from token or header. returning " + "null ");
}
return null;
}
use of com.sun.identity.plugin.session.SessionProvider in project OpenAM by OpenRock.
the class FSRegistrationInitiationServlet method getValidToken.
/**
* Retrieves the session from HTTPRequest object.
* @param request HTTP request object
* @return valid session from the request object;
* <code>null</code> otherwise.
*/
private Object getValidToken(HttpServletRequest request) {
FSUtils.debug.message("Entered FSRegistrationInitiationServlet::getValidToken");
try {
SessionProvider sessionProvider = SessionManager.getProvider();
Object ssoToken = sessionProvider.getSession(request);
if ((ssoToken == null) || (!sessionProvider.isValid(ssoToken))) {
FSUtils.debug.error("Session is not valid redirecting for authentication");
return null;
}
return ssoToken;
} catch (SessionException e) {
FSUtils.debug.error("SessionException caught: ", e);
return null;
}
}
use of com.sun.identity.plugin.session.SessionProvider in project OpenAM by OpenRock.
the class DefaultIDPAccountMapper method getNameID.
@Override
public NameID getNameID(Object session, String hostEntityID, String remoteEntityID, String realm, String nameIDFormat) throws SAML2Exception {
String userID;
try {
SessionProvider sessionProv = SessionManager.getProvider();
userID = sessionProv.getPrincipalName(session);
} catch (SessionException se) {
throw new SAML2Exception(SAML2Utils.bundle.getString("invalidSSOToken"));
}
String nameIDValue = null;
if (nameIDFormat.equals(SAML2Constants.NAMEID_TRANSIENT_FORMAT)) {
String sessionIndex = IDPSSOUtil.getSessionIndex(session);
if (sessionIndex != null) {
IDPSession idpSession = IDPCache.idpSessionsByIndices.get(sessionIndex);
if (idpSession != null) {
List<NameIDandSPpair> list = idpSession.getNameIDandSPpairs();
if (list != null) {
for (NameIDandSPpair pair : list) {
if (pair.getSPEntityID().equals(remoteEntityID)) {
nameIDValue = pair.getNameID().getValue();
break;
}
}
}
}
}
if (nameIDValue == null) {
nameIDValue = getNameIDValueFromUserProfile(realm, hostEntityID, userID, nameIDFormat);
if (nameIDValue == null) {
nameIDValue = SAML2Utils.createNameIdentifier();
}
}
} else {
nameIDValue = getNameIDValueFromUserProfile(realm, hostEntityID, userID, nameIDFormat);
if (nameIDValue == null) {
if (nameIDFormat.equals(SAML2Constants.PERSISTENT)) {
nameIDValue = SAML2Utils.createNameIdentifier();
} else {
throw new SAML2Exception(bundle.getString("unableToGenerateNameIDValue"));
}
}
}
NameID nameID = AssertionFactory.getInstance().createNameID();
nameID.setValue(nameIDValue);
nameID.setFormat(nameIDFormat);
nameID.setNameQualifier(hostEntityID);
nameID.setSPNameQualifier(remoteEntityID);
nameID.setSPProvidedID(null);
return nameID;
}
use of com.sun.identity.plugin.session.SessionProvider in project OpenAM by OpenRock.
the class LibertyManager method getUser.
/**
* Returns the user from <code>HttpServletRequest</code>.
*
* @param request HTTP servlet request.
* @return the user from <code>HttpServletRequest</code>.
*/
public static String getUser(HttpServletRequest request) {
Object ssoToken = null;
try {
SessionProvider sessionProvider = SessionManager.getProvider();
ssoToken = sessionProvider.getSession(request);
if (ssoToken != null && sessionProvider.isValid(ssoToken)) {
debug.message("LibertyManager: getUser: token is valid");
return sessionProvider.getPrincipalName(ssoToken);
}
return null;
} catch (SessionException ssoe) {
debug.error("LibertyManager: getUser: SessionException: ", ssoe);
return null;
}
}
use of com.sun.identity.plugin.session.SessionProvider in project OpenAM by OpenRock.
the class LibertyManagerClient method getDiscoveryResourceOffering.
/**
* Returns the discovery service bootstrap resource offering.
* @param token Single Sign On Token.
* @param hostProviderID Hosted <code>ProviderID</code>.
* @return <code>ResourceOffering</code> Discovery Service bootstrap
* resource offering.
* @exception FSException if any failure.
*/
public ResourceOffering getDiscoveryResourceOffering(Object token, String hostProviderID) throws FSException {
try {
SessionProvider sessionProvider = SessionManager.getProvider();
String tokenID = sessionProvider.getSessionID(token);
String cacheKey = tokenID + DISCO_RO;
ResourceOffering ro = (ResourceOffering) bootStrapCache.get(cacheKey);
if (ro != null) {
return ro;
}
String[] objs = { tokenID, hostProviderID };
String resourceOffering = (String) client.send("getDiscoveryResourceOffering", objs, null, null);
if ((resourceOffering == null) || (resourceOffering.length() == 0)) {
if (FSUtils.debug.messageEnabled()) {
FSUtils.debug.message("LibertyManagerClient.getDiscovery" + "ResourceOffering: ResouceOffering is null or empty");
}
return null;
}
Document doc = XMLUtils.toDOMDocument(resourceOffering, FSUtils.debug);
ro = new ResourceOffering(doc.getDocumentElement());
sessionProvider.addListener(token, new LibertyClientSSOTokenListener());
bootStrapCache.put(cacheKey, ro);
return ro;
} catch (SessionException se) {
if (FSUtils.debug.messageEnabled()) {
FSUtils.debug.message("LibertyManagerClient.getDiscovery" + "ResourceOffering: InvalidSessionToken", se);
}
throw new FSException(FSUtils.bundle.getString("invalidSSOToken"));
} catch (DiscoveryException de) {
FSUtils.debug.error("LibertyManagerClient.getDiscovery" + "ResourceOffering: Invalid ResourceOffering", de);
throw new FSException(FSUtils.bundle.getString("invalidResourceOffering"));
} catch (Exception ex) {
FSUtils.debug.error("LibertyManagerClient.getDiscovery" + "ResourceOffering: SOAPClient Exception", ex);
throw new FSException(FSUtils.bundle.getString("soapException"));
}
}
Aggregations