2 * Copyright (c) 2015 Brocade Communications Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.aaa.shiro.moon;
10 import com.google.common.collect.ImmutableSet;
12 import java.io.Serializable;
15 import org.opendaylight.aaa.api.Claim;
18 * MoonPrincipal contains all user's information returned by moon on successful authentication
19 * @author Alioune BA alioune.ba@orange.com
22 public class MoonPrincipal {
24 private final String username;
25 private final String domain;
26 private final String userId;
27 private final Set<String> roles;
28 private final String token;
31 public MoonPrincipal(String username, String domain, String userId, Set<String> roles, String token) {
32 this.username = username;
39 public MoonPrincipal createODLPrincipal(String username, String domain,
40 String userId, Set<String> roles, String token) {
42 return new MoonPrincipal(username, domain, userId, roles,token);
45 public Claim principalToClaim (){
46 return new MoonClaim("", this.getUserId(), this.getUsername(), this.getDomain(), this.getRoles());
49 public String getUsername() {
53 public String getDomain() {
57 public String getUserId() {
61 public Set<String> getRoles() {
65 public String getToken(){
69 public class MoonClaim implements Claim, Serializable {
70 private static final long serialVersionUID = -8115027645190209125L;
71 private int hashCode = 0;
72 private String clientId;
73 private String userId;
75 private String domain;
76 private ImmutableSet<String> roles;
78 public MoonClaim(String clientId, String userId, String user, String domain, Set<String> roles) {
79 this.clientId = clientId;
83 this.roles = ImmutableSet.<String> builder().addAll(roles).build();
85 if (userId.isEmpty() || user.isEmpty() || roles.isEmpty() || roles.contains("")) {
86 throw new IllegalStateException("The Claim is missing one or more of the required fields.");
91 public String clientId() {
96 public String userId() {
101 public String user() {
106 public String domain() {
111 public Set<String> roles() {
114 public String getClientId() {
118 public void setClientId(String clientId) {
119 this.clientId = clientId;
122 public String getUserId() {
126 public void setUserId(String userId) {
127 this.userId = userId;
130 public String getUser() {
134 public void setUser(String user) {
138 public String getDomain() {
142 public void setDomain(String domain) {
143 this.domain = domain;
146 public ImmutableSet<String> getRoles() {
150 public void setRoles(ImmutableSet<String> roles) {
155 public String toString() {
156 return "clientId:" + clientId + "," + "userId:" + userId + "," + "userName:" + user
157 + "," + "domain:" + domain + "," + "roles:" + roles ;