📄 mathservice.java
字号:
/* * This file is licensed under the terms of the Globus Toolkit Public License * v3, found at http://www.globus.org/toolkit/legal/4.0/license-v3.html. * * This notice must appear in redistributions of this file, with or without * modification. */package org.globus.examples.services.security.first.impl;import java.rmi.RemoteException;import javax.security.auth.Subject;import org.apache.commons.logging.Log;import org.apache.commons.logging.LogFactory;import org.globus.examples.stubs.MathService_instance_4op.AddResponse;import org.globus.examples.stubs.MathService_instance_4op.DivideResponse;import org.globus.examples.stubs.MathService_instance_4op.MultiplyResponse;import org.globus.examples.stubs.MathService_instance_4op.SubtractResponse;import org.globus.gsi.jaas.JaasSubject;import org.globus.wsrf.NoSuchResourceException;import org.globus.wsrf.ResourceContext;import org.globus.wsrf.ResourceContextException;import org.globus.wsrf.security.SecurityManager;public class MathService { static Log logger = LogFactory.getLog(MathService.class); /* * Private method that gets a reference to the resource specified in the * endpoint reference. */ private MathResource getResource() throws RemoteException { Object resource = null; try { resource = ResourceContext.getResourceContext().getResource(); } catch (NoSuchResourceException e) { throw new RemoteException("Specified resource does not exist", e); } catch (ResourceContextException e) { throw new RemoteException("Error during resource lookup", e); } catch (Exception e) { throw new RemoteException("", e); } MathResource mathResource = (MathResource) resource; return mathResource; } /* Implementation of add, subtract, and getValue operations */ public AddResponse add(int a) throws RemoteException { logSecurityInfo("add"); MathResource mathResource = getResource(); mathResource.setValue(mathResource.getValue() + a); mathResource.setLastOp("ADDITION"); return new AddResponse(); } public SubtractResponse subtract(int a) throws RemoteException { logSecurityInfo("subtract"); MathResource mathResource = getResource(); mathResource.setValue(mathResource.getValue() - a); mathResource.setLastOp("SUBTRACTION"); return new SubtractResponse(); } public MultiplyResponse multiply(int a) throws RemoteException { logSecurityInfo("multiply"); MathResource mathResource = getResource(); mathResource.setValue(mathResource.getValue() * a); mathResource.setLastOp("MULTIPLICATION"); return new MultiplyResponse(); } public DivideResponse divide(int a) throws RemoteException { logSecurityInfo("divide"); MathResource mathResource = getResource(); mathResource.setValue(mathResource.getValue() / a); mathResource.setLastOp("DIVISION"); return new DivideResponse(); } private void logSecurityInfo(String methodName) { Subject subject; logger.info("SECURITY INFO FOR METHOD '" + methodName + "'"); // Print out the caller String identity = SecurityManager.getManager().getCaller(); logger.info("The caller is:" + identity); // Print out the invocation subject subject = JaasSubject.getCurrentSubject(); logger.info("INVOCATION SUBJECT"); logger.info(subject == null ? "NULL" : subject.toString()); try { // Print out service subject logger.info("SERVICE SUBJECT"); subject = SecurityManager.getManager().getServiceSubject(); logger.info(subject == null ? "NULL" : subject.toString()); } catch (Exception e) { logger.warn("Unable to obtain service subject"); } try { // Print out system subject logger.info("SYSTEM SUBJECT"); subject = SecurityManager.getManager().getSystemSubject(); logger.info(subject == null ? "NULL" : subject.toString()); } catch (Exception e) { logger.warn("Unable to obtain system subject"); } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -