001/* 002 * (C) Copyright 2015 Nuxeo SA (http://nuxeo.com/) and others. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 * 016 * Contributors: 017 * François Maturel 018 */ 019 020package org.nuxeo.ecm.platform.ui.web.keycloak; 021 022import java.util.Set; 023 024import org.apache.commons.lang3.StringUtils; 025import org.nuxeo.ecm.platform.api.login.UserIdentificationInfo; 026 027/** 028 * @since 7.4 029 */ 030public class KeycloakUserInfo extends UserIdentificationInfo { 031 032 private static final long serialVersionUID = 6894397878763275157L; 033 034 protected String firstName; 035 036 protected String lastName; 037 038 protected String company; 039 040 protected Set<String> roles; 041 042 private KeycloakUserInfo(String emailAsUserName, String password) { 043 super(emailAsUserName, password); 044 } 045 046 public KeycloakUserInfo(String emailAsUserName, String password, String firstName, String lastName, String company) { 047 super(emailAsUserName, password); 048 049 if (emailAsUserName == null || StringUtils.isEmpty(emailAsUserName)) { 050 throw new IllegalStateException("A valid username should always be provided"); 051 } 052 053 this.firstName = firstName; 054 this.lastName = lastName; 055 this.company = company; 056 } 057 058 public String getFirstName() { 059 return firstName; 060 } 061 062 public String getLastName() { 063 return lastName; 064 } 065 066 public String getCompany() { 067 return company; 068 } 069 070 public Set<String> getRoles() { 071 return roles; 072 } 073 074 public void setRoles(Set<String> roles) { 075 this.roles = roles; 076 } 077 078 public static class KeycloakUserInfoBuilder { 079 protected String token; 080 081 protected String userName; 082 083 protected String password; 084 085 protected String authPluginName; 086 087 protected String company; 088 089 protected String lastName; 090 091 protected String firstName; 092 093 private KeycloakUserInfoBuilder() { 094 } 095 096 public static KeycloakUserInfoBuilder aKeycloakUserInfo() { 097 return new KeycloakUserInfoBuilder(); 098 } 099 100 public KeycloakUserInfoBuilder withToken(String token) { 101 this.token = token; 102 return this; 103 } 104 105 public KeycloakUserInfoBuilder withUserName(String userName) { 106 this.userName = userName; 107 return this; 108 } 109 110 public KeycloakUserInfoBuilder withPassword(String password) { 111 this.password = password; 112 return this; 113 } 114 115 public KeycloakUserInfoBuilder withAuthPluginName(String authPluginName) { 116 this.authPluginName = authPluginName; 117 return this; 118 } 119 120 public KeycloakUserInfoBuilder withCompany(String company) { 121 this.company = company; 122 return this; 123 } 124 125 public KeycloakUserInfoBuilder withLastName(String lastName) { 126 this.lastName = lastName; 127 return this; 128 } 129 130 public KeycloakUserInfoBuilder withFirstName(String firstName) { 131 this.firstName = firstName; 132 return this; 133 } 134 135 public KeycloakUserInfo build() { 136 KeycloakUserInfo keycloakUserInfo = new KeycloakUserInfo(userName, password, firstName, lastName, company); 137 keycloakUserInfo.setToken(token); 138 keycloakUserInfo.setAuthPluginName(authPluginName); 139 return keycloakUserInfo; 140 } 141 } 142}