📄 licenseserver.java
字号:
shopID = si.getShopId();
}
if (casFlag == null || "".equals(casFlag.trim())) {
casFlag = si.getCasFlag();
}
}
// The below has been remarked since those values are in the MMIMessage itself.
//verifyLicenseRequestInput(userID, contentID, shopID);
if (action.equals(Const.GET_LICENSE)) {
handleLicenseRequest(userID, contentID, shopID, casFlag, request, response);
}
if (action.equals(Const.VERIFY_SIGNATURE)) {
// A user's status is never set to authenticated in the session object.
// Probably when a VERIFY SIGNATURE message is received
// the status should be set to authenticated.
if (verifyVoucher(request)) {
if(casFlag == null) {
sendMMIMessageResponse(userID, contentID, shopID, request, response);
} else if(casFlag.equals("1")){
sendLicense(userID, contentID, shopID, response);
//sendLicense...
} else if(casFlag.equals("0")) {
// nothing
} else {
// error
}
} else {
throw new LicenseServerException(
LicenseServerException.EC_NO_ERROR_CODE,
"Data send by Opera has been tampered"
);
}
}
}
m_log.finer("Leaving Function...");
}
/**
* This method retrieves the license from the database
*
* @param userId
* @param contentId
* @throws LicenseServerException
* @return License
*/
private License getLicense(String userId, String contentId) throws LicenseServerException{
return getLicenseFromDatabase(userId, contentId, "operaShop0");
}
/**
* This method generates a response for an MMI request
*
* @param mmiMessageRequest
* @param com.sun.sjc.idtv.vod.shared.data.RightsInfo[]
* @return MMIMessage
*/
private MMIMessage generateRightsResponse(MMIMessage mmiMessageRequest, com.sun.sjc.idtv.vod.shared.data.RightsInfo[] ri) {
m_log.finer("Entering generateRightsResponse");
// check user
// check if the user has rights to content
// check if the rights has not expired
// check if the user has rights to apply verb on content
// check if the user has remaining rights to apply verb on content
// check if the user has rights to apply verb on content with the verb specific arguments
MMIMessage mmiMessageResponse = new MMIMessage();
mmiMessageResponse.setMMIVersion("1.0");
MMIResponse mmiResponse = new MMIResponse();
if(mmiMessageRequest == null) {
m_log.severe("ERROR: MMIMESSAGEREQUEST IS EMPTY");
}
MMIRequest mmiRequest = (MMIRequest)mmiMessageRequest.getMMIDataObject();
MMIRightsRequestElement[] mmiRightsRequestElement = mmiRequest.getRightsSegment().getMMIRightsRequestElement();
Status[] status = new Status[1];
if(ri == null) {
status[0] = new Status("RightsElementError");
} else {
status[0] = new Status("RequestOK");
}
mmiResponse.setStatus(status);
mmiResponse.setResponseId(new ResponseId("1003"));
// m_log.finer("SignatureSegment"+mmiRequest.getSignatureSegment().print("/n"));
Signature signature = new Signature();
SigAlg sigAlg = new SigAlg();
SignatureSegment signatureSegment = new SignatureSegment(sigAlg,signature);
mmiResponse.setSignatureSegment(signatureSegment);
RequestHash requestHash = new RequestHash("jAxX0LfgwutvEdJb748IU4L8obXZPXfqTZ"); //
HashAlg hashAlg = new HashAlg("http://www.w3.org/2001/10/xml-exc-c14n#");
RequestHashSegment requestHashSegment = new RequestHashSegment();
requestHashSegment.setHashAlg(hashAlg);
requestHashSegment.setRequestHash(requestHash);
mmiResponse.setRequestHashSegment(requestHashSegment);
MMIRightsResponseElement[] mmiRightsResponseElement = new MMIRightsResponseElement[mmiRightsRequestElement.length];
boolean found = false;
boolean denied = false; boolean granted = false;
boolean error = false;
int riCountCheck = 0, CountCheck=0;
for(int i=0; i<mmiRightsRequestElement.length; i++) {
int grantCount = 0;
int verbCount = 0;
String strReqElemId = mmiRightsRequestElement[i].getReqElemId().getReqElemId();
mmiRightsResponseElement[i] = new MMIRightsResponseElement();
// assign request element id to identify the current request element
mmiRightsResponseElement[i].setReqElemId(new ReqElemId(strReqElemId));
boolean userFound = false;
if(ri != null) {
// FIX - THERE SEEMS TO BE SOME REUSABLE LOGIC BETWEEN HERE
// and /DReaM/DReaMBackendSvcs/vod-server-cvs-ejb/src/java/com/sun/sjc/idtv/vod/server/comm/ConductorControllerServlet.java
//
for(int j=0; j<ri.length; j++) {
// interating through rightsInfo
m_log.finer("J="+j);
ContentId[] contentId = mmiRightsRequestElement[i].getContentId();
if(contentId == null) {
} else {
for(int k=0;k<contentId.length;k++) {
m_log.finer("K="+k);
// check contentId against RightsInfo
if(ri[j].movieName.equals(contentId[k].getContentId())) {
org.omc.dream.mmi.common.VerbElement[] verbElements = mmiRightsRequestElement[i].getVerbElement();
int intNumVerbElements = verbElements.length;
try {
for(int l=0;l<intNumVerbElements;l++) {
m_log.finer("L="+l);
com.sun.sjc.idtv.vod.shared.data.VerbElement[] riVerbElements = ri[j].verbElements;
if(riVerbElements != null) {
m_log.finer("LENGTH="+riVerbElements.length);
for(int n=0; n<riVerbElements.length; n++) {
m_log.finer("N="+n);
if(verbElements[i].getVerb().getVerb().equalsIgnoreCase(riVerbElements[n].verbName)) {
m_log.finer("riVerbElements="+riVerbElements[n].verbName);
verbCount++;
if(riVerbElements[n].verbArgName.equalsIgnoreCase("Count")) {
riCountCheck++;
if(verbElements[l].getCount()!= null) {
if(Integer.parseInt(verbElements[l].getCount().getCount()) <= Integer.parseInt(riVerbElements[n].verbArgValue)) {
granted = true; n=riVerbElements.length; grantCount++;
m_log.finer("GRANTED IN LOOP");
} else {
denied = true; n=riVerbElements.length;
m_log.finer("DENIED IN LOOP");
}
}
}
}
}
}
if (riCountCheck == 0 && verbCount > 0) {
granted=true;grantCount++;
}
// if(verbCount < riVerbElements.length) {
// granted=false;grantCount=0;
// }
riCountCheck=0;
verbCount=0;
}
} catch(Exception e) {
e.printStackTrace();
}
}
}
}
}
} else {
error = true;
}
if(error) {
mmiRightsResponseElement[i].setNotification(new Notification("error"));
m_log.finer("ERROR");
error = false;
} else if(grantCount==mmiRightsRequestElement[i].getVerbElement().length) {
mmiRightsResponseElement[i].setNotification(new Notification("granted"));
m_log.finer("GRANTED");
try {
License lic = getLicense(ri[0].userID, mmiRightsRequestElement[i].getContentId()[0].getContentId());
if (lic != null) {
InputStream is = lic.getLicense();
byte[] bytes = new byte[188]; // MAGIC NUMBER FIX THIS
try {
while(is.read(bytes) != -1) {
}
BASE64Encoder b = new BASE64Encoder();
String encodedKeys=b.encode(bytes);
encodedKeys=URLEncoder.encode(encodedKeys, "UTF-8");
m_log.finer("END OF LINE EXIST? :"+encodedKeys.indexOf('\n'));
m_log.finer("END OF LINE EXIST? :"+encodedKeys.indexOf('\r'));
mmiRightsResponseElement[i].setKeys(new Keys(encodedKeys));
} catch(Exception ioe) {
ioe.printStackTrace();
}
}
m_log.finer("Leaving Function...");
} catch(LicenseServerException lse) {
lse.printStackTrace();
}
} else {
mmiRightsResponseElement[i].setNotification(new Notification("denied"));
m_log.finer("DENIED");
}
grantCount=0;
//Fix for multiple keys
}
mmiResponse.setMMIRightsResponseElement(mmiRightsResponseElement);
mmiMessageResponse.setMMIDataObject(mmiResponse);
m_log.info("MMIResponse: "+mmiMessageResponse.print("\n"));
return mmiMessageResponse;
}
/**
* If a secure voucherGenerator is implemented, then this method
* is used to decrypt and verify the voucher.
*
* @param req
* @return true if data send by OPERA server has not been tampered.
* false otherwise
*/
boolean verifyVoucher(HttpServletRequest req) {
return true;
}
boolean verifyVoucher(String[] vouchers) {
return true;
}
/**
* Process the request for a license.
*
* @param userID
* @param contentID
* @param shopID
* @param request
* @param response
* @throws ServletException
* @throws IOException
*/
private void handleLicenseRequest(String userID, String contentID, String shopID, String casFlag, HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
m_log.finer("Entering Function...");
// See if the session exists for the particular
// user and if not then create a new session
// and get it verified by the Proxy Server
//
HttpSession session = request.getSession(true);
SessionInfo si = (SessionInfo) session.getAttribute("session");
MMIMessage mmiMessage = (MMIMessage) session.getAttribute("MMIMessage");
if (si == null) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -