
com.vmware.photon.controller.model.resources.SessionFactoryService Maven / Gradle / Ivy
/*
* Copyright (c) 2018 VMware, Inc. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed
* under the License is distributed on an "AS IS" BASIS, without warranties or
* conditions of any kind, EITHER EXPRESS OR IMPLIED. See the License for the
* specific language governing permissions and limitations under the License.
*/
package com.vmware.photon.controller.model.resources;
import com.vmware.photon.controller.model.resources.SessionService.SessionState;
import com.vmware.xenon.common.FactoryService;
import com.vmware.xenon.common.Operation;
import com.vmware.xenon.common.Service;
/**
* The purpose of this custom FactoryService is to ensure only a system service is able to create
* new {@link SessionState} documents.
*/
public class SessionFactoryService extends FactoryService {
public SessionFactoryService() {
super(SessionState.class);
}
@Override
public void authorizeRequest(Operation op) {
// The following allows a system user to create new session states. This also implies
// that the caller is running on the same Xenon ServiceHost
if (op.getAuthorizationContext() != null && op.getAuthorizationContext().isSystemUser()) {
op.complete();
return;
}
op.fail(Operation.STATUS_CODE_UNAUTHORIZED);
}
@Override
public Service createServiceInstance() {
return new SessionService();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy