
org.xlcloud.console.entitlements.controllers.AccessTokenEntitlementsBean Maven / Gradle / Ivy
The newest version!
/*
* Copyright 2012 AMG.lab, a Bull Group Company
*
* 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 org.xlcloud.console.entitlements.controllers;
import javax.annotation.PostConstruct;
import javax.inject.Inject;
import javax.inject.Named;
import org.primefaces.model.DefaultTreeNode;
import org.primefaces.model.TreeNode;
import org.xlcloud.console.context.EntitlementEngine;
import org.xlcloud.console.context.IdentityContext;
import org.xlcloud.console.controllers.request.RequestParameters;
import org.xlcloud.console.controllers.request.path.ConsolePathParams;
import org.xlcloud.console.entitlements.EntitlementDictionaryRepository;
import org.xlcloud.console.entitlements.nodes.EntitlementNode;
import org.xlcloud.console.entitlements.nodes.predicates.AccessTokenEntitlementOwnershipPredicate;
import org.xlcloud.console.extensions.scope.ViewScoped;
import org.xlcloud.service.AccessToken;
import org.xlcloud.service.User;
import org.xlcloud.service.api.AccessTokensApi;
import org.xlcloud.service.api.UsersApi;
/**
* TODO Documentation
*
* @author Konrad Król, AMG.net
*/
@Named
@ViewScoped
public class AccessTokenEntitlementsBean {
@Inject
private EntitlementDictionaryRepository repository;
@Inject
private EntitlementEngine entitlementEngine;
@Inject
private IdentityContext identityContext;
@Inject
private RequestParameters requestParameters;
@Inject
private AccessTokensApi accessTokensApi;
@Inject
private UsersApi usersApi;
private TreeNode root;
private AccessToken accessToken;
private User accessTokenUser;
@PostConstruct
public void initialize() {
String requestedTokenId = getRequestedAccessTokenId();
accessToken = accessTokensApi.getAccessToken(requestedTokenId);
accessToken.setEntitlements(accessTokensApi.getAccessTokenEntitlements(requestedTokenId));
accessTokenUser = usersApi.getUser(accessToken.getUserId());
TreeNode rootNode = new DefaultTreeNode();
TreeNode highLevelNode = new EntitlementNode(repository.getMainEntitlementDictionary(),
new AccessTokenEntitlementOwnershipPredicate(accessToken, accessTokenUser, entitlementEngine, identityContext), rootNode);
highLevelNode.setExpanded(true);
if (highLevelNode.getChildCount() > 0) {
root = rootNode;
}
}
/**
* Gets the value of {@link #root}.
* @return value of {@link #root}
*/
public TreeNode getRoot() {
return root;
}
/**
* Sets the value of {@link #repository}.
* @param repository - value
*/
public void setRepository(EntitlementDictionaryRepository repository) {
this.repository = repository;
}
/**
* Sets the value of {@link #entitlementEngine}.
* @param entitlementEngine - value
*/
public void setEntitlementEngine(EntitlementEngine entitlementEngine) {
this.entitlementEngine = entitlementEngine;
}
/**
* Sets the value of {@link #requestParameters}.
* @param requestParameters - value
*/
public void setRequestParameters(RequestParameters requestParameters) {
this.requestParameters = requestParameters;
}
/**
* Sets the value of {@link #accessTokensApi}.
* @param accessTokensApi - value
*/
public void setAccessTokensApi(AccessTokensApi accessTokensApi) {
this.accessTokensApi = accessTokensApi;
}
/**
* Sets the value of {@link #usersApi}.
* @param usersApi - value
*/
public void setUsersApi(UsersApi usersApi) {
this.usersApi = usersApi;
}
/**
* Gets the value of {@link #accessToken}.
* @return value of {@link #accessToken}
*/
public AccessToken getAccessToken() {
return accessToken;
}
private String getRequestedAccessTokenId() {
return requestParameters.getParameter(ConsolePathParams.ACCESS_TOKEN_ID);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy