private Map<String, Object> serviceInvoker( String localName, ModelService modelService, Map<String, Object> context) throws GenericServiceException { if (UtilValidate.isEmpty(modelService.location)) { throw new GenericServiceException("Cannot run Groovy service with empty location"); } Map<String, Object> params = FastMap.newInstance(); params.putAll(context); context.put(ScriptUtil.PARAMETERS_KEY, params); DispatchContext dctx = dispatcher.getLocalContext(localName); context.put("dctx", dctx); context.put("dispatcher", dctx.getDispatcher()); context.put("delegator", dispatcher.getDelegator()); try { ScriptContext scriptContext = ScriptUtil.createScriptContext(context, protectedKeys); ScriptHelper scriptHelper = (ScriptHelper) scriptContext.getAttribute(ScriptUtil.SCRIPT_HELPER_KEY); if (scriptHelper != null) { context.put(ScriptUtil.SCRIPT_HELPER_KEY, scriptHelper); } Script script = InvokerHelper.createScript( GroovyUtil.getScriptClassFromLocation( this.getLocation(modelService), groovyClassLoader), GroovyUtil.getBinding(context)); Object resultObj = null; if (UtilValidate.isEmpty(modelService.invoke)) { resultObj = script.run(); } else { resultObj = script.invokeMethod(modelService.invoke, EMPTY_ARGS); } if (resultObj == null) { resultObj = scriptContext.getAttribute(ScriptUtil.RESULT_KEY); } if (resultObj != null && resultObj instanceof Map<?, ?>) { return cast(resultObj); } Map<String, Object> result = ServiceUtil.returnSuccess(); result.putAll( modelService.makeValid(scriptContext.getBindings(ScriptContext.ENGINE_SCOPE), "OUT")); return result; } catch (GeneralException ge) { throw new GenericServiceException(ge); } catch (Exception e) { return ServiceUtil.returnError(e.getMessage()); } }
protected Layout getPortalPageLayout(long userId, long groupId, String portalPageName) throws Exception { Layout portalPageLayout = null; boolean privateLayout = true; List<Layout> layouts = LayoutLocalServiceUtil.getLayouts(groupId, privateLayout); for (Layout layout : layouts) { if (layout.getName(Locale.US).equals(portalPageName)) { portalPageLayout = layout; } } if (portalPageLayout == null) { long parentLayoutId = LayoutConstants.DEFAULT_PARENT_LAYOUT_ID; String type = LayoutConstants.TYPE_PORTLET; boolean hidden = false; String friendlyURL = "/" + portalPageName.toLowerCase(); portalPageLayout = ServiceUtil.addLayout( userId, groupId, privateLayout, parentLayoutId, portalPageName, portalPageName, portalPageName, type, hidden, friendlyURL); } return portalPageLayout; }
@GET @Path("creator") @Produces(MediaType.TEXT_HTML) public void createHtmlPart(@PathParam("projectId") final String projectId) throws URISyntaxException, IOException { MagicDrawManager.loadSysMLProjects(); List<String> possibleBlocks = new ArrayList<String>(); possibleBlocks.add("NONE"); for (com.nomagic.uml2.ext.magicdraw.classes.mdkernel.Class mdBlock : MagicDrawManager.mdSysmlBlocks) { possibleBlocks.add("BLOCK___" + mdBlock.getQualifiedName()); } EClass eClass = ServiceUtil.getEClass("PartProperty"); httpServletRequest.setAttribute( "creatorUri", MagicDrawManager.baseHTTPURI + "/services/" + projectId + "/partproperties"); httpServletRequest.setAttribute("eclass", eClass); httpServletRequest.setAttribute("possibleBlocks", possibleBlocks); RequestDispatcher rd = httpServletRequest.getRequestDispatcher("/sysml/sysml_partproperty_creator.jsp"); try { rd.forward(httpServletRequest, httpServletResponse); } catch (Exception e) { e.printStackTrace(); throw new WebApplicationException(e); } }
@Override public void runSyncIgnore( String serviceName, int transactionTimeout, boolean requireNewTransaction, Object... context) throws ServiceAuthException, ServiceValidationException, GenericServiceException { runSyncIgnore( serviceName, ServiceUtil.makeContext(context), transactionTimeout, requireNewTransaction); }
private boolean evalPermissionService( ModelService origService, DispatchContext dctx, Map<String, ? extends Object> context) { ModelService permission; if (permissionServiceName == null) { Debug.logWarning("No ModelService found; no service name specified!", module); return false; } try { permission = dctx.getModelService(permissionServiceName); } catch (GenericServiceException e) { Debug.logError(e, "Failed to get ModelService: " + e.toString(), module); return false; } if (permission == null) { Debug.logError("No ModelService found with the name [" + permissionServiceName + "]", module); return false; } permission.auth = true; Map<String, Object> ctx = permission.makeValid(context, ModelService.IN_PARAM); if (UtilValidate.isNotEmpty(action)) { ctx.put("mainAction", action); } if (UtilValidate.isNotEmpty(permissionResourceDesc)) { ctx.put("resourceDescription", permissionResourceDesc); } else if (origService != null) { ctx.put("resourceDescription", origService.name); } LocalDispatcher dispatcher = dctx.getDispatcher(); Map<String, Object> resp; String failMessage = null; try { resp = dispatcher.runSync(permission.name, ctx, 300, true); failMessage = (String) resp.get("failMessage"); } catch (GenericServiceException e) { Debug.logError(failMessage + e.getMessage(), module); return false; } if (ServiceUtil.isError(resp) || ServiceUtil.isFailure(resp)) { Debug.logError(failMessage, module); return false; } return ((Boolean) resp.get("hasPermission")).booleanValue(); }
protected Group getSite(long companyId, long userId, String name) throws Exception { Group site = null; try { site = GroupLocalServiceUtil.getGroup(companyId, name); } catch (NoSuchGroupException e) { site = ServiceUtil.addActiveOpenGroup(userId, name); } return site; }
@Test public void testSpecParser() { // No collaborators needed to test method Map<String, Integer> result = null; result = ServiceUtil.parseServiceSpec("http:80,https:443"); assertEquals(result.size(), 2); assertTrue(result.containsKey("http")); assertTrue(result.containsKey("https")); assertEquals(result.get("http").intValue(), 80); assertEquals(result.get("https").intValue(), 443); }
@Override public void runAsync( String serviceName, GenericRequester requester, boolean persist, int transactionTimeout, boolean requireNewTransaction, Object... context) throws ServiceAuthException, ServiceValidationException, GenericServiceException { runAsync( serviceName, ServiceUtil.makeContext(context), requester, persist, transactionTimeout, requireNewTransaction); }
@Path("/devices/{deviceLibraryIdentifier}/registrations/{passTypeIdentifier}/{serialNumber}") @POST public Response registerDeviceForPassPushNotifications( @PathParam("deviceLibraryIdentifier") String deviceLibraryIdentifier, @PathParam("passTypeIdentifier") String passTypeIdentifier, @PathParam("serialNumber") String serialNumber, @HeaderParam("Authorization") @DefaultValue("") String authorization, String jsonDictionaryWithPushToken) { PassDAO pass = new PassDAO(serialNumber); if (!pass.retrieve()) { // pass not found // response is UNAUTHORIZED in order to prevent trial/error/guessing for passes log.warn("pass does not exist: {}", serialNumber); return Response.status(Response.Status.UNAUTHORIZED).build(); } if (!AuthUtil.isAuthorized(authorization, pass.getAuthenticationToken())) { log.warn("invalid authorization: {}", authorization); return Response.status(Response.Status.UNAUTHORIZED).build(); } String pushToken = ServiceUtil.getPushTokenFromBody(jsonDictionaryWithPushToken); DeviceDAO device = new DeviceDAO(deviceLibraryIdentifier); device.retrieve(); if (device.addRegistration(passTypeIdentifier, serialNumber, pushToken) == 1) { // really added a new record if (device.store()) { return Response.status(Response.Status.CREATED).build(); } } else { // nothing added, was already in list return Response.status(Response.Status.OK).build(); } return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build(); }
protected void setupUsers(long companyId, long userId) throws Exception { ServiceUtil.addUser(userId, companyId, "John", "Adams"); ServiceUtil.addUser(userId, companyId, "Samuel", "Adams"); ServiceUtil.addUser(userId, companyId, "Josiah", "Bartlett"); ServiceUtil.addUser(userId, companyId, "Carter", "Braxton"); ServiceUtil.addUser(userId, companyId, "Charles", "Carroll"); ServiceUtil.addUser(userId, companyId, "Benjamin", "Franklin"); ServiceUtil.addUser(userId, companyId, "Elbridge", "Gerry"); ServiceUtil.addUser(userId, companyId, "John", "Hancock"); ServiceUtil.addUser(userId, companyId, "Thomas", "Jefferson"); ServiceUtil.addUser(userId, companyId, "Francis", "Lewis"); ServiceUtil.addUser(userId, companyId, "Philip", "Livingston"); ServiceUtil.addUser(userId, companyId, "Thomas", "McKean"); ServiceUtil.addUser(userId, companyId, "Arthur", "Middleton"); ServiceUtil.addUser(userId, companyId, "John", "Penn"); ServiceUtil.addUser(userId, companyId, "George", "Read"); ServiceUtil.addUser(userId, companyId, "John", "Rutledge"); ServiceUtil.addUser(userId, companyId, "Roger", "Sherman"); ServiceUtil.addUser(userId, companyId, "Thomas", "Stone"); ServiceUtil.addUser(userId, companyId, "George", "Taylor"); ServiceUtil.addUser(userId, companyId, "George", "Washington"); ServiceUtil.addUser(userId, companyId, "John", "Witherspoon"); ServiceUtil.addUser(userId, companyId, "Oliver", "Wolcott"); ServiceUtil.addUser(userId, companyId, "George", "Wythe"); }
@Override public GenericResultWaiter runAsyncWait(String serviceName, boolean persist, Object... context) throws ServiceAuthException, ServiceValidationException, GenericServiceException { return runAsyncWait(serviceName, ServiceUtil.makeContext(context), persist); }
@Override public void runAsync(String serviceName, boolean persist, Object... context) throws ServiceAuthException, ServiceValidationException, GenericServiceException { runAsync(serviceName, ServiceUtil.makeContext(context), persist); }
@Override public void runAsync(String serviceName, GenericRequester requester, Object... context) throws ServiceAuthException, ServiceValidationException, GenericServiceException { runAsync(serviceName, ServiceUtil.makeContext(context), requester); }
/** * A {@link ResourceDefinition} for a {@link SecurityRealm} backed by a {@link KeyStore}. * * @author <a href="mailto:[email protected]">Darran Lofthouse</a> */ class KeyStoreRealmDefinition extends SimpleResourceDefinition { static final ServiceUtil<SecurityRealm> REALM_SERVICE_UTIL = ServiceUtil.newInstance( SECURITY_REALM_RUNTIME_CAPABILITY, ElytronDescriptionConstants.KEYSTORE_REALM, SecurityRealm.class); static final SimpleAttributeDefinition KEYSTORE = new SimpleAttributeDefinitionBuilder( ElytronDescriptionConstants.KEYSTORE, ModelType.STRING, false) .setAllowExpression(true) .setMinSize(1) .setFlags(AttributeAccess.Flag.RESTART_RESOURCE_SERVICES) .setCapabilityReference(KEYSTORE_CAPABILITY, SECURITY_REALM_CAPABILITY, true) .build(); private static final AbstractAddStepHandler ADD = new RealmAddHandler(); private static final OperationStepHandler REMOVE = new RealmRemoveHandler(ADD); KeyStoreRealmDefinition() { super( new Parameters( PathElement.pathElement(ElytronDescriptionConstants.KEYSTORE_REALM), ElytronExtension.getResourceDescriptionResolver( ElytronDescriptionConstants.KEYSTORE_REALM)) .setAddHandler(ADD) .setRemoveHandler(REMOVE) .setAddRestartLevel(OperationEntry.Flag.RESTART_RESOURCE_SERVICES) .setRemoveRestartLevel(OperationEntry.Flag.RESTART_RESOURCE_SERVICES)); } @Override public void registerAttributes(ManagementResourceRegistration resourceRegistration) { resourceRegistration.registerReadWriteAttribute(KEYSTORE, null, new WriteAttributeHandler()); } private static class RealmAddHandler extends AbstractAddStepHandler { private RealmAddHandler() { super(SECURITY_REALM_RUNTIME_CAPABILITY, KEYSTORE); } @Override protected void performRuntime(OperationContext context, ModelNode operation, ModelNode model) throws OperationFailedException { ServiceTarget serviceTarget = context.getServiceTarget(); RuntimeCapability<Void> runtimeCapability = SECURITY_REALM_RUNTIME_CAPABILITY.fromBaseCapability(context.getCurrentAddressValue()); ServiceName realmName = runtimeCapability.getCapabilityServiceName(SecurityRealm.class); KeyStoreRealmService keyStoreRealmService = new KeyStoreRealmService(); ServiceBuilder<SecurityRealm> serviceBuilder = serviceTarget.addService(realmName, keyStoreRealmService); String keyStoreCapabilityName = RuntimeCapability.buildDynamicCapabilityName( KEYSTORE_CAPABILITY, KEYSTORE.resolveModelAttribute(context, model).asString()); ServiceName keyStoreServiceName = context.getCapabilityServiceName(keyStoreCapabilityName, KeyStore.class); KEY_STORE_UTIL.addInjection( serviceBuilder, keyStoreRealmService.getKeyStoreInjector(), keyStoreServiceName); commonDependencies(serviceBuilder).setInitialMode(Mode.ACTIVE).install(); } } private static class RealmRemoveHandler extends ServiceRemoveStepHandler { public RealmRemoveHandler(AbstractAddStepHandler addOperation) { super(addOperation, SECURITY_REALM_RUNTIME_CAPABILITY); } @Override protected ServiceName serviceName(String name) { return REALM_SERVICE_UTIL.serviceName(name); } } private static class WriteAttributeHandler extends RestartParentWriteAttributeHandler { WriteAttributeHandler() { super(ElytronDescriptionConstants.KEYSTORE_REALM, KEYSTORE); } @Override protected ServiceName getParentServiceName(PathAddress pathAddress) { return SECURITY_REALM_RUNTIME_CAPABILITY .fromBaseCapability(pathAddress.getLastElement().getValue()) .getCapabilityServiceName(SecurityRealm.class); } } }
@Override protected ServiceName serviceName(String name) { return REALM_SERVICE_UTIL.serviceName(name); }
static { // 초기 틀에서 static을 사용하면 뒷부분도 이렇게 static을 해야 하는 경우가 생길 수 있기 때문에 세심히 고민할 것 con = ServiceUtil.getConnect(); // System.out.println(con); // 제대로 되는지 확인 } // --static 블럭