| /** |
| * |
| * Copyright (c) 2011, 2016 - Loetz GmbH&Co.KG (69115 Heidelberg, Germany) |
| * |
| * All rights reserved. This program and the accompanying materials |
| * are made available under the terms of the Eclipse Public License v1.0 |
| * which accompanies this distribution, and is available at |
| * http://www.eclipse.org/legal/epl-v10.html |
| * |
| * Contributors: |
| * Christophe Loetz (Loetz GmbH&Co.KG) - initial implementation |
| */ |
| package org.eclipse.osbp.authentication.providerimpl; |
| |
| import java.util.Collection; |
| import java.util.HashSet; |
| |
| import org.apache.shiro.authz.SimpleAuthorizationInfo; |
| import org.apache.shiro.subject.PrincipalCollection; |
| import org.eclipse.osbp.ui.api.useraccess.AbstractPosition; |
| import org.eclipse.osbp.ui.api.useraccess.IPermissionList; |
| |
| /** |
| * The Class AuthorizationInformation holds metadata of the authenticated subject. |
| */ |
| public class AuthorizationInformation extends SimpleAuthorizationInfo { |
| |
| /** The Constant serialVersionUID. */ |
| private static final long serialVersionUID = 8654353182167477248L; |
| |
| /** The position. */ |
| private final AbstractPosition fPosition; |
| |
| /** The portal id. */ |
| private final String fPortalId; |
| |
| /** The principal. */ |
| private final PrincipalCollection fPrincipal; |
| |
| /** |
| * Instantiates a new authorization information. |
| * |
| * @param portalId the portal id |
| * @param principals the principals |
| * @param position the position |
| * @param roles the roles |
| * @param permissions the permissions |
| */ |
| public AuthorizationInformation(String portalId, PrincipalCollection principals, AbstractPosition position, Collection<String> roles, IPermissionList permissions) { |
| super(); |
| fPortalId = portalId; |
| fPrincipal = principals; |
| fPosition = position; |
| if(roles != null) { |
| super.setRoles(new HashSet<String>(roles)); |
| } |
| if (permissions != null) { |
| for (String permission : permissions.getPermissions()) { |
| while (permission.endsWith(":*")) { |
| permission = permission.substring(0, permission.length()-2); |
| } |
| super.addStringPermission(permission); |
| } |
| } |
| } |
| |
| /** |
| * Gets the portal id. |
| * |
| * @return the portal id |
| */ |
| public String getPortalId() { |
| return fPortalId; |
| } |
| |
| /** |
| * Gets the username. |
| * |
| * @return the username |
| */ |
| public String getUsername() { |
| return fPrincipal.getPrimaryPrincipal().toString(); |
| } |
| |
| /** |
| * Gets the position. |
| * |
| * @return the position |
| */ |
| public AbstractPosition getPosition() { |
| return fPosition; |
| } |
| |
| } |