| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
package org.kuali.student.common.ui.server.gwt.old; |
| 17 | |
|
| 18 | |
import java.util.Map; |
| 19 | |
|
| 20 | |
import org.apache.commons.lang.StringUtils; |
| 21 | |
import org.apache.log4j.Logger; |
| 22 | |
import org.kuali.rice.kew.service.WorkflowUtility; |
| 23 | |
import org.kuali.rice.kew.webservice.SimpleDocumentActionsWebService; |
| 24 | |
import org.kuali.rice.kim.bo.types.dto.AttributeSet; |
| 25 | |
import org.kuali.rice.kim.service.IdentityManagementService; |
| 26 | |
import org.kuali.rice.kim.service.IdentityManagementService; |
| 27 | |
import org.kuali.student.common.assembly.data.AssemblyException; |
| 28 | |
import org.kuali.student.common.assembly.data.Data; |
| 29 | |
import org.kuali.student.common.assembly.data.Metadata; |
| 30 | |
import org.kuali.student.common.assembly.old.Assembler; |
| 31 | |
import org.kuali.student.common.assembly.old.data.SaveResult; |
| 32 | |
import org.kuali.student.common.rice.StudentIdentityConstants; |
| 33 | |
import org.kuali.student.common.rice.authorization.PermissionType; |
| 34 | |
import org.kuali.student.common.ui.client.service.BaseDataOrchestrationRpcService; |
| 35 | |
import org.kuali.student.common.ui.client.service.DataSaveResult; |
| 36 | |
import org.kuali.student.common.ui.client.service.exceptions.OperationFailedException; |
| 37 | |
import org.kuali.student.common.ui.shared.IdAttributes; |
| 38 | |
import org.kuali.student.common.util.security.SecurityUtils; |
| 39 | |
|
| 40 | |
import com.google.gwt.user.server.rpc.RemoteServiceServlet; |
| 41 | |
|
| 42 | |
|
| 43 | |
|
| 44 | |
|
| 45 | |
|
| 46 | |
@Deprecated |
| 47 | 0 | public abstract class AbstractBaseDataOrchestrationRpcGwtServlet extends RemoteServiceServlet implements BaseDataOrchestrationRpcService { |
| 48 | |
|
| 49 | |
|
| 50 | |
|
| 51 | |
|
| 52 | |
|
| 53 | |
|
| 54 | |
private static final long serialVersionUID = 1L; |
| 55 | |
|
| 56 | 0 | final Logger LOG = Logger.getLogger(AbstractBaseDataOrchestrationRpcGwtServlet.class); |
| 57 | |
|
| 58 | |
private Assembler<Data, Void> assembler; |
| 59 | |
|
| 60 | |
private SimpleDocumentActionsWebService simpleDocService; |
| 61 | |
private WorkflowUtility workflowUtilityService; |
| 62 | |
private IdentityManagementService permissionService; |
| 63 | |
private IdentityManagementService identityService; |
| 64 | |
|
| 65 | |
@Override |
| 66 | |
public Data getData(String dataId) { |
| 67 | |
try { |
| 68 | 0 | return assembler.get(dataId); |
| 69 | 0 | } catch (AssemblyException e) { |
| 70 | 0 | LOG.error("Error getting Data.",e); |
| 71 | |
} |
| 72 | 0 | return null; |
| 73 | |
} |
| 74 | |
|
| 75 | |
@Override |
| 76 | |
public Metadata getMetadata(String id, Map<String,String> idAttributes) { |
| 77 | |
|
| 78 | |
try { |
| 79 | |
|
| 80 | 0 | String idType = ""; |
| 81 | 0 | if (idAttributes != null){ |
| 82 | 0 | idType = idAttributes.get(IdAttributes.ID_TYPE); |
| 83 | |
} |
| 84 | 0 | return assembler.getMetadata(idType, id, getDefaultMetaDataType(), getDefaultMetaDataState()); |
| 85 | 0 | } catch (AssemblyException e) { |
| 86 | 0 | LOG.error("Error getting Metadata.",e); |
| 87 | |
} |
| 88 | 0 | return null; |
| 89 | |
} |
| 90 | |
|
| 91 | |
@Override |
| 92 | |
public DataSaveResult saveData(Data data) throws OperationFailedException { |
| 93 | |
try { |
| 94 | 0 | SaveResult<Data> saveResult = assembler.save(data); |
| 95 | 0 | if (saveResult != null) { |
| 96 | 0 | return new DataSaveResult(saveResult.getValidationResults(), saveResult.getValue()); |
| 97 | |
} |
| 98 | 0 | } catch (Exception e) { |
| 99 | 0 | LOG.error("Unable to save", e); |
| 100 | 0 | throw new OperationFailedException("Unable to save"); |
| 101 | 0 | } |
| 102 | 0 | return null; |
| 103 | |
} |
| 104 | |
|
| 105 | |
|
| 106 | |
protected String getCurrentUser() { |
| 107 | 0 | String username = SecurityUtils.getCurrentPrincipalId(); |
| 108 | |
|
| 109 | 0 | if(username==null&&this.getThreadLocalRequest().getSession().getAttribute("backdoorId")!=null){ |
| 110 | 0 | username=(String)this.getThreadLocalRequest().getSession().getAttribute("backdoorId"); |
| 111 | |
} |
| 112 | 0 | return username; |
| 113 | |
} |
| 114 | |
|
| 115 | |
protected boolean checkDocumentLevelPermissions() { |
| 116 | 0 | return false; |
| 117 | |
} |
| 118 | |
|
| 119 | |
public Boolean isAuthorized(PermissionType type, Map<String,String> attributes) { |
| 120 | 0 | String user = getCurrentUser(); |
| 121 | 0 | boolean result = false; |
| 122 | 0 | if (checkDocumentLevelPermissions()) { |
| 123 | 0 | if (type == null) { |
| 124 | 0 | return null; |
| 125 | |
} |
| 126 | 0 | String namespaceCode = type.getPermissionNamespace(); |
| 127 | 0 | String permissionTemplateName = type.getPermissionTemplateName(); |
| 128 | 0 | AttributeSet roleQuals = new AttributeSet(StudentIdentityConstants.DOCUMENT_TYPE_NAME, getDefaultWorkflowDocumentType()); |
| 129 | 0 | if (attributes != null) { |
| 130 | 0 | roleQuals.putAll(attributes); |
| 131 | |
} |
| 132 | 0 | if (StringUtils.isNotBlank(namespaceCode) && StringUtils.isNotBlank(permissionTemplateName)) { |
| 133 | 0 | LOG.info("Checking Permission '" + namespaceCode + "/" + permissionTemplateName + "' for user '" + user + "'"); |
| 134 | 0 | result = getPermissionService().isAuthorizedByTemplateName(user, namespaceCode, permissionTemplateName, null, roleQuals); |
| 135 | |
} |
| 136 | |
else { |
| 137 | 0 | LOG.info("Can not check Permission with namespace '" + namespaceCode + "' and template name '" + permissionTemplateName + "' for user '" + user + "'"); |
| 138 | 0 | return Boolean.TRUE; |
| 139 | |
} |
| 140 | 0 | } |
| 141 | |
else { |
| 142 | 0 | LOG.info("Will not check for document level permissions. Defaulting authorization to true."); |
| 143 | 0 | result = true; |
| 144 | |
} |
| 145 | 0 | LOG.info("Result of authorization check for user '" + user + "': " + result); |
| 146 | 0 | return Boolean.valueOf(result); |
| 147 | |
} |
| 148 | |
|
| 149 | |
protected abstract String deriveAppIdFromData(Data data); |
| 150 | |
protected abstract String deriveDocContentFromData(Data data); |
| 151 | |
protected abstract String getDefaultWorkflowDocumentType(); |
| 152 | |
protected abstract String getDefaultMetaDataState(); |
| 153 | |
protected abstract String getDefaultMetaDataType(); |
| 154 | |
|
| 155 | |
|
| 156 | |
public void setAssembler(Assembler<Data, Void> assembler) { |
| 157 | 0 | this.assembler = assembler; |
| 158 | 0 | } |
| 159 | |
|
| 160 | |
public IdentityManagementService getPermissionService() { |
| 161 | 0 | return permissionService; |
| 162 | |
} |
| 163 | |
|
| 164 | |
public void setPermissionService(IdentityManagementService permissionService) { |
| 165 | 0 | this.permissionService = permissionService; |
| 166 | 0 | } |
| 167 | |
|
| 168 | |
public IdentityManagementService getIdentityService() { |
| 169 | 0 | return identityService; |
| 170 | |
} |
| 171 | |
|
| 172 | |
public void setIdentityService(IdentityManagementService identityService) { |
| 173 | 0 | this.identityService = identityService; |
| 174 | 0 | } |
| 175 | |
|
| 176 | |
public void setSimpleDocService(SimpleDocumentActionsWebService simpleDocService) { |
| 177 | 0 | this.simpleDocService = simpleDocService; |
| 178 | 0 | } |
| 179 | |
|
| 180 | |
public void setWorkflowUtilityService(WorkflowUtility workflowUtilityService) { |
| 181 | 0 | this.workflowUtilityService = workflowUtilityService; |
| 182 | 0 | } |
| 183 | |
|
| 184 | |
protected Assembler<Data, Void> getAssembler() { |
| 185 | 0 | return assembler; |
| 186 | |
} |
| 187 | |
|
| 188 | |
protected SimpleDocumentActionsWebService getSimpleDocService() { |
| 189 | 0 | return simpleDocService; |
| 190 | |
} |
| 191 | |
|
| 192 | |
protected WorkflowUtility getWorkflowUtilityService() { |
| 193 | 0 | return workflowUtilityService; |
| 194 | |
} |
| 195 | |
|
| 196 | |
|
| 197 | |
} |