/* * Copyright (c) 2013 Cisco Systems, Inc. and others. 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 */ package org.opendaylight.controller.usermanager; import java.io.Serializable; import java.util.ArrayList; import java.util.Collections; import java.util.Date; import java.util.List; import org.opendaylight.controller.sal.authorization.UserLevel; import org.springframework.security.core.GrantedAuthority; import org.springframework.security.core.authority.SimpleGrantedAuthority; /** * Represents a user that was successfully authenticated and authorized * It contains the user role for which the user was authorized and the * date on which it was authenticated and authorized */ public class AuthenticatedUser implements Serializable { private static final long serialVersionUID = 1L; private List userRoles; private Date accessDate; public AuthenticatedUser(String name) { userRoles = null; accessDate = new Date(); } public void setRoleList(List roleList) { this.userRoles = roleList; } public void setRoleList(String[] roleArray) { userRoles = new ArrayList(roleArray.length); for (String role : roleArray) { String target = role.trim(); if (!target.isEmpty()) { userRoles.add(target); } } } public List getUserRoles() { return userRoles == null ? Collections. emptyList() : new ArrayList(userRoles); } public void addUserRole(String string) { userRoles.add(string); } public String getAccessDate() { return accessDate.toString(); } public List getGrantedAuthorities(UserLevel usrLvl) { List roles = new ArrayList(); roles.add(new SimpleGrantedAuthority(new ODLUserLevel(usrLvl) .getAuthority())); return roles; } }